Exemple #1
0
        public async Task <Result> ConnectDeviceAsync(IDevice device, IDeviceConnection deviceConnection)
        {
            var res = await deviceConnection.TryOpenConnectionAsync(device.DeviceLogger);

            if (device.DeviceLogger == null)
            {
                device.DeviceLogger = _loggerGetFunc();
            }
            if (res.IsSuccess)
            {
                if (device.DeviceConnection != deviceConnection)
                {
                    device?.DeviceConnection?.Dispose();
                }
            }
            //инициализация подключения (добавление логгеров, датапровайдеров)
            device.InitializeConnection(deviceConnection);
            ConnectableItemChanged?.Invoke(new ConnectableItemChangingContext(device, ItemModifyingTypeEnum.Connected));
            if (res.IsSuccess)
            {
                if (device.DeviceConnection != deviceConnection)
                {
                    device.DeviceConnection.Dispose();
                }
                return(Result.Create(true));
            }

            return(res);
        }
Exemple #2
0
        public void Refresh()
        {
            ConnectableItemChanged?.Invoke(
                new ConnectableItemChangingContext(null, ItemModifyingTypeEnum.Refresh));
            foreach (var item in ConnectableItems)
            {
                try
                {
                    item.DeviceConnection.CloseConnection();
                }
                catch (Exception ex)
                {
                    _logService.LogMessage(ex.Message);
                }
            }

            ConnectableItems.Clear();
        }
Exemple #3
0
 public void AddConnectableItem(IConnectable device)
 {
     ConnectableItems.Add(device);
     ConnectableItemChanged?.Invoke(new ConnectableItemChangingContext(device, ItemModifyingTypeEnum.Add));
 }