/// <summary>
        /// Parse dataset file from feed and return as DatasetFile
        /// </summary>
        /// <param name="originalDatasetFile">local dataset file</param>
        /// <returns></returns>
        public DatasetFile GetDatasetFile(DatasetFile originalDatasetFile)
        {
            var getFeedTask = HttpClient.GetStringAsync(originalDatasetFile.DatasetUrl);

            Log.Debug("Fetch dataset file from " + originalDatasetFile.DatasetUrl);
            return(new AtomFeedParser().ParseDatasetFile(getFeedTask.Result, originalDatasetFile));
        }
        public List <DatasetFile> ParseDatasetFiles(string xml, Dataset dataset)
        {
            var datasetFiles = new List <DatasetFile>();

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);

            string xpath = "//a:feed/a:entry";

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

            nsmgr.AddNamespace("a", "http://www.w3.org/2005/Atom");
            nsmgr.AddNamespace("inspire_dls", "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0");

            var nodes = xmlDoc.SelectNodes(xpath, nsmgr);

            foreach (XmlNode childrenNode in nodes)
            {
                var datasetFile = new DatasetFile();
                datasetFile.Title        = childrenNode.SelectSingleNode("a:title", nsmgr).InnerXml;
                datasetFile.Description  = childrenNode.SelectSingleNode("a:category", nsmgr).InnerXml;
                datasetFile.Url          = childrenNode.SelectSingleNode("a:link", nsmgr).Attributes[1].Value;
                datasetFile.LastUpdated  = childrenNode.SelectSingleNode("a:updated", nsmgr).InnerXml;
                datasetFile.Organization = childrenNode.SelectSingleNode("a:author/a:name", nsmgr).InnerXml;
                datasetFile.Projection   = GetProjection(childrenNode.SelectNodes("a:category", nsmgr));
                datasetFile.Restrictions = GetRestrictions(childrenNode.SelectNodes("a:category", nsmgr));
                datasetFile.DatasetId    = dataset.Title;
                datasetFile.DatasetUrl   = dataset.Url;

                datasetFiles.Add(datasetFile);
            }
            return(datasetFiles);
        }
        private List <DatasetFile> ConvertToModel(List <DatasetFileViewModel> datasetFilesViewModel)
        {
            var datasetFiles = new List <DatasetFile>();

            foreach (var datasetFileViewModel in datasetFilesViewModel)
            {
                var datasetFile = new DatasetFile(datasetFileViewModel);
                datasetFiles.Add(datasetFile);
            }
            return(datasetFiles);
        }
Beispiel #4
0
 public DatasetFileViewModel(DatasetFile datasetFile, string epsgName, bool selectedForDownload = false)
 {
     Title               = datasetFile.Title;
     Description         = datasetFile.Description;
     Url                 = datasetFile.Url;
     LastUpdated         = datasetFile.LastUpdated;
     Organization        = datasetFile.Organization;
     Category            = datasetFile.Projection;
     DatasetId           = datasetFile.DatasetId;
     DatasetUrl          = datasetFile.DatasetUrl;
     Id                  = GetId();
     SelectedForDownload = selectedForDownload;
     IsRestricted        = datasetFile.IsRestricted();
     Restrictions        = datasetFile.Restrictions;
     EpsgName            = epsgName;
 }
Beispiel #5
0
        public DownloadUsageEntries(DatasetFile datasetFile)
        {
            MetadataUuid = datasetFile.DatasetId; // TODO legg til metadata uuid i dataset file..
            var title = datasetFile.Title.Split(',');

            if (title.Length == 3)
            {
                AreaCode = title[1].Trim();
                AreaName = title[2];
                Format   = title[0];
            }
            else if (title.Length == 2)
            {
                AreaName = title[1];
                Format   = title[0];
            }
            Projection = datasetFile.Projection;
        }
 public DatasetFileViewModel(DatasetFile datasetFile, string epsgName, bool selectedForDownload = false)
 {
     Title               = datasetFile.Title;
     Description         = datasetFile.Description;
     Url                 = datasetFile.Url;
     LastUpdated         = datasetFile.LastUpdated;
     Organization        = datasetFile.Organization;
     Category            = datasetFile.Projection;
     Format              = datasetFile.Format;
     AreaCode            = datasetFile.AreaCode;
     AreaLabel           = datasetFile.AreaLabel;
     County              = datasetFile.County;
     DatasetId           = datasetFile.DatasetId;
     DatasetUrl          = FixDatasetUrl(datasetFile.DatasetUrl);
     Id                  = GetId();
     SelectedForDownload = selectedForDownload;
     IsRestricted        = datasetFile.IsRestricted();
     Restrictions        = datasetFile.Restrictions;
     EpsgName            = epsgName;
 }
