예제 #1
0
        Task ITileSource.InitAsync()
        {
            var title = String.IsNullOrEmpty(this.configuration.Title) ?
                        this.configuration.Id :
                        this.configuration.Title;

            var minZoom = this.configuration.MinZoom ?? 0;
            var maxZoom = this.configuration.MaxZoom ?? 20;

            // Re-create configuration
            this.configuration = new SourceConfiguration
            {
                Id                 = this.configuration.Id,
                Type               = this.configuration.Type,
                Format             = ImageFormats.MapboxVectorTile,
                Title              = title,
                Abstract           = this.configuration.Abstract,
                Tms                = this.configuration.Tms ?? true,
                Srs                = Utils.SrsCodes.EPSG3857,
                Location           = this.configuration.Location,
                ContentType        = Utils.EntitiesConverter.TileFormatToContentType(ImageFormats.MapboxVectorTile),
                MinZoom            = minZoom,
                MaxZoom            = maxZoom,
                GeographicalBounds = null,
                TileWidth          = Utils.WebMercator.DefaultTileWidth,
                TileHeight         = Utils.WebMercator.DefaultTileHeight,
                Cache              = null, // TODO: ? possible to implement
                PostGis            = configuration.PostGis,
            };

            return(Task.CompletedTask);
        }
        private int?TryGetItemIndexFromConfiguration(long sourceId, string tagname)
        {
            SourceConfiguration source = null;

            for (var i = 0; i < _configuration.Current.Sources.Count; i++)
            {
                if (_configuration.Current.Sources[i].SourceId == sourceId)
                {
                    source = _configuration.Current.Sources[i];
                }
            }

            if (source != null)
            {
                for (var i = 0; i < source.Items.Length; i++)
                {
                    var item = source.Items[i];
                    if (item.TryGetValue("tagname", out var itemTagname))
                    {
                        if (itemTagname is string t && t.ToLowerInvariant() == tagname.ToLowerInvariant())
                        {
                            return(i);
                        }
                    }
                }
            }

            return(null);
        }
예제 #3
0
 public static string GetTileUrl(
     SourceConfiguration configuration,
     int x, int y, int z)
 {
     return(GetMapUrl(
                configuration,
                Utils.WebMercator.TileSize, // TODO: ? high resolution tiles ?
                Utils.WebMercator.TileSize,
                Utils.WebMercator.GetTileBounds(x, y, z),
                true,
                0xFFFFFF));
 }
예제 #4
0
 /// <summary>
 /// 配置资源文件
 /// </summary>
 /// <param name="configuElement"></param>
 public static void Configure(XmlElement configuElement)
 {
     lock (SyncObject)
     {
         m_Source = new SourceConfiguration(configuElement);
         //如果采用element配置,则说明用户自行监控配置文件,无需重复监测,释放文件监控
         if (m_Watcher != null)
         {
             m_Watcher.Dispose();
             m_Watcher = null;
         }
     }
 }
예제 #5
0
        private void ApplySettings()
        {
            Sources.SelectedValue = _settings.SourceStoreConfiguration.StoreFullName;
            SourceConfiguration.LoadConfiguration(_settings.SourceStoreConfiguration, true);
            Destinations.SelectedValue = _settings.DestinationStoreConfiguration.StoreFullName;
            DestinationConfiguration.LoadConfiguration(_settings.DestinationStoreConfiguration, false);
            MappingSource.LoadItems(_settings.SourceStoreConfiguration.Columns.Select(x => x.Name));
            MappingDestination.LoadItems(_settings.DestinationStoreConfiguration.Columns.Select(x => x.Name));
            Mappings.LoadItems(_settings.Mappings.Select(x => x.DisplayName));
            ProcessorMappings.LoadItems(_settings.Mappings.Select(x => x.DisplayName));
            PreProcessors.LoadItems(_settings.Mappings.SelectMany(x => x.PreProcesses.Select(y => x.DisplayName + "|" + y.DisplayName)));

            UpdateControlState();
        }
        public LocalFilesTileSource(SourceConfiguration configuration)
        {
            if (String.IsNullOrEmpty(configuration.Id))
            {
                throw new ArgumentException("Source identifier is null or empty string");
            }

            if (String.IsNullOrEmpty(configuration.Location))
            {
                throw new ArgumentException("Source location is null or empty string");
            }

            this.configuration = configuration; // Will be changed later in InitAsync
        }
