private void OnError()
        {
            Task.Run(() =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Error error = Errors.LastError;

                    ContentView_Scripting_textScript.Text = "Error code: " + error.Id + "\n" + error.Message;

                    Utils.Print("[ Scripting ] " + ContentView_Scripting_textScript.Text + ((error.HasMessagePopup) ? " | " + error.MessagePopup : string.Empty));

                    Device.BeginInvokeOnMainThread(() =>
                    {
                        backdark_bg.IsVisible           = false;
                        indicator.IsVisible             = false;
                        ContentView_Scripting.IsEnabled = true;
                        _userTapped = false;
                        ContentView_Scripting_label_read.Text = "Script Execution Error";

                        Device.OpenUri(new Uri(resultCallback + "?" +
                                               "status=error" +
                                               Compression.GetUriParameter() +
                                               "&message=" + Compression.CompressToUrlUsingGlobal("Error code: " + error.Id + "\n" + error.MessagePopup) +
                                               "&output_filename=" + resultScriptName +
                                               "&output_data=" + Compression.CompressToUrlUsingGlobal(Errors.lastErrorLogGenerated)));

                        FormsApp.ble_interface.Close();

                        // Close the app
                        System.Diagnostics.Process.GetCurrentProcess().Kill();
                    });
                });
            });
        }
        private void OnFinish(object sender, MTUComm.Action.ActionFinishArgs e)
        {
            Task.Run(() =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    try
                    {
                        ContentView_Scripting_textScript.Text = "";
                        Parameter[] allParams = e.Result.getParameters();

                        for (int k = 0; k < allParams.Length; k++)
                        {
                            String res = allParams[k].getLogDisplay() + ": " + allParams[k].Value;
                            String val = ContentView_Scripting_textScript.Text;
                            ContentView_Scripting_textScript.Text = val + res + "\r\n";
                        }

                        ActionResult[] allports = e.Result.getPorts();

                        for (int i = 0; i < allports.Length; i++)
                        {
                            ActionResult actionResult = allports[i];
                            Parameter[] portParams    = actionResult.getParameters();

                            for (int j = 0; j < portParams.Length; j++)
                            {
                                String res = portParams[j].getLogDisplay() + ": " + portParams[j].Value;
                                String val = ContentView_Scripting_textScript.Text;
                                ContentView_Scripting_textScript.Text = val + res + "\r\n";
                            }
                        }

                        string xmlResultTocallback = ((MTUComm.Action)sender).GetResultXML(e.Result);

                        Device.BeginInvokeOnMainThread(() =>
                        {
                            backdark_bg.IsVisible           = false;
                            indicator.IsVisible             = false;
                            ContentView_Scripting.IsEnabled = true;
                            _userTapped = false;
                            ContentView_Scripting_label_read.Text = "Successful Script Execution";

                            Device.OpenUri(new Uri(resultCallback + "?" +
                                                   "status=success" +
                                                   Compression.GetUriParameter() +
                                                   "&output_filename=" + resultScriptName +
                                                   "&output_data=" + Compression.CompressToUrlUsingGlobal(xmlResultTocallback)));

                            FormsApp.ble_interface.Close();

                            System.Diagnostics.Process.GetCurrentProcess().Kill();
                        });
                    }
                    catch (Exception ex)
                    {
                    }
                });
            });
        }
        public async void UpdateFiles()
        {
            String sMessage;

            // Upload log files
            if (GenericUtilsClass.NumLogFilesToUpload(Mobile.LogPath) > 0)
            {
                bool bUpload = await GenericUtilsClass.UploadFiles(false);

                int numFiles = GenericUtilsClass.NumFilesUploaded;

                sMessage = (bUpload) ? $" ** {numFiles.ToString()} Files uploaded successfully ** " : "Error while uploading files to the FTP server";
            }
            else
            {
                sMessage = "There are not log files to upload";
            }

            Device.OpenUri(new Uri(resultCallback + "?" +
                                   "status=success" +
                                   Compression.GetUriParameter() +
                                   "&output_filename=UploadingFiles" +
                                   "&output_data=" + Compression.CompressToUrlUsingGlobal(sMessage)));

            System.Diagnostics.Process.GetCurrentProcess().Kill();
            return;
        }