Exemple #1
0
        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); }
        }
Exemple #2
0
        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); }
        }
Exemple #3
0
        public async Task <bool> DeleteLibraryAsync(string id)
        {
            try
            {
                await App.Navigation().PopAsync();

                // LOCATE LIBRARY
                var library = this.GetLibrary(id);
                if (library == null)
                {
                    Helpers.AppCenter.TrackEvent("Library.Delete.NotFound", $"LibraryID:{id}"); return(false);
                }
                library.Removed = true;

                // LIBRARY SERVICE
                using (var service = new Services.LibraryService(library))
                {
                    // REMOVE FILES
                    if (!await service.RemoveLibrary())
                    {
                        return(false);
                    }
                    Messaging.Send(Messaging.enMessages.LibraryRemoved.ToString(), library);

                    // STORE LIBRARY
                    this.Libraries.RemoveAll(x => x.ID == library.ID);
                    this.RemoveLibrary(library);
                    this.SaveLibraries();
                }

                // ENGINE
                var engine = Engines.Engine.Get(library.Type);
                await engine.DeleteLibrary(library);

                return(true);
            }
            catch (Exception ex) { Helpers.AppCenter.TrackEvent(ex); return(false); }
        }