public static TraktObject saveObject(TraktObject traktObject, Type type) { try { traktObject.DownloadTime = DateTime.Now; using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { if (!isoStore.DirectoryExists(traktObject.getFolder())) { isoStore.CreateDirectory(traktObject.getFolder()); } String fileName = traktObject.getFolder() + "/" + traktObject.getIdentifier() + ".json"; using (var isoFileStream = isoStore.CreateFile(fileName)) { DataContractJsonSerializer ser = new DataContractJsonSerializer(type); ser.WriteObject(isoFileStream, traktObject); isoFileStream.Close(); } } return(traktObject); } catch (IsolatedStorageException) { return(traktObject); } }
public static TraktObject LoadObject(String file, Type type) { try { using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream stream = isoStore.OpenFile(file, FileMode.Open)) { var ser = new DataContractJsonSerializer(type); TraktObject traktObject = (TraktObject)ser.ReadObject(stream); stream.Close(); return(traktObject); } } } catch (IsolatedStorageException) { return(null); } }