Exemple #1
0
        public async Task RemoveLayerFromCapabilities(ServiceRecord serviceRecord, string capabilitiesPath, LayerRecord layerRecord)
        {
            if (layerRecord == null)
            {
                return;
            }
            #region  除数据库及数据
            _configContext.Layers.Remove(layerRecord);
            var ret = await _configContext.SaveChangesAsync();

            DeleteDataSet(layerRecord.Path);
            #endregion
            #region  除XML中的图层
            IOgcService ogcService = GetOgcService(serviceRecord.Type, serviceRecord.Version);
            switch (serviceRecord.Type)
            {
            case OgcServiceType.Wmts:
                IWmtsService wmtsService  = ogcService as IWmtsService;
                Capabilities capabilities = GetCapabilities(wmtsService, capabilitiesPath);
                wmtsService.RemoveLayerType(capabilities, layerRecord.Name);
                SaveCapabilities(wmtsService, capabilitiesPath, capabilities);
                break;
            }
            #endregion
        }
Exemple #2
0
        public bool AddLayerToCapabilities(ServiceRecord serviceRecord, string capabilitiesPath, string layerPath)
        {
            bool        ret        = false;
            IOgcService ogcService = GetOgcService(serviceRecord.Type, serviceRecord.Version);

            switch (serviceRecord.Type)
            {
            case OgcServiceType.Wmts:
                IWmtsService wmtsService  = ogcService as IWmtsService;
                Capabilities capabilities = GetCapabilities(wmtsService, capabilitiesPath);
                if (capabilities != null)
                {
                    LayerType layerType = wmtsService.AddLayerType(capabilities, layerPath);
                    if (layerType != null)
                    {
                        SaveCapabilities(wmtsService, capabilitiesPath, capabilities);
                        ret = true;
                    }
                }
                break;
            }
            if (ret)
            {
                string      destName    = Path.GetFileNameWithoutExtension(layerPath);
                LayerRecord layerRecord = new LayerRecord()
                {
                    Name    = destName,
                    Path    = layerPath,
                    Service = serviceRecord
                };
                _configContext.Layers.Add(layerRecord);
            }
            return(ret);
        }
        public async Task <bool> CreateService(string serviceName, string serviceType, string version, IEnumerable <string> files)
        {
            bool   ret = false;
            string url = null;

            if (string.IsNullOrEmpty(serviceName) || string.IsNullOrEmpty(serviceType) || string.IsNullOrEmpty(version) || files == null || files.Count() == 0)
            {
                return(ret);
            }
            bool isExisted = await ExistedService(serviceName, serviceType, version);

            if (isExisted)
            {
                return(ret);
            }
            string      href             = JsonSettings.DefaultSettings.GetValue <string>("href");
            string      capabilitiesPath = null;
            IOgcService ogcService       = OgcServiceHelper.GetOgcService(serviceType, version);
            Dictionary <string, string> layerNameAndPathes = new Dictionary <string, string>();

            if (ogcService is IWmtsService wmts1Service)
            {
                href = $"{href}/SharpMapServer/Services/{serviceName}/MapServer/Wmts";
                Capabilities capabilities = wmts1Service.CreateCapabilities(href);
                string       directory    = null;
                foreach (var file in files)
                {
                    if (directory == null)
                    {
                        directory = Path.GetDirectoryName(file);
                    }
                    LayerType layerType = wmts1Service.AddContent(capabilities, file);
                    string    name      = Path.GetFileNameWithoutExtension(file);
                    layerNameAndPathes[name] = file;
                }
                capabilitiesPath = Path.Combine(directory, "WMTSCapabilities.xml");
                using (StreamWriter sw = new StreamWriter(capabilitiesPath))
                {
                    wmts1Service.XmlSerialize(sw, capabilities);
                }
                url = $"{href}/1.0.0/WMTSCapabilities.xml";
            }
            else
            {
                return(ret);
            }
            ret = await AddServiceRecord(serviceName, serviceType, version, capabilitiesPath);

            ServiceRecord serviceRecord = await GetServiceRecord(serviceName, serviceType, version);

            foreach (var item in layerNameAndPathes)
            {
                bool result = await AddLayerRecord(serviceRecord, item.Key, item.Value);
            }
            if (!ret)
            {
                File.Delete(capabilitiesPath);
            }
            return(ret);
        }
