예제 #1
0
        private async Task <ConnectionParams> AttachToService()
        {
            ProgressMessage = __AppServices.LocalizedString("Connecting_Service_Progress");
            IsInProgress    = true;

            ServiceAttachResult result = await __AppServices.AttachToService();

            ProgressMessage = "";
            IsInProgress    = false;

            if (result.IsError)
            {
                SetError(__AppServices.LocalizedString("ErrorCaption_IVPNServiceCouldNotStart"), result.ErrorMessage);
                return(new ConnectionParams(0, 0));
            }

            return(new ConnectionParams(result.Port, result.Secret));
        }
예제 #2
0
        public InitViewModel(
            AppState appState,
            IApplicationServices appServices,
            IAppNavigationService navigationService,
            Service service,
            AppSettings settings)
        {
            __AppState          = appState;
            __AppServices       = appServices;
            __NavigationService = navigationService;
            __Service           = service;
            __Settings          = settings;

            RetryCommand = new RelayCommand(RetryConnection);

            __IsInProgress    = true;
            __ProgressMessage = __AppServices.LocalizedString("Initializing");

            __Service.ServiceExceptionRaised += ServiceExceptionRaised;
            __Service.ServiceDisconnected    += ServiceDisconnected;
        }
예제 #3
0
        private async Task <PrivateEmailInfo> GenerateNewEmailRequest(OnErrorDelegate onErrorDelegate = null)
        {
            try
            {
                CancellationTokenSource src = new CancellationTokenSource();
                var response = await ApiServices.Instance.PrivateEmailGenerateAsync(src.Token);


                PrivateEmailInfo email = new PrivateEmailInfo(response.Email, response.ForwardToEmail, response.Notes);
                ObservableCollection <PrivateEmailInfo> emails = PrivateEmails;
                emails.Add(email);
                PrivateEmails = emails;

                OnNewEmailGenerated(email);
                return(email);
            } catch (OperationCanceledException) {
                return(null);
            }
            catch (TimeoutException) {
                DoNotifyError(onErrorDelegate, __AppServices.LocalizedString("Error_ApiRequestTimeout"));
                return(null);
            }
            catch (WebException ex)
            {
                Logging.Info($"REST request exception : {ex}");
                DoNotifyError(onErrorDelegate,
                              __AppServices.LocalizedString("Error_RestServer_ConnectionError_Title"),
                              __AppServices.LocalizedString("Error_RestServer_ConnectionError"));
                return(null);
            }
            catch (Exception ex)
            {
                Logging.Info($"REST request exception : {ex}");
                DoNotifyError(onErrorDelegate, __AppServices.LocalizedString("Error_RestServer_Communication")
                              + Environment.NewLine
                              + Environment.NewLine
                              + $"{IVPNException.GetDetailedMessage(ex)}");
                return(null);
            }
        }