Exemplo n.º 1
0
 static void Monitor(int deviceId, string longitude, string latitude, string warningTemp, DatabaseConnection database)
 {
     var warningThreshhold = double.Parse(warningTemp);
     Sensor tempProbe = new Sensor();
     while (true)
     {
         var tempReading = GetCurrentTemp(tempProbe);
         if (tempReading > warningThreshhold)
             Console.Out.WriteLine(String.Format("WARNING: Temperature reading of {0} exceeded the warning threshhold of {1}."
                 , tempReading, warningTemp));
         database.WriteTemperature(tempReading, deviceId, longitude, latitude, tempReading > warningThreshhold);
         Thread.Sleep(10000);
     }
 }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     if(args.Length != 4 || args[0] == "-help" || args[0] == "-h")
     {
         Console.Out.WriteLine("Must Pass four arguments to the process");
         Console.Out.WriteLine("1) Device Id - This must be registered in the Database");
         Console.Out.WriteLine("2) Latitude");
         Console.Out.WriteLine("3) Longitude");
         Console.Out.WriteLine("4) Warning Temp");
     }
     int deviceId = int.Parse(args[0]);
     DatabaseConnection database = new DatabaseConnection();
     try
     {
         database.ActivateDevice(deviceId);
         Task.Factory.StartNew(() => Monitor(deviceId, args[1], args[2], args[3], database));
         Console.Out.WriteLine("Press any key to quit");
         Console.ReadKey();
         database.DeactivateDevices(deviceId);
     }
     catch
     {
         database.DeactivateDevices(deviceId);
         throw;
     }
 }