public async Task <bool> NewLibraryAsync(LibraryType libraryType) { try { App.HideNavigation(); // ENGINE var engine = Engines.Engine.Get(libraryType); var library = await engine.NewLibrary(); if (library == null) { return(false); } // ADD LIBRARY library.ID = Guid.NewGuid().ToString(); if (!await this.AddLibraryAsync(library)) { return(false); } // STORE LIBRARY this.SaveLibrary(library); this.SaveLibraries(); // LIBRARY SERVICE using (var services = new Services.LibraryService(library)) { await services.InitializeLibrary(); } Services.LibraryService.RefreshLibrary(library); return(true); } catch (Exception ex) { Helpers.AppCenter.TrackEvent(ex); return(false); } }
public async Task LoadLibrariesAsync() { try { // LIBRARY IDs var libraryIDsJSON = await Task.FromResult(Xamarin.Essentials.Preferences.Get(LibraryIDs, "[]")); var libraryIDs = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(libraryIDsJSON); // LIBRARY CONTENT foreach (var libraryID in libraryIDs) { var libraryJSON = Xamarin.Essentials.Preferences.Get($"{LibraryIDs}.{libraryID}", ""); if (!string.IsNullOrEmpty(libraryJSON)) { var library = Newtonsoft.Json.JsonConvert.DeserializeObject <LibraryModel>(libraryJSON); await this.AddLibraryAsync(library); } } // LIBRARY SERVICE foreach (var library in this.Libraries) { using (var services = new Services.LibraryService(library)) { await services.InitializeLibrary(); } } foreach (var library in this.Libraries) { Services.LibraryService.RefreshLibrary(library); } } catch (Exception ex) { Helpers.AppCenter.TrackEvent(ex); } }