示例#1
0
        private async void OnReadCommand(object obj)
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            ProgressDialogConfig    progressDialogConfig    = new ProgressDialogConfig()
            {
                Title      = "Reading...",
                CancelText = "Cancel",
                OnCancel   = cancellationTokenSource.Cancel
            };
            var diag = _userDialogs.Progress(progressDialogConfig);

            try
            {
                var uri = new Uri(path);
                HttpResponseMessage response = await _client.GetAsync(uri, cancellationTokenSource.Token);

                if (response.IsSuccessStatusCode)
                {
                    var a = await response.Content.ReadAsStringAsync();

                    LightBoxConfigModel lightBoxConfigModel = (LightBoxConfigModel)JsonConvert.DeserializeObject(a, typeof(LightBoxConfigModel));
                    this.APName     = lightBoxConfigModel.accessPoint;
                    this.APPassword = lightBoxConfigModel.password;
                    this.MAC        = lightBoxConfigModel.mac;
                    this.Site       = lightBoxConfigModel.url;

                    //Saving to memory
                    await _appSettingsManager.AddDeviceAsync(new DeviceModel()
                    {
                        Mac   = lightBoxConfigModel.mac,
                        Site  = lightBoxConfigModel.url,
                        Panel = "1"
                    });
                }
            }
            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("OnReadCommand");
        }