Example #1
0
        private async Task RenameDeviceAsync()
        {
            try
            {
                var result = await _dialogService.ShowInputDialogAsync("Rename", "Enter a new name for the device", Device.Name, "Device name", "Rename", "Cancel", _disappearingTokenSource.Token);

                if (result.IsOk)
                {
                    if (string.IsNullOrWhiteSpace(result.Result))
                    {
                        await _dialogService.ShowMessageBoxAsync("Warning", "Device name can not be empty.", "Ok", _disappearingTokenSource.Token);

                        return;
                    }

                    await _dialogService.ShowProgressDialogAsync(
                        false,
                        async (progressDialog, token) => await Device.RenameDeviceAsync(Device, result.Result),
                        "Renaming...");
                }
            }
            catch (OperationCanceledException)
            {
            }
        }
Example #2
0
            public DeviceOutputViewModel(Device device, int channel)
            {
                Device  = device;
                Channel = channel;
                Output  = 0;

                TouchUpCommand = new Command(() => Output = 0);
            }
Example #3
0
        private async Task ConnectAsync()
        {
            _connectionTokenSource = new CancellationTokenSource();
            DeviceConnectionResult connectionResult = DeviceConnectionResult.Ok;

            await _dialogService.ShowProgressDialogAsync(
                false,
                async (progressDialog, token) =>
            {
                using (token.Register(() => _connectionTokenSource?.Cancel()))
                {
                    connectionResult = await Device.ConnectAsync(
                        _reconnect,
                        OnDeviceDisconnected,
                        Enumerable.Empty <ChannelConfiguration>(),
                        true,
                        true,
                        _connectionTokenSource.Token);
                }
            },
                Translate("Connecting"),
                null,
                Translate("Cancel"));

            _connectionTokenSource.Dispose();
            _connectionTokenSource = null;

            if (Device.DeviceState == DeviceState.Connected)
            {
                _reconnect = true;

                if (Device.DeviceType == DeviceType.BuWizz)
                {
                    SetBuWizzOutputLevel(BuWizzOutputLevel);
                }
                else if (Device.DeviceType == DeviceType.BuWizz2)
                {
                    SetBuWizzOutputLevel(BuWizz2OutputLevel);
                }
            }
            else
            {
                if (!_isDisappearing)
                {
                    if (connectionResult == DeviceConnectionResult.Error)
                    {
                        await _dialogService.ShowMessageBoxAsync(
                            Translate("Warning"),
                            Translate("FailedToConnect"),
                            Translate("Ok"),
                            _disappearingTokenSource.Token);
                    }

                    await NavigationService.NavigateBackAsync();
                }
            }
        }
Example #4
0
 private void OnDeviceDisconnected(Device device)
 {
     _uIThreadService.RunOnMainThread(() =>
     {
         if (!_isDisappearing)
         {
             _connectionTask = ConnectAsync();
         }
     });
 }
Example #5
0
        public override async void OnDisappearing()
        {
            _isDisappearing = true;
            _disappearingTokenSource.Cancel();

            if (_connectionTokenSource != null && _connectionTask != null)
            {
                _connectionTokenSource.Cancel();
                await _connectionTask;
            }

            await Device.DisconnectAsync();
        }
Example #6
0
        public override async void OnDisappearing()
        {
            _isDisappearing = true;
            _disappearingTokenSource.Cancel();

            Device.DeviceStateChanged -= DeviceStateChangedHandler;

            if (_connectionTokenSource != null)
            {
                _connectionTokenSource.Cancel();
                await _connectionTask;
            }

            await Device.DisconnectAsync();
        }
Example #7
0
 private async Task DeleteDeviceAsync(Device device)
 {
     try
     {
         if (await _dialogService.ShowQuestionDialogAsync("Confirm", $"Are you sure to delete device {device.Name}?", "Yes", "No", _disappearingTokenSource.Token))
         {
             await _dialogService.ShowProgressDialogAsync(
                 false,
                 async (progressDialog, token) => await DeviceManager.DeleteDeviceAsync(device),
                 "Deleting...");
         }
     }
     catch (OperationCanceledException)
     {
     }
 }
