コード例 #1
0
 public static async Task UploadFilesTaskSettings()
 {
     if (GenericUtilsClass.UploadLogFiles())
     {
         Application.Current.MainPage.DisplayAlert("Alert", "Log files successfully uploaded", "Ok");
     }
     else
     {
         Application.Current.MainPage.DisplayAlert("Error", "Log files could not be uploaded", "Ok");
     }
 }
コード例 #2
0
    public bool InstallFTPProcess()
    {
        //Configure download FTP
        if (Mobile.IsNetAvailable())
        {
            bool result = false;
            tcs = new TaskCompletionSource <bool>();
            // Console.WriteLine($"------------------------------------FTP  Thread: {Thread.CurrentThread.ManagedThreadId}");
            Device.BeginInvokeOnMainThread(async() =>
                {
                    MainPage = new NavigationPage(new FtpDownloadSettings(tcs));
                    //PopupNavigation.Instance.PushAsync(new FtpDownloadSettings());

                    result = await tcs.Task;

                    if (!this.InitializeConfiguration())
                    {
                        GenericUtilsClass.DeleteConfigFiles(Mobile.ConfigPath);
                        return;
                    }

                    NewConfigVersion = GenericUtilsClass.CheckFTPConfigVersion();
                    //GenericUtilsClass.SetInstallMode("FTP");

                    if (this.abortMission)
                    {
                        this.ShowErrorAndKill(new ConfigurationFilesNotFoundException());
                        return;
                    }
                    await SecureStorage.SetAsync("ConfigVersion", NewConfigVersion);

                    if (!Data.Get.IsFromScripting)
                    {
                        //Console.WriteLine($"------------------------------------Login  Thread: {Thread.CurrentThread.ManagedThreadId}");
                        Application.Current.MainPage = new NavigationPage(new AclaraViewLogin(dialogs));
                    }
                    else
                    {
                        tcs1.SetResult(true);
                    }
                });

            return(false);
        }
        else
        {
            this.ShowErrorAndKill(new NoInternetException());
            this.abortMission = true;
            return(false);
        }
    }
コード例 #3
0
    private bool UpdateConfigFiles()
    {
        if (Mobile.configData.HasIntune || Mobile.configData.HasFTP)
        {
            if (Mobile.IsNetAvailable())
            {
                GenericUtilsClass.DownloadConfigFiles(out string sFileCert);
                if (!Mobile.configData.IsCertLoaded && !string.IsNullOrEmpty(sFileCert))
                {
                    Mobile.configData.StoreCertificate(Mobile.configData.CreateCertificate(null, sFileCert));
                }

                return(true);
            }
            //this.ShowErrorAndKill(new NoInternetException());
            //MainPage.DisplayAlert("Attention", "There is not connection at this moment, try again later","OK");
            return(false);
        }
        else
        {
            Mobile.configData.HasFTP = false;

            // Check if all configuration files are available in public folder
            bool HasPublicFiles = GenericUtilsClass.HasDeviceAllXmls(Mobile.ConfigPublicPath);
            //this.abortMission = !this.HasDeviceAllXmls(Mobile.ConfigPublicPath);
            if (HasPublicFiles)
            {
                bool CPD = false;
                if (GenericUtilsClass.TagGlobal(true, "ConfigPublicDir", out dynamic value))
                {
                    if (value != null)
                    {
                        bool.TryParse((string)value, out CPD);
                    }
                }
                GenericUtilsClass.CopyConfigFiles(!CPD, Mobile.ConfigPublicPath, Mobile.ConfigPath, out string sFileCert);
                if (!string.IsNullOrEmpty(sFileCert))
                {
                    Mobile.configData.StoreCertificate(Mobile.configData.CreateCertificate(null, sFileCert));
                }

                if (!GenericUtilsClass.HasDeviceAllXmls(Mobile.ConfigPath))
                {
                    return(true);
                }
            }
            return(true);
        }
    }
