Ejemplo n.º 1
0
        public void HandleUrl(Uri url, IBluetoothLowEnergyAdapter adapter)
        {
            try
            {
                ScriptingMode = true;
                ble_interface.Close();

                #region WE HAVE TO DISABLE THE BLUETOOTH ANTENNA, IN ORDER TO DISCONNECT FROM PREVIOUS CONNECTION, IF WE WENT FROM INTERACTIVE TO SCRIPTING MODE

                adapter.DisableAdapter();
                adapter.EnableAdapter(); //Android shows a window to allow bluetooth

                #endregion
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }

            if (url != null)
            {
                string path = Mobile.GetPath();
                NameValueCollection query = HttpUtility.ParseQueryString(url.Query);

                var script_name = query.Get("script_name");
                var script_data = query.Get("script_data");
                var callback    = query.Get("callback");

                if (script_name != null)
                {
                    path = Path.Combine(path, script_name.ToString());
                }

                if (script_data != null)
                {
                    File.WriteAllText(path, Base64Decode(script_data));
                }

                if (callback != null) /* ... */ } {
                Task.Run(async() =>
                {
                    await Task.Delay(1000); Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        //Settings.IsLoggedIn = false;
                        //credentialsService.DeleteCredentials ();

                        MainPage = new NavigationPage(new AclaraViewScripting(path, callback, script_name));
                        await MainPage.Navigation.PopToRootAsync(true);
                    });
                });
        }
    }
Ejemplo n.º 2
0
 private async Task ToggleAdapter(Boolean enable)
 {
     StopScan();
     try
     {
         await(enable ? m_bleAdapter.EnableAdapter() : m_bleAdapter.DisableAdapter());
     }
     catch (SecurityException ex)
     {
         m_dialogs.Toast(ex.Message);
         Log.Debug(ex, nameof(BleDeviceScannerViewModel));
     }
     RaisePropertyChanged(nameof(IsAdapterEnabled));
 }
Ejemplo n.º 3
0
        public async void HandleUrl(Uri url, IBluetoothLowEnergyAdapter adapter)
        {
            Data.Set("IsFromScripting", true);

            Utils.Print("FormsApp: Scripting [ " + Data.Get.IsFromScripting + " ]");

            if (this.abortMission)
            {
                return;
            }

            try
            {
                if (ble_interface != null &&
                    ble_interface.IsOpen())
                {
                    ble_interface.Close();
                }

                #region WE HAVE TO DISABLE THE BLUETOOTH ANTENNA, IN ORDER TO DISCONNECT FROM PREVIOUS CONNECTION, IF WE WENT FROM INTERACTIVE TO SCRIPTING MODE

                await adapter.DisableAdapter();

                await adapter.EnableAdapter(); //Android shows a window to allow bluetooth

                #endregion
            }
            catch (Exception e)
            {
                Utils.Print(e.StackTrace);
            }

            if (url != null)
            {
                //string path = Mobile.ConfigPath;
                //ConfigPaths();
                string path = Mobile.ConfigPath;
                NameValueCollection query = HttpUtility.ParseQueryString(url.Query);

                var script_name = query.Get("script_name");
                var script_data = query.Get("script_data");
                var callback    = query.Get("callback");

                if (script_name != null)
                {
                    path = Path.Combine(path, "___" + script_name.ToString());
                }

                if (script_data != null)
                {
                    File.WriteAllText(path, Base64Decode(script_data));
                }

                if (callback != null) /* ... */ } {
                if (MainPage == null)  // no interactive
                {
                    tcs1 = new TaskCompletionSource <bool>();
                    bool result = await tcs1.Task;
                }

                await Task.Run(async() =>
                {
                    await Task.Delay(1000); Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        //Settings.IsLoggedIn = false;
                        //credentialsService.DeleteCredentials ();

                        MainPage = new NavigationPage(new AclaraViewScripting(path, callback, script_name));

                        await MainPage.Navigation.PopToRootAsync(true);
                    });
                });
        }
    }