static void Main(string[] args)
        {
            Console.WriteLine("Enter commands:");

            string line;

            Console.WriteLine("Enter one or more lines of text (press CTRL+Z to exit):");
            Console.WriteLine();
            do
            {
                line = Console.ReadLine();
                if (line != null)
                {
                    switch (line.ToLower())
                    {
                    case "qoff":
                    {
                        qObserver.Close();
                        break;
                    }

                    case "q":
                    {
                        var serviceBus = new QueueClient(subscriberConnectionString, Queues.GeneralCommand);
                        qObserver = new ObserverClient(serviceBus);

                        break;
                    }

                    case "s":
                    {
                        var serviceBus = new QueueClient(publisherConnectionString, Queues.GeneralCommand);
                        qMessenger = new MessengerClient(serviceBus);
                        Task.Factory.StartNew(async() =>
                            {
                                await qMessenger.Send(new GeneralCommand
                                {
                                    Command = "Cosole Test Command",
                                    Id      = Guid.NewGuid(),
                                    CommandDataCollection = new List <CommandData>()
                                    {
                                        new CommandData {
                                            Data = true, DataType = typeof(bool).ToString()
                                        }
                                    }
                                });
                            });

                        break;
                    }

                    case "t":
                    {
                        var topicClient = new TopicClient(publisherConnectionString, "general-info");
                        tMessenger = new MessengerClient(topicClient);
                        Task.Factory.StartNew(async() =>
                            {
                                await tMessenger.Send(new TopicMessage
                                {
                                    Id      = Guid.NewGuid(),
                                    Message = "Topic Message from a console application"
                                });
                            });

                        //Task.Factory.StartNew(async () =>
                        //{
                        //    var sender = new MessageSender(publisherConnectionString, "general-info");
                        //    await sender.SendAsync(new Message { MessageId = Guid.NewGuid().ToString() });
                        //    await sender.CloseAsync();
                        //});

                        break;
                    }

                    case "to":
                    {
                        //receiver = new MessageReceiver(subscriberConnectionString, "general-info");
                        //receiver.RegisterMessageHandler((m, c) =>
                        //{
                        //    Console.WriteLine($"Received Topic with id : {m.CorrelationId}");
                        //    return Task.FromResult(true);
                        //},
                        //new MessageHandlerOptions((ex)=> { Console.WriteLine(ex.Exception.Message); return Task.FromResult(true); })
                        //{
                        //    MaxConcurrentCalls = 2,
                        //    AutoComplete = false
                        //});

                        var topicObserver = new SubscriptionClient(subscriberConnectionString, "general-info", "gis");
                        tObserver = new ObserverClient(topicObserver, false);

                        tObserver.RegisterForNotificationOf <TopicMessage>(async(m) =>
                            {
                                if (m is TopicMessage topicMessage)
                                {
                                    Console.WriteLine(topicMessage.Message);
                                }
                                await Task.FromResult(true);
                            });
                        break;
                    }

                    case "peek":
                    {
                        Task.Factory.StartNew(async() =>
                            {
                                var receiver     = new MessageReceiver(subscriberConnectionString, "general-info");
                                bool hasMessages = true;
                                while (hasMessages)
                                {
                                    Message message = await receiver.PeekAsync();
                                    hasMessages     = message != null;
                                    if (hasMessages)
                                    {
                                        Console.WriteLine(message.CorrelationId);
                                    }
                                }
                                await receiver.CloseAsync();
                            });

                        break;
                    }

                    default:
                        break;
                    }
                }
            } while (line != null);
        }
示例#2
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
                    });
                }
            }
        }