Ejemplo n.º 1
0
        private async Task ConnectToServiceAsync(int port, UInt64 secret)
        {
            ClearError();

            ProgressMessage = __AppServices.LocalizedString("Connecting_Service_Progress");
            IsInProgress    = true;

            try
            {
                // old versions compatibility. Sending old-stype credentials (if exists) to a service
                Requests.RawCredentials credentialsToRegister = null;
                if (__Settings.GetOldStyleCredentials(out string AccountID,
                                                      out string Session,
                                                      out string OvpnUser,
                                                      out string OvpnPass,
                                                      out string WgPublicKey,
                                                      out string WgPrivateKey,
                                                      out string WgLocalIP,
                                                      out Int64 WgKeyGenerated))
                {
                    credentialsToRegister = new Requests.RawCredentials()
                    {
                        AccountID      = AccountID,
                        Session        = Session,
                        OvpnUser       = OvpnUser,
                        OvpnPass       = OvpnPass,
                        WgPublicKey    = WgPublicKey,
                        WgPrivateKey   = WgPrivateKey,
                        WgLocalIP      = WgLocalIP,
                        WgKeyGenerated = WgKeyGenerated
                    };
                    Logging.Info("Connecting to a daemon. Registering RAW credentials...");
                }

                await __Service.InitializeAsync(port, secret, credentialsToRegister);
            }
            finally
            {
                IsInProgress = false;
            }

            if (__Service.State != ServiceState.Uninitialized)
            {
                // If username and password are defined - do not show LogIn View
                if (!__AppState.IsLoggedIn())
                {
                    __NavigationService.NavigateToLogInPage(NavigationAnimation.FadeToLeft);
                }
                else
                {
                    __NavigationService.NavigateToMainPage(NavigationAnimation.FadeToLeft);
                }
            }
        }
Ejemplo n.º 2
0
        public async Task <bool> InitializeAsync(int port, UInt64 secret, Requests.RawCredentials creds)
        {
            if (__State != ServiceState.Uninitialized)
            {
                return(true);
            }

            __InitializationSignal.Reset();

            __ServiceProxy.Initialize(port, secret, creds);
            await Task.Run(() =>
            {
                while (!__ServiceProxy.IsExiting)
                {
                    if (__InitializationSignal.WaitOne(100))
                    {
                        break;
                    }
                }
            });

            if (__ServiceProxy.IsExiting)
            {
                return(false);
            }

            if (State != ServiceState.Uninitialized)
            {
                await UpdateKillSwitchIsEnabled();
                await UpdateKillSwitchIsPersistent();

                ServiceInitialized(this, new EventArgs());
            }

            return(State == ServiceState.Disconnected);
        }