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();
            }
        }
Пример #2
0
        private async void OnWriteCommand(object obj)
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            ProgressDialogConfig    progressDialogConfig    = new ProgressDialogConfig()
            {
                Title      = "Writing...",
                CancelText = "Cancel",
                OnCancel   = cancellationTokenSource.Cancel
            };
            var diag = _userDialogs.Progress(progressDialogConfig);

            try
            {
                var uri    = new Uri(path);
                var values = new Dictionary <string, string>
                {
                    { "accessPoint", this.APName },
                    { "password", this.APPassword },
                    { "reboot", "false" }
                };

                var content  = new FormUrlEncodedContent(values);
                var response = await _client.PostAsync(path, content, cancellationTokenSource.Token);

                var responseString = await response.Content.ReadAsStringAsync();

                Debug.WriteLine(responseString);
            }
            catch (OperationCanceledException ex)
            {
                Debug.WriteLine("OperationCanceledException");
            }
            catch (Exception ex)
            {
                diag.Hide();
                await _userDialogs.AlertAsync("Something went wrong...");

                Debug.WriteLine(ex.Message);
            }
            finally
            {
                diag.Hide();
            }
            Debug.WriteLine("OnWriteCommand");
        }
Пример #3
0
        /// <summary>
        /// Tries to connect device.
        /// </summary>
        /// <returns>The to connect device.</returns>
        /// <param name="deviceViewModel">Device view model.</param>
        /// <param name="showPrompt">If set to <c>true</c> show prompt.</param>
        private async Task <bool> TryToConnectDevice(int index = -1, bool showPrompt = true)
        {
            try
            {
                CancellationTokenSource tokenSource = new CancellationTokenSource();

                var config = new ProgressDialogConfig()
                {
                    Title           = $"Trying to establish connection with '{DeviceName}'",
                    CancelText      = "Cancel",
                    IsDeterministic = false,
                    MaskType        = MaskType.None,
                    OnCancel        = tokenSource.Cancel
                };

                bool didConnect = false;
                using (var progress = _userDialogs.Progress(config))
                {
                    progress.Show();
                    if (index > -1)
                    {
                        didConnect = await _bluetoothService.ConnectDevice(SensorDevice, tokenSource, index);
                    }
                    else
                    {
                        didConnect = await _bluetoothService.ConnectDevice(SensorDevice, tokenSource, -1);
                    }
                }

                tokenSource.Dispose();

                if (!didConnect)
                {
                    return(false);
                }
                _userDialogs.Toast($"\tConnected to {SensorDevice.Name}");

                RaisePropertyChanged("ConnectOrDisposeActionString");
                RaisePropertyChanged("ImageSource");
                return(true);
            }
            catch (Exception ex)
            {
                _userDialogs.Alert(ex.Message, "Connection error");
                _log.Trace(ex.Message);
                return(false);
            }
            finally
            {
                _userDialogs.HideLoading();
                Update();
            }
        }
Пример #4
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();
            }
        }
Пример #5
0
        async private void Progress()
        {
            var cancelled = false;

            using (var dlg = _dialogs.Progress("進捗ダメです", () => cancelled = true))
            {
                while (!cancelled && dlg.PercentComplete < 100)
                {
                    await Task.Delay(TimeSpan.FromMilliseconds(500));

                    dlg.PercentComplete += 5;
                }
            }
        }
Пример #6
0
        public FileManagerViewModel(IUserDialogs dialogs, IFileSystem fileSystem)
        {
            this.dialogs    = dialogs;
            this.fileSystem = fileSystem;

            this.Select = ReactiveCommand.Create <FileEntryViewModel>(entry =>
            {
                var cfg = new ActionSheetConfig().SetCancel();

                if (entry.IsDirectory)
                {
                    cfg.Add("Enter", () => this.CurrentPath = entry.Entry.FullName);
                }
                else
                {
                    cfg.Add("Copy", () =>
                    {
                        var progress = dialogs.Progress(new ProgressDialogConfig
                        {
                            Title = "Copying File"
                        });

                        var fn     = Path.GetFileNameWithoutExtension(entry.Entry.Name);
                        var ext    = Path.GetExtension(entry.Entry.Name);
                        var newFn  = ext.IsEmpty() ? $"fn_1" : $"{fn}_1.{ext}";
                        var target = new FileInfo(newFn);
                        var file   = new FileInfo(entry.Entry.FullName);
                        file
                        .CopyProgress(target, true)
                        .Subscribe(p =>
                        {
                            progress.Title           = "Copying File - Seconds Left: " + p.TimeRemaining.TotalSeconds;
                            progress.PercentComplete = p.PercentComplete;
                        });
                    });
                }
                cfg.Add("Delete", () => Confirm("Delete " + entry.Name, entry.Entry.Delete));
                dialogs.ActionSheet(cfg);
            });

            this.showBack = this.WhenAnyValue(x => x.CurrentPath)
                            .Select(x => x == this.CurrentPath)
                            .ToProperty(this, x => x.ShowBack);

            this.WhenAnyValue(x => x.CurrentPath)
            .Skip(1)
            .Subscribe(_ => this.LoadEntries())
            .DisposeWith(this.DestroyWith);
        }
