Пример #1
0
        /// <summary>
        /// Saves the current contents of the UserApplicationStore.
        /// </summary>
        public static void Save()
        {
            IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly();

            using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream("userpreferences.xml", System.IO.FileMode.Truncate, file))
            {
                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fs))
                {
                    writer.Write(UserApplicationStore.Serialize(UserApplicationStore.store));
                    writer.Close();
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Loads and populates the static <see cref="Store"/> property.
        /// </summary>
        public static void Load()
        {
            IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForAssembly();

            using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream("userpreferences.xml", System.IO.FileMode.OpenOrCreate, file))
            {
                if (fs != null)
                {
                    System.IO.StreamReader reader = new System.IO.StreamReader(fs);
                    string preferenceData         = string.Empty;
                    preferenceData = reader.ReadToEnd();
                    reader.Close();

                    // We are opening or creating, we could have no file present.
                    if (!string.IsNullOrEmpty(preferenceData.Trim()))
                    {
                        UserApplicationStore.store = (Model.UserApplicationStore)UserApplicationStore.DeSerialize(
                            preferenceData, typeof(Model.UserApplicationStore)
                            );
                    }
                }
            }
        }