public static void SaveCapabilities(IWmtsService wmtsService, string capabilitiesPath, Capabilities capabilities) { using (StreamWriter sw = new StreamWriter(capabilitiesPath)) { wmtsService.XmlSerialize(sw, capabilities); } }
private async Task <ContentResult> GetCapabilities(string serviceName, GetCapabilities getCapabilities) { ContentResult result = new ContentResult() { ContentType = "application/xml" }; int statusCode = 200; ExceptionReport exception = null; if (string.IsNullOrWhiteSpace(serviceName)) { exception = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "serviceName", exceptionText: "Bad request"); statusCode = 400; goto Exception; } string version = null; if (getCapabilities.AcceptVersions?.Length > 0) { version = getCapabilities.AcceptVersions[0]; } if (string.IsNullOrWhiteSpace(version)) { exception = ExceptionReportHelper.GetExceptionReport("MissingParameterValue", "version", exceptionText: "Bad request"); statusCode = 400; goto Exception; } if (version != "1.0.0") { exception = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", "version", exceptionText: "Bad request"); statusCode = 400; goto Exception; } ServiceRecord serviceRecord = await GetServiceRecord(serviceName, version); if (serviceRecord == null) { exception = ExceptionReportHelper.GetExceptionReport("InvalidParameterValue", exceptionText: "Bad request"); statusCode = 400; goto Exception; } if (!System.IO.File.Exists(serviceRecord.Path)) { exception = ExceptionReportHelper.GetExceptionReport("NoApplicableCode", exceptionText: "Internal server error"); statusCode = 500; goto Exception; } IWmtsService wmts1Service = GetWmts1Service(version); Capabilities capabilities = wmts1Service.GetCapabilities(serviceRecord.Path, getCapabilities); if (getCapabilities.AcceptFormats?.Length > 0) { result.ContentType = getCapabilities.AcceptFormats[0].Trim(); } StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { wmts1Service.XmlSerialize(sw, capabilities); sw.Close(); } result.Content = sb.ToString(); goto Success; Exception: result.Content = XmlHelper.XmlSerialize(exception, Encoding, null); Success: result.StatusCode = statusCode; return(result); }