Example #1
0
        public Device(
            string deviceId,
            DeviceBehaviour deviceBehaviour,
            EventHubTransport transport)
        {
            this.deviceId        = deviceId;
            this.transport       = transport;
            this.deviceBehaviour = deviceBehaviour;
            int peakFrequencyInTicks = Convert.ToInt32(Math.Ceiling((double)PEAK_FREQUENCY_IN_SECONDS / REPORT_FREQUENCY_IN_SECONDS));

            this.dscGenerator         = new SampleDataGenerator(0, 0.6);
            this.temperatureGenerator = new SampleDataGenerator(22, 24, 30, peakFrequencyInTicks);
            this.humidityGenerator    = new SampleDataGenerator(20, 50);
            this.vibrationGenerator   = new SampleDataGenerator(0, 10);

            this.loadGenerator = !this.deviceBehaviour.IsService ? new SampleDataGenerator(200, 800) : new SampleDataGenerator(300, 1200);
        }
Example #2
0
        static void Main(string[] args)
        {
            ctsSource = new CancellationTokenSource();

            // Event hub connection string
            var connectionString =
                "";
            var transport = new EventHubTransport(connectionString);

            try
            {
                var deviceFactory = new DeviceFactory(transport);

                var dataRows = new List <string[]>();
                var csvLines = File.ReadAllLines(@"Data/SimulationDevices.csv", Encoding.UTF8);
                var rawrows  = csvLines.Skip(1); // skip header row
                foreach (string line in rawrows)
                {
                    dataRows.Add(line.Split(','));
                }

                Console.WriteLine($"Preparing {dataRows.Count} devices...");

                var devices = deviceFactory.GenerateDevices(dataRows);

                StartSendLoopAsync(devices);

                Console.WriteLine($"Press any key to stop the loop or wait for {durationMinutes} minute(s)...");
                Console.ReadKey();
                ctsSource.Cancel();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                transport.CloseTransport().GetAwaiter();
            }
        }
Example #3
0
 public DeviceFactory(EventHubTransport transport)
 {
     this.transport = transport;
 }