다음을 통해 공유


방법: 격리된 저장소의 공간 부족 상태 예상

업데이트: 2007년 11월

격리된 저장소를 사용하는 코드는 격리된 저장소 파일과 디렉터리가 있는 데이터 컴파트먼트의 최대 크기를 지정하는 할당 한도의 제약을 받습니다. 이 값은 보안 정책에서 정의하고 관리자가 구성할 수 있습니다. 데이터를 쓸 때 최대 허용 크기를 초과하면 IsolatedStorageException이 throw되고 작업이 실패합니다. 이렇게 되면 데이터 저장소가 꽉 차서 응용 프로그램이 요청을 거부할 수 있는 악성 서비스 공격 거부 문제를 방지할 수 있습니다. 이런 이유로 인해 지정된 쓰기 작업이 실패할 수 있는지 여부를 판단할 수 있도록 격리된 저장소는 IsolatedStorage.CurrentSizeIsolatedStorage.MaximumSize라는 두 가지 읽기 전용 속성을 제공합니다. 이 두 속성을 사용하면 저장소에 쓰는 작업으로 인해 저장소의 최대 허용 크기가 초과되는지 여부를 판단할 수 있습니다. 이 속성을 사용할 때는 격리된 저장소에 동시에 액세스할 수 있음을 명심하십시오. 따라서 남은 저장소 크기를 계산하는 경우 저장소에 쓰는 시간에 따라 저장소 공간이 사용될 수 있습니다. 그러나 사용 가능한 저장소의 상한값에 도달하는지 여부를 판단하기 위해 저장소의 최대 크기를 사용할 수는 있습니다.

또 다른 중요한 고려 사항으로 최대 크기 속성이 제대로 동작하려면 어셈블리에 대한 증명이 있어야 합니다. 따라서 이 메서드는 GetUserStoreForAssembly(), GetUserStoreForDomain() 또는 GetStore()를 사용해서 만든 IsolatedStorageFile 개체에서만 호출될 수 있습니다. GetEnumerator()에서 반환되는 경우와 같이, 다른 방법으로 만들어진 IsolatedStorageFile 개체는 정확한 최대 크기를 반환하지 않습니다.

AnticipatingOutOfSpaceConditions 예제

다음 코드 예제에서는 격리된 저장소를 가져오고 몇 개의 파일을 만든 다음 저장소의 남은 공간을 측정합니다. 남은 공간은 바이트 단위로 보고됩니다.

Imports System
Imports System.IO
Imports System.IO.IsolatedStorage

Public Module modmain

   Sub Main()

      ' Get an isolated store for user, domain, and assembly and put it into 
      ' an IsolatedStorageFile object.

      Dim isoStore As IsolatedStorageFile
      isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, Nothing, Nothing)

      ' Create a few placeholder files in the isolated store.

      Dim aStream As New IsolatedStorageFileStream("InTheRoot.txt", FileMode.Create, isoStore)
      Dim bStream As New IsolatedStorageFileStream("Another.txt", FileMode.Create, isoStore)
      Dim cStream As New IsolatedStorageFileStream("AThird.txt", FileMode.Create, isoStore)
      Dim dStream As New IsolatedStorageFileStream("AFourth.txt", FileMode.Create, isoStore)
      Dim eStream As New IsolatedStorageFileStream("AFifth.txt", FileMode.Create, isoStore)

      ' Use the CurrentSize and MaximumSize methods to find remaining
      ' space.
      ' Cast that number into a long type and put it into a variable.

      Dim spaceLeft As Long
      spaceLeft = CLng((isoStore.MaximumSize.ToString) - isoStore.CurrentSize.ToString)

      Console.WriteLine("CurrentSize: " + isoStore.CurrentSize.ToString)

      Console.WriteLine("Space Left: " + spaceLeft.ToString + " (might be very large if no quota is set)")

   End Sub
End Module
using System;
using System.IO;
using System.IO.IsolatedStorage;

public class CheckingSpace{

   public static void Main(){

      // Get an isolated store for this assembly and put it into an
      // IsolatedStoreFile object.

      IsolatedStorageFile isoStore =  IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);

      // Create a few placeholder files in the isolated store.

      new IsolatedStorageFileStream("InTheRoot.txt", FileMode.Create, isoStore);
      new IsolatedStorageFileStream("Another.txt", FileMode.Create, isoStore);
      new IsolatedStorageFileStream("AThird.txt", FileMode.Create, isoStore);
      new IsolatedStorageFileStream("AFourth.txt", FileMode.Create, isoStore);
      new IsolatedStorageFileStream("AFifth.txt", FileMode.Create, isoStore);

      // Use the CurrentSize and MaximumSize methods to find remaining 
      // space.
      // Cast that number into a long type and put it into a variable.
      long spaceLeft =(long)(isoStore.MaximumSize - isoStore.CurrentSize);

      Console.WriteLine(spaceLeft+ " bytes of space remain in this isolated store.");
      
   }// End of Main.

}

참고 항목

개념

방법: 격리된 저장소의 저장소 가져오기

참조

IsolatedStorageFile

기타 리소스

격리된 저장소 작업 수행