예제 #1
0
 private void run(object obj)
 {
     while (true)
     {
         Thread.Sleep(60000);
         try
         {
             // cleanup
             while (EventLists.Count > 200)
             {
                 EventLists.RemoveAt(0);
             }
             while (DeviceLogs.Count > 200)
             {
                 DeviceLogs.RemoveAt(0);
             }
             // save data
             hashDevices    = saveData(hashDevices, JsonConvert.SerializeObject(Devices), "devices");
             hashDeviceLogs = saveData(hashDeviceLogs, JsonConvert.SerializeObject(DeviceLogs), "devicelogs");
             hashEventLists = saveData(hashEventLists, JsonConvert.SerializeObject(EventLists), "eventlists");
             hashJbalotrons = saveData(hashJbalotrons, JsonConvert.SerializeObject(Jablotrons), "jablotrons");
         }
         catch
         {
         }
     }
 }
예제 #2
0
        public EnergyUsage()
        {
            // --- DEVICE STUBS
            // Creating fake devices and device logs for that device
            int    device1   = 1;
            int    device2   = 2;
            Device myDevice1 = new Device(device1, "Living room", 90, "Lightbulb");
            Device myDevice2 = new Device(device2, "Kitchen", 85, "Fridge");

            allDevices.Add(myDevice1);
            allDevices.Add(myDevice2);

            // --- DEVICE LOG STUBS
            DeviceLogs deviceLog1 = new DeviceLogs(1, device1, new DateTime(2018, 02, 10, 11, 00, 00), "on");
            DeviceLogs deviceLog2 = new DeviceLogs(2, device1, new DateTime(2018, 02, 10, 13, 32, 00), "off");
            DeviceLogs deviceLog3 = new DeviceLogs(3, device2, new DateTime(2018, 02, 11, 15, 08, 00), "on");
            DeviceLogs deviceLog4 = new DeviceLogs(4, device2, new DateTime(2018, 02, 11, 15, 10, 00), "off");

            allDeviceLogs.Add(deviceLog1);
            allDeviceLogs.Add(deviceLog2);
            allDeviceLogs.Add(deviceLog3);
            allDeviceLogs.Add(deviceLog4);
        }