Beispiel #1
0
        /// <summary>
        /// Gets the login page.
        /// </summary>
        public void GetLoginPage()
        {
            Credentials       = CredentialsManager.GetAllCredentials();
            SystemCredentials = CredentialsManager.GetSystemCredentials();
            var p1   = new SystemLoginPage();
            var page = new NavigationPage(p1);

            if (!string.IsNullOrEmpty(SystemCredentials.Key))
            {
                int    sysLoginCount    = 0;
                string sysLoginAnswer   = "";
                bool   sysLoginFinished = false;
                Task.Run(async() =>
                {
                    while (sysLoginAnswer != PheidiNetworkManager.GoodResult && sysLoginAnswer != AppResources.Erreur_MauvaisEmailOuMdp && sysLoginCount < 10)
                    {
                        sysLoginAnswer = await PheidiNetworkManager.SystemLogin(SystemCredentials.Value["Username"], SystemCredentials.Value["Password"]);
                        sysLoginCount++;
                    }
                    sysLoginFinished = true;
                });

                while (!sysLoginFinished)
                {
                    Task.Delay(500).Wait();
                }
                if (sysLoginAnswer == PheidiNetworkManager.GoodResult)
                {
                    Page p2 = new ServerLoginPage();
                    if (ServerInfoList.Count == 0)
                    {
                        MainPage = page;
                        NotificationManager.DisplayAlert(AppResources.Erreur_AucunServeur, AppResources.Erreur_Title, "OK", () => { });
                    }
                    else if (ServerInfoList.Count == 1)
                    {
                        bool   serverLoginFinished = false;
                        int    serverLoginCount    = 0;
                        string answer = "";
                        Task.Run(async() =>
                        {
                            if (Credentials.Any((arg) => arg.Value["SystemCredentialsNoseq"] == SystemCredentials.Key && arg.Value["ServerNoseq"] == ServerInfoNoseq))
                            {
                                var credentials = Credentials.First((arg) => arg.Value["SystemCredentialsNoseq"] == SystemCredentials.Key && arg.Value["ServerNoseq"] == ServerInfoList[0].Noseq);
                                answer          = await PheidiNetworkManager.UserLogin(credentials.Value["Username"], credentials.Value["Password"], false);
                                if (answer != PheidiNetworkManager.GoodResult)
                                {
                                    CredentialsManager.DeleteUser(credentials.Key);
                                }
                                else
                                {
                                    UserNoseq = credentials.Key;
                                }
                            }
                            else
                            {
                                while ((answer != PheidiNetworkManager.GoodResult && answer != AppResources.Erreur_MauvaisEmailOuMdp) && serverLoginCount < 10)
                                {
                                    answer = await PheidiNetworkManager.UserLogin(SystemCredentials.Value["Username"], SystemCredentials.Value["Password"], false);
                                    serverLoginCount++;
                                }

                                if (answer == PheidiNetworkManager.GoodResult)
                                {
                                    UserNoseq = SystemCredentials.Key;
                                }
                            }
                            serverLoginFinished = true;
                        });

                        while (!serverLoginFinished)
                        {
                            Task.Delay(500).Wait();
                        }

                        if (answer != PheidiNetworkManager.GoodResult)
                        {
                            page.Navigation.PushAsync(p2);
                            MainPage = page;
                        }
                        else if (answer == PheidiNetworkManager.GoodResult)
                        {
                            answer = string.Empty;
                            Task.Run(async() =>
                            {
                                answer = await PheidiNetworkManager.GetPMH();
                            });
                            while (string.IsNullOrEmpty(answer))
                            {
                                Task.Delay(500).Wait();
                            }
                            if (PMH.Count > 1)
                            {
                                Page p3 = new PmhPage();
                                page.Navigation.PushAsync(p3);
                                MainPage = page;
                            }
                            else
                            {
                                Instance.GetToApplication();
                            }
                        }
                    }
                    else
                    {
                        page.Navigation.PushAsync(p2);
                        MainPage = page;
                    }
                }
                else
                {
                    MainPage = page;
                }
            }
            else
            {
                MainPage = page;
                if (!Current.Properties.ContainsKey("DeviceIsPublic"))
                {
                    string        message   = AppResources.Alerte_SeulUsagerAppareil_Message;
                    string        title     = AppResources.Alerte_SeulUsagerAppareil_Title;
                    string        confirm   = AppResources.Oui;
                    string        cancel    = AppResources.Non;
                    System.Action onConfirm = () => { DeviceIsShared = false; };
                    System.Action onCancel  = () => { DeviceIsShared = true; };
                    NotificationManager.DisplayAlert(message, title, confirm, cancel, onConfirm, onCancel);
                }
            }
        }