Exemplo n.º 1
0
        public async Task <List <DeviceInfoDTO> > GetAllDeviceInfo()
        {
            var deviceInfos = await dbContext.Device.ToListAsync();

            var deviceInfoDTOs = new List <DeviceInfoDTO>();

            foreach (var device in deviceInfos)
            {
                var deviceInfoDTO = new DeviceInfoDTO()
                {
                    Id          = device.Id,
                    Description = device.Description,
                    Function    = device.Func,
                    Name        = device.Name,
                    IsAlive     = false
                };
                try
                {
                    HttpClient client = await GetHttpClient(device.Ip);

                    var response = await client.GetAsync("/info");

                    var responseString = response.Content.ReadAsStringAsync().Result;
                    var responseDevice = JsonConvert.DeserializeObject <ADeviceInfo>(responseString);
                    deviceInfoDTO.Ip      = responseDevice.Ip;
                    deviceInfoDTO.IsAlive = true;
                }
                catch (Exception ex)
                {
                }
                deviceInfoDTOs.Add(deviceInfoDTO);
            }
            return(deviceInfoDTOs);
        }
        public SettingsDropoffWindEditFm(Utils.Operation operation, DeviceInfoDTO model)
        {
            InitializeComponent();

            _deviceId  = (operation == Utils.Operation.Add) ? -1 : model.DeviceId;
            _operation = operation;
            dropoffWindBS.DataSource = model;

            nameTBox.DataBindings.Add("EditValue", dropoffWindBS, "Name");
            windNumberTBox.DataBindings.Add("EditValue", dropoffWindBS, "SettingValue");
        }
        private bool FindDeviceNameDuplicate(DeviceInfoDTO item)
        {
            bool result = false;

            if (ConfigClass.Instance.DeviceSettingsList != null)
            {
                var source = (ConfigClass.Instance.DeviceSettingsList).FirstOrDefault(s => s.Name == item.Name);

                if (source != null)
                {
                    result = (source.DeviceId != item.DeviceId) ? true : false;
                }
            }

            return(result);
        }