Exemple #1
0
 public bool Persist()
 {
     using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
     {
         using (var fs = new IsolatedStorageFileStream(Common.UserDataStore, FileMode.Create, isf))
         {
             DataContractJSONSerializationHelper.Serialize(fs, this);
             return(true);
         }
     }
     return(false);
 }
Exemple #2
0
        public static UserData GetUserData()
        {
            UserData userData = null;

            try
            {
                using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    //isf.DeleteFile(StoreName);
                    // try get from storage
                    using (var fs = new IsolatedStorageFileStream(Common.UserDataStore, FileMode.OpenOrCreate, isf))
                    {
                        userData = DataContractJSONSerializationHelper.Deserialize(fs, typeof(UserData)) as UserData;
                    }
                }
            }
            catch (IsolatedStorageException)
            {
            }

            // if not existant create new instance with default values
            return(userData ?? (new UserData()));
        }