示例#1
0
        private async Task Connect()
        {
            Status    = "";
            StatusSub = "";
            Retry     = false;
            Active    = true;
            if (!Api.RefreshSettings(Settings.Profile))
            {
                Status    = Platform.GetLocalizedString("Pages/LoadingPage/InvalidAddress");
                StatusSub = Platform.GetLocalizedString("Pages/LoadingPage/InvalidAddressSub");
                await Reload();

                return;
            }
            var serverInfo = await ServerProvider.GetServerInfo();

            if (serverInfo == null)
            {
                var address = Settings.Profile.ServerAddress;
                if (address.Contains("127.0.0.") || address.Contains("localhost"))
                {
                    Status    = Platform.GetLocalizedString("Pages/LoadingPage/NoConnectionLocalHost");
                    StatusSub = Platform.GetLocalizedString("Pages/LoadingPage/NoConnectionLocalHostSub");
                }
                else
                {
                    Status = Platform.GetLocalizedString("Pages/LoadingPage/NoConnection");
                }
                Active = false;
                await Task.Delay(TimeSpan.FromSeconds(2.5));

                Retry = true;
                return;
            }
            else if (serverInfo._unauthorized)
            {
                Status = Platform.GetLocalizedString("Pages/LoadingPage/InvalidKey");
                await Reload();

                return;
            }
            if (serverInfo.version < Updates.MIN_VERSION)
            {
                Status = Platform.GetLocalizedString("Pages/LoadingPage/InstanceNotSupported").AsFormat(serverInfo.version, Updates.MIN_VERSION);
                await Reload();

                return;
            }
            else if (serverInfo.version > Updates.MAX_VERSION)
            {
                Status    = Platform.GetLocalizedString("Pages/LoadingPage/ClientNotSupported").AsFormat(serverInfo.version);
                StatusSub = Platform.GetLocalizedString("Pages/LoadingPage/ClientRange").AsFormat(Updates.MIN_VERSION, Updates.MAX_VERSION);
                await Reload();

                return;
            }

            if (!await Api.Validate())
            {
                await Reload(0.5);

                return;
            }

            Api.ServerInfo = serverInfo;
            await Archives.ReloadArchives();

            Api.ControlFlags.Check(serverInfo);
            Active = false;
            Platform.GoToPage(Pages.HostTab, PagesTransition.DrillIn);
        }