Esempio n. 1
0
        public async static void RemoveAllData()
        {
            IFolder rootFolder = FileSystem.Current.LocalStorage;
            ExistenceCheckResult kuchaFolderExists = await rootFolder.CheckExistsAsync("Kucha");

            if (kuchaFolderExists == ExistenceCheckResult.FolderExists)
            {
                IFolder kuchaFolder = await rootFolder.GetFolderAsync("Kucha");

                await kuchaFolder.DeleteAsync();

                kuchaContainer       = null;
                App.Current.MainPage = new UI.LoginPage();
            }
        }
Esempio n. 2
0
        public async static Task <bool> RefreshLocalData()
        {
            if (kuchaContainer == null)
            {
                kuchaContainer = new KuchaContainer();
            }
            List <CaveDistrictModel> caveDistrictModels = Connection.GetCaveDistrictModels();

            if (caveDistrictModels == null)
            {
                return(false);
            }
            kuchaContainer.CaveDistricts = caveDistrictModels;

            List <CaveRegionModel> caveRegionModels = Connection.GetCaveRegionModels();

            if (caveRegionModels != null)
            {
                kuchaContainer.CaveRegions = caveRegionModels;
            }
            else
            {
                return(false);
            }

            List <CaveSiteModel> caveSiteModels = Connection.GetCaveSiteModels();

            if (caveSiteModels != null)
            {
                kuchaContainer.CaveSites = caveSiteModels;
            }
            else
            {
                return(false);
            }

            List <CaveTypeModel> caveTypeModels = Connection.GetCaveTypeModels();

            if (caveTypeModels != null)
            {
                kuchaContainer.CaveTypes          = caveTypeModels;
                kuchaContainer.CaveTypeDictionary = new Dictionary <string, CaveTypeModel>
                {
                    { "Any", null }
                };
                foreach (CaveTypeModel c in caveTypeModels)
                {
                    kuchaContainer.CaveTypeDictionary.Add(c.nameEN, c);
                }
            }
            else
            {
                return(false);
            }

            List <CaveModel> caveModels = Connection.GetAllCaves();

            if (caveModels != null)
            {
                kuchaContainer.Caves = caveModels;
            }
            else
            {
                return(false);
            }

            List <IconographyModel> iconographieModels = Connection.GetIconographyModels();

            if (iconographieModels != null)
            {
                kuchaContainer.Iconographies = iconographieModels;
            }
            else
            {
                return(false);
            }

            kuchaContainer.TimeStamp = DateTime.UtcNow;
            IFolder rootFolder  = FileSystem.Current.LocalStorage;
            IFolder kuchaFolder = await rootFolder.CreateFolderAsync("Kucha", CreationCollisionOption.OpenIfExists);

            IFile kuchaContainerStorage = await kuchaFolder.CreateFileAsync("KuchaContainer", CreationCollisionOption.ReplaceExisting);

            await kuchaContainerStorage.WriteAllTextAsync(JsonConvert.SerializeObject(kuchaContainer));

            return(true);
        }
Esempio n. 3
0
        //Global
        /// <summary>
        /// Only used during App Launch
        /// </summary>
        public async static void LoadPersistantData()
        {
            IFolder rootFolder = FileSystem.Current.LocalStorage;
            ExistenceCheckResult kuchaFolderExists = await rootFolder.CheckExistsAsync("Kucha");

            bool loadSuccess = false;

            if (kuchaFolderExists == ExistenceCheckResult.FolderExists)
            {
                IFolder kuchaFolder = await rootFolder.GetFolderAsync("Kucha");

                IFile kuchaContainerFile;
                if (kuchaFolder != null)
                {
                    ExistenceCheckResult kuchaFileExists = await kuchaFolder.CheckExistsAsync("KuchaContainer");

                    if (kuchaFileExists == ExistenceCheckResult.FileExists)
                    {
                        kuchaContainerFile = await kuchaFolder.GetFileAsync("KuchaContainer");

                        if (kuchaContainerFile != null)
                        {
                            string fileString = await kuchaContainerFile.ReadAllTextAsync();

                            kuchaContainer = JsonConvert.DeserializeObject <KuchaContainer>(fileString);
                            if (kuchaContainer != null)
                            {
                                loadSuccess = true;
                            }
                            else
                            {
                                kuchaContainer = new KuchaContainer();
                            }
                        }
                    }
                    else
                    {
                        await kuchaFolder.CreateFileAsync("KuchaContainer", CreationCollisionOption.ReplaceExisting);

                        kuchaContainer = new KuchaContainer();
                    }
                }
            }
            else
            {
                //Kucha Folder does not exist - Create Folder and empty file
                await rootFolder.CreateFolderAsync("Kucha", CreationCollisionOption.ReplaceExisting);

                IFolder kuchaFolder = await rootFolder.GetFolderAsync("Kucha");

                await kuchaFolder.CreateFileAsync("KuchaContainer", CreationCollisionOption.ReplaceExisting);
            }

            if (!loadSuccess)
            {
                kuchaContainer = new KuchaContainer();
            }
            Connection.LoadCachedSessionID();

            Device.BeginInvokeOnMainThread(() => ((App)App.Current).LoadingPersistantDataFinished());
        }