Beispiel #7
0
        public List <DatasetFile> ParseDatasetFiles(string xml, string datasetTitle, string datasetUrl)
        {
            var datasetFiles = new List <DatasetFile>();

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);

            string xpath = "//a:feed/a:entry";

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

            nsmgr.AddNamespace("a", "http://www.w3.org/2005/Atom");
            nsmgr.AddNamespace("inspire_dls", "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0");
            nsmgr.AddNamespace("gn", "http://geonorge.no/Atom");

            var nodes = xmlDoc.SelectNodes(xpath, nsmgr);

            foreach (XmlNode childrenNode in nodes)
            {
                var datasetFile = new DatasetFile();
                datasetFile.Title        = childrenNode.SelectSingleNode("a:title", nsmgr).InnerXml;
                datasetFile.Description  = GetDescription(childrenNode, nsmgr);
                datasetFile.Url          = GetUrl(childrenNode, nsmgr);
                datasetFile.LastUpdated  = GetLastUpdated(childrenNode, nsmgr);
                datasetFile.Projection   = GetProjection(childrenNode.SelectNodes("a:category", nsmgr));
                datasetFile.Format       = GetFormat(childrenNode.SelectSingleNode("a:title", nsmgr), childrenNode.SelectNodes("a:category", nsmgr));
                datasetFile.Restrictions = GetRestrictions(childrenNode.SelectNodes("a:category", nsmgr));
                datasetFile.DatasetId    = datasetTitle;
                datasetFile.DatasetUrl   = datasetUrl;
                datasetFile.AreaCode     = GetAreaCode(childrenNode.SelectNodes("a:category", nsmgr));
                datasetFile.AreaLabel    = GetAreaLabel(childrenNode.SelectNodes("a:category", nsmgr));
                datasetFile.Organization = GetOrganization(childrenNode, nsmgr, null, datasetFile);
                datasetFile.County       = GetCounty(childrenNode, nsmgr, datasetFile);

                datasetFiles.Add(datasetFile);
            }
            return(datasetFiles);
        }
Beispiel #8
0
        internal DatasetFile ParseDatasetFile(string xml, DatasetFile originalDatasetFile)
        {
            var datasetFileFromFeed = new DatasetFile();

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xml);

            string xpath = "//a:feed/a:entry";

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

            nsmgr.AddNamespace("a", "http://www.w3.org/2005/Atom");
            nsmgr.AddNamespace("inspire_dls", "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0");
            nsmgr.AddNamespace("gn", "http://geonorge.no/Atom");

            var nodes = xmlDoc.SelectNodes(xpath, nsmgr);

            foreach (XmlNode childrenNode in nodes)
            {
                string title      = childrenNode.SelectSingleNode("a:title", nsmgr).InnerXml;
                string projection = GetProjection(childrenNode.SelectNodes("a:category", nsmgr));

                if (originalDatasetFile.Title == title && originalDatasetFile.Projection == projection)
                {
                    datasetFileFromFeed.Title        = title;
                    datasetFileFromFeed.Description  = GetDescription(childrenNode, nsmgr);
                    datasetFileFromFeed.Url          = GetUrl(childrenNode, nsmgr);
                    datasetFileFromFeed.LastUpdated  = GetLastUpdated(childrenNode, nsmgr);
                    datasetFileFromFeed.Projection   = projection;
                    datasetFileFromFeed.Restrictions = GetRestrictions(childrenNode.SelectNodes("a:category", nsmgr));
                    datasetFileFromFeed.DatasetId    = originalDatasetFile.DatasetId;
                    datasetFileFromFeed.DatasetUrl   = originalDatasetFile.DatasetUrl;
                    datasetFileFromFeed.Organization = GetOrganization(childrenNode, nsmgr, null, datasetFileFromFeed);
                }
            }
            return(datasetFileFromFeed);
        }