コード例 #4
0
        public static async Task UploadFilesTask()
        {
            var res = await Application.Current.MainPage.DisplayAlert("Alert", "Detected pending log files. Do you want to Upload them?", "Ok", "Cancel");

            if (res)
            {
                if (GenericUtilsClass.UploadLogFiles())
                {
                    Application.Current.MainPage.DisplayAlert("Alert", "Log files successfully uploaded", "Ok");
                }
                else
                {
                    Application.Current.MainPage.DisplayAlert("Error", "Log files could not be uploaded", "Ok");
                }
            }
        }
コード例 #5
0
        private void  LoadConfigurationAndOpenScene(IUserDialogs dialogs)
        {
            //ConfigPaths();

            // Only download configuration files from FTP when all are not installed

            bool Result = true;

            if (!GenericUtilsClass.HasDeviceAllXmls(Mobile.ConfigPath))
            {
                Result = InitialConfigProcess();
                //Install certificate if needed(Convert from.cer to base64 string / .txt)
                if (!GenericUtilsClass.GenerateBase64Certificate(Mobile.ConfigPath))
                {
                    this.ShowErrorAndKill(new CertificateFileNotValidException());

                    return;
                }
            }

            if (Result)
            {
                // Load configuration files
                // If some configuration file is not present, Configuration.cs initialization should avoid
                // launch exception when try to parse xmls, to be able to use generating the log error
                if (!this.InitializeConfiguration())
                {
                    GenericUtilsClass.DeleteConfigFiles(Mobile.ConfigPath);
                    return;
                }

                if (!Mobile.configData.HasIntune)
                {
                    Utils.Print("Local parameters loaded..");
                }
                else
                {
                    Utils.Print("Intune parameters loaded..");
                }
                if (Mobile.configData.HasIntune || Mobile.configData.HasFTP)
                {
                    Utils.Print("FTP: " + Mobile.configData.ftpDownload_Host + ":" + Mobile.configData.ftpDownload_Port + " - "
                                + Mobile.configData.ftpDownload_User + " [ " + Mobile.configData.ftpDownload_Pass + " ]");
                    if (Mobile.configData.IsCertLoaded)
                    {
                        Utils.Print("Certificate: " + Mobile.configData.certificate.Subject + " [ " + Mobile.configData.certificate.NotAfter + " ]");
                    }
                }

                if (this.abortMission)
                {
                    this.ShowErrorAndKill(new ConfigurationFilesNotFoundException());

                    return;
                }

                if (!Data.Get.IsFromScripting)
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        Application.Current.MainPage = new NavigationPage(new AclaraViewLogin(dialogs));
                        // await MainPage.Navigation.PopToRootAsync(true);
                    });
                }
                else
                {
                    tcs1.SetResult(true);
                }
            }
        }
