private static IsolatedStorageDatabase getDatabaseFromIsolatedStorage() { IsolatedStorageDatabase database = null; try { using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) { using (var iStreamForEndpoint = new IsolatedStorageFileStream(_isolatedStorageDatabaseFileName, FileMode.Open, isoStore)) { using (var readerForEndpoint = new StreamReader(iStreamForEndpoint)) { var json = readerForEndpoint.ReadToEnd(); database = JsonConvert.DeserializeObject <IsolatedStorageDatabase>(json, new JsonSerializerSettings { Error = deserialiseErrorEventHandler }); } } } } catch (FileNotFoundException) { database = null; } return(database); }
public static void saveDatabaseToIsolatedStorage(IsolatedStorageDatabase database) { using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null)) { using (var oStream = new IsolatedStorageFileStream(_isolatedStorageDatabaseFileName, FileMode.Create, isoStore)) { using (var writer = new StreamWriter(oStream)) { writer.Write(JsonConvert.SerializeObject(database)); } } } }
public static IsolatedStorageDatabase GetInstance() { if (_db == null) { _db = getDatabaseFromIsolatedStorage(); } if (_db == null) { var d = new IsolatedStorageDatabase(); d.People = new List <Person>(); d.PictureFiles = new List <PictureFile>(); d.PictureFileGroupLookups = new List <PictureFileGroupLookup>(); d.PicturePersons = new List <PicturePerson>(); _db = d; saveDatabaseToIsolatedStorage(d); } return(_db); }