/// <summary> /// Gets OperationsMetadata section /// </summary> /// <returns></returns> protected virtual OperationsMetadata GetOperationsMetadata(IHttpContextAccessor accessor, IMemoryCache cache, IServiceProvider serviceProvider) { OperationsMetadata om = new OperationsMetadata(); // Add services information base on configuration foreach (ServiceOperationElement operationInfo in this.Services.ToList()) { // Take only SOS services if (!operationInfo.Service.Equals(this.ServiceName, StringComparison.OrdinalIgnoreCase)) { continue; } BaseOperation operationHandler = operationInfo.CreateHandlerInstance(accessor, cache, serviceProvider); Operation operation = new Operation(); operation.Name = operationInfo.Operation; // Add operation dcps if (operationHandler.OperationDcps != null) { foreach (Dcp dcp in operationHandler.OperationDcps) { operation.Dcps.Add(dcp); } } // Add operation parameters if (operationHandler.OperationParameters != null) { foreach (DomainType parameter in operationHandler.OperationParameters) { operation.Parameters.Add(parameter); } } // Add operation constrains if (operationHandler.OperationConstraints != null) { foreach (DomainType constraint in operationHandler.OperationConstraints) { operation.Constraints.Add(constraint); } } // Add operation metadata if (operationHandler.OperationMetadata != null) { foreach (MetadataType metadata in operationHandler.OperationMetadata) { operation.Metadata.Add(metadata); } } om.Operations.Add(operation); } // Specify service parameter om.Parameters.Add(new DomainType() { Name = "service", AllowedValues = new Collection <object>() { new Terradue.ServiceModel.Ogc.Ows11.ValueType(this.ServiceName), }, }); om.Parameters.Add(new DomainType() { Name = "version", AllowedValues = new Collection <object>(), }); if (this.SupportedVersions.Count > 0) { DomainType parameter = om.Parameters[om.Parameters.Count - 1]; foreach (var version in this.SupportedVersions) { parameter.AllowedValues.Add(new Terradue.ServiceModel.Ogc.Ows11.ValueType(version)); } } return(om); }
public virtual Capabilities CreateCapabilities(string href) { #region ServiceIdentification LanguageStringType[] titles = new LanguageStringType[] { new LanguageStringType() { Value = "Web Map Tile Service" } }; LanguageStringType[] abstracts = new LanguageStringType[] { new LanguageStringType() { Value = "Service that contrains the map access interface to some TileMatrixSets" } }; LanguageStringType[] keyword1 = new LanguageStringType[] { new LanguageStringType() { Value = "tile" } }; KeywordsType keywordsType1 = new KeywordsType() { Keyword = keyword1 }; LanguageStringType[] keyword2 = new LanguageStringType[] { new LanguageStringType() { Value = "map" } }; KeywordsType keywordsType2 = new KeywordsType() { Keyword = keyword2 }; KeywordsType[] keywords = new KeywordsType[] { keywordsType1, keywordsType2 }; CodeType serviceType = new CodeType() { Value = "OGC WMTS" }; string[] serviceTypeVersion = new string[] { "1.0.0" }; string fees = "none"; string[] accessConstraints = new string[] { "none" }; ServiceIdentification serviceIdentification = new ServiceIdentification() { Title = titles, Abstract = abstracts, Keywords = keywords, ServiceType = serviceType, ServiceTypeVersion = serviceTypeVersion, Fees = fees, AccessConstraints = accessConstraints }; #endregion #region ServiceProvider string poroviderName = "SharpMapServer"; OnlineResourceType providerSiteType = new OnlineResourceType() { href = href }; string[] voices = new string[] { "0000-00000000" }; string[] facsimiles = new string[] { "0001-00000001" }; TelephoneType phone = new TelephoneType() { Voice = voices, Facsimile = facsimiles }; string[] deliveryPoints = new string[] { "jinjiang" }; string city = "chengdu"; string administrativeArea = "sichuan"; string country = "china"; string[] electronicMailAddress = new string[] { "*****@*****.**" }; string postalCode = "123456"; AddressType address = new AddressType() { DeliveryPoint = deliveryPoints, City = city, AdministrativeArea = administrativeArea, Country = country, ElectronicMailAddress = electronicMailAddress, PostalCode = postalCode }; ContactType contactInfo = new ContactType() { Phone = phone, Address = address }; string individualName = "lc"; string positionName = "Senior Software Engineer"; ResponsiblePartySubsetType serviceContact = new ResponsiblePartySubsetType() { IndividualName = individualName, PositionName = positionName, ContactInfo = contactInfo }; ServiceProvider serviceProvider = new ServiceProvider() { ProviderName = poroviderName, ProviderSite = providerSiteType, ServiceContact = serviceContact }; #endregion #region OperationsMetadata Operation getCapabilitiesOperation = GetOperation(href, "GetCapabilities"); Operation getTileOperation = GetOperation(href, "GetTile"); Operation getFeatureinfoOperation = GetOperation(href, "GetFeatureinfo"); Operation[] operations = new Operation[] { getCapabilitiesOperation, getTileOperation, getFeatureinfoOperation }; OperationsMetadata operationsMetadata = new OperationsMetadata() { Operation = operations }; #endregion Capabilities capabilities = new Capabilities() { ServiceIdentification = serviceIdentification, ServiceProvider = serviceProvider, OperationsMetadata = operationsMetadata }; return(capabilities); }
static void TestWmts() { XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides(); XmlAttributes ddsAttrs = new XmlAttributes(); XmlElementAttribute layerAttr = new XmlElementAttribute { ElementName = "Layer", Type = typeof(LayerType) }; ddsAttrs.XmlElements.Add(layerAttr); attrOverrides.Add(typeof(ContentsBaseType), "DatasetDescriptionSummary", ddsAttrs); #region ServiceIdentification LanguageStringType[] titles = new LanguageStringType[] { new LanguageStringType() { Value = "Web Map Tile Service" } }; LanguageStringType[] abstracts = new LanguageStringType[] { new LanguageStringType() { Value = "Service that contrains the map access interface to some TileMatrixSets" } }; LanguageStringType[] keyword1 = new LanguageStringType[] { new LanguageStringType() { Value = "tile" } }; KeywordsType keywordsType1 = new KeywordsType() { Keyword = keyword1 }; LanguageStringType[] keyword2 = new LanguageStringType[] { new LanguageStringType() { Value = "map" } }; KeywordsType keywordsType2 = new KeywordsType() { Keyword = keyword2 }; KeywordsType[] keywords = new KeywordsType[] { keywordsType1, keywordsType2 }; CodeType serviceType = new CodeType() { Value = "OGC WMTS" }; string[] serviceTypeVersion = new string[] { "1.0.0" }; string fees = "none"; string[] accessConstraints = new string[] { "none" }; ServiceIdentification serviceIdentification = new ServiceIdentification() { Title = titles, Abstract = abstracts, Keywords = keywords, ServiceType = serviceType, ServiceTypeVersion = serviceTypeVersion, Fees = fees, AccessConstraints = accessConstraints }; #endregion string href = "http://123"; #region ServiceProvider string poroviderName = "SharpMapServer"; OnlineResourceType providerSiteType = new OnlineResourceType() { href = href }; string[] voices = new string[] { "0000-00000000" }; string[] facsimiles = new string[] { "0001-00000001" }; TelephoneType phone = new TelephoneType() { Voice = voices, Facsimile = facsimiles }; string[] deliveryPoints = new string[] { "jinjiang" }; string city = "chengdu"; string administrativeArea = "sichuan"; string country = "china"; string[] electronicMailAddress = new string[] { "*****@*****.**" }; string postalCode = "123456"; AddressType address = new AddressType() { DeliveryPoint = deliveryPoints, City = city, AdministrativeArea = administrativeArea, Country = country, ElectronicMailAddress = electronicMailAddress, PostalCode = postalCode }; ContactType contactInfo = new ContactType() { Phone = phone, Address = address }; string individualName = "lc"; string positionName = "Senior Software Engineer"; ResponsiblePartySubsetType serviceContact = new ResponsiblePartySubsetType() { IndividualName = individualName, PositionName = positionName, ContactInfo = contactInfo }; ServiceProvider serviceProvider = new ServiceProvider() { ProviderName = poroviderName, ProviderSite = providerSiteType, ServiceContact = serviceContact }; #endregion #region OperationsMetadata Operation getCapabilitiesOperation = CapabilitiesHelper.GetOperation(href, "GetCapabilities"); Operation getTileOperation = CapabilitiesHelper.GetOperation(href, "GetTile"); Operation getFeatureinfoOperation = CapabilitiesHelper.GetOperation(href, "GetFeatureinfo"); Operation[] operations = new Operation[] { getCapabilitiesOperation, getTileOperation, getFeatureinfoOperation }; OperationsMetadata operationsMetadata = new OperationsMetadata() { Operation = operations }; #endregion Capabilities capabilities = new Capabilities() { ServiceIdentification = serviceIdentification, ServiceProvider = serviceProvider, OperationsMetadata = operationsMetadata }; IWmtsService wmts1Service = OgcServiceHelper.GetOgcService("WMTS", "1.0.0") as IWmtsService; wmts1Service.AddContent(capabilities, @"E:\LC\数据\双流\2014年遥感影像.img"); List <object> objs = new List <object>(); capabilities.Themes = new Themes[] { new Themes() { Theme = new Theme[] { new Theme() { Identifier = new CodeType() { Value = "123" } } } } }; objs.Add(capabilities); StringBuilder sb = new StringBuilder(); using (TextWriter tw = new StringWriter(sb)) { foreach (var item in objs) { if (item == null) { continue; } var serializer = new XmlSerializer(item.GetType(), attrOverrides); serializer.Serialize(tw, item); var val = sb.ToString(); File.WriteAllText("123.xml", val); sb.Clear(); } } }