Beispiel #1
0
        static async Task SendingCarEventData()
        {
            var eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);

            while (true)
            {
                try
                {
                    var city = GetLocation();

                    var info = new CarEvent()
                    {
                        vin  = GetRandomVIN(),
                        city = city,
                        outsideTemperature = GetOutsideTemp(city),
                        engineTemperature  = GetEngineTemp(city),
                        speed        = GetSpeed(city),
                        fuel         = random.Next(0, 40),
                        engineoil    = GetOil(city),
                        tirepressure = GetTirePressure(city),
                        odometer     = random.Next(0, 200000),
                        accelerator_pedal_position = random.Next(0, 100),
                        parking_brake_status       = GetRandomBoolean(),
                        headlamp_status            = GetRandomBoolean(),
                        brake_pedal_status         = GetRandomBoolean(),
                        transmission_gear_position = GetGearPos(),
                        ignition_status            = GetRandomBoolean(),
                        windshield_wiper_status    = GetRandomBoolean(),
                        abs       = GetRandomBoolean(),
                        timestamp = DateTime.UtcNow
                    };
                    var       serializedString = JsonConvert.SerializeObject(info);
                    EventData data             = new EventData(Encoding.UTF8.GetBytes(serializedString));
                    //{
                    //    PartitionKey = info.productId.ToString()
                    //};

                    // Set user properties if needed
                    data.Properties.Add("Type", "Telemetry_" + DateTime.Now.ToLongTimeString());
                    //Console.WriteLine("{0} > Sending message: {1}", DateTime.Now.ToString(), data.ToString());
                    Console.WriteLine("{0} > Sending message: {1}", DateTime.Now.ToString(), serializedString.ToString());
                    //await eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(data.ToString())));
                    await eventHubClient.SendAsync(data);
                }
                catch (Exception exception)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("{0} > Exception: {1}", DateTime.Now.ToString(), exception.Message);
                    Console.ResetColor();
                }

                await Task.Delay(200);
            }
        }
Beispiel #2
0
        private static async Task SendingCarEventData()
        {
            EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(Program.connectionString, Program.eventHubName);

            while (true)
            {
                try
                {
                    string   city = Program.GetLocation();
                    CarEvent info = new CarEvent()
                    {
                        vin  = Program.GetRandomVIN(),
                        city = city,
                        outsideTemperature = Program.GetOutsideTemp(city),
                        engineTemperature  = Program.GetEngineTemp(city),
                        speed        = Program.GetSpeed(city),
                        fuel         = Program.random.Next(0, 40),
                        engineoil    = Program.GetOil(city),
                        tirepressure = Program.GetTirePressure(city),
                        odometer     = Program.random.Next(0, 200000),
                        accelerator_pedal_position = Program.random.Next(0, 100),
                        parking_brake_status       = Program.GetRandomBoolean(),
                        headlamp_status            = Program.GetRandomBoolean(),
                        brake_pedal_status         = Program.GetRandomBoolean(),
                        transmission_gear_position = Program.GetGearPos(),
                        ignition_status            = Program.GetRandomBoolean(),
                        windshield_wiper_status    = Program.GetRandomBoolean(),
                        abs       = Program.GetRandomBoolean(),
                        timestamp = DateTime.UtcNow
                    };
                    string    serializedString = JsonConvert.SerializeObject((object)info);
                    EventData data             = new EventData(Encoding.UTF8.GetBytes(serializedString));
                    data.get_Properties().Add("Type", (object)("Telemetry_" + DateTime.Now.ToLongTimeString()));
                    Console.WriteLine("{0} > Sending message: {1}", (object)DateTime.Now.ToString(), (object)serializedString.ToString());
                    await eventHubClient.SendAsync(data);
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("{0} > Exception: {1}", (object)DateTime.Now.ToString(), (object)ex.Message);
                    Console.ResetColor();
                }
                await Task.Delay(200);
            }
        }