Exemple #4
0
        public async Task <bool> CreateCapabilities(OgcServiceType serviceType, string serviceVersion, string serviceName)
        {
            bool ret = false;

            if (_configContext == null || _servicePathManager == null || string.IsNullOrEmpty(serviceVersion) || string.IsNullOrEmpty(serviceName) || string.IsNullOrEmpty(_host))
            {
                Debug.WriteLine("参数不能为空");
                return(ret);
            }
            ServiceRecord serviceRecord = await _configContext.Services.FirstOrDefaultAsync(x => x.Type == serviceType && x.Version == serviceVersion && x.Name == serviceName);

            if (serviceRecord != null)
            {
                return(ret);
            }
            string serviceDirectory = _servicePathManager.GetServiceDirectory(serviceType, serviceVersion, serviceName);

            if (!Directory.Exists(serviceDirectory))
            {
                Directory.CreateDirectory(serviceDirectory);
            }
            string      servicePath = null;
            IOgcService ogcService  = GetOgcService(serviceType, serviceVersion);

            if (ogcService is IWmtsService wmtsService)
            {
                string routTemplate = GetRoutTemplate <WmtsController>();
                routTemplate = routTemplate.Replace("{serviceName}", serviceName);
                string href = $"{_host}/{routTemplate}";
                //string href = $"{_host}/EMap/Services/{serviceName}/MapServer/Wmts";
                Capabilities capabilities = wmtsService.CreateCapabilities(href);
                servicePath = Path.Combine(serviceDirectory, "WMTSCapabilities.xml");
                SaveCapabilities(wmtsService, servicePath, capabilities);
            }
            else
            {
                return(ret);
            }
            serviceRecord = new ServiceRecord()
            {
                Name    = serviceName,
                Path    = servicePath,
                Type    = serviceType,
                Version = serviceVersion
            };
            _configContext.Services.Add(serviceRecord);
            var result = await _configContext.SaveChangesAsync();

            ret = true;
            return(ret);
        }
Exemple #5
0
        public static IOgcService GetOgcService(OgcServiceType serviceType, string serviceVersion)
        {
            IOgcService ogcService = null;

            if (string.IsNullOrWhiteSpace(serviceVersion))
            {
                return(ogcService);
            }
            switch (serviceType)
            {
            case OgcServiceType.Wfs:
                switch (serviceVersion)
                {
                case "2.0.0":
                    //serviceFasctory = new DsWfs2ServiceFactory();
                    break;
                }
                break;

            case OgcServiceType.Wcs:
                switch (serviceVersion)
                {
                case "2.0.0":
                    //serviceFasctory = new DsWfs2ServiceFactory();
                    break;
                }
                break;

            case OgcServiceType.Wmts:
                switch (serviceVersion)
                {
                case "1.0.0":
                    //DsWmts1ServiceFactory dsWmts1ServiceFactory = new DsWmts1ServiceFactory();
                    ogcService = new GdalWmtsService();
                    break;
                }
                break;

            case OgcServiceType.Wms:
                switch (serviceVersion)
                {
                case "2.0.0":
                    //serviceFasctory = new DsWfs2ServiceFactory();
                    break;
                }
                break;
            }
            return(ogcService);
        }
Exemple #6
0
        public static IOgcService GetOgcService(string serviceType, string version)
        {
            IOgcService ogcService = null;

            if (string.IsNullOrWhiteSpace(serviceType) || string.IsNullOrWhiteSpace(version))
            {
                return(ogcService);
            }
            switch (serviceType.ToLower())
            {
            case "wfs":
                switch (version)
                {
                case "2.0.0":
                    //serviceFasctory = new DsWfs2ServiceFactory();
                    break;
                }
                break;

            case "wcs":
                switch (version)
                {
                case "2.0.0":
                    //serviceFasctory = new DsWfs2ServiceFactory();
                    break;
                }
                break;

            case "wmts":
                switch (version)
                {
                case "1.0.0":
                    DsWmts1ServiceFactory dsWmts1ServiceFactory = new DsWmts1ServiceFactory();
                    ogcService = dsWmts1ServiceFactory?.GetService();
                    break;
                }
                break;

            case "wms":
                switch (version)
                {
                case "2.0.0":
                    //serviceFasctory = new DsWfs2ServiceFactory();
                    break;
                }
                break;
            }
            return(ogcService);
        }