public IEnumerable <BrokeredMessage> GenerateBrokeredMessageCollection(int brokeredMessageCount, WriteToLogDelegate writeToLog)
        {
            if (brokeredMessageCount < 0)
            {
                return(null);
            }
            var random      = new Random();
            var messageList = new List <BrokeredMessage>();

            for (var i = 0; i < brokeredMessageCount; i++)
            {
                try
                {
                    var normalState = AlertState == (int)OnOff.Off ? OnOff.On : OnOff.Off;
                    var alertState  = AlertState == (int)OnOff.Off ? OnOff.Off : OnOff.On;
                    var payload     = new OnOffDeviceEvent
                    {
                        EventId   = EventId++,
                        DeviceId  = random.Next(MinDeviceId, MaxDeviceId + 1),
                        Value     = random.Next(1, 101) <= AlertPercentage ? alertState : normalState,
                        Timestamp = DateTime.UtcNow
                    };
                    var text = MessageFormat == MessageFormat.Json
                        ? JsonSerializerHelper.Serialize(payload)
                        : XmlSerializerHelper.Serialize(payload);
                    var brokeredMessage = new BrokeredMessage(text.ToMemoryStream())
                    {
                        MessageId = payload.DeviceId.ToString(CultureInfo.InvariantCulture),
                    };
                    brokeredMessage.Properties.Add("eventId", payload.EventId);
                    brokeredMessage.Properties.Add("deviceId", payload.DeviceId);
                    brokeredMessage.Properties.Add("value", (int)payload.Value);
                    brokeredMessage.Properties.Add("time", DateTime.UtcNow.Ticks);
                    brokeredMessage.Properties.Add("city", City);
                    brokeredMessage.Properties.Add("country", Country);
                    brokeredMessage.Label = Label;
                    messageList.Add(brokeredMessage);
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrWhiteSpace(ex.Message))
                    {
                        writeToLog(string.Format(CultureInfo.CurrentCulture, ExceptionFormat, ex.Message));
                    }
                    if (ex.InnerException != null && !string.IsNullOrWhiteSpace(ex.InnerException.Message))
                    {
                        writeToLog(string.Format(CultureInfo.CurrentCulture, InnerExceptionFormat, ex.InnerException.Message));
                    }
                }
            }
            if (writeToLog != null)
            {
                writeToLog(string.Format(BrokeredMessageCreatedFormat, messageList.Count));
            }
            return(messageList);
        }
        public IEnumerable <EventData> GenerateEventDataCollection(int eventDataCount, WriteToLogDelegate writeToLog)
        {
            if (eventDataCount < 0)
            {
                return(null);
            }
            var random = new Random();
            var list   = new List <EventData>();

            for (var i = 0; i < eventDataCount; i++)
            {
                try
                {
                    var normalState = AlertState == (int)OnOff.Off ? OnOff.On : OnOff.Off;
                    var alertState  = AlertState == (int)OnOff.Off ? OnOff.Off : OnOff.On;
                    var payload     = new OnOffDeviceEvent
                    {
                        DeviceId = random.Next(MinDeviceId, MaxDeviceId + 1),
                        Value    = random.Next(1, 101) <= AlertPercentage ? alertState : normalState
                    };
                    var eventData = new EventData((MessageFormat == MessageFormat.Json
                        ? JsonSerializerHelper.Serialize(payload)
                        : XmlSerializerHelper.Serialize(payload)).ToMemoryStream())
                    {
                        PartitionKey = payload.DeviceId.ToString(CultureInfo.InvariantCulture),
                    };
                    eventData.Properties.Add("deviceId", payload.DeviceId);
                    eventData.Properties.Add("value", (int)payload.Value);
                    eventData.Properties.Add("time", DateTime.UtcNow.Ticks);
                    eventData.Properties.Add("city", City);
                    eventData.Properties.Add("country", Country);
                    list.Add(eventData);
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrWhiteSpace(ex.Message))
                    {
                        writeToLog(string.Format(CultureInfo.CurrentCulture, ExceptionFormat, ex.Message));
                    }
                    if (ex.InnerException != null && !string.IsNullOrWhiteSpace(ex.InnerException.Message))
                    {
                        writeToLog(string.Format(CultureInfo.CurrentCulture, InnerExceptionFormat, ex.InnerException.Message));
                    }
                }
            }
            if (writeToLog != null)
            {
                writeToLog(string.Format(EventDataCreatedFormat, list.Count));
            }
            return(list);
        }
 public IEnumerable<BrokeredMessage> GenerateBrokeredMessageCollection(int brokeredMessageCount, WriteToLogDelegate writeToLog)
 {
     if (brokeredMessageCount < 0)
     {
         return null;
     }
     var random = new Random();
     var messageList = new List<BrokeredMessage>();
     for (var i = 0; i < brokeredMessageCount; i++)
     {
         try
         {
             var normalState = AlertState == (int)OnOff.Off ? OnOff.On : OnOff.Off;
             var alertState = AlertState == (int)OnOff.Off ? OnOff.Off : OnOff.On;
             var payload = new OnOffDeviceEvent
             {
                 DeviceId = random.Next(MinDeviceId, MaxDeviceId + 1),
                 Value = random.Next(1, 101) <= AlertPercentage ? alertState : normalState
             };
             var text = MessageFormat == MessageFormat.Json
                 ? JsonSerializerHelper.Serialize(payload)
                 : XmlSerializerHelper.Serialize(payload);
             var brokeredMessage = new BrokeredMessage(text.ToMemoryStream())
             {
                 MessageId = payload.DeviceId.ToString(CultureInfo.InvariantCulture),
             };
             brokeredMessage.Properties.Add("deviceId", payload.DeviceId);
             brokeredMessage.Properties.Add("value", (int)payload.Value);
             brokeredMessage.Properties.Add("time", DateTime.UtcNow.Ticks);
             brokeredMessage.Properties.Add("city", City);
             brokeredMessage.Properties.Add("country", Country);
             brokeredMessage.Label = Label;
             messageList.Add(brokeredMessage);
         }
         catch (Exception ex)
         {
             if (!string.IsNullOrWhiteSpace(ex.Message))
             {
                 writeToLog(string.Format(CultureInfo.CurrentCulture, ExceptionFormat, ex.Message));
             }
             if (ex.InnerException != null && !string.IsNullOrWhiteSpace(ex.InnerException.Message))
             {
                 writeToLog(string.Format(CultureInfo.CurrentCulture, InnerExceptionFormat, ex.InnerException.Message));
             }
         }
     }
     if (writeToLog != null)
     {
         writeToLog(string.Format(BrokeredMessageCreatedFormat, messageList.Count));
     }
     return messageList;
 } 
        public IEnumerable<EventData> GenerateEventDataCollection(int eventDataCount, WriteToLogDelegate writeToLog)
        {
            if (eventDataCount < 0)
            {
                return null;
            }
            var random = new Random();
            var list = new List<EventData>();
            for (var i = 0; i < eventDataCount; i++)
            {
                try
                {
                    var normalState = AlertState == (int)OnOff.Off ? OnOff.On : OnOff.Off;
                    var alertState = AlertState == (int)OnOff.Off ? OnOff.Off : OnOff.On;
                    var payload = new OnOffDeviceEvent
                    {
                        EventId = EventId++,
                        DeviceId = random.Next(MinDeviceId, MaxDeviceId + 1),
                        Value = random.Next(1, 101) <= AlertPercentage ? alertState : normalState,
                        Timestamp = DateTime.UtcNow
                    };
                    var eventData = new EventData((MessageFormat == MessageFormat.Json
                        ? JsonSerializerHelper.Serialize(payload)
                        : XmlSerializerHelper.Serialize(payload)).ToMemoryStream())
                    {
                        PartitionKey = payload.DeviceId.ToString(CultureInfo.InvariantCulture),

                    };
                    eventData.Properties.Add("eventId", payload.EventId);
                    eventData.Properties.Add("deviceId", payload.DeviceId);
                    eventData.Properties.Add("value", (int)payload.Value);
                    eventData.Properties.Add("time", DateTime.UtcNow.Ticks);
                    eventData.Properties.Add("city", City);
                    eventData.Properties.Add("country", Country);
                    list.Add(eventData);
                }
                catch (Exception ex)
                {
                    if (!string.IsNullOrWhiteSpace(ex.Message))
                    {
                        writeToLog(string.Format(CultureInfo.CurrentCulture, ExceptionFormat, ex.Message));
                    }
                    if (ex.InnerException != null && !string.IsNullOrWhiteSpace(ex.InnerException.Message))
                    {
                        writeToLog(string.Format(CultureInfo.CurrentCulture, InnerExceptionFormat, ex.InnerException.Message));
                    }
                }
            }
            if (writeToLog != null)
            {
                writeToLog(string.Format(EventDataCreatedFormat, list.Count));
            }
            return list;
        }