/// <summary> /// Save the added discrepancy to the json file /// </summary> private void SaveJson() { foreach (var item in _discrepanciesGenerator.dcList) { foreach (var dictionary in item.discrepancyDictionary) { if (dictionary.difficulty > 10) { dictionary.difficulty = 10; } } } // copies the dcGen list. List <Discrepancy> dcList = _discrepanciesGenerator.dcList; // creates new DcList object to store JSOn in. DcList dcObject = new DcList(dcList); string json = JsonUtility.ToJson(dcObject); File.WriteAllText(_path, json); }
public void SetServiceProps(DcList references) { // determine the service url, name and type LinkedList<String> schemeVals = references.get(DcList.getScheme(DcList.Scheme.SERVER)); if (schemeVals.Count > 0) { mapServerURL = chkStr(schemeVals.First.Value); } if (mapServerURL == null) mapServerURL = String.Empty; ; schemeVals = references.get(DcList.getScheme(DcList.Scheme.SERVICE)); if (schemeVals.Count > 0) { serviceName = chkStr(schemeVals.First.Value); } schemeVals = references.get(DcList.getScheme(DcList.Scheme.SERVICE_TYPE)); if (schemeVals.Count > 0) { this.Protocol = (schemeVals.First.Value); } if ((mapServerURL.Length > 0) && (this.Protocol == null)) { this.Protocol = CswProfile.DeduceProtocolFromURL(mapServerURL); } // handle the case where an ArcIMS service has been specified with // server/service/this.Protocol parameters if ((mapServerURL.Length > 0) && (this.Protocol.Equals("image", StringComparison.CurrentCultureIgnoreCase) || this.Protocol.Equals("feature") || this.Protocol.Equals("metadata"))) { if ((serviceName.Length > 0)) { String esrimap = "servlet/com.esri.esrimap.Esrimap"; if (mapServerURL.IndexOf("esrimap") == -1) { if (mapServerURL.IndexOf("?") == -1) { if (!mapServerURL.EndsWith("/")) mapServerURL += "/"; mapServerURL = mapServerURL + esrimap + "?ServiceName=" + serviceName; } } else { if (mapServerURL.IndexOf("?") == -1) { mapServerURL = mapServerURL + "?ServiceName=" + serviceName; } else if (mapServerURL.IndexOf("ServiceName=") == -1) { mapServerURL = mapServerURL + "&ServiceName=" + serviceName; } } } if (this.Protocol.Equals("image")) { this.Protocol = "aims"; } } // if the resource url has not been directly specified through a "scheme" attribute, // then attempt to pick the best fit for the collection of references if (mapServerURL.Length == 0) { foreach (DcList.Value reference in references) { if (reference != null) { String url = reference.getValue(); String type = CswProfile.DeduceProtocolFromURL(url); if (type.Length > 0) { mapServerURL = url; this.Protocol = type; break; } } } } }
/// <summary> /// Determins resource urls /// </summary> /// <param name="cswRecord">CswRecord object</param> /// <param name="references">List of references</param> private void determineResourceUrl(CswRecord cswRecord, DcList references) { // initialize String resourceUrl = ""; String serviceType = ""; String serviceName = ""; // determine the service url, name and type LinkedList<String> schemeVals = references.get(DcList.getScheme(DcList.Scheme.SERVER)); if (schemeVals.Count > 0) { resourceUrl = chkStr(schemeVals.First.Value); } schemeVals = references.get(DcList.getScheme(DcList.Scheme.SERVICE)); if (schemeVals.Count > 0) { serviceName = chkStr((schemeVals.First.Value)); } schemeVals = references.get(DcList.getScheme(DcList.Scheme.SERVICE_TYPE)); if (schemeVals.Count > 0) { serviceType = (schemeVals.First.Value); } if ((resourceUrl.Length > 0) && (serviceType.Length == 0)) { serviceType = getServiceType(resourceUrl); } // handle the case where an ArcIMS service has been specified with // server/service/serviceType parameters if ((resourceUrl.Length > 0) && (serviceType.Equals("image", StringComparison.CurrentCultureIgnoreCase) || serviceType.Equals("feature") || serviceType.Equals("metadata"))) { if ((serviceName.Length > 0)) { String esrimap = "servlet/com.esri.esrimap.Esrimap"; if (resourceUrl.IndexOf("esrimap") == -1) { if (resourceUrl.IndexOf("?") == -1) { if (!resourceUrl.EndsWith("/")) resourceUrl += "/"; resourceUrl = resourceUrl + esrimap + "?ServiceName=" + serviceName; } } else { if (resourceUrl.IndexOf("?") == -1) { resourceUrl = resourceUrl + "?ServiceName=" + serviceName; } else if (resourceUrl.IndexOf("ServiceName=") == -1) { resourceUrl = resourceUrl + "&ServiceName=" + serviceName; } } } if (serviceType.Equals("image")) { serviceType = "aims"; } } // if the resource url has not been directly specified through a "scheme" attribute, // then attempt to pick the best fit for the collection of references if (resourceUrl.Length == 0) { foreach (DcList.Value reference in references) { if (reference != null) { String url = reference.getValue(); String type = getServiceType(url); if (type.Length > 0) { resourceUrl = url; serviceType = type; break; } } } } // update the record cswRecord.MapServerURL = resourceUrl; cswRecord.ServiceName = serviceName; cswRecord.ServiceType = serviceType; }
/// <summary> /// Parse a CSW response. /// </summary> /// <remarks> /// The CSW response is parsed and the records collection is populated /// with the result.The reponse is parsed based on the response xslt. /// </remarks> /// <param name="param1">The string response</param> /// <param name="param2">The recordlist which needs to be populated</param> public void ReadCSWGetRecordsResponse(string responsestring, CswRecords recordslist) { try { TextReader textreader = new StringReader(responsestring); XmlTextReader xmltextreader = new XmlTextReader(textreader); //load the Xml doc XPathDocument xPathDoc = new XPathDocument(xmltextreader); if (responsexsltobj == null) { responsexsltobj = new XslCompiledTransform(); XsltSettings settings = new XsltSettings(true, true); responsexsltobj.Load(responsexslt, settings, new XmlUrlResolver()); } //create the output stream StringWriter writer = new StringWriter(); //do the actual transform of Xml responsexsltobj.Transform(xPathDoc, null, writer); writer.Close(); //populate CswRecords XmlDocument doc = new XmlDocument(); doc.LoadXml(writer.ToString()); XmlNodeList xmlnodes = doc.GetElementsByTagName("Record"); foreach (XmlNode xmlnode in xmlnodes) { CswRecord record = new CswRecord(); record.ID = xmlnode.SelectSingleNode("ID").InnerText; record.Title = xmlnode.SelectSingleNode("Title").InnerText; record.Abstract = xmlnode.SelectSingleNode("Abstract").InnerText; String lowercorner = ""; if (this.SupportSpatialBoundary) { lowercorner = xmlnode.SelectSingleNode("LowerCorner").InnerText; } String uppercorner = ""; if (this.SupportSpatialBoundary) { uppercorner = xmlnode.SelectSingleNode("UpperCorner").InnerText; } if ((lowercorner.Length > 0 && uppercorner.Length > 0)) { /* record.BoundingBox.Maxx = Double.Parse(lowercorner.Substring(0, lowercorner.IndexOf(' '))); record.BoundingBox.Miny = Double.Parse(lowercorner.Substring(lowercorner.IndexOf(' ') + 1)); record.BoundingBox.Minx = Double.Parse(uppercorner.Substring(0, uppercorner.IndexOf(' '))); record.BoundingBox.Maxy = Double.Parse(uppercorner.Substring(uppercorner.IndexOf(' ') + 1));*/ Boolean parseFlag = false; CultureInfo cultureInfo = new CultureInfo("en-us"); double pareseResult = 0.0; parseFlag = Double.TryParse(lowercorner.Substring(0, lowercorner.IndexOf(' ')), NumberStyles.Number, cultureInfo, out pareseResult); record.BoundingBox.Minx = pareseResult; parseFlag = Double.TryParse(lowercorner.Substring(lowercorner.IndexOf(' ') + 1), NumberStyles.Number, cultureInfo, out pareseResult); record.BoundingBox.Miny = pareseResult; parseFlag = Double.TryParse(uppercorner.Substring(0, uppercorner.IndexOf(' ')), NumberStyles.Number, cultureInfo, out pareseResult); record.BoundingBox.Maxx = pareseResult; parseFlag = Double.TryParse(uppercorner.Substring(uppercorner.IndexOf(' ') + 1), NumberStyles.Number, cultureInfo, out pareseResult); record.BoundingBox.Maxy = pareseResult; if (parseFlag == false) { throw new Exception("Number format error"); } } else { record.BoundingBox.Maxx = 500.00; record.BoundingBox.Miny = 500.00; record.BoundingBox.Minx = 500.00; record.BoundingBox.Maxy = 500.00; } XmlNode node = xmlnode.SelectSingleNode("Type"); if (node != null) { record.IsLiveDataOrMap = node.InnerText.Equals("liveData", StringComparison.OrdinalIgnoreCase); if (!record.IsLiveDataOrMap) { record.IsLiveDataOrMap = node.InnerText.Equals("downloadableData", StringComparison.OrdinalIgnoreCase); } } else { record.IsLiveDataOrMap = false; } XmlNode referencesNode = xmlnode.SelectSingleNode("References"); if (referencesNode != null) { String references = referencesNode.InnerText; DcList list = new DcList(); list.add(references); determineResourceUrl(record, list); /* LinkedList<String> serverList = list.get(DcList.getScheme(DcList.Scheme.SERVER)); if (serverList.Count > 0) { String serviceType = getServiceType(serverList.First.Value); if (serviceType.Equals("aims") || serviceType.Equals("ags") || serviceType.Equals("wms") || serviceType.Equals("wcs")) { record.MapServerURL = serverList.First.Value; } }*/ } else record.MapServerURL = ""; recordslist.AddRecord(record.ID.GetHashCode(), record); } } catch (Exception e) { throw e; } //return recordslist; }
/// <summary> /// Read a CSW metadata response. /// </summary> /// <remarks> /// The CSW metadata response is read. /// The CSw record is updated with the metadata /// </remarks> /// <param name="param1">The metadata response string</param> /// <param name="param2">The CSW record for the record</param> public void ReadCSWGetMetadataByIDResponse(string response, CswRecord record) { if (metadataxslt == null || metadataxslt.Equals("")) { record.FullMetadata = response; record.MetadataResourceURL = ""; } else { //create the output stream StringWriter writer = new StringWriter(); TextReader textreader = new StringReader(response); XmlTextReader xmltextreader = new XmlTextReader(textreader); //load the Xml doc XPathDocument xpathDoc = new XPathDocument(xmltextreader); if (metadataxsltobj == null) { metadataxsltobj = new XslCompiledTransform(); //enable document() support XsltSettings settings = new XsltSettings(true, true); metadataxsltobj.Load(metadataxslt, settings, new XmlUrlResolver()); } //do the actual transform of Xml metadataxsltobj.Transform(xpathDoc, null, writer); writer.Close(); // full metadata or resource url String outputStr = writer.ToString(); if (IsUrl(outputStr)) { if (outputStr.Contains("\u2715")) { DcList list = new DcList(); list.add(outputStr); LinkedList<String> serverList = list.get(DcList.getScheme(DcList.Scheme.SERVER)); LinkedList<String> documentList = list.get(DcList.getScheme(DcList.Scheme.METADATA_DOCUMENT)); if (serverList.Count > 0) { String serviceType = getServiceType(serverList.First.Value); if (serviceType.Equals("aims") || serviceType.Equals("ags") || serviceType.Equals("wms") || serviceType.Equals("wcs")) { record.MapServerURL = serverList.First.Value; } } else record.MapServerURL = ""; if (documentList.Count > 0) record.MetadataResourceURL = documentList.First.Value; } else { if (getServiceType(response).Equals("ags")) { outputStr = outputStr.Replace("http", "|http"); string[] s = outputStr.Split('|'); for (int i = 0; i < s.Length; i++) { if (s[i].ToString().Contains("MapServer")) record.MapServerURL = s[i]; else record.MetadataResourceURL = s[i]; } } else { record.MapServerURL = ""; record.MetadataResourceURL = outputStr; } } record.FullMetadata = ""; } else { record.MapServerURL = ""; record.MetadataResourceURL = ""; record.FullMetadata = outputStr; } } }