/// <summary> /// Loads the thumbnails etc on the UI thread due to limitations with BitMapImage in /// Background threads. /// </summary> /// <param name="notUsed"> /// The not used. /// </param> public async void LoadXMLUIItems(object notUsed) { _CommonLogging.RoutineEntry("LoadXMLUIItems"); _commonNotifications.DataLogEntryAdd("Organising data after load"); { { // Called in order of media linkages from Media outwards await OrganiseMediaRepository().ConfigureAwait(false); await OrganiseSourceRepository().ConfigureAwait(false); await OrganiseCitationRepository().ConfigureAwait(false); await OrganiseEventRepository().ConfigureAwait(false); await OrganiseFamilyRepository().ConfigureAwait(false); await OrganiseHeaderRepository().ConfigureAwait(false); await OrganiseNameMapRepository().ConfigureAwait(false); OrganiseNoteRepository(); await OrganisePlaceRepository().ConfigureAwait(false); await OrganiseRepositoryRepository().ConfigureAwait(false); await OrganiseTagRepository().ConfigureAwait(false); await OrganiseAddressRepository().ConfigureAwait(false); await OrganisePersonNameRepository().ConfigureAwait(false); // People last as they pretty much depend on everything else await OrganisePersonRepository().ConfigureAwait(false); // Apart from BookMarks await OrganiseBookMarkRepository().ConfigureAwait(false); // Final cleanup pending use of some sort of dependency graph on the whole thing await OrganiseMisc().ConfigureAwait(false); await _commonNotifications.DataLogHide(); } } _commonNotifications.DataLogEntryAdd(null); _commonNotifications.DataLogEntryAdd("Load XML UI Complete - Data ready for display"); // save the data in a serial format for next time App.Current.Services.GetService <IMessenger>().Send(new DataSaveSerialEvent(true)); // let everybody know we have finished loading data App.Current.Services.GetService <IMessenger>().Send(new DataLoadCompleteEvent(true)); _CommonLogging.RoutineExit(nameof(LoadXMLUIItems)); }
/// <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); }
/// <summary> /// Deserialise the previously serialised repository. Perform as a single step so that it /// goes faster at the cost of providing less feedbak to the user. /// </summary> public async Task DeSerializeRepository() { localGVLogging.RoutineEntry(nameof(DeSerializeRepository)); try { DataContractSerializer ser = new DataContractSerializer(typeof(DataInstance)); using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { // Check of the file exists if (!isoStore.FileExists(GetSerialFile())) { ErrorInfo tt = new ErrorInfo("DeSerializeRepository", "File Does not exist. Reload the GPKG file") { { "File", GetSerialFile() }, }; App.Current.Services.GetService <IErrorNotifications>().NotifyError(tt); CommonLocalSettings.DataSerialised = false; return; } //byte[] buffer = new byte[1024]; IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(GetSerialFile(), FileMode.Open, isoStore); //var ttt = await isoStream.ReadAsync(buffer, 0, 100); JsonSerializerOptions serializerOptions = GetSerializerOptions(); DataInstance t = await JsonSerializer.DeserializeAsync <DataInstance>(isoStream, serializerOptions); // Check for nulls if (t.AddressData != null) { DataStore.Instance.DS.AddressData = t.AddressData; } else { CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("Bad Address deserialisation error. Data loading cancelled. Restart the program and reload the data.")); } if (t.BookMarkCollection != null) { DataStore.Instance.DS.BookMarkCollection = t.BookMarkCollection; } else { CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("Bad BookMark deserialisation error. Data loading cancelled. Restart the program and reload the data.")); } if (t.CitationData != null) { DataStore.Instance.DS.CitationData = t.CitationData; } else { CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("Bad Citation deserialisation error. Data loading cancelled. Restart the program and reload the data.")); } if (t.EventData != null) { DataStore.Instance.DS.EventData = t.EventData; } else { CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("Bad Event deserialisation error. Data loading cancelled. Restart the program and reload the data.")); } if (t.FamilyData != null) { DataStore.Instance.DS.FamilyData = t.FamilyData; } else { CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("Bad Family deserialisation error. Data loading cancelled. Restart the program and reload the data.")); } if (t.MediaData != null) { DataStore.Instance.DS.MediaData = t.MediaData; } else { CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("Bad Media deserialisation error. Data loading cancelled. Restart the program and reload the data.")); } if (t.PersonData != null) { DataStore.Instance.DS.PersonData = t.PersonData; } else { CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("Bad Person deserialisation error. Data loading cancelled. Restart the program and reload the data.")); } if (t.PersonNameData != null) { DataStore.Instance.DS.PersonNameData = t.PersonNameData; } else { CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("Bad Person Name deserialisation error. Data loading cancelled. Restart the program and reload the data.")); } // Check for nulls if (t.SourceData != null) { DataStore.Instance.DS.SourceData = t.SourceData; } else { CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("Bad Source data deserialisation error. Data loading cancelled. Restart the program and reload the data.")); } // Check for nulls if (t.TagData != null) { DataStore.Instance.DS.TagData = t.TagData; } else { CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyError(new ErrorInfo("Bad Tag data deserialisation error. Data loading cancelled. Restart the program and reload the data.")); } // TODO Finish setting the checks up on these DataStore.Instance.DS.HeaderData = t.HeaderData; DataStore.Instance.DS.NameMapData = t.NameMapData; DataStore.Instance.DS.NoteData = t.NoteData; DataStore.Instance.DS.PlaceData = t.PlaceData; DataStore.Instance.DS.RepositoryData = t.RepositoryData; } localGVLogging.RoutineExit(nameof(DeSerializeRepository)); } catch (Exception ex) { localGVLogging.Progress("DeSerializeRepository - Exception "); CommonLocalSettings.DataSerialised = false; App.Current.Services.GetService <IErrorNotifications>().NotifyException("Old data deserialisation error. Data loading cancelled", ex); } return; }