예제 #1
0
        /// <summary>
        /// Gramps export XML plus media.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        public async void PickFile()
        {
            BaseCL.LogProgress("Calling folder picker");

            try
            {
                if (await StoreFileUtility.PickCurrentInputFile().ConfigureAwait(false))
                {
                    BaseCL.LogProgress("Tell someone to load the file");

                    // Remove the old dateTime stamps so the files get reloaded even if they have
                    // been seen before
                    CommonLocalSettings.SetReloadDatabase();

                    BaseEventAggregator.GetEvent <DataLoadStartEvent>().Publish(false);

                    BaseEventAggregator.GetEvent <PageNavigateEvent>().Publish(nameof(MessageLogPage));

                    await DataStore.CN.ChangeLoadingMessage("File picked").ConfigureAwait(false);
                }
                else
                {
                    BaseCL.LogProgress("File picker error");
                    DataStore.CN.NotifyAlert("No input file was selected");

                    // Allow another pick if required
                    LocalCanHandleDataFolderChosen = true;
                }
            }
            catch (Exception ex)
            {
                DataStore.CN.NotifyException("Exception when using File Picker", ex);
            }
        }
        private async Task StartLoad()
        {
            BaseCL.Progress("Tell someone to load the file");

            // Remove the old dateTime stamps so the files get reloaded even if they have been seen before
            CommonLocalSettings.SetReloadDatabase();

            SharedSharp.Common.SharedSharpNavigation.NavigateHub();

            await Task.Delay(500);

            App.Current.Services.GetService <IMessenger>().Send(new DataLoadStartEvent(true));
        }
예제 #3
0
        /// <summary>
        /// Loads the data asynchronous.
        /// </summary>
        /// <returns>
        /// Task indicating if the data is loaded successfully.
        /// </returns>
        public async Task <bool> TriggerLoadSerialDataAsync()
        {
            try
            {
                _CL.LogRoutineEntry("TriggerLoadSerialDataAsync");

                // await DataStore.CN.ChangeLoadingMessage("Checking for Serialised GRAMPS data").ConfigureAwait(false);
                if (DataStore.DS.IsDataLoaded == false)
                {
                    if (CommonLocalSettings.DataSerialised)
                    {
                        await DataStore.CN.ChangeLoadingMessage("Loading GRAMPS Serial data").ConfigureAwait(false);

                        localStoreSerial.DeSerializeRepository();

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

                        UpdateSettings();

                        await localPostLoad.LoadSerialUiItems().ConfigureAwait(false);

                        await DataStore.CN.ChangeLoadingMessage("GRAMPS Serial data load complete").ConfigureAwait(false);

                        // let everybody know we have finished loading data
                        _EventAggregator.GetEvent <DataLoadCompleteEvent>().Publish(null);
                    }
                    else
                    {
                        await DataStore.CN.ChangeLoadingMessage("GRAMPS Serial data load failed.").ConfigureAwait(false);

                        CommonLocalSettings.SetReloadDatabase();
                    }
                }
            }
            catch (Exception ex)
            {
                CommonLocalSettings.DataSerialised = false;

                DataStore.CN.NotifyException("Trying to load existing serialised data", ex);

                CommonLocalSettings.SetReloadDatabase();

                throw;
            }

            _CL.LogRoutineExit("");

            return(false);
        }
예제 #4
0
        /// <summary>
        /// Loads the data asynchronous.
        /// </summary>
        /// <returns>
        /// Task indicating if the data is loaded successfully.
        /// </returns>
        public async Task <bool> TriggerLoadSerialDataAsync()
        {
            try
            {
                _CL.RoutineEntry("TriggerLoadSerialDataAsync");

                _commonNotifications.DataLogEntryAdd("Checking for Serialised GRAMPS data");
                if (DataStore.Instance.DS.IsDataLoaded == false)
                {
                    if (CommonLocalSettings.DataSerialised)
                    {
                        _commonNotifications.DataLogEntryAdd("Loading GRAMPS Serial data");

                        await _StoreSerial.DeSerializeRepository();

                        UpdateSavedLocalSettings();

                        await _PostLoad.LoadSerialUiItems().ConfigureAwait(false);

                        _commonNotifications.DataLogEntryReplace("GRAMPS Serial data load complete");

                        // let everybody know we have finished loading data
                        App.Current.Services.GetService <IMessenger>().Send(new DataLoadCompleteEvent(true));
                    }
                    else
                    {
                        _commonNotifications.DataLogEntryAdd("GRAMPS Serial data load failed.");

                        CommonLocalSettings.SetReloadDatabase();
                    }
                }
            }
            catch (Exception ex)
            {
                CommonLocalSettings.DataSerialised = false;

                _commonNotifications.NotifyException("Trying to load existing serialised data", ex);

                CommonLocalSettings.SetReloadDatabase();

                throw;
            }

            _CL.RoutineExit("");

            return(false);
        }
예제 #5
0
        /// <summary>
        /// Loads the sample data.
        /// </summary>
        public void LoadSample()
        {
            BaseCL.LogProgress("Load sample data");

            CommonRoutines.ListEmbeddedResources();

            // Load Resource
            var assemblyExec = Assembly.GetExecutingAssembly();
            var resourceName = "GrampsView.AnythingElse.SampleData.EnglishTudorHouse.gpkg";

            DataStore.AD.CurrentInputStream = assemblyExec.GetManifestResourceStream(resourceName);

            DataStore.AD.CurrentInputStreamPath = "AnythingElse/Sample Data/EnglishTudorHouse.gpkg";

            BaseCL.LogProgress("Tell someone to load the file");

            // Remove the old dateTime stamps so the files get reloaded even if they have been seen before
            CommonLocalSettings.SetReloadDatabase();

            BaseEventAggregator.GetEvent <DataLoadStartEvent>().Publish(false);

            BaseEventAggregator.GetEvent <PageNavigateEvent>().Publish(nameof(MessageLogPage));
        }
예제 #6
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);
        }
예제 #7
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 file DataStore.AD.CurrentInputFile = await StoreFileNames.FileGetFirstGPKG().ConfigureAwait(false);

                if (DataStore.AD.CurrentInputFile != null)
                {
                    //if (await StoreFileNames.FileModifiedSinceLastSaveAsync(CommonConstants.SettingsGPKGFileLastDateTimeModified, DataStore.AD.CurrentInputFile.).ConfigureAwait(false))
                    //{
                    await DataStore.CN.ChangeLoadingMessage("Later version of Gramps XML data plus Media  compressed file found. Loading it into the program").ConfigureAwait(false);

                    await TriggerLoadGPKGFileAsync(false).ConfigureAwait(false);

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

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

                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 = await StoreFolder.FolderGetFileAsync(DataStore.AD.CurrentDataFolder, CommonConstants.StorageXMLFileName).ConfigureAwait(false);

                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
            {
                //if (!(DataStore.AD.CurrentDataFolder.Status.LatestException is null))
                //{
                //    DataStore.CN.NotifyException("StartDataLoadAsync", DataStore.AD.CurrentDataFolder.Status.LatestException);
                //}

                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);
        }