Example #1
0
 public EventSender(Device device, SimulatorConfiguration config, Func<object,byte[]> serializer)
 {
     _serializer = serializer;
     var connectionString = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessSignature(
         device.Endpoint, device.EventHubName, device.Id, device.Token);
     _eventHubSender = EventHubSender.CreateFromConnectionString(connectionString);
 }
Example #2
0
 public static UpdateTemperatureEvent ThirtyDegreeTemperatureEventFactory(Random random, Device device)
 {
     return new UpdateTemperatureEvent
     {
         DeviceId = device.Id,
         TimeObserved = DateTime.UtcNow,
         Temperature = 30,
     };
 }
Example #3
0
        public static UpdateTemperatureEvent TemperatureEventFactory(Random random, Device device)
        {
            if (!device.CurrentTemperature.HasValue)
            {
                device.CurrentTemperature = random.Next(25);
            }
            else
            {
                var temperatureChange = random.Next(-2, 3);
                device.CurrentTemperature += temperatureChange;
            }

            return new UpdateTemperatureEvent
            {
                DeviceId = device.Id,
                TimeObserved = DateTime.UtcNow,
                Temperature = device.CurrentTemperature.Value,
            };
        }
Example #4
0
 public object CreateNewEvent(Device device)
 {
     return _eventFactory(_random, device);
 }
Example #5
0
        private static async Task SimulateDeviceAsync(
            Device device,
            Func<EventEntry[]> produceEventsForScenario,
            Func<object, Task<bool>> sendEventsAsync,
            TimeSpan waitBeforeStarting,
            IObserver<int> totalCount,
            CancellationToken token)
        {
            ScenarioSimulatorEventSource.Log.WarmingUpFor(device.Id, waitBeforeStarting.Ticks);

            try
            {
                await Task.Delay(waitBeforeStarting, token);
            }
            catch (TaskCanceledException)
            {
                return;
            }

            var messagingEntries = produceEventsForScenario();

            device.ObservableEventCount
                .Sum()
                .Subscribe(total => ScenarioSimulatorEventSource.Log.FinalEventCount(device.Id, total));

            device.ObservableEventCount
                .Subscribe(totalCount.OnNext);

            await device.RunSimulationAsync(messagingEntries, sendEventsAsync, token).ConfigureAwait(false);
        }