Beispiel #9
0
        private string GetOrganization(XmlNode childrenNode, XmlNamespaceManager nsmgr, Dataset dataset, DatasetFile datasetFile = null)
        {
            string organization = "";

            if ((dataset != null && dataset.Url.Contains("miljodirektoratet")) ||
                (datasetFile != null && datasetFile.Url.Contains("miljodirektoratet")))
            {
                nsmgr.RemoveNamespace("gn", "http://geonorge.no/Atom");
                nsmgr.AddNamespace("gn", "http://geonorge.no/geonorge");
            }

            var organizationGN = childrenNode.SelectSingleNode("a:author/gn:organisation", nsmgr);

            if (organizationGN != null)
            {
                organization = organizationGN.InnerXml;
            }
            else if (childrenNode.SelectSingleNode("a:author/a:name", nsmgr) != null)
            {
                organization = childrenNode.SelectSingleNode("a:author/a:name", nsmgr).InnerXml;
            }
            else
            {
                organization = "Kartverket";
            }

            if (dataset != null && string.IsNullOrEmpty(dataset.Organization) && dataset.Url.Contains("ngu.no"))
            {
                organization = "Norges geologiske undersøkelse";
            }
            else if (dataset != null && string.IsNullOrEmpty(dataset.Organization) && dataset.Url.Contains("nibio.no"))
            {
                organization = "Norsk institutt for bioøkonomi";
            }

            if (datasetFile != null && string.IsNullOrEmpty(datasetFile.Organization) && datasetFile.Url.Contains("ngu.no"))
            {
                organization = "Norges geologiske undersøkelse";
            }
            else if (datasetFile != null && string.IsNullOrEmpty(datasetFile.Organization) && datasetFile.Url.Contains("nibio.no"))
            {
                organization = "Norsk institutt for bioøkonomi";
            }

            return(organization);
        }
Beispiel #10
0
        private string GetCounty(XmlNode node, XmlNamespaceManager nsmgr, DatasetFile datasetFile)
        {
            if (int.TryParse(datasetFile.AreaCode, out _) && (datasetFile.AreaCode.Length == 2 || datasetFile.AreaCode.Length == 4))
            {
                if (datasetFile.AreaCode.Length == 2)
                {
                    return(datasetFile.AreaCode);
                }
                else
                {
                    return(datasetFile.AreaCode.Substring(0, 2));
                }
            }
            else if (datasetFile.Organization == "Norges geologiske undersøkelse" || datasetFile.Organization == "Norsk institutt for bioøkonomi")
            {
                var summary = node.SelectSingleNode("a:summary", nsmgr)?.InnerXml;
                if (!string.IsNullOrEmpty(summary) && summary.EndsWith(".zip"))
                {
                    if (datasetFile.Organization == "Norges geologiske undersøkelse")
                    {
                        var data = summary.Split('_');
                        if (data.Length > 1)
                        {
                            var county = data[1];
                            if (int.TryParse(county, out _) && (county.Length == 2 || county.Length == 4))
                            {
                                if (county.Length == 2)
                                {
                                    return(county);
                                }
                                else
                                {
                                    return(county.Substring(0, 2));
                                }
                            }
                        }
                    }
                    else if (datasetFile.Organization == "Norsk institutt for bioøkonomi")
                    {
                        var data = summary.Split('_');
                        if (data.Length > 1)
                        {
                            var countyData = data[0];
                            if (countyData.Contains("-"))
                            {
                                var county = countyData.Split('-')[1];
                                if (int.TryParse(county, out _) && (county.Length == 2 || county.Length == 4))
                                {
                                    if (county.Length == 2)
                                    {
                                        return(county);
                                    }
                                    else
                                    {
                                        return(county.Substring(0, 2));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                string filename = datasetFile.Url.Split('/').Last();
                var    data     = filename.Split('_');
                if (data.Length > 1)
                {
                    var county = data[1];
                    if (int.TryParse(county, out _) && (county.Length == 2 || county.Length == 4))
                    {
                        if (county.Length == 2)
                        {
                            return(county);
                        }
                        else
                        {
                            return(county.Substring(0, 2));
                        }
                    }
                }
            }

            return("");
        }
        private static string GetEpsgName(List <Projections> projections, DatasetFile selectedFile)
        {
            var projection = projections.FirstOrDefault(p => p.Epsg == selectedFile.Projection);

            return(projection != null ? projection.Name : selectedFile.Projection);
        }
        private static string GetEpsgName(DatasetFile selectedFile)
        {
            var projection = ApplicationService.GetProjections().FirstOrDefault(p => p.Epsg == selectedFile.Projection);

            return(projection != null ? projection.Name : selectedFile.Projection);
        }