예제 #7
0
 private static void CreateLocalTiles(SourceConfiguration tileSource)
 {
     // Create files Z\X\Y structure
     for (var z = tileSource.MinZoom.Value; z <= tileSource.MaxZoom.Value; z++)
     {
         Directory.CreateDirectory(Path.Join(LocalFilesPath, z.ToString(CultureInfo.InvariantCulture)));
         for (var x = 0; x < 1 << z; x++)
         {
             var zxPath = Path.Join(LocalFilesPath, z.ToString(CultureInfo.InvariantCulture), x.ToString(CultureInfo.InvariantCulture));
             Directory.CreateDirectory(zxPath);
             for (var y = 0; y < 1 << z; y++)
             {
                 var tilePath = Path.Join(zxPath, y.ToString(CultureInfo.InvariantCulture)) + "." + tileSource.Format;
                 var tile     = new TileDataStub(x, y, z);
                 File.WriteAllBytes(tilePath, tile.ToByteArray());
             }
         }
     }
 }
예제 #8
0
        public RasterTileSource(SourceConfiguration configuration)
        {
            // TODO: report real WMS layer bounds from raster bounds
            // TODO: EPSG:4326 tile response (for WMTS, WMS)
            // TODO: add support for MapInfo RASTER files
            // TODO: add support for multiple rasters (directory with rasters)

            if (String.IsNullOrEmpty(configuration.Id))
            {
                throw new ArgumentException("Source identifier is null or empty string");
            }

            if (String.IsNullOrEmpty(configuration.Location))
            {
                throw new ArgumentException("Source location is null or empty string");
            }

            this.configuration = configuration; // Will be changed later in InitAsync
        }
예제 #9
0
 private static void Configure(string packageConfigPath, bool hasLock)
 {
     if (hasLock)
     {
         lock (SyncObject)
         {
             // 读取配置
             m_Source = new SourceConfiguration(packageConfigPath);
             //监控配置文件
             WatcheConfiguration(packageConfigPath);
         }
     }
     else
     {
         // 读取配置
         m_Source = new SourceConfiguration(packageConfigPath);
         //监控配置文件
         WatcheConfiguration(packageConfigPath);
     }
 }
예제 #10
0
        private const string EPSG3857 = Utils.SrsCodes.EPSG3857; // TODO: EPSG:4326 support

        public static string GetCapabilitiesUrl(SourceConfiguration configuration)
        {
            var location = configuration.Location;

            if (String.IsNullOrWhiteSpace(location))
            {
                throw new ArgumentException("Location must be valid string");
            }

            var baseUri = Utils.UrlHelper.GetQueryBase(location);
            var items   = Utils.UrlHelper.GetQueryParameters(location);

            // Version
            var wmsVersion = String.Empty; // Default WMS version not set for GetCapabilities

            if (configuration.Wms != null && !String.IsNullOrWhiteSpace(configuration.Wms.Version))
            {
                wmsVersion = configuration.Wms.Version;
            }
            else if (items.Any(kvp => kvp.Key == WmsQueryVersion))
            {
                wmsVersion = items.First(kvp => kvp.Key == WmsQueryVersion).Value;
            }

            RemoveKnownParameters(items);
            items.RemoveAll(kvp => String.Compare(kvp.Key, WmsQueryStyles, StringComparison.OrdinalIgnoreCase) == 0); // TODO: add styles to WMS configuration and RemoveKnownParameters()

            var qb = new QueryBuilder(items)
            {
                { WmsQueryService, Identifiers.Wms },
                { WmsQueryRequest, Identifiers.GetCapabilities }
            };

            if (!String.IsNullOrEmpty(wmsVersion))
            {
                qb.Add(WmsQueryVersion, wmsVersion);
            }

            return(baseUri + qb.ToQueryString());
        }
