다음을 통해 공유


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

업데이트: 2010년 12월

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

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

예제

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

Imports System
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 of Main.
End Class
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.
}
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();
}

참고 항목

참조

IsolatedStorageFile

개념

격리된 저장소

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

변경 기록

날짜

변경 내용

이유

2010년 12월

AvailableFreeSpace 속성에 대한 정보가 추가되었습니다.

향상된 기능 관련 정보