Ejemplo n.º 1
0
        /// <summary>
        /// Public constructor for TurbofanDevice class.
        /// </summary>
        /// <param name="deviceNumber">Integer number of the data series device to send</param>
        /// <param name="iotHubConnectionString">Connection string for the IoT Hub in which to create the device</param>
        /// <param name="fileManager">TrainingFileManager for the dataset to be read and sent</param>
        public TurbofanDevice(int deviceNumber, string iotHubConnectionString, TrainingFileManager fileManager, string gatewayFqdn = null)
        {
            deviceUnitNumber = deviceNumber;
            string deviceId = $"Client_{deviceNumber:000}";

            deviceConnectionString = GetIotHubDevice(iotHubConnectionString, deviceId, gatewayFqdn).Result;
            trainingFileManager    = fileManager;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the set of tasks that will send data to the IoT hub.
        /// </summary>
        /// <param name="fileManager">TrainingFileManager for the data set for devices to send.</param>
        /// <returns></returns>
        private static List <Task> SetupDeviceRunTasks(TrainingFileManager fileManager)
        {
            List <Task> deviceTasks = new List <Task>();

            string iotHubConnectionString = GetConnectionString();
            int    maxDevice   = GetMaxDevice(fileManager);
            string gatewayHost = gatewayHostNameOption.HasValue() ? gatewayHostNameOption.Value() : null;

            for (int i = 1; i <= maxDevice; i++)
            {
                var device = new TurbofanDevice(i, iotHubConnectionString, fileManager, gatewayHost);
                devices.Add(device);
                deviceTasks.Add(device.RunDeviceAsync());
            }

            return(deviceTasks);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Main entry point for the device harness. If args are not passed default data set FD003
        /// is used and program prompts for IoT Hub connection string
        /// </summary>
        /// <param name="args">-x "hub connection string" -d "FDOO3" -c "certificate path" -m "maximum # devices"</param>
        static void Main(string[] args)
        {
            InitializeApp();
            app.OnExecute(() =>
            {
                InstallCertificate();

                string trainingSet = GetDataSet();
                var fileManager    = new TrainingFileManager(trainingSet);

                List <Task> deviceRunTasks = SetupDeviceRunTasks(fileManager);
                Task.WhenAll(deviceRunTasks).Wait();

                return(0);
            });

            app.Execute(args);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Return the number of devices for which to send, which will be the lower
        /// of the number of devices in the data set and the value of the passed in max devices
        /// </summary>
        /// <param name="filemanager">TrainingFileManager for the data set for devices to send.</param>
        /// <returns></returns>
        private static int GetMaxDevice(TrainingFileManager filemanager)
        {
            int maxDevices = filemanager.MaxDeviceId;

            if (!maxDevicesOption.HasValue())
            {
                return(maxDevices);
            }

            int.TryParse(maxDevicesOption.Value(), out int maxRequested);

            if (maxRequested == 0)
            {
                return(maxDevices);
            }

            return(Math.Min(maxRequested, maxDevices));
        }