예제 #11
0
        Task ITileSource.InitAsync()
        {
            if (String.IsNullOrEmpty(this.configuration.Location))
            {
                throw new InvalidOperationException("configuration.Location is null or empty");
            }

            Tiff.SetErrorHandler(new DisableErrorHandler()); // TODO: ? redirect output?

            this.rasterProperties = ReadGeoTiffProperties(this.configuration.Location);

            var title = String.IsNullOrEmpty(this.configuration.Title) ?
                        this.configuration.Id :
                        this.configuration.Title;

            var minZoom = this.configuration.MinZoom ?? 0;
            var maxZoom = this.configuration.MaxZoom ?? 24;

            // Re-create configuration
            this.configuration = new SourceConfiguration
            {
                Id                 = this.configuration.Id,
                Type               = this.configuration.Type,
                Format             = ImageFormats.Png, // TODO: ? multiple output formats ?
                Title              = title,
                Abstract           = this.configuration.Abstract,
                Tms                = false,
                Srs                = U.SrsCodes.EPSG3857,                                           // TODO: only EPSG:3857 'output' SRS currently supported
                Location           = this.configuration.Location,
                ContentType        = U.EntitiesConverter.TileFormatToContentType(ImageFormats.Png), // TODO: other output formats
                MinZoom            = minZoom,
                MaxZoom            = maxZoom,
                GeographicalBounds = this.rasterProperties.GeographicalBounds,
                Cache              = null, // Not used for local raster file source
                PostGis            = null,
            };

            return(Task.CompletedTask);
        }
예제 #12
0
        private void ListBoxSelectedIndexChanged(object sender, EventArgs e)
        {
            var control = (ListBox)sender;

            if (control.SelectedItems.Count > 0)
            {
                var dataStore = (control.SelectedValue ?? control.SelectedItem).ToString();

                if (control == Sources)
                {
                    _settings.SourceStoreConfiguration.StoreFullName = dataStore;
                    _settings.SourceStoreConfiguration.Filter        = GetStoreFilter(dataStore);
                    SourceConfiguration.LoadConfiguration(_settings.SourceStoreConfiguration, true);
                }
                else if (control == Destinations)
                {
                    _settings.DestinationStoreConfiguration.StoreFullName = dataStore;
                    _settings.DestinationStoreConfiguration.Filter        = GetStoreFilter(dataStore);
                    DestinationConfiguration.LoadConfiguration(_settings.DestinationStoreConfiguration, false);
                }
            }

            UpdateControlState();
        }
        Task ITileSource.InitAsync()
        {
            // Configuration values priority:
            // 1. Default values for MBTiles source type.
            // 2. Actual values (MBTiles metadata table values).
            // 3. Values from configuration file - overrides given above, if provided.

            if (String.IsNullOrEmpty(this.configuration.Location))
            {
                throw new InvalidOperationException("configuration.Location is null or empty");
            }

            this.repository = new MBTiles.Repository(configuration.Location, false);
            var metadata = new MBTiles.Metadata(this.repository.ReadMetadata());

            var title = String.IsNullOrEmpty(this.configuration.Title) ?
                        (!String.IsNullOrEmpty(metadata.Name) ? metadata.Name : this.configuration.Id) :
                        this.configuration.Title;

            var format = String.IsNullOrEmpty(this.configuration.Format) ?
                         (!String.IsNullOrEmpty(metadata.Format) ? metadata.Format : ImageFormats.Png) :
                         this.configuration.Format;

            // Get tile width and height from first tile, for raster formats
            var tileWidth  = Utils.WebMercator.DefaultTileWidth;
            var tileHeight = Utils.WebMercator.DefaultTileHeight;
            var firstTile  = this.repository.ReadFirstTile();

            if (firstTile != null && (format == ImageFormats.Png || format == ImageFormats.Jpeg))
            {
                var size = Utils.ImageHelper.GetImageSize(firstTile);
                if (size.HasValue)
                {
                    tileWidth  = size.Value.Width;
                    tileHeight = size.Value.Height;
                }
            }

            var minZoom = this.configuration.MinZoom ?? metadata.MinZoom ?? null;
            var maxZoom = this.configuration.MaxZoom ?? metadata.MaxZoom ?? null;

            if (minZoom == null || maxZoom == null)
            {
                var zoomRange = this.repository.GetZoomLevelRange();
                if (zoomRange.HasValue)
                {
                    minZoom = zoomRange.Value.Min;
                    maxZoom = zoomRange.Value.Max;
                }
                else
                {
                    minZoom = 0;
                    maxZoom = 20;
                }
            }

            // Re-create configuration
            this.configuration = new SourceConfiguration
            {
                Id                 = this.configuration.Id,
                Type               = this.configuration.Type,
                Format             = format,
                Title              = title,
                Abstract           = this.configuration.Abstract,
                Tms                = this.configuration.Tms ?? true, // Default true for the MBTiles, following the Tile Map Service Specification.
                Srs                = Utils.SrsCodes.EPSG3857,        // MBTiles supports only Spherical Mercator tile grid
                Location           = this.configuration.Location,
                ContentType        = Utils.EntitiesConverter.TileFormatToContentType(format),
                MinZoom            = minZoom,
                MaxZoom            = maxZoom,
                GeographicalBounds = metadata.Bounds, // Can be null, if no corresponding record in 'metadata' table
                TileWidth          = tileWidth,
                TileHeight         = tileHeight,
                Cache              = null, // Not used for MBTiles source
            };

            return(Task.CompletedTask);
        }
예제 #14
0
 public PlayerConfiguration()
 {
     Render   = new RenderConfiguration();
     Source   = new SourceConfiguration();
     Compress = new CompressConfiguration();
 }
 public DeltaPOneForwardSolver(SourceConfiguration sourceConfiguration, double beamRadius)
     : base(sourceConfiguration, beamRadius)
 {
     this.ForwardModel = ForwardModel.DeltaPOne;
 }
예제 #16
0
 public NewsGenerator(IServiceScopeFactory serviceScopeFactory, INewsRepository newsRepository, IOptions <SourceConfiguration> sources)
 {
     _serviceScopeFactory = serviceScopeFactory;
     _newsRepository      = newsRepository;
     _sourceConfiguration = sources.Value;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="SourceConfigurationViewModel"/> class
        /// </summary>
        /// <param name="session">The current session</param>
        /// <param name="iteration">The current iteration</param>
        /// <param name="onUpdateAction">The action to perform on update</param>
        /// <param name="onLightUpdateAction">The action to perform on update without need to rebuild relationship configiguration</param>
        /// <param name="settings">The module settings</param>
        /// <param name="source">The source <see cref="SourceConfiguration"/></param>
        public SourceConfigurationViewModel(ISession session, Iteration iteration, Action onUpdateAction, Action onLightUpdateAction,
                                            RelationshipMatrixPluginSettings settings, SourceConfiguration source) : this(session, iteration, onUpdateAction, onLightUpdateAction, settings)
        {
            this.IncludeSubcategories = source.IncludeSubcategories;

            this.SelectedBooleanOperatorKind = source.SelectedBooleanOperatorKind;
            this.SelectedClassKind           = source.SelectedClassKind;
            this.SelectedDisplayKind         = source.SelectedDisplayKind;
            this.SelectedSortKind            = source.SelectedSortKind;
            this.selectedSortOrder           = source.SortOrder;

            this.OnLightUpdateAction = onLightUpdateAction;

            // populate selected categories
            var categories = new List <Category>();

            foreach (var iid in source.SelectedCategories)
            {
                var category = this.PossibleCategories.FirstOrDefault(c => c.Iid == iid);

                if (category != null)
                {
                    categories.Add(category);
                }
            }
            this.SelectedCategories = new List <Category>(categories);

            // populate selected owners
            var owners = new List <DomainOfExpertise>();

            foreach (var iid in source.SelectedOwners)
            {
                var domainOfExpertise = this.PossibleOwners.FirstOrDefault(d => d.Iid == iid);
                if (domainOfExpertise != null)
                {
                    owners.Add(domainOfExpertise);
                }
            }
            this.SelectedOwners = new List <DomainOfExpertise>(owners);
        }
 protected DiffusionForwardSolverBase(SourceConfiguration sourceConfiguration, double beamDiameter)
     : base(sourceConfiguration, beamDiameter)
 {
 }
예제 #19
0
        public static string GetMapUrl(
            SourceConfiguration configuration,
            int width,
            int height,
            Models.Bounds boundingBox,
            bool isTransparent,
            uint backgroundColor)
        {
            var location = configuration.Location;

            if (String.IsNullOrWhiteSpace(location))
            {
                throw new ArgumentException("Location must be valid string");
            }

            var baseUri = Utils.UrlHelper.GetQueryBase(location);
            var items   = Utils.UrlHelper.GetQueryParameters(location);

            // Version
            var wmsVersion = Identifiers.Version111; // Default WMS version is 1.1.1

            if (configuration.Wms != null && !String.IsNullOrWhiteSpace(configuration.Wms.Version))
            {
                wmsVersion = configuration.Wms.Version;
            }
            else if (items.Any(kvp => kvp.Key == WmsQueryVersion))
            {
                wmsVersion = items.First(kvp => kvp.Key == WmsQueryVersion).Value;
            }

            // Layers
            var layers = String.Empty;

            if (configuration.Wms != null && !String.IsNullOrWhiteSpace(configuration.Wms.Layer))
            {
                layers = configuration.Wms.Layer; // TODO: ? multiple layers
            }
            else if (items.Any(kvp => kvp.Key == WmsQueryLayers))
            {
                layers = items.First(kvp => kvp.Key == WmsQueryLayers).Value;
            }

            // Format
            var format = MediaTypeNames.Image.Png;

            if (!String.IsNullOrWhiteSpace(configuration.ContentType))
            {
                format = configuration.ContentType;
            }

            RemoveKnownParameters(items);

            var qb = new QueryBuilder(items)
            {
                { WmsQueryService, Identifiers.Wms },
                { WmsQueryRequest, Identifiers.GetMap },
                { WmsQueryVersion, wmsVersion },
                { WmsQueryLayers, layers },
                { (wmsVersion == Identifiers.Version130) ? WmsQueryCrs : WmsQuerySrs, EPSG3857 }, // TODO: EPSG:4326 support
                { WmsQueryBBox, boundingBox.ToBBoxString() },
                { WmsQueryWidth, width.ToString(CultureInfo.InvariantCulture) },
                { WmsQueryHeight, height.ToString(CultureInfo.InvariantCulture) },
                { WmsQueryFormat, format },
            };

            if (isTransparent)
            {
                qb.Add(WmsQueryTransparent, "true");
            }

            qb.Add(WmsQueryBackgroundColor, "0x" + backgroundColor.ToString("X8"));

            return(baseUri + qb.ToQueryString());
        }
        public static string GetTileKvpUrl(
            SourceConfiguration configuration,
            int x, int y, int z)
        {
            if (String.IsNullOrWhiteSpace(configuration.Location))
            {
                throw new ArgumentException("Location must be valid string");
            }

            // TODO: choose WMTS query with parameters or ResourceUrl with placeholders
            var baseUrl = configuration.Location;

            if (IsResourceUrl(baseUrl))
            {
                return(baseUrl
                       .Replace("{" + WmtsQueryTileCol + "}", x.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase)
                       .Replace("{" + WmtsQueryTileRow + "}", y.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase)
                       .Replace("{" + WmtsQueryTileMatrix + "}", z.ToString(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase));
            }
            else
            {
                var baseUri = Utils.UrlHelper.GetQueryBase(baseUrl);
                var items   = Utils.UrlHelper.GetQueryParameters(baseUrl);

                // Layer
                var layer = String.Empty;
                if (configuration.Wmts != null && !String.IsNullOrWhiteSpace(configuration.Wmts.Layer))
                {
                    layer = configuration.Wmts.Layer;
                }
                else if (items.Any(kvp => kvp.Key == WmtsQueryLayer))
                {
                    layer = items.First(kvp => kvp.Key == WmtsQueryLayer).Value;
                }

                // Style
                var style = "normal";
                if (configuration.Wmts != null && !String.IsNullOrWhiteSpace(configuration.Wmts.Style))
                {
                    style = configuration.Wmts.Style;
                }
                else if (items.Any(kvp => kvp.Key == WmtsQueryStyle))
                {
                    style = items.First(kvp => kvp.Key == WmtsQueryStyle).Value;
                }

                // TileMatrixSet
                var tileMatrixSet = String.Empty;
                if (configuration.Wmts != null && !String.IsNullOrWhiteSpace(configuration.Wmts.TileMatrixSet))
                {
                    tileMatrixSet = configuration.Wmts.TileMatrixSet;
                }
                else if (items.Any(kvp => kvp.Key == WmtsQueryTilematrixSet))
                {
                    tileMatrixSet = items.First(kvp => kvp.Key == WmtsQueryTilematrixSet).Value;
                }

                // Format
                var format = MediaTypeNames.Image.Png;
                if (!String.IsNullOrWhiteSpace(configuration.ContentType))
                {
                    format = configuration.ContentType;
                }

                var qb = new QueryBuilder
                {
                    { WmtsQueryService, Identifiers.WMTS },
                    { WmtsQueryRequest, Identifiers.GetTile },
                    { WmtsQueryVersion, Identifiers.Version100 },
                    { WmtsQueryLayer, layer },
                    { WmtsQueryStyle, style },
                    { WmtsQueryTilematrixSet, tileMatrixSet },
                    { WmtsQueryFormat, format },
                    { WmtsQueryTileMatrix, z.ToString(CultureInfo.InvariantCulture) },
                    { WmtsQueryTileCol, x.ToString(CultureInfo.InvariantCulture) },
                    { WmtsQueryTileRow, y.ToString(CultureInfo.InvariantCulture) },
                };

                return(baseUri + qb.ToQueryString());
            }
        }
        public IRequest Marshall(CreateConfigurationTemplateRequest createConfigurationTemplateRequest)
        {
            IRequest request = new DefaultRequest(createConfigurationTemplateRequest, "AmazonElasticBeanstalk");

            request.Parameters.Add("Action", "CreateConfigurationTemplate");
            request.Parameters.Add("Version", "2010-12-01");
            if (createConfigurationTemplateRequest != null && createConfigurationTemplateRequest.IsSetApplicationName())
            {
                request.Parameters.Add("ApplicationName", StringUtils.FromString(createConfigurationTemplateRequest.ApplicationName));
            }
            if (createConfigurationTemplateRequest != null && createConfigurationTemplateRequest.IsSetTemplateName())
            {
                request.Parameters.Add("TemplateName", StringUtils.FromString(createConfigurationTemplateRequest.TemplateName));
            }
            if (createConfigurationTemplateRequest != null && createConfigurationTemplateRequest.IsSetSolutionStackName())
            {
                request.Parameters.Add("SolutionStackName", StringUtils.FromString(createConfigurationTemplateRequest.SolutionStackName));
            }
            if (createConfigurationTemplateRequest != null)
            {
                SourceConfiguration sourceConfiguration = createConfigurationTemplateRequest.SourceConfiguration;
                if (sourceConfiguration != null && sourceConfiguration.IsSetApplicationName())
                {
                    request.Parameters.Add("SourceConfiguration.ApplicationName", StringUtils.FromString(sourceConfiguration.ApplicationName));
                }
                if (sourceConfiguration != null && sourceConfiguration.IsSetTemplateName())
                {
                    request.Parameters.Add("SourceConfiguration.TemplateName", StringUtils.FromString(sourceConfiguration.TemplateName));
                }
            }
            if (createConfigurationTemplateRequest != null && createConfigurationTemplateRequest.IsSetEnvironmentId())
            {
                request.Parameters.Add("EnvironmentId", StringUtils.FromString(createConfigurationTemplateRequest.EnvironmentId));
            }
            if (createConfigurationTemplateRequest != null && createConfigurationTemplateRequest.IsSetDescription())
            {
                request.Parameters.Add("Description", StringUtils.FromString(createConfigurationTemplateRequest.Description));
            }

            if (createConfigurationTemplateRequest != null)
            {
                List <ConfigurationOptionSetting> optionSettingsList = createConfigurationTemplateRequest.OptionSettings;
                int optionSettingsListIndex = 1;
                foreach (ConfigurationOptionSetting optionSettingsListValue in optionSettingsList)
                {
                    if (optionSettingsListValue != null && optionSettingsListValue.IsSetNamespace())
                    {
                        request.Parameters.Add("OptionSettings.member." + optionSettingsListIndex + ".Namespace", StringUtils.FromString(optionSettingsListValue.Namespace));
                    }
                    if (optionSettingsListValue != null && optionSettingsListValue.IsSetOptionName())
                    {
                        request.Parameters.Add("OptionSettings.member." + optionSettingsListIndex + ".OptionName", StringUtils.FromString(optionSettingsListValue.OptionName));
                    }
                    if (optionSettingsListValue != null && optionSettingsListValue.IsSetValue())
                    {
                        request.Parameters.Add("OptionSettings.member." + optionSettingsListIndex + ".Value", StringUtils.FromString(optionSettingsListValue.Value));
                    }

                    optionSettingsListIndex++;
                }
            }

            return(request);
        }
        Task ITileSource.InitAsync()
        {
            if (String.IsNullOrEmpty(this.configuration.Location))
            {
                throw new InvalidOperationException("configuration.Location is null or empty");
            }

            if (String.IsNullOrEmpty(this.configuration.Format)) // TODO: from first file, if any
            {
                throw new InvalidOperationException("configuration.Format is null or empty");
            }

            // Configuration values priority:
            // 1. Default values for local files source type.
            // 2. Actual values (from first found tile properties).
            // 3. Values from configuration file - overrides given above, if provided.

            // Detect zoom levels range - build list of folders
            var zoomLevels = new List <int>();
            var xIndex     = this.configuration.Location.IndexOf("{x}", StringComparison.OrdinalIgnoreCase);
            var yIndex     = this.configuration.Location.IndexOf("{y}", StringComparison.OrdinalIgnoreCase);
            var zIndex     = this.configuration.Location.IndexOf("{z}", StringComparison.OrdinalIgnoreCase);

            if ((zIndex < yIndex) && (zIndex < xIndex))
            {
                var baseFolder = new Uri(this.configuration.Location.Substring(0, zIndex)).LocalPath;
                foreach (var directory in Directory.GetDirectories(baseFolder))
                {
                    if (Int32.TryParse(Path.GetFileName(directory), out int zoomLevel)) // Directory name is integer number
                    {
                        zoomLevels.Add(zoomLevel);
                    }
                }
            }

            var title = String.IsNullOrEmpty(this.configuration.Title) ?
                        this.configuration.Id :
                        this.configuration.Title;

            var srs = String.IsNullOrWhiteSpace(this.configuration.Srs) ? Utils.SrsCodes.EPSG3857 : this.configuration.Srs.Trim().ToUpper();

            var minZoom = this.configuration.MinZoom ?? (zoomLevels.Count > 0 ? zoomLevels.Min(z => z) : 0);
            var maxZoom = this.configuration.MaxZoom ?? (zoomLevels.Count > 0 ? zoomLevels.Max(z => z) : 20);

            // TODO: TileWidh, TileHeight from file properties (with supported image extension)

            // Re-create configuration
            this.configuration = new SourceConfiguration
            {
                Id                 = this.configuration.Id,
                Type               = this.configuration.Type,
                Format             = this.configuration.Format, // TODO: from file properties (extension)
                Title              = title,
                Abstract           = this.configuration.Abstract,
                Tms                = this.configuration.Tms ?? false, // Default is tms=false for file storage
                Srs                = srs,
                Location           = this.configuration.Location,
                ContentType        = Utils.EntitiesConverter.TileFormatToContentType(this.configuration.Format), // TODO: from file properties
                MinZoom            = minZoom,
                MaxZoom            = maxZoom,
                GeographicalBounds = null, // TODO: compute bounds (need to scan all folders ?)
                Cache              = null, // Not used for local files source
            };

            // TODO: tile width, tile height from first tile

            return(Task.CompletedTask);
        }
예제 #23
0
        async Task ITileSource.InitAsync()
        {
            // Configuration values priority:
            // 1. Default values for http source type.
            // 2. Actual values (from source metadata).
            // 3. Values from configuration file - overrides given above, if provided.

            this.client = new HttpClient()
            {
                Timeout = TimeSpan.FromSeconds(15),
            };                                                                      // TODO: custom headers from configuration

            var sourceCapabilities = await this.GetSourceCapabilitiesAsync();

            // TODO: combine capabilies with configuration
            var title = String.IsNullOrEmpty(this.configuration.Title) ?
                        this.configuration.Id :
                        this.configuration.Title;

            var minZoom = this.configuration.MinZoom ?? 0;
            var maxZoom = this.configuration.MaxZoom ?? 24;

            if (String.IsNullOrEmpty(this.configuration.Type))
            {
                throw new InvalidOperationException("configuration.Type is null or empty");
            }

            if (String.IsNullOrEmpty(this.configuration.Format)) // TODO: get from metadata
            {
                throw new InvalidOperationException("configuration.Format is null or empty");
            }

            // Default is tms=false for simple XYZ tile services
            var tms = this.configuration.Tms ?? (this.configuration.Type.ToLowerInvariant() == SourceConfiguration.TypeTms);
            var srs = String.IsNullOrWhiteSpace(this.configuration.Srs) ? Utils.SrsCodes.EPSG3857 : this.configuration.Srs.Trim().ToUpper();

            // Re-create configuration
            this.configuration = new SourceConfiguration
            {
                Id                 = this.configuration.Id,
                Type               = this.configuration.Type.ToLowerInvariant(),
                Format             = this.configuration.Format,   // TODO: from source service/layer capabilities
                Title              = title,
                Abstract           = this.configuration.Abstract, // TODO: from source layer capabilities
                Tms                = tms,
                Srs                = srs,
                Location           = this.configuration.Location,
                ContentType        = Utils.EntitiesConverter.TileFormatToContentType(this.configuration.Format), // TODO: from source service capabilities
                MinZoom            = minZoom,
                MaxZoom            = maxZoom,
                GeographicalBounds = sourceCapabilities?.GeographicalBounds,
                TileWidth          = sourceCapabilities != null ? sourceCapabilities.TileWidth : Utils.WebMercator.DefaultTileWidth,
                TileHeight         = sourceCapabilities != null ? sourceCapabilities.TileHeight : Utils.WebMercator.DefaultTileHeight,
                Cache              = (srs == Utils.SrsCodes.EPSG3857) ? this.configuration.Cache : null, // Only Web Mercator is supported in MBTiles specification
                Wmts               = this.configuration.Wmts,
                Wms                = this.configuration.Wms,
                PostGis            = null,
            };

            if (this.configuration.Cache != null)
            {
                var dbpath = this.configuration.Cache.DbFile;
                if (String.IsNullOrEmpty(dbpath))
                {
                    throw new InvalidOperationException("DBpath is null or empty string");
                }

                if (File.Exists(dbpath))
                {
                    this.cache = new MBT.CacheRepository(dbpath);
                }
                else
                {
                    this.cache = MBT.CacheRepository.CreateEmpty(dbpath);
                }
            }
        }