Beispiel #1
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);
        }
    }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
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);
            }
        }