다음을 통해 공유


방법: 격리된 스토리지의 공간 부족 상태 예상

격리된 스토리지를 사용하는 코드는 격리된 스토리지 파일 및 디렉터리가 있는 데이터 구획의 최대 크기를 지정하는 할당량에 의해 제한됩니다. 이 할당 한도는 보안 정책에서 정의하고 관리자가 구성할 수 있습니다. 데이터를 쓸 때 최대 허용 크기를 초과하면 IsolatedStorageException 예외가 throw되고 작업이 실패합니다. 이를 통해 데이터 스토리지가 가득 차서 애플리케이션이 요청을 거부하는 문제를 발생시킬 수 있는 악성 서비스 거부 공격을 방지할 수 있습니다.

지정된 쓰기 시도가 이러한 이유로 실패할 가능성이 있는지 확인할 수 있도록 IsolatedStorage 클래스는 세 가지 읽기 전용 속성 즉, AvailableFreeSpace, UsedSizeQuota를 제공합니다. 이러한 속성을 사용하여 저장소에 쓰는 작업으로 인해 저장소의 최대 허용 크기가 초과되는지 여부를 판단할 수 있습니다. 격리된 스토리지에 동시에 액세스할 수 있음을 명심하십시오. 따라서 남은 스토리지 크기를 컴퓨팅하는 경우 스토리지에 쓰는 시간에 따라 스토리지 공간이 사용될 수 있습니다. 그러나 사용 가능한 스토리지의 상한값에 도달하는지 여부를 판단하기 위해 스토리지의 최대 크기를 사용할 수는 있습니다.

Quota 속성이 제대로 동작하려면 어셈블리에 대한 증명이 있어야 합니다. 따라서 이 속성을 IsolatedStorageFile, GetUserStoreForAssembly, 또는 GetUserStoreForDomain 메서드를 사용하여 만들어진 GetStore 개체에서만 검색해야 합니다. 다른 방법으로 만들어진 IsolatedStorageFile 개체(예: GetEnumerator 메서드에서 반환된 개체)는 정확한 최대 크기를 반환하지 않습니다.

예시

다음 코드 예제에서는 격리된 저장소를 가져오고 몇 개의 파일을 만들며 AvailableFreeSpace 속성을 검색합니다. 남아 있는 공간은 바이트로 보고됩니다.

using namespace System;
using namespace System::IO;
using namespace System::IO::IsolatedStorage;

public ref 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, (Type ^)nullptr, (Type ^)nullptr);

        // Create a few placeholder files in the isolated store.
        gcnew IsolatedStorageFileStream("InTheRoot.txt", FileMode::Create, isoStore);
        gcnew IsolatedStorageFileStream("Another.txt", FileMode::Create, isoStore);
        gcnew IsolatedStorageFileStream("AThird.txt", FileMode::Create, isoStore);
        gcnew IsolatedStorageFileStream("AFourth.txt", FileMode::Create, isoStore);
        gcnew IsolatedStorageFileStream("AFifth.txt", FileMode::Create, isoStore);

        Console::WriteLine(isoStore->AvailableFreeSpace + " bytes of space remain in this isolated store.");
    } // End of Main.
};

int main()
{
    CheckingSpace::Main();
}
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);

        Console.WriteLine(isoStore.AvailableFreeSpace + " bytes of space remain in this isolated store.");
    } // End of Main.
}
Imports System.IO
Imports System.IO.IsolatedStorage

Public Class CheckingSpace
    Public Shared Sub Main()
        ' Get an isolated store for this assembly and put it into an
        ' IsolatedStoreFile object.
        Dim isoStore As IsolatedStorageFile = _
            IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or _
            IsolatedStorageScope.Assembly, 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)

        Console.WriteLine(isoStore.AvailableFreeSpace + " bytes of space remain in this isolated store.")
    End Sub
End Class

참고 항목