コード例 #6
0
        private bool InitialConfigProcess()
        {
            if (Mobile.configData.HasIntune)
            {
                if (Mobile.IsNetAvailable())
                {
                    GenericUtilsClass.DownloadConfigFiles();
                    return(true);
                }
                this.ShowErrorAndKill(new NoInternetException());
                //MainPage.DisplayAlert("Attention", "There is not connection at this moment, try again later","OK");
                return(false);
            }
            else
            {
                Mobile.configData.HasFTP = false;
                SecureStorage.RemoveAll();
                // Check if all configuration files are available in public folder
                bool HasPublicFiles = GenericUtilsClass.HasDeviceAllXmls(Mobile.ConfigPublicPath);
                //this.abortMission = !this.HasDeviceAllXmls(Mobile.ConfigPublicPath);
                if (HasPublicFiles)
                {
                    //// Install certificate if needed ( Convert from .cer to base64 string / .txt )
                    //if (!GenericUtilsClass.GenerateBase64Certificate(Mobile.ConfigPublicPath))
                    //{
                    //    this.ShowErrorAndKill(new CertificateFileNotValidException());

                    //    return false;
                    //}
                    //File.Copy(file.FullName, Path.Combine(url_to_copy, file.Name), true);
                    bool CPD = false;
                    if (GenericUtilsClass.TagGlobal("ConfigPublicDir", out dynamic value))
                    {
                        if (value != null)
                        {
                            bool.TryParse((string)value, out CPD);
                        }
                    }
                    GenericUtilsClass.CopyConfigFilesToPrivate(!CPD);

                    if (!GenericUtilsClass.HasDeviceAllXmls(Mobile.ConfigPath))
                    {
                        return(true);
                    }
                }
                else
                {
                    //Configure download FTP
                    if (Mobile.IsNetAvailable())
                    {
                        bool result = false;
                        tcs = new TaskCompletionSource <bool>();
                        // Console.WriteLine($"------------------------------------FTP  Thread: {Thread.CurrentThread.ManagedThreadId}");
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            MainPage = new NavigationPage(new FtpDownloadSettings(tcs));
                            //PopupNavigation.Instance.PushAsync(new FtpDownloadSettings());

                            result = await tcs.Task;

                            // Install certificate if needed ( Convert from .cer to base64 string / .txt )
                            if (!GenericUtilsClass.GenerateBase64Certificate(Mobile.ConfigPath))
                            {
                                this.ShowErrorAndKill(new CertificateFileNotValidException());

                                return;
                            }

                            if (!this.InitializeConfiguration())
                            {
                                return;
                            }

                            if (this.abortMission)
                            {
                                this.ShowErrorAndKill(new ConfigurationFilesNotFoundException());

                                return;
                            }
                            if (!Data.Get.IsFromScripting)
                            {
                                Console.WriteLine($"------------------------------------Login  Thread: {Thread.CurrentThread.ManagedThreadId}");
                                Application.Current.MainPage = new NavigationPage(new AclaraViewLogin(dialogs));
                            }
                            else
                            {
                                tcs1.SetResult(true);
                            }
                        });

                        return(false);
                    }
                    else
                    {
                        this.ShowErrorAndKill(new NoInternetException());
                        this.abortMission = true;
                        return(false);
                    }
                }
                return(true);
            }
        }
コード例 #7
0
        private void  LoadConfigurationAndOpenScene(IUserDialogs dialogs)
        {
            //ConfigPaths();

            // Only download configuration files from FTP when all are not installed

            bool Result = true;



            if (!GenericUtilsClass.HasDeviceAllXmls(Mobile.ConfigPath))
            {
                Result = InitialConfigProcess();
                SecureStorage.SetAsync("ConfigVersion", NewConfigVersion);
            }
            else
            {
                DateCheck = SecureStorage.GetAsync("DateCheck").Result;
                if (DateCheck != DateTime.Today.ToShortDateString())  // once per day
                {
                    SecureStorage.SetAsync("DateCheck", DateTime.Today.ToShortDateString());
                    ConfigVersion    = SecureStorage.GetAsync("ConfigVersion").Result;
                    NewConfigVersion = SecureStorage.GetAsync("ConfigVersion").Result;

                    if (GenericUtilsClass.TagGlobal(false, "CheckConfigFiles", out dynamic value))
                    {
                        if (value != null)
                        {
                            bool.TryParse((string)value, out CheckConfigFiles);
                        }
                    }
                    if (CheckConfigFiles)
                    {
                        if (Mobile.configData.HasFTP || Mobile.configData.HasIntune)
                        {
                            NewConfigVersion = GenericUtilsClass.CheckFTPConfigVersion();
                        }
                        else
                        {
                            NewConfigVersion = GenericUtilsClass.CheckPubConfigVersion();
                        }

                        if (!NewConfigVersion.Equals(ConfigVersion))
                        {
                            // backup actual config files
                            GenericUtilsClass.BackUpConfigFiles();

                            Result = UpdateConfigFiles();
                        }
                    }
                }
            }


            if (Result)
            {
                ConfigVersion = SecureStorage.GetAsync("ConfigVersion").Result;
                // Load configuration files
                // If some configuration file is not present, Configuration.cs initialization should avoid
                // launch exception when try to parse xmls, to be able to use generating the log error
                if (!this.InitializeConfiguration())
                {
                    if (CheckConfigFiles)
                    {
                        GenericUtilsClass.RestoreConfigFiles();
                        return;
                    }
                    else
                    {
                        GenericUtilsClass.DeleteConfigFiles(Mobile.ConfigPath);
                        GenericUtilsClass.SetInstallMode("None");
                        return;
                    }
                }

                if (this.abortMission)
                {
                    this.ShowErrorAndKill(new ConfigurationFilesNotFoundException());

                    return;
                }

                if (!String.IsNullOrEmpty(NewConfigVersion))
                {
                    ConfigVersion = NewConfigVersion;
                    SecureStorage.SetAsync("ConfigVersion", ConfigVersion);
                }

                Utils.Print($"Config version: { ConfigVersion} ");
                if (!Mobile.configData.HasIntune)
                {
                    Utils.Print("Local parameters loaded..");
                }
                else
                {
                    Utils.Print("Intune parameters loaded..");
                }
                if (Mobile.configData.HasIntune || Mobile.configData.HasFTP)
                {
                    Utils.Print("FTP: " + Mobile.configData.ftpDownload_Host + ":" + Mobile.configData.ftpDownload_Port + " - "
                                + Mobile.configData.ftpDownload_User + " [ " + Mobile.configData.ftpDownload_Pass + " ]");
                    if (Mobile.configData.IsCertLoaded)
                    {
                        Utils.Print("Certificate: " + Mobile.configData.certificate.Subject + " [ " + Mobile.configData.certificate.NotAfter + " ]");
                    }
                }



                if (!Data.Get.IsFromScripting)
                {
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        Application.Current.MainPage = new NavigationPage(new AclaraViewLogin(dialogs));
                        // await MainPage.Navigation.PopToRootAsync(true);
                    });
                }
                else
                {
                    tcs1.SetResult(true);
                }
            }
        }
