Update() публичный Метод

public Update ( IDevice newDevice = null ) : void
newDevice IDevice
Результат void
        private async Task <bool> ConnectDeviceAsync(DeviceListItemViewModel device, bool showPrompt = true)
        {
            if (showPrompt && !await _userDialogs.ConfirmAsync($"Connect to device '{device.Name}'?"))
            {
                return(false);
            }

            try
            {
                CancellationTokenSource tokenSource       = new CancellationTokenSource();
                ConnectParameters       connectParameters = new ConnectParameters();

                await Adapter.ConnectToDeviceAsync(device.Device, connectParameters, tokenSource.Token);

                _userDialogs.ShowSuccess($"Initializing Reader, Please Wait.", 8000);

                PreviousGuid = device.Device.Id;

                return(true);
            }
            catch (Exception ex)
            {
                _userDialogs.Alert(ex.Message, "Connection error");
                Mvx.Trace(ex.Message);
                return(false);
            }
            finally
            {
                //_userDialogs.HideLoading();
                device.Update();
            }
        }
        private async void ConnectAndDisposeDevice(DeviceListItemViewModel item)
        {
            try
            {
                using (item.Device)
                {
                    //_userDialogs.ShowLoading($"Connecting to {item.Name} ...");
                    await Adapter.ConnectToDeviceAsync(item.Device);

                    item.Update();
                    //_userDialogs.ShowSuccess($"Connected {item.Device.Name}");

                    //_userDialogs.HideLoading();
                    //for (var i = 5; i >= 1; i--)
                    //{
                    //    _userDialogs.ShowLoading($"Disconnect in {i}s...");

                    //    await Task.Delay(1000);

                    //    _userDialogs.HideLoading();
                    //}
                }
            }
            catch (Exception ex)
            {
                _userDialogs.Alert(ex.Message, "Failed to connect and dispose.");
            }
            finally
            {
                _userDialogs.HideLoading();
            }
        }
        private async Task <bool> ConnectDeviceAsync(DeviceListItemViewModel device, bool showPrompt = true)
        {
            if (device.IsConnected)
            {
                return(true);
            }

            if (showPrompt && !await _userDialogs.ConfirmAsync($"Connect to device '{device.Name}'?"))
            {
                return(false);
            }
            try
            {
                _userDialogs.ShowLoading("Connecting ...");

                await Adapter.ConnectToDeviceAync(device.Device);

                _userDialogs.InfoToast($"Connected to {device.Device.Name}.");

                PreviousGuid = device.Device.Id;
                return(true);
            }
            catch (Exception ex)
            {
                _userDialogs.Alert(ex.Message, "Connection error");
                Mvx.Trace(ex.Message);
                return(false);
            }
            finally
            {
                _userDialogs.HideLoading();
                device.Update();
            }
        }
        private async void DisconnectDevice(DeviceListItemViewModel device)
        {
            if (BleMvxApplication._reader.Status != CSLibrary.HighLevelInterface.READERSTATE.DISCONNECT)
            {
                BleMvxApplication._reader.DisconnectAsync();
            }

            try
            {
                if (!device.IsConnected)
                {
                    return;
                }

                _userDialogs.ShowLoading($"Disconnecting {device.Name}...");

                await Adapter.DisconnectDeviceAsync(device.Device);
            }
            catch (Exception ex)
            {
                _userDialogs.Alert(ex.Message, "Disconnect error");
            }
            finally
            {
                device.Update();
                _userDialogs.HideLoading();
            }
        }
        private async Task <bool> ConnectDeviceAsync(DeviceListItemViewModel device, bool showPrompt = true)
        {
            //if (device.IsConnected)
            //{
            //    return true;
            //}

            if (showPrompt && !await _userDialogs.ConfirmAsync($"Connect to device '{device.Name}'?"))
            {
                return(false);
            }
            try
            {
                CancellationTokenSource tokenSource = new CancellationTokenSource();

                var config = new ProgressDialogConfig()
                {
                    Title           = $"Connecting to '{device.Id}'",
                    CancelText      = "Cancel",
                    IsDeterministic = false,
                    OnCancel        = tokenSource.Cancel
                };

                using (var progress = _userDialogs.Progress(config))
                {
                    progress.Show();

                    await Adapter.ConnectToDeviceAsync(device.Device, new ConnectParameters(forceBleTransport : false), tokenSource.Token);
                }

                _userDialogs.ShowSuccess($"Connected to {device.Device.Name}.");

                PreviousGuid = device.Device.Id;
                return(true);
            }
            catch (Exception ex)
            {
                _userDialogs.Alert(ex.Message, "Connection error");
                Mvx.Trace(ex.Message);
                return(false);
            }
            finally
            {
                _userDialogs.HideLoading();
                device.Update();
            }
        }
