Ejemplo n.º 1
0
        /// <summary>
        /// Triggers the load GPKG file asynchronous.
        /// </summary>
        /// <param name="deleteOld">
        /// if set to <c>true</c> [delete old].
        /// </param>
        /// <param name="gpkgFileName">
        /// Name of the GPKG file.
        /// </param>
        /// <returns>
        /// </returns>
        public async Task <bool> TriggerLoadGPKGFileAsync(bool deleteOld)
        {
            Analytics.TrackEvent("TriggerLoadGPKGFileAsync",
                                 new Dictionary <string, string> {
                { "FileName", DataStore.AD.CurrentInputFile.FilePath },
            });

            if (!DataStore.AD.CurrentInputFileValid)
            {
                return(false);
            }

            // HockeyClient.Current.TrackEvent("TriggerLoadGPKGFileAsync");
            await DataStore.CN.ChangeLoadingMessage("Loading GPKG data").ConfigureAwait(false);

            // await DataStore.CN.MajorStatusAdd("Loading GRAMPS XML data");
            {
                if (DataStore.AD.CurrentInputFileValid)
                {
                    // TODO create data folder await localStoreFile.SetDataFolderLocalStorage();

                    // Clear image cache
                    await ImageService.Instance.InvalidateCacheAsync(CacheType.All).ConfigureAwait(false);

                    // 1) Initialise local data copies (if any exist)
                    if (deleteOld)
                    {
                        await localStoreFile.DataStorageInitialiseAsync().ConfigureAwait(false);
                    }

                    // TODO work out how to delte excess files based on keepign the ones in the GPKG file
                    //// Delete directories of files. Assume files in root are ok
                    // IReadOnlyList<StorageFolder> t = await DataStore.AD.CurrentDataFolder.GetFoldersAsync();

                    // foreach (StorageFolder item in t) { await item.DeleteAsync(); }
                    await localStoreFile.DecompressTAR().ConfigureAwait(false);

                    // Save the current Index File modified date for later checking TODO How doe
                    // sthis work if only loading picked file?
                    // StoreFileNames.SaveFileModifiedSinceLastSave(CommonConstants.SettingsGPKGFileLastDateTimeModified, DataStore.AD.CurrentInputFile);
                }
            }

            await DataStore.CN.MajorStatusDelete().ConfigureAwait(false);

            await DataStore.CN.ChangeLoadingMessage(null).ConfigureAwait(false);

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the data load asynchronous. Order is:
        /// 1) UnTar new *.GPKG file
        /// 2) UnZip new data.GRAMPS file
        /// 3) Load new data.XML file
        /// 4) ELSE load Serial file.
        /// </summary>
        /// <returns>
        /// Returns a empty task.
        /// </returns>
        public async Task <bool> StartDataLoadAsync()
        {
            IFileInfoEx GrampsFile = new FileInfoEx();

            _commonNotifications.DataLogEntryAdd("Loading Data...");

            if (DataStore.Instance.DS.IsDataLoaded)
            {
                return(true);
            }

            //await _commonNotifications.DataLogShow();

            // Clear the repositories in case we had to restart after being interupted.
            ClearRepositories();

            // Create the DataStorage Folder
            DataStore.Instance.AD.CurrentDataFolder = new CurrentDataFolder();

            if (DataStore.Instance.AD.CurrentDataFolder.Valid)
            {
                // 1) Init Data Storage
                if (DataStore.Instance.AD.CurrentInputStreamValid)
                {
                    // Clear the file system
                    await _StoreFile.DataStorageInitialiseAsync().ConfigureAwait(false);
                }

                // 1a) UnTar *.GPKG
                if (DataStore.Instance.AD.CurrentInputStreamFileType == ".gpkg")
                {
                    GrampsFile = await TriggerLoadGPKGFileAsync().ConfigureAwait(false);
                }

                // 1b) UnTar *.GRAMPS
                if (DataStore.Instance.AD.CurrentInputStreamFileType == ".gramps")
                {
                    _commonNotifications.DataLogEntryAdd("Later version of Gramps XML data compressed file found. Loading it into the program");

                    File.Copy(DataStore.Instance.AD.CurrentInputStreamPath, Path.Combine(DataStore.Instance.AD.CurrentDataFolder.Path, Common.Constants.StorageXMLFileName));

                    GrampsFile = new FileInfoEx();  // Mark as invalid as do not need to unzip
                }

                // 2) UnZip new data.GRAMPS file
                if (GrampsFile.Valid)
                {
                    if (CommonLocalSettings.ModifiedComparedToSettings(GrampsFile, Common.Constants.SettingsGPRAMPSFileLastDateTimeModified))
                    {
                        _commonNotifications.DataLogEntryAdd("Later version of Gramps data file found. Loading it into the program");

                        await TriggerLoadGRAMPSFileAsync(false).ConfigureAwait(false);
                    }
                }

                // 3) Load new data.XML file
                IFileInfoEx dataXML = new FileInfoEx(argFileName: Common.Constants.StorageXMLFileName);

                if (dataXML.Valid)
                {
                    if (CommonLocalSettings.ModifiedComparedToSettings(dataXML, Common.Constants.SettingsXMLFileLastDateTimeModified))
                    {
                        _commonNotifications.DataLogEntryAdd("Later version of Gramps XML data file found. Loading it into the program");

                        // Load the new data
                        await TriggerLoadGrampsUnZippedFolderAsync().ConfigureAwait(false);

                        Analytics.TrackEvent($"Load GPKG file: {DataStore.Instance.AD.CurrentInputStreamPath}");

                        return(true);
                    }
                }

                if (CommonLocalSettings.DataSerialised)
                {
                    // 4) ELSE load Serial file
                    await TriggerLoadSerialDataAsync().ConfigureAwait(false);

                    // await _commonNotifications.DataLogHide();
                }

                return(true);
            }
            else
            {
                _commonNotifications.NotifyError(new ErrorInfo("DataStorageFolder not valid.  It will need to be reloaded..."));

                CommonLocalSettings.SetReloadDatabase();
            }

            // TODO Handle special messages if there is a problem

            _commonNotifications.DataLogEntryAdd("Unable to load Datafolder");
            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Starts the data load asynchronous. Order is:
        /// 1) UnTar new *.GPKG file
        /// 2) UnZip new data.GRAMPS file
        /// 3) Load new data.XML file
        /// 4) ELSE load Serial file.
        /// </summary>
        /// <returns>
        /// Returns a empty task.
        /// </returns>
        public async Task <bool> StartDataLoadAsync()
        {
            await DataStore.CN.ChangeLoadingMessage("Loading Data...").ConfigureAwait(false);

            if (DataStore.DS.IsDataLoaded)
            {
                return(true);
            }

            // Clear the repositories in case we had to restart after being interupted.
            ClearRepositories();

            DataStore.AD.LoadDataStore();

            if (DataStore.AD.CurrentDataFolderValid)
            {
                // 1) UnTar *.GPKG
                if (DataStore.AD.CurrentInputStreamValid)
                {
                    await DataStore.CN.ChangeLoadingMessage("Later version of Gramps XML data plus Media  compressed file found. Loading it into the program").ConfigureAwait(false);

                    // Clear the file system
                    await localStoreFile.DataStorageInitialiseAsync().ConfigureAwait(false);

                    await TriggerLoadGPKGFileAsync().ConfigureAwait(false);
                }

                // 2) UnZip new data.GRAMPS file
                FileInfoEx GrampsFile = StoreFolder.FolderGetFile(DataStore.AD.CurrentDataFolder, CommonConstants.StorageGRAMPSFileName);

                if (GrampsFile.Valid)
                {
                    if (StoreFileNames.FileModifiedSinceLastSaveAsync(CommonConstants.SettingsGPRAMPSFileLastDateTimeModified, GrampsFile))
                    {
                        await DataStore.CN.ChangeLoadingMessage("Later version of Gramps data file found. Loading it into the program").ConfigureAwait(false);

                        await TriggerLoadGRAMPSFileAsync(false).ConfigureAwait(false);
                    }
                }

                // 3) Load new data.XML file
                FileInfoEx dataXML = StoreFolder.FolderGetFile(DataStore.AD.CurrentDataFolder, CommonConstants.StorageXMLFileName);

                if (dataXML.Valid)
                {
                    if (StoreFileNames.FileModifiedSinceLastSaveAsync(CommonConstants.SettingsXMLFileLastDateTimeModified, dataXML))
                    {
                        await DataStore.CN.ChangeLoadingMessage("Later version of Gramps XML data file found. Loading it into the program").ConfigureAwait(false);

                        // Load the new data
                        await TriggerLoadGrampsUnZippedFolderAsync().ConfigureAwait(false);

                        return(true);
                    }
                }

                if (CommonLocalSettings.DataSerialised)
                {
                    // 4) ELSE load Serial file
                    await TriggerLoadSerialDataAsync().ConfigureAwait(false);
                }

                await DataStore.CN.ChangeLoadingMessage(null).ConfigureAwait(false);

                return(true);
            }
            else
            {
                DataStore.CN.NotifyError("DataStorageFolder not valid.  It will need to be reloaded...");

                CommonLocalSettings.SetReloadDatabase();
            }

            // TODO Handle special messages if there is a problem

            await DataStore.CN.ChangeLoadingMessage("Unable to load Datafolder").ConfigureAwait(false);

            return(false);
        }