コード例 #8
0
        private bool InitialConfigProcess()
        {
            string Mode = GenericUtilsClass.ChekInstallMode();

            if (Mode.Equals("Intune"))
            {
                if (Mobile.IsNetAvailable())
                {
                    var MamServ = DependencyService.Get <IMAMService>();
                    MamServ.UtilMAMService();
                    if (Mobile.configData.HasIntune)
                    {
                        NewConfigVersion = GenericUtilsClass.CheckFTPConfigVersion();
                        GenericUtilsClass.DownloadConfigFiles(out string sFileCert);
                        if (!Mobile.configData.IsCertLoaded && !string.IsNullOrEmpty(sFileCert))
                        {
                            Mobile.configData.StoreCertificate(Mobile.configData.CreateCertificate(null, sFileCert));
                        }

                        return(true);
                    }
                    else
                    {
                        this.ShowErrorAndKill(new IntuneCredentialsException());
                        GenericUtilsClass.SetInstallMode("None");
                        return(false);
                    }
                }
                else
                {
                    this.ShowErrorAndKill(new NoInternetException());
                }
                //MainPage.DisplayAlert("Attention", "There is not connection at this moment, try again later","OK");
                return(false);
            }
            else if (Mode.Equals("Manual"))
            {
                Mobile.configData.HasFTP = false;

                // Check if all configuration files are available in public folder
                bool HasPublicFiles = GenericUtilsClass.HasDeviceAllXmls(Mobile.ConfigPublicPath);
                //this.abortMission = !this.HasDeviceAllXmls(Mobile.ConfigPublicPath);
                if (HasPublicFiles)
                {
                    bool CPD = false;
                    if (GenericUtilsClass.TagGlobal(true, "ConfigPublicDir", out dynamic value))
                    {
                        if (value != null)
                        {
                            bool.TryParse((string)value, out CPD);
                        }
                    }
                    GenericUtilsClass.CopyConfigFiles(!CPD, Mobile.ConfigPublicPath, Mobile.ConfigPath, out string sFileCert);
                    if (!string.IsNullOrEmpty(sFileCert))
                    {
                        Mobile.configData.StoreCertificate(Mobile.configData.CreateCertificate(null, sFileCert));
                    }


                    NewConfigVersion = GenericUtilsClass.CheckPubConfigVersion();

                    //if (!GenericUtilsClass.HasDeviceAllXmls(Mobile.ConfigPath))
                    return(true);
                }
                else
                {
                    this.ShowErrorAndKill(new ConfigurationFilesNotFoundException());
                    GenericUtilsClass.SetInstallMode("None");
                    return(false);
                }
            }
            else
            {
                //{
                //    //Configure download FTP
                //    if (Mobile.IsNetAvailable())
                //    {
                //         bool result =false;
                //         tcs = new TaskCompletionSource<bool>();
                //        // Console.WriteLine($"------------------------------------FTP  Thread: {Thread.CurrentThread.ManagedThreadId}");
                //        Device.BeginInvokeOnMainThread(async () =>
                //        {

                //            MainPage = new NavigationPage(new FtpDownloadSettings(tcs));
                //            //PopupNavigation.Instance.PushAsync(new FtpDownloadSettings());

                //            result = await tcs.Task;

                //            if (!this.InitializeConfiguration())
                //            {
                //                GenericUtilsClass.DeleteConfigFiles(Mobile.ConfigPath);
                //                return;
                //            }

                //           //NewConfigVersion = GenericUtilsClass.CheckFTPConfigVersion();
                //            GenericUtilsClass.SetInstallMode("FTP");

                //            if (this.abortMission)
                //            {
                //                this.ShowErrorAndKill(new ConfigurationFilesNotFoundException());

                //                return;
                //            }
                //            //await SecureStorage.SetAsync("ConfigVersion", NewConfigVersion);

                //            if ( ! Data.Get.IsFromScripting )
                //            {
                //                Console.WriteLine($"------------------------------------Login  Thread: {Thread.CurrentThread.ManagedThreadId}");
                //                Application.Current.MainPage = new NavigationPage(new AclaraViewLogin(dialogs));
                //            }
                //            else
                //                tcs1.SetResult(true);
                //        });

                //        return false;
                //    }
                //    else
                //    {
                //        this.ShowErrorAndKill(new NoInternetException());
                //        this.abortMission = true;
                //        return false;
                //    }
                //}
                return(true);
            }
        }