Пример #6
0
        private async void ConnectAndDisposeDevice(DeviceListItemViewModel item)
        {
            try
            {
                using (item.Device)
                {
                    _userDialogs.ShowLoading($"Connecting to {item.Name} ...");
                    await Adapter.ConnectToDeviceAsync(item.Device);

                    // TODO make this configurable
                    var resultMTU = await item.Device.RequestMtuAsync(60);

                    System.Diagnostics.Debug.WriteLine($"Requested MTU. Result is {resultMTU}");

                    // TODO make this configurable
                    var resultInterval = item.Device.UpdateConnectionInterval(ConnectionInterval.High);
                    System.Diagnostics.Debug.WriteLine($"Set Connection Interval. Result is {resultInterval}");

                    item.Update();
                    //_userDialogs.ShowSuccess($"Connected {item.Device.Name}");
                    _userDialogs.Toast($"Connected {item.Device.Name}");

                    _userDialogs.HideLoading();
                    for (var i = 5; i >= 1; i--)
                    {
                        _userDialogs.ShowLoading($"Disconnect in {i}s...");

                        await Task.Delay(1000);

                        _userDialogs.HideLoading();
                    }
                }
            }
            catch (Exception ex)
            {
                _userDialogs.Alert(ex.Message, "Failed to connect and dispose.");
            }
            finally
            {
                _userDialogs.HideLoading();
            }
        }
Пример #7
0
        private async void DisconnectDevice(DeviceListItemViewModel device)
        {
            try {
                device.IsMaster = false;
                device.IsSlave  = false;
                if (!device.IsConnected)
                {
                    return;
                }

                _userDialogs.ShowLoading($"Disconnecting {device.Name}...");

                await Adapter.DisconnectDeviceAsync(device.Device);
            } catch (Exception ex) {
                _userDialogs.Alert(ex.Message, "Disconnect error");
            } finally {
                device.Update();
                _userDialogs.HideLoading();
            }
        }
Пример #8
0
        private async void DisconnectDevice(DeviceListItemViewModel device)
        {
            try
            {
                if (!device.IsConnected)
                {
                    return;
                }

                await UVIZIO.disconnectDevice(device, _userDialogs);
            }
            catch (Exception ex)
            {
                _userDialogs.Alert("Unable to Disconnect", "Disconnect error");
            }
            finally
            {
                device.Update();
                _userDialogs.HideLoading();
            }
        }
Пример #9
0
        private async Task <bool> ConnectDeviceAsync(DeviceListItemViewModel device, bool showPrompt = true)
        {
            try
            {
                CancellationTokenSource tokenSource = new CancellationTokenSource();

                var config = new ProgressDialogConfig()
                {
                    Title           = $"Connecting to '{device.Name}'",
                    CancelText      = "Cancel",
                    IsDeterministic = false,
                    OnCancel        = tokenSource.Cancel
                };

                using (var progress = _userDialogs.Progress(config))
                {
                    progress.Show();

                    await Adapter.ConnectToDeviceAsync(device.Device, tokenSource.Token);
                }

                _userDialogs.ShowSuccess($"Connected to {device.Device.Name}.");

                PreviousGuid = device.Device.Id;
                PreviousName = device.Name;
                return(true);
            }
            catch (Exception ex)
            {
                _userDialogs.Alert("Could not connect to " + device.Name, "Connection error");
                Mvx.Trace(ex.Message);
                return(false);
            }
            finally
            {
                _userDialogs.HideLoading();
                device.Update();
            }
        }