Exemple #1
0
 public Task <bool> AddDevice(Device device)
 {
     if (string.IsNullOrWhiteSpace(device.Id))
     {
         device.Id = Guid.NewGuid().ToString();
     }
     if (DeviceLogHandlers.Any())
     {
         Task.Run(async() =>
         {
             foreach (var handler in DeviceLogHandlers)
             {
                 try
                 {
                     await handler.AddDevice(device);
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine(ex);
                 }
             }
         });
     }
     return(DeviceDatabase.Shared.InsertDevice(device));
 }
Exemple #2
0
        public async Task UpdateCurrentState(DeviceState state)
        {
            if (DeviceLogHandlers.Any())
            {
                Task.WhenAll(DeviceLogHandlers.Select(handler => Task.Run(async() =>
                {
                    try
                    {
                        await handler.DeviceUpdate(state);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                })).ToList());
                //await Task.WhenAll(
            }
            await DeviceDatabase.Shared.InsertDeviceState(state);

            if (state.PropertyKey == DevicePropertyKey.Level)
            {
                var switchState = new DeviceState
                {
                    Value       = state.IntValue > 0,
                    PropertyKey = DevicePropertyKey.SwitchState,
                    DeviceId    = state.DeviceId,
                    DataType    = DataTypes.Bool,
                };
                await UpdateCurrentState(switchState);
            }
        }
Exemple #3
0
 public Task UpdateCurrentState(DeviceState state)
 {
     if (DeviceLogHandlers.Any())
     {
         Task.Run(async() => {
             foreach (var handler in DeviceLogHandlers)
             {
                 try {
                     await handler.DeviceUpdate(state);
                 } catch (Exception ex) {
                     Console.WriteLine(ex);
                 }
             }
         });
     }
     return(DeviceDatabase.Shared.InsertDeviceState(state));
 }
Exemple #4
0
 public Task <bool> AddDevice(Device device)
 {
     if (DeviceLogHandlers.Any())
     {
         Task.Run(async() => {
             foreach (var handler in DeviceLogHandlers)
             {
                 try {
                     await handler.AddDevice(device);
                 } catch (Exception ex) {
                     Console.WriteLine(ex);
                 }
             }
         });
     }
     return(DeviceDatabase.Shared.InsertDevice(device));
 }