コード例 #9
0
        private void CallToInitApp(
            IBluetoothLowEnergyAdapter adapter,
            IUserDialogs dialogs,
            string appVersion)
        {
            // Catch unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
            TaskScheduler.UnobservedTaskException      += TaskSchedulerOnUnobservedTaskException;

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

            appVersion_str = appVersion;

            deviceId = CrossDeviceInfo.Current.Id;

            // Profiles manager
            credentialsService = new CredentialsService();

            // Initializes Bluetooth
            ble_interface = new BleSerial(adapter);

            AppResources.Culture = CrossMultilingual.Current.DeviceCultureInfo;

            // Config path
            ConfigPaths();

            string Mode = GenericUtilsClass.ChekInstallMode();

            if (Data.Get.IsAndroid && Mode.Equals("None"))
            {
                var MamServ = DependencyService.Get <IMAMService>();
                MamServ.UtilMAMService();
                if (Mobile.configData.HasIntune)
                {
                    GenericUtilsClass.SetInstallMode("Intune");
                    this.LoadConfigurationAndOpenScene(dialogs);
                    return;
                }
            }

            // var MamServ = DependencyService.Get<IMAMService>();
            // MamServ.UtilMAMService();

            if (VersionTracking.IsFirstLaunchEver || Mode.Equals("None"))
            {
                SecureStorage.RemoveAll();
                Device.BeginInvokeOnMainThread(() =>
                {
                    MainPage = new NavigationPage(new AclaraInstallPage());
                });
            }
            else
            {
                if (Mode.Equals("Intune"))
                {
                    var MamServ = DependencyService.Get <IMAMService>();
                    MamServ.UtilMAMService();
                }
                else if (Mode.Equals("FTP"))
                {
                    // Check if FTP settings is in securestorage
                    GenericUtilsClass.CheckFTPDownload();
                }

                this.LoadConfigurationAndOpenScene(dialogs);
            }
        }