Aracılığıyla paylaş


Nasıl yapılır: Yalıtılmış Depolama ile Alan Dolu Koşullarını Öngörme

Yalıtılmış depolama kullanan kod, yalıtılmış depolama dosyalarının ve dizinlerinin bulunduğu veri bölmesi için en büyük boyutu belirten bir kotayla kısıtlanır. Kota güvenlik ilkesi tarafından tanımlanır ve yöneticiler tarafından yapılandırılabilir. Veri yazmaya çalıştığınızda izin verilen boyut üst sınırı aşılırsa bir IsolatedStorageException özel durum oluşturulur ve işlem başarısız olur. Bu, veri depolama alanı doldurulduğundan uygulamanın istekleri reddetmesine neden olabilecek kötü amaçlı hizmet reddi saldırılarını önlemeye yardımcı olur.

Belirli bir yazma girişiminin bu nedenle başarısız olup olmayacağını belirlemenize yardımcı olmak için sınıfı IsolatedStorage üç salt okunur özellik sağlar: AvailableFreeSpace, UsedSizeve Quota. Mağazaya yazmanın, deponun izin verilen en büyük boyutunun aşılmasına neden olup olmayacağını belirlemek için bu özellikleri kullanabilirsiniz. Yalıtılmış depolamaya eşzamanlı olarak erişilebileceğini unutmayın; bu nedenle, kalan depolama miktarını hesapladığınızda depolama alanı depoya yazmaya çalıştığınız zamana kadar kullanılabilir. Ancak, kullanılabilir depolamada üst sınıra ulaşılıp ulaşılmayacağını saptamaya yardımcı olması için deponun en büyük boyutunu kullanabilirsiniz.

özelliği, Quota derlemenin düzgün çalışması için kanıta bağlıdır. Bu nedenle, bu özelliği yalnızca , GetUserStoreForDomainveya GetStore yöntemi kullanılarak GetUserStoreForAssemblyoluşturulan nesnelerde IsolatedStorageFile almanız gerekir. IsolatedStorageFile başka bir yolla oluşturulan nesneler (örneğin, yönteminden GetEnumerator döndürülen nesneler) doğru bir en büyük boyut döndürmez.

Örnek

Aşağıdaki kod örneği yalıtılmış bir depo alır, birkaç dosya oluşturur ve özelliğini alır AvailableFreeSpace . Kalan alan bayt cinsinden bildirilir.

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

Ayrıca bkz.