Пример #1
0
        static void OutputMessageInfo(string action, EventData data, MetricEvent info)
        {
            if (data == null)
            {
                return;
            }

            if (info != null)
            {
                Console.WriteLine("{0}{1} - Device {2}.", action, data, info.DeviceId);
            }
        }
Пример #2
0
        public static async void SendEvent(MetricEvent info)
        {
            // Create EventHubClient
            EventHubClient client = EventHubClient.CreateFromConnectionString(GetServiceBusConnectionString(), EventHubName); 

            try
            {
                Trace.WriteLine(String.Format("Sending message to Event Hub {0}", client.Path));

                var serializedString = JsonConvert.SerializeObject(info);
                EventData data = new EventData(Encoding.UTF8.GetBytes(serializedString));

                // Send the metric to Event Hub
                await client.SendAsync(data);

            }
            catch (Exception exp)
            {
                Trace.WriteLine("Error on send: " + exp.Message);
            }

            client.CloseAsync().Wait();
        }