Example #8
0
        private async Task ConnectAsync()
        {
            _connectionTokenSource = new CancellationTokenSource();
            DeviceConnectionResult connectionResult = DeviceConnectionResult.Ok;

            await _dialogService.ShowProgressDialogAsync(
                false,
                async (progressDialog, token) =>
            {
                token.Register(() => _connectionTokenSource.Cancel());

                connectionResult = await Device.ConnectAsync(_connectionTokenSource.Token);
            },
                "Connecting...",
                null,
                "Cancel");

            _connectionTokenSource.Dispose();
            _connectionTokenSource = null;

            if (Device.DeviceState == DeviceState.Connected)
            {
                if (Device.DeviceType == DeviceType.BuWizz)
                {
                    SetBuWizzOutputLevel(BuWizzOutputLevel);
                }
                else if (Device.DeviceType == DeviceType.BuWizz2)
                {
                    SetBuWizzOutputLevel(BuWizz2OutputLevel);
                }
            }
            else
            {
                if (!_isDisappearing)
                {
                    if (connectionResult == DeviceConnectionResult.Error)
                    {
                        await _dialogService.ShowMessageBoxAsync("Warning", "Failed to connect to device.", "Ok", _disappearingTokenSource.Token);
                    }

                    await NavigationService.NavigateBackAsync();
                }
            }
        }
 private async Task DeleteDeviceAsync(Device device)
 {
     try
     {
         if (await _dialogService.ShowQuestionDialogAsync(
                 Translate("Confirm"),
                 $"{Translate("AreYouSureToDeleteDevice")} '{device.Name}'?",
                 Translate("Yes"),
                 Translate("No"),
                 _disappearingTokenSource.Token))
         {
             await _dialogService.ShowProgressDialogAsync(
                 false,
                 async (progressDialog, token) => await DeviceManager.DeleteDeviceAsync(device),
                 Translate("Deleting"));
         }
     }
     catch (OperationCanceledException)
     {
     }
 }
Example #10
0
        private async Task RenameDeviceAsync()
        {
            try
            {
                var result = await _dialogService.ShowInputDialogAsync(
                    Device.Name,
                    Translate("DeviceName"),
                    Translate("Rename"),
                    Translate("Cancel"),
                    KeyboardType.Text,
                    (deviceName) => !string.IsNullOrEmpty(deviceName),
                    _disappearingTokenSource.Token);

                if (result.IsOk)
                {
                    if (string.IsNullOrWhiteSpace(result.Result))
                    {
                        await _dialogService.ShowMessageBoxAsync(
                            Translate("Warning"),
                            Translate("DeviceNameCanNotBeEmpty"),
                            Translate("Ok"),
                            _disappearingTokenSource.Token);

                        return;
                    }

                    await _dialogService.ShowProgressDialogAsync(
                        false,
                        async (progressDialog, token) => await Device.RenameDeviceAsync(Device, result.Result),
                        Translate("Renaming"),
                        token : _disappearingTokenSource.Token);
                }
            }
            catch (OperationCanceledException)
            {
            }
        }
Example #11
0
 private void SetBuWizzOutputLevel(int level)
 {
     Device.SetOutputLevel(level);
 }
Example #12
0
 private void OnDeviceDisconnected(Device device)
 {
 }
Example #13
0
        private async Task ConnectAsync()
        {
            while (!_connectionTokenSource.IsCancellationRequested)
            {
                if (Device.DeviceState != DeviceState.Connected)
                {
                    var connectionResult = DeviceConnectionResult.Ok;

                    var dialogResult = await _dialogService.ShowProgressDialogAsync(
                        false,
                        async (progressDialog, token) =>
                    {
                        using (token.Register(() => _connectionTokenSource?.Cancel()))
                        {
                            connectionResult = await Device.ConnectAsync(
                                _reconnect,
                                OnDeviceDisconnected,
                                Enumerable.Empty <ChannelConfiguration>(),
                                true,
                                true,
                                _connectionTokenSource.Token);
                        }
                    },
                        Translate("ConnectingTo"),
                        Device.Name,
                        Translate("Cancel"),
                        _connectionTokenSource.Token);

                    if (dialogResult.IsCancelled)
                    {
                        await Device.DisconnectAsync();

                        if (!_isDisappearing)
                        {
                            await NavigationService.NavigateBackAsync();
                        }

                        return;
                    }
                    else
                    {
                        if (connectionResult == DeviceConnectionResult.Error)
                        {
                            await _dialogService.ShowMessageBoxAsync(
                                Translate("Warning"),
                                Translate("FailedToConnect"),
                                Translate("Ok"),
                                _disappearingTokenSource.Token);

                            if (!_isDisappearing)
                            {
                                await NavigationService.NavigateBackAsync();
                            }

                            return;
                        }
                        else
                        {
                            if (Device.DeviceType == DeviceType.BuWizz)
                            {
                                SetBuWizzOutputLevel(BuWizzOutputLevel);
                            }
                            else if (Device.DeviceType == DeviceType.BuWizz2)
                            {
                                SetBuWizzOutputLevel(BuWizz2OutputLevel);
                            }
                        }
                    }
                }
                else
                {
                    await Task.Delay(50);
                }
            }
        }