public static async Task <IActionResult> Traffic(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post")] TrafficRaw message,
            [SignalR(HubName = "simulator")] IAsyncCollector <SignalRMessage> signalRMessages)
        {
            var ti = new TrafficInfo();

            ti.EndpointLabel = Environment.GetEnvironmentVariable("EndpointLabel");
            ti.Endpoint      = Environment.GetEnvironmentVariable("Endpoint"); // A B or C
            ti.Source        = message.Source;
            ti.Style         = message.Style;

            ti.Ticks = DateTime.UtcNow.Ticks;

            await signalRMessages.AddAsync(
                new SignalRMessage
            {
                Target    = "ReceiveTrafficData",
                Arguments = new[] { ti }
            });

            return(new OkResult());
        }
Exemplo n.º 2
0
        static async Task Main(string[] args)
        {
            var endpoint = System.Environment.GetEnvironmentVariable("Url");
            var sleep    = System.Environment.GetEnvironmentVariable("SleepTime");
            var source   = System.Environment.GetEnvironmentVariable("Source");
            var style    = System.Environment.GetEnvironmentVariable("Style");

            HttpClient client = new HttpClient();

            Console.WriteLine("Started.");

            while (true)
            {
                var tr = new TrafficRaw()
                {
                    Source = source,
                    Style  = style
                };

                try
                {
                    var data = JsonConvert.SerializeObject(tr);

                    Console.WriteLine($"Sending to {endpoint} - data {data}");
                    var r = await client.PostAsync(endpoint, new StringContent(data));

                    Console.WriteLine($"{data}");

                    Thread.Sleep(int.Parse(sleep));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
            }
        }