public static async Task <Card> addNewCardAsync(string name) { //TODO: DO NOT ALLOW DUPLICATE CARD NAMES //if (allCardsDict.ContainsKey(name)) throw new Exception("ERROR: New Card name already exists, this may corrupt file structure"); // For now alllow overwrite of existing card, this happens when an online card is accepted again if (allCardsDict.ContainsKey(name)) { allCardsDict.Remove(name); } //Create new card and add to album and storage Card newCard = new Card { name = name, creationTime = DateTime.Now, linkManager = new LinkManager() }; allCardsDict.Add(name, newCard); //Serialize JSON to a newly created file IFile newCardFile = await FileSystem.Current.LocalStorage.CreateFileAsync(Path.Combine(FilePaths.allCardsPath, name), CreationCollisionOption.ReplaceExisting); JSONSerialManager.serialize(newCardFile.Path, newCard); return(newCard); }
public async static Task initializeAsync() { await readDayMediaAsync(); loadMediaIntoCollection(); string mediaLinkManagerPath = Path.Combine(FilePaths.rootPath, "AllMediaLinkManager"); if (File.Exists(mediaLinkManagerPath)) { mediaLinkManager = JSONSerialManager.deserialize <LinkManager>(Path.Combine(FilePaths.rootPath, "AllMediaLinkManager")); } if (mediaLinkManager == null) { mediaLinkManager = new LinkManager(); } string favoriteManagerPath = Path.Combine(FilePaths.rootPath, "AllMediaFavoriteManager"); if (File.Exists(favoriteManagerPath)) { favoriteManager = JSONSerialManager.deserialize <FavoriteManager>(Path.Combine(FilePaths.rootPath, "AllMediaFavoriteManager")); } if (favoriteManager == null) { favoriteManager = new FavoriteManager(); } }
private async static Task <List <AbMediaContent> > deserializeContactFilesAsyc(IFolder dir) { IList <IFile> files = await dir.GetFilesAsync(); List <AbMediaContent> filesRead = new List <AbMediaContent>(files.Count); foreach (IFile file in files) { ContactMediaContent media = JSONSerialManager.deserialize <ContactMediaContent>(file.Path); if (media != null) { // Unfortunately ContactMedia fileds are not loaded when its JSON constructor is called media.initialize(media.name, media.phoneNumber, media.imageFilePath); filesRead.Add(media); } } return(filesRead); }
/// <summary> /// Must be called in starting activity! /// </summary> public async static Task initializeAsync() { await FilePaths.initFoldersAsync(); allCardsDict = new Dictionary <string, Card>(); //Read in and deserialize all JSON file cards List <Card> allCards = await JSONSerialManager.deserializeDirAsync <Card>(FilePaths.allCardsDir); foreach (Card card in allCards) { //NOTE: exception handling for messed up serialization leading to null writes if (card != null) { allCardsDict.Add(card.name, card); } } //Read in all MEDIA await MediaManager.initializeAsync(); //FirebaseDownloadManager downloadManager = new FirebaseDownloadManager(); //downloadManager.initialize(); }
public static void saveMediaLinkManager() { JSONSerialManager.serialize(Path.Combine(FilePaths.rootPath, "AllMediaLinkManager"), mediaLinkManager); }