2012-06-20 42 views
7

Tôi đang chuyển ứng dụng đã xuất bản của mình trong Windows Phone, để giành chiến thắng 8. Trong khi cố gắng viết vào số IsolatedStorage tương đương, ApplicationDataContainer, tôi nhận được một ngoại lệ. Trường hợp ngoại lệ nóiKích thước cho ứng dụngDataCompositeValue

Lỗi: Kích thước của các thiết lập quản lý nhà nước đã vượt quá giới hạn

Tôi không chắc chắn nếu điều này là cách chính xác của việc sử dụng các ApplicationDataContainer.

public void WriteToIsolatedStorage() 
    { 
     try 
     { 

      ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; 
      ApplicationDataCompositeValue composite = new ApplicationDataCompositeValue(); 

      if (localSettings.Containers.ContainsKey("LoveCycleSetting")) 
      { 
       localSettings.DeleteContainer("LoveCycleSetting"); 
      } 

      composite["GetWeekStart"] = m_bWeekStart; 

      composite["iHistCount"] = m_iHistCount; 

      composite["dtHistory"] = this.DateTimeToString(m_dtHistory); 

      composite["avgCycleTime"] = m_iAvgCycleTime; 
     } 
    } 

Trường hợp ngoại lệ xảy ra ở dòng cuối cùng thứ hai. m_dtHistory là một mảng chuỗi có kích thước 400. Vì vậy, ApplicationDataCompositeValue có kích thước cố định? Hay tôi phải viết mảng m_dtHistory vào một tập tin? Cuz trong WindowsPhone tôi có thể trực tiếp viết mảng vào IsolatedStorageSettings.

Sẽ rất hữu ích nếu ai đó có thể hướng dẫn tôi về điều này hoặc cung cấp liên kết.

Alfah

+1

là gì giá trị của [http://msdn.microsoft.com/en-US/library/windows/apps/windows.storage.applicationdata.roamingstoragequota](http://msdn .microsoft.com/en-US/library/windows/apps/windows.storage.applicationdata.roamingstoragequota) –

+0

Phiên bản tiếng Đức của Lỗi này có thể là HRESULT 0x80073DC8 "Die Größe des Einstellungswerts des Zustands-Quản lý mũ den Grenzwert überschritten" –

Trả lời

6

Vâng, trớ trêu thay cài đặt lưu trữ dễ dàng hơn trên điện thoại hơn WinRT. Thay vào đó, bạn chỉ có thể tuần tự hóa một tệp. Dưới đây là những gì tôi đã làm (được sao chép một phần từ mã đã có trong SuspensionManager.cs), hoạt động cho cả hai loại giá trị và tham chiếu.

internal static async Task<bool> SaveSetting(string Key, Object value) 
    { 
     var ms = new MemoryStream(); 
     DataContractSerializer serializer = new DataContractSerializer(value.GetType()); 
     serializer.WriteObject(ms, value); 
     await ms.FlushAsync(); 

     // Uncomment this to preview the contents being written 
     /*char[] buffer = new char[ms.Length]; 
     ms.Seek(0, SeekOrigin.Begin); 
     var sr = new StreamReader(ms); 
     sr.Read(buffer, 0, (int)ms.Length);*/ 

     ms.Seek(0, SeekOrigin.Begin); 
     StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(Key, CreationCollisionOption.ReplaceExisting); 
     using (Stream fileStream = await file.OpenStreamForWriteAsync()) 
     { 
      await ms.CopyToAsync(fileStream); 
      await fileStream.FlushAsync(); 
     } 
     return true; 
    } 

    // Necessary to pass back both the result and status from an async function since you can't pass by ref 
    internal class ReadResults 
    { 
     public bool Success { get; set; } 
     public Object Result { get; set; } 
    } 
    internal async static Task<ReadResults> ReadSetting<type>(string Key, Type t) 
    { 
     var rr = new ReadResults(); 

     try 
     { 
      var ms = new MemoryStream(); 
      DataContractSerializer serializer = new DataContractSerializer(t); 

      StorageFile file = await ApplicationData.Current.LocalFolder.GetFileAsync(Key); 
      using (IInputStream inStream = await file.OpenSequentialReadAsync()) 
      { 
       rr.Result = (type)serializer.ReadObject(inStream.AsStreamForRead()); 
      } 
      rr.Success = true; 
     } 
     catch (FileNotFoundException) 
     { 
      rr.Success = false; 
     } 
     return rr; 
    } 
0

Tôi đọc ở đâu đó nhưng bị mất tài liệu tham khảo rằng kích thước là 64KB

+1

nope , nó thậm chí không thể xử lý 20KB dữ liệu – balint

+0

Tôi nghĩ rằng ông là đúng rằng tổng số cho tất cả các giá trị là 64 kilobyte. Tối đa cho các giá trị riêng lẻ có thể nhỏ hơn nhiều. –

Các vấn đề liên quan