Пример #1
0
 /// <summary>
 /// Fills a dictionary with the values stored in an isolated store,
 /// for application.
 /// </summary>
 /// <param name="sd">The dictionary to fill.</param>
 /// <param name="scope">The degree of scope for the isolated store : a bitwise combination of the IsolatedStorageScope values.</param>
 /// <param name="fileName">The file name.</param>
 public static void LoadForApplication(StorableDictionary sd, IsolatedStorageScope scope, string fileName)
 {
     using (IsolatedStorageFile storage = IsolatedStorageFile.GetStore(scope, null))
     {
         LoadFromStorageFile(storage, sd, fileName);
     }
 }
Пример #2
0
 /// <summary>
 /// Saves a dictionary in an user-scoped isolated storage corresponding to the calling code's application identity.
 /// This requires a ClickOnce aplication (see http://blogs.msdn.com/shawnfa/archive/2006/01/18/514407.aspx).
 /// </summary>
 /// <param name="sd">The dictionary to save.</param>
 /// <param name="fileName">The file name.</param>
 public static void SaveToUserStoreForApplication(StorableDictionary sd, string fileName)
 {
     SaveForApplication(sd,
                        IsolatedStorageScope.Application |
                        IsolatedStorageScope.User,
                        fileName);
 }
Пример #3
0
 /// <summary>
 /// Saves a dictionary in an user-scoped isolated storage corresponding to the application domain identity and Perspective.Core assembly identity.
 /// </summary>
 /// <param name="sd">The dictionary to save.</param>
 /// <param name="fileName">The file name.</param>
 public static void SaveToUserStoreForDomain(StorableDictionary sd, string fileName)
 {
     SaveForDomain(sd,
                   IsolatedStorageScope.Assembly |
                   IsolatedStorageScope.Domain |
                   IsolatedStorageScope.User,
                   fileName);
 }
Пример #4
0
 private static void SaveToStorageFile(
     IsolatedStorageFile storage,
     StorableDictionary sd,
     string fileName)
 {
     using (IsolatedStorageFileStream stream =
                new IsolatedStorageFileStream(fileName, FileMode.Create, storage))
     {
         XmlSerializer xs = new XmlSerializer(typeof(StorableDictionary));
         xs.Serialize(stream, sd);
     }
 }
Пример #5
0
 /// <summary>
 /// Save a dictionary into an isolated storage corresponding to the kind of application (installed or ClickOnce deployed).
 /// </summary>
 /// <param name="sd">The dictionary to save.</param>
 /// <param name="fileName">The file name.</param>
 public static void Save(StorableDictionary sd, string fileName)
 {
     if (ApplicationDeployment.IsNetworkDeployed)
     {
         IsolatedStorageHelper.SaveToUserStoreForApplication(
             sd,
             fileName);
     }
     else
     {
         IsolatedStorageHelper.SaveToUserStoreForDomain(
             sd,
             fileName);
     }
 }
Пример #6
0
 private static void LoadFromStorageFile(
     IsolatedStorageFile storage,
     StorableDictionary sd,
     string fileName)
 {
     string[] files = storage.GetFileNames(fileName);
     if ((files.Length > 0) && (files[0] == fileName))
     {
         using (Stream stream =
                    new IsolatedStorageFileStream(fileName, FileMode.Open, storage))
         {
             if (stream.Length > 0)
             {
                 XmlSerializer      xs  = new XmlSerializer(typeof(StorableDictionary));
                 StorableDictionary sd2 = (StorableDictionary)xs.Deserialize(stream); //, sd);
                 foreach (KeyValuePair <string, object> kvp in sd2)
                 {
                     sd.Add(kvp.Key, kvp.Value);
                 }
             }
         }
     }
 }
Пример #7
0
        /// <summary>
        /// Saves a dictionary in an isolated store
        /// for application.
        /// </summary>
        /// <param name="sd">The dictionary to save.</param>
        /// <param name="scope">The degree of scope for the isolated store : a bitwise combination of the IsolatedStorageScope values.</param>
        /// <param name="fileName">The file name.</param>
        public static void SaveForApplication(StorableDictionary sd, IsolatedStorageScope scope, string fileName)
        {
            IsolatedStorageFile storage = IsolatedStorageFile.GetStore(scope, null);

            SaveToStorageFile(storage, sd, fileName);
        }