/// <summary>
        /// load events from external storage.
        /// </summary>
        /// <param name="eventRepository">
        /// The event repository.
        /// </param>
        /// <returns>
        /// Flag of loaded successfully.
        /// </returns>
        public async Task LoadPlacesAsync()
        {
            await DataStore.CN.MajorStatusAdd(nameof(LoadPlacesAsync)).ConfigureAwait(false);

            {
                // XNamespace ns = grampsXMLNameSpace;
                try
                {
                    // Run query
                    var de =
                        from el in localGrampsXMLdoc.Descendants(ns + "placeobj")
                        select el;

                    // action any data found
                    if (!(de == null))
                    {
                        // get Place fields

                        // Loop through results to get the Place data;
                        foreach (XElement pPlaceElement in de)
                        {
                            PlaceModel loadPlace = DV.PlaceDV.NewModel();

                            // Place attributes
                            loadPlace.LoadBasics(GetBasics(pPlaceElement));
                            //loadPlace.Id = (string)pPlaceElement.Attribute("id");

                            //loadPlace.Change = GetDateTime(pPlaceElement, "change");
                            //loadPlace.Priv = SetPrivateObject((string)pPlaceElement.Attribute("priv"));
                            //loadPlace.Handle = (string)pPlaceElement.Attribute("handle");

                            if (String.IsNullOrEmpty(loadPlace.Handle))
                            {
                            }

                            if (loadPlace.Id == "P0018")
                            {
                            }

                            loadPlace.GCode = GetElement(pPlaceElement, "code");

                            loadPlace.GType = (string)pPlaceElement.Attribute("type");

                            // Load other Place fields
                            loadPlace.GPTitle = GetElement(pPlaceElement, "ptitle");

                            XElement pName = pPlaceElement.Element(ns + "pname");

                            loadPlace.GLocation = GetPlaceLocationModelCollection(pPlaceElement);

                            loadPlace.GPlaceNames = GetPlaceNameModelCollection(pPlaceElement);

                            loadPlace.GCitationRefCollection.Clear();
                            loadPlace.GCitationRefCollection.AddRange(GetCitationCollection(pPlaceElement));

                            loadPlace.GMediaRefCollection = await GetObjectCollection(pPlaceElement).ConfigureAwait(false);

                            loadPlace.GNoteRefCollection = GetNoteCollection(pPlaceElement);

                            loadPlace.GPlaceRefCollection = GetPlaceRefCollection(pPlaceElement);

                            loadPlace.GTagRefCollection = GetTagCollection(pPlaceElement);

                            loadPlace.GURLCollection = GetURLCollection(pPlaceElement);

                            // save the event
                            DV.PlaceDV.PlaceData.Add(loadPlace);
                        }

                        // sort the collection eventRepository.Items.Sort(EventModel => EventModel);

                        // let everybody know
                    }
                }
                catch (Exception e)
                {
                    // TODO handle this
                    await DataStore.CN.MajorStatusAdd(e.Message).ConfigureAwait(false);

                    throw;
                }
            }

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

            return;
        }
Example #2
0
        public async Task LoadPlacesAsync()
        {
            _iocCommonNotifications.DataLogEntryAdd("Loading Place data");
            {
                try
                {
                    // Run query
                    var de =
                        from el in localGrampsXMLdoc.Descendants(ns + "placeobj")
                        select el;

                    // action any data found
                    if (!(de == null))
                    {
                        // get Place fields

                        // Loop through results to get the Place data;
                        foreach (XElement pPlaceElement in de)
                        {
                            PlaceModel loadPlace = new PlaceModel();

                            // Place attributes
                            loadPlace.LoadBasics(GetBasics(pPlaceElement));

                            //if (String.IsNullOrEmpty(loadPlace.Handle))
                            //{
                            //}

                            if (loadPlace.Id == "P0273")
                            {
                            }

                            // Load other Place fields
                            loadPlace.GType = (string)pPlaceElement.Attribute("type");

                            loadPlace.GPTitle = GetElement(pPlaceElement, "ptitle");

                            loadPlace.GPlaceNames = GetPlaceNameModelCollection(pPlaceElement);

                            if (string.IsNullOrEmpty(loadPlace.GPlaceNames[0].DeRef.GValue))
                            {
                            }

                            loadPlace.GCode = GetElement(pPlaceElement, "code");

                            XElement coord = pPlaceElement.Element(ns + "coord");
                            if (!(coord is null))
                            {
                                double.TryParse(GetAttribute(coord, "lat"), out double latDouble);
                                double.TryParse(GetAttribute(coord, "long"), out double longDouble);

                                loadPlace.GCoordLat  = latDouble;
                                loadPlace.GCoordLong = longDouble;
                            }

                            loadPlace.GPlaceParentCollection       = GetPlaceRefCollection(pPlaceElement);
                            loadPlace.GPlaceParentCollection.Title = "Parent Places";

                            loadPlace.GLocation = GetPlaceLocationModelCollection(pPlaceElement);

                            loadPlace.GMediaRefCollection = await GetObjectCollection(pPlaceElement).ConfigureAwait(false);

                            loadPlace.GURLCollection = GetURLCollection(pPlaceElement);

                            loadPlace.GNoteRefCollection = GetNoteCollection(pPlaceElement);

                            loadPlace.GCitationRefCollection.Clear();
                            loadPlace.GCitationRefCollection.AddRange(GetCitationCollection(pPlaceElement));

                            loadPlace.GTagRefCollection = GetTagCollection(pPlaceElement);

                            // save the event
                            DV.PlaceDV.PlaceData.Add(loadPlace);
                        }
                    }
                }
                catch (Exception e)
                {
                    _iocCommonNotifications.NotifyException("Exception loading Place data from the file", e);

                    throw;
                }
            }

            _iocCommonNotifications.DataLogEntryReplace("Place load complete");

            return;
        }