Пример #7
0
        async void ShowDialog(string Msg)
        {
            var config = new ProgressDialogConfig()
            {
                Title           = Msg,
                IsDeterministic = true,
                MaskType        = MaskType.Gradient,
            };

            using (var progress = _userDialogs.Progress(config))
            {
                progress.Show();
                await System.Threading.Tasks.Task.Delay(1000);
            }
        }
        private async void ConnectToPreviousDeviceAsync()
        {
            IDevice device;

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

                var config = new ProgressDialogConfig()
                {
                    Title           = $"Searching for '{PreviousGuid}'",
                    CancelText      = "Cancel",
                    IsDeterministic = false,
                    OnCancel        = tokenSource.Cancel
                };

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

                    device = await Adapter.ConnectToKnownDeviceAsync(PreviousGuid, connectParameters, tokenSource.Token);
                }

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

                var deviceItem = Devices.FirstOrDefault(d => d.Device.Id == device.Id);
                if (deviceItem == null)
                {
                    deviceItem = new DeviceListItemViewModel(device);
                    Devices.Add(deviceItem);
                    //await Task.Delay(9000);
                }
                else
                {
                    deviceItem.Update(device);
                }
            }
            catch (Exception ex)
            {
                _userDialogs.ShowError(ex.Message, 5000);
                return;
            }
        }
Пример #9
0
        private async Task <bool> ConnectDeviceAsync(IDevice device, bool showPrompt = true)
        {
            if (showPrompt && !await _userDialogs.ConfirmAsync($"Connect to device '{device.Name}'?"))
            {
                return(false);
            }

            CancellationTokenSource tokenSource = new CancellationTokenSource();

            try
            {
                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, new ConnectParameters(autoConnect : true, forceBleTransport : true), tokenSource.Token);
                }

                await _userDialogs.AlertAsync($"Connected to {device.Name}.");

                return(true);
            }
            catch (Exception ex)
            {
                await _userDialogs.AlertAsync(ex.Message, "Connection error");

                Trace.Message(ex.Message);
                return(false);
            }
            finally
            {
                _userDialogs.HideLoading();
                tokenSource.Dispose();
                tokenSource = null;
            }
        }
Пример #10
0
        public async Task <bool> TryConnectDevice(IDevice device, bool showPrompt = 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, new ConnectParameters(autoConnect : false, forceBleTransport : true), tokenSource.Token);
                }
                ConnectedDeice = device;
                await userDialogs.AlertAsync($"Connected to {device.Name}.");

                return(true);
            }
            catch (Exception ex)
            {
                await userDialogs.AlertAsync(ex.Message, "Connection error");

                Plugin.BLE.Abstractions.Trace.Message(ex.Message);
                return(false);
            }
            finally
            {
                userDialogs.HideLoading();
            }
        }
        public DetailViewModel(LocationRepository locationsRepository, IAppSettings appSettings, IUserDialogs userDialogs, IMvxMessenger messenger, IDeviceInfoService deviceInfoService)
        {
            _locationsRepository = locationsRepository;

            _appSettings       = appSettings;
            _messenger         = messenger;
            _deviceInfoService = deviceInfoService;

            _progressDialogs = userDialogs.Progress(new ProgressDialogConfig
            {
                Title           = Resources.AppResources.ProgressDialog_Loading,
                IsDeterministic = false,
                AutoShow        = false
            });

            ChangeLocationCommand = new MvxAsyncCommand <Location>(OnChangeLocationCommandExecute);

            _deviceInfoService.DeviceMarginsChanged += delegate
            {
                RaisePropertyChanged(nameof(SafeAreaMargins));
            };
        }
Пример #12
0
        private async void OnSendCommand(object obj)
        {
            var data1 = StatesToString(PresetModel.FirstPanel);
            var data2 = StatesToString(PresetModel.SecondPanel);
            var data3 = StatesToString(PresetModel.ThirdPanel);
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            ProgressDialogConfig    progressDialogConfig    = new ProgressDialogConfig()
            {
                Title      = "Sending...",
                CancelText = "Cancel",
                OnCancel   = cancellationTokenSource.Cancel
            };
            var diag = _userDialogs.Progress(progressDialogConfig);
            await Task.Run(async() =>
            {
                var res = deviceModels.Where(x => x.IsEnabled == true);
                if (res == null)
                {
                    return;
                }
                foreach (var device in res)
                {
                    try
                    {
                        var data = default(string);
                        switch (device.Panel)
                        {
                        case "1":
                            data = data1;
                            break;

                        case "2":
                            data = data2;
                            break;

                        case "3":
                            data = data3;
                            break;
                        }

                        HttpClient httpClient = new HttpClient();
                        //httpClient.Timeout = Constants.HttpRequestTimeout;
                        string path = device.Site + Constants.ControlPath;
                        var uri     = new Uri(path);
                        var values  = new Dictionary <string, string> {
                            { "ledsData", data }
                        };
                        var content  = new FormUrlEncodedContent(values);
                        var response = await httpClient.PostAsync(path, content, cancellationTokenSource.Token);
                        Debug.WriteLine(response);
                    }
                    catch (OperationCanceledException ex)
                    {
                        Debug.WriteLine("OperationCanceledException");
                        return;
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            });

            diag.Hide();
            Debug.WriteLine("SendDataToLamposhniiServerAsync");
        }