Exemple #1
0
        protected virtual bool AddDeviceInternal(DeviceBase device)
        {
            if (!_canCreateDevices || device == null || !device.IsConfigurationValid())
            {
                return(false);
            }

            _devices.Add(device);
            PersistingService.SaveAsync(Name, device);
            return(true);
        }
        public async Task SaveAsync(string gatewayName, DeviceBase device)
        {
            var properties = GetProperties(device);

            var dto = new DeviceDto
            {
                Gateway = gatewayName,
                Id = $"{gatewayName}.{device.Id}",
                Name = device.Name,
                Properties = JsonConvert.SerializeObject(properties)
            };

            using (var database = new Database("ConnectionString"))
            {
                var result = await database.UpdateAsync("Device", "Id", dto, dto.Id, new[] {"Gateway", "Name", "Properties"});

                if (result == 1)
                {
                    return;
                }

                await database.InsertAsync("Device", "Id", false, dto);
            }
        }
Exemple #3
0
 protected bool Equals(DeviceBase other)
 {
     return(Id.Equals(other.Id));
 }
 protected bool Equals(DeviceBase other)
 {
     return Id.Equals(other.Id);
 }