Beispiel #1
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine($"Polling Time is {pollingTime} seconds");
            //Calculate milliseconds to give to the method below for waiting
            pollingTimeMS = pollingTime * 1000;

            //Initialize azure cloud client
            client = new AzureCloudClient(azureIoTConnectionString);

            while (true)
            {
                try
                {
                    // Check the value of the sensor
                    sensor.Measure();
                    double sensortemp = sensor.TemperatureInFahrenheit;
                    double sensorhum  = sensor.Humidity;

                    //Check for invalid values
                    if (double.IsNaN(sensortemp) || double.IsNaN(sensorhum))
                    {
                        throw new Exception($"Sensor not working - Temperature:{sensortemp}, Humidity:{sensorhum}");
                    }

                    //Sending payload to the cloud
                    Debug.WriteLine($"Temp: {sensortemp.ToString()}F Humidity: {sensorhum}%.");
                    DataObject data = new DataObject()
                    {
                        Temperature = sensortemp,
                        Humidity    = sensorhum,
                        DeviceName  = deviceName
                    };
                    client.WriteData(data);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                //Wait for the alloted polling time in milliseconds
                Task.Delay(pollingTimeMS).Wait();
            }
        }
 /// <summary>
 /// set Repositories
 /// </summary>
 /// <param name="products"></param>
 /// <param name="file"></param>
 /// <param name="order"></param>
 public OrdersController(ICloudClient <FirestoreDb, Product> products, ICloudClient <CloudBlobContainer, Product> file, ICloudClient <FirestoreDb, Order> order)
 {
     _products = products;
     _file     = file;
     _order    = order;
 }
 /// <summary>
 ///
 /// </summary>
 public ProductsController(ILogger <ProductsController> logger, ICloudClient <FirestoreDb, Product> products)
 {
     _logger   = logger;
     _products = products;
 }
 public ProductRepository_FireBase(IConfiguration config, IMemoryCache cache, ICloudClient <CloudBlobContainer, Product> file)
 {
     _config = config;
     _cache  = cache;
     _file   = file;
 }