public void add_new_model_with_properties_to_the_layer_collection_expect_entry()
        {
            var service = new LayerInitializationFileService(Container.GetService <IFileProvider>());

            int beginningCount = service.Models.Count();

            var newLayer = new LayerInformationModel
            {
                Identifier = Guid.NewGuid(),
                Name       = Guid.NewGuid().ToString().Substring(0, 6),
                Properties = new Property[]
                {
                    new Property {
                        Name = LayerProperties.FileExt, Value = "json", ValueType = typeof(string)
                    },
                    new Property {
                        Name = LayerProperties.TileAccessTemplate, Value = "http://Server/v1/tiles/tileName/{z}/{x}/{y}.vector.pbf?access_token={token}"
                    }
                }
            };

            service.AddLayer(newLayer);

            Assert.AreEqual(beginningCount + 1, service.Models.Count());
            Assert.AreEqual("json", newLayer.Properties.First(p => p.Name == LayerProperties.FileExt).Value);
            Assert.AreEqual(
                "http://Server/v1/tiles/tileName/{z}/{x}/{y}.vector.pbf?access_token={token}",
                newLayer.Properties.First(p => p.Name == LayerProperties.TileAccessTemplate).Value);
        }
Пример #2
0
        public LayerInitializationFileService(IFileProvider fileProvider, string serverIP = "")
        {
            this.fileProvider = fileProvider;
            this.serverIP     = serverIP;
            foreach (var item in this.fileProvider.GetDirectoryContents("/"))
            {
                var name             = Path.GetFileNameWithoutExtension(item.PhysicalPath);
                var layerInformation = new LayerInformationModel()
                {
                    Identifier = Guid.NewGuid(),
                    Name       = name,
                    Path       = item.PhysicalPath,
                    Properties = new Property[]
                    {
                        new Property {
                            Name = LayerProperties.FileExt, Value = Path.GetExtension(item.PhysicalPath), ValueType = typeof(string)
                        },
                        new Property {
                            Name = LayerProperties.TileAccessTemplate, Value = serverIP + "/v1/tiles/" + name + "/{z}/{x}/{y}.vector.pbf?access_token={token}"
                        }
                    }
                };

                models.Add(layerInformation);

                files.Add(item.Name, item.PhysicalPath);
            }
        }
        public void with_layer_model_expect_serialization()
        {
            var id    = Guid.NewGuid();
            var model = new LayerInformationModel()
            {
                Identifier = id,
                Name       = "Colorado Outline",
                Path       = "filesystem",
                Properties = new Property[]
                {
                    new Property()
                    {
                        Name = "StorageInfo", Value = "FileSystem", ValueType = typeof(string)
                    }
                }
            };

            var serial   = model.SerializeToJson();
            var deserial = serial.DeserializeJson <LayerInformationModel>();

            Assert.AreEqual(id, deserial.Identifier);
            Assert.AreEqual("Colorado Outline", deserial.Name);
            Assert.AreEqual("filesystem", deserial.Path);
            Assert.AreEqual("StorageInfo", deserial.Properties[0].Name);
            Assert.AreEqual("FileSystem", deserial.Properties[0].Value);
            Assert.AreEqual(typeof(string), deserial.Properties[0].ValueType);
        }
Пример #4
0
        public void AddLayer(LayerInformationModel model)
        {
            var properties = new List <Property>();

            var tileTemplate = new Property
            {
                Name  = LayerProperties.TileAccessTemplate,
                Value = serverIP + "/v1/tiles/" + model.Name + "/{z}/{x}/{y}.vector.pbf?access_token={token}"
            };

            var fileExtension = new Property
            {
                Name      = LayerProperties.FileExt,
                Value     = !string.IsNullOrEmpty(model.Path) ? Path.GetExtension(model.Path) : string.Empty,
                ValueType = typeof(string)
            };

            if (model.Properties != null)
            {
                properties.AddRange(model.Properties);

                if (!model.Properties.Any(p => p.Name.ToLower() == LayerProperties.TileAccessTemplate))
                {
                    properties.Add(tileTemplate);
                }
                if (!model.Properties.Any(p => p.Name.ToLower() == LayerProperties.FileExt))
                {
                    properties.Add(fileExtension);
                }
                if (model.Properties.Any(p => p.Name.ToLower() == LayerProperties.Features))
                {
                    var featuresProperty = model.Properties.First(p => p.Name.ToLower() == LayerProperties.Features);
                    try
                    {
                        var features = (IEnumerable <IGeometryItem>)featuresProperty.Value;
                        featureCache.StoreBy(model.Identifier, features);
                        featuresProperty.Value = features.Count();
                    }
                    catch (Exception ex)
                    {
                        featuresProperty.Value = $"An error occurred while attempting to access/overwrite the features. {ex.Message} : {ex.StackTrace}";
                    }
                    properties.Remove(properties.First(p => p.Name.ToLower() == LayerProperties.Features));
                    properties.Add(featuresProperty);
                }
            }
            else
            {
                properties.Add(tileTemplate);
                properties.Add(fileExtension);
            }

            model.Properties = properties.ToArray();
            models.Add(model);
        }
        public void add_new_model_to_the_layer_collection_expect_entry()
        {
            var service = new LayerInitializationFileService(Container.GetService <IFileProvider>());

            int beginningCount = service.Models.Count();

            var newLayer = new LayerInformationModel
            {
                Identifier = Guid.NewGuid(),
                Name       = Guid.NewGuid().ToString().Substring(0, 6)
            };

            service.AddLayer(newLayer);

            Assert.AreEqual(beginningCount + 1, service.Models.Count());
        }
        public async Task add_new_model_to_the_layer__with_features_expect_tile_rendering()
        {
            var layerService = new LayerInitializationFileService(Container.GetService <IFileProvider>());

            // Simulates the generation of projected features from a GEOJSON file //
            var simpleFeatures = Container.GetService <IConfigurationStrategy>().Into <List <Feature> >("populated_points_two_projected");

            var newLayer = new LayerInformationModel
            {
                Identifier = Guid.NewGuid(),
                Name       = Guid.NewGuid().ToString().Substring(0, 6),
                Properties = new Property[]
                {
                    new Property {
                        Name = LayerProperties.Features, Value = simpleFeatures, ValueType = typeof(List <IGeometryItem>)
                    }
                }
            };

            layerService.AddLayer(newLayer);

            // the Add layer method removes the features and replaces it with a count //
            Assert.AreEqual(2, newLayer.Properties.First(p => p.Name == LayerProperties.Features).Value);

            // NOW try to retrieve the tile from memory //
            var context = new SimpleTileContext()
            {
                Identifier = newLayer.Name,
                MaxZoom    = 14,
                Buffer     = 64,
                Extent     = 4096,
                Tolerance  = 3
            };
            var accessor  = new LayerTileCacheAccessor(() => new MockTransformedCacheStorage(), () => new MockRawCacheStorage());
            var generator = new Generator(context, accessor, layerService);
            var retriever = new TileRetrieverService(accessor, context, generator);

            var tile = await retriever.GetTile(1, 0, 0);

            Assert.IsNotNull(tile);
        }
Пример #7
0
        internal async Task CommandReceiver(IMessage message)
        {
            if (message is GeneralCommand gCommand)
            {
                // This will be the function that receives a command from the event framework //
                // and processes the command into a valid data conversion //
                var topic = new TopicMessage {
                    Message =
                        $"Tile Processing request started for {gCommand.Command}, for ID:{gCommand.Id.ToString()}"
                };
                messageRepository.AddMessage(topic);
                await messenger.Send(topic);

                try
                {
                    var fileName     = gCommand.CommandDataCollection.FirstOrDefault(cd => cd.DataType == "filename")?.Data?.ToString();
                    var uploadedFile = await fileRepository.Get(gCommand.Id.ToString(), fileName);

                    string converted = uploadedFile.GetDataContentsAsString(Encoding.UTF8);
                    string uniqueId  = GenerateUniqueId(gCommand.Id);
                    var    context   = new GeoJsonContext(uploadedFile.TextContents)
                    {
                        Identifier = fileName + $"_{uniqueId}",
                        MaxZoom    = 14,
                        Buffer     = 64,
                        Extent     = 4096,
                        Tolerance  = 3
                    };

                    var pipeline = new DetermineCollectionsTypePipeline()
                                   .ExtendWith(new ParseGeoJsonToFeatures()
                                               .IterateWith(new ProjectGeoJSONToGeometric(
                                                                (geoItem) => new WebMercatorProcessor(geoItem)))
                                               .ExtendWith(new GeometricSimplification())
                                               .ExtendWith(new InitializeProjectedFeatures(tileService)));

                    await pipeline.Process(context);

                    var layerModel = new LayerInformationModel
                    {
                        Identifier = gCommand.Id,
                        Name       = context.Identifier,
                        Properties = new Property[]
                        {
                            new Property {
                                Name = "features", Value = context.TileFeatures, ValueType = typeof(List <IGeometryItem>)
                            }
                        }
                    };
                    layerService.AddLayer(layerModel);

                    var topicFinished = new TopicMessage
                    {
                        Message = $"Tile Processing request FINISHED for {gCommand.Command}, for ID:{gCommand.Id.ToString()}"
                    };
                    messageRepository.AddMessage(topicFinished);
                    await messenger.Send(topicFinished);
                }
                catch (Exception ex)
                {
                    await logger.Log(new MessageLogEntry
                    {
                        Type        = LogType.Error.ToString(),
                        Title       = $"Processing the command {gCommand.Command} failed while building the projected data. Error Message : {ex.Message}",
                        Id          = gCommand.CorrellationId,
                        MessageBody = ex.StackTrace
                    });
                }
            }
        }