Exemple #1
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_CONFIRM_ACCOUNT)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Valid and operative confirmation link
                    Tcs?.TrySetResult(ConfirmAccountResult.Success);
                    break;

                case MErrorType.API_ENOENT:     // Wrong password
                case MErrorType.API_EKEY:       // Wrong password
                    Tcs?.TrySetResult(ConfirmAccountResult.WrongPassword);
                    break;

                default:     // failed confirm
                    Tcs?.TrySetResult(ConfirmAccountResult.Unknown);
                    break;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_INVITE_CONTACT)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull invite contact process
                    Tcs?.TrySetResult(InviteContactResult.Success);
                    break;

                case MErrorType.API_EACCESS:     // Remind not allowed (two week period since started or last reminder)
                    Tcs?.TrySetResult(InviteContactResult.RemindNotAllowed);
                    break;

                case MErrorType.API_EEXIST:     // Contact already exists
                    Tcs?.TrySetResult(InviteContactResult.AlreadyExists);
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(InviteContactResult.Unknown);
                    break;
                }
            }
        }
Exemple #3
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_QUERY_RECOVERY_LINK)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successful reset
                    Tcs?.TrySetResult(request.getFlag() ? RecoverLinkType.Recovery : RecoverLinkType.ParkAccount);
                    break;

                case MErrorType.API_EEXPIRED:
                    Tcs?.TrySetResult(RecoverLinkType.Expired);
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(RecoverLinkType.Unknown);
                    break;
                }
            }
        }
            /// <summary>
            /// Connect the stream to a accepted stream instance and start the producer
            /// </summary>
            /// <param name="stream"></param>
            internal bool TryConnect(HybridConnectionStream stream)
            {
                if (_open.IsCancellationRequested)
                {
                    // Stream closed, but proxy tries to connect, reject
                    return(false);
                }
                // Ensure previous producer task finishes
                if (_producerTask != null && !_producerTask.IsCompleted)
                {
                    if (_streaming != null)
                    {
                        _streaming.Cancel();
                        try {
                            _producerTask.Wait();
                        }
                        catch (Exception) {
                            return(false);
                        }
                    }
                }

                _codec.Stream = stream;
                _streaming    = new CancellationTokenSource();
                _producerTask = ReceiveProducerAsync(_streaming.Token);
                Tcs.TrySetResult(this);
                return(true);
            }
Exemple #5
0
        /// <summary>
        /// Attach the stream to a accepted stream instance and start to produce/consume
        /// </summary>
        /// <param name="stream"></param>
        public virtual Task OpenAsync(S stream)
        {
            if (_open.IsCancellationRequested)
            {
                // Stream closed, but proxy tries to connect, reject
                return(null);
            }
            lock (this) {
                // Start pumping...
                var codecStream = stream.AsCodecStream(_encoding);
                var pumps       = Task.WhenAll(new Task[] {
                    Task.Factory.StartNew(async() =>
                                          await SendConsumerAsync(codecStream), _open.Token).Unwrap(),
                    Task.Factory.StartNew(async() =>
                                          await ReceiveProducerAsync(codecStream), _open.Token).Unwrap()
                }).ContinueWith(t => CloseStreamAsync(codecStream, t.IsFaulted)).Unwrap();

                if (_pumps != null)
                {
                    // Reconnect
                    _pumps = _pumps.ContinueWith(async(t) => {
                        await pumps.ConfigureAwait(false);
                    });
                }
                else
                {
                    // First connect
                    _pumps = pumps;
                    Tcs.TrySetResult(this);
                }
                ProxyEventSource.Log.StreamOpened(this, stream);

                return(pumps);
            }
        }
Exemple #6
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_CONFIRM_CHANGE_EMAIL_LINK)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull change email process
                    Tcs?.TrySetResult(ConfirmChangeEmailResult.Success);
                    return;

                case MErrorType.API_EARGS:     // User logged into an incorrect account
                    Tcs?.TrySetResult(ConfirmChangeEmailResult.WrongAccount);
                    return;

                case MErrorType.API_ENOENT:     // Wrong password
                    Tcs?.TrySetResult(ConfirmChangeEmailResult.WrongPassword);
                    return;

                case MErrorType.API_EACCESS:     // No user is logged in
                    Tcs?.TrySetResult(ConfirmChangeEmailResult.UserNotLoggedIn);
                    return;

                default:     // Unknown result, but not successful
                    Tcs?.TrySetResult(ConfirmChangeEmailResult.Unknown);
                    return;
                }
            }
        }
Exemple #7
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_LOGOUT)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:         // Successfull log out from folder
                case MErrorType.API_ESID:       // Under certain circumstances, this request might return this error code.
                                                // It should not be taken as an error, since the reason is that the logout
                                                // action has been notified before the reception of the logout response itself.
                    Tcs?.TrySetResult(true);
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(false);
                    break;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_MULTI_FACTOR_AUTH_CHECK)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull check multi-factor authentication process
                    if (Tcs != null)
                    {
                        Tcs.TrySetResult(request.getFlag() ?
                                         MultiFactorAuthStatus.Enabled :
                                         MultiFactorAuthStatus.Disabled);
                    }
                    break;

                default:     // Default error processing
                    if (Tcs != null)
                    {
                        Tcs.TrySetResult(MultiFactorAuthStatus.Unknown);
                    }
                    break;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_LOGIN)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Login was successful
                    Tcs?.TrySetResult(LoginToFolderResult.Success);
                    return;

                case MErrorType.API_EARGS:
                    Tcs?.TrySetResult(DecryptionAlert ?
                                      LoginToFolderResult.InvalidDecryptionKey :         // No valid decryption key
                                      LoginToFolderResult.InvalidHandleOrDecryptionKey); // Handle length or Key length no valid
                    return;

                case MErrorType.API_EINCOMPLETE:     // Link has not decryption key
                    Tcs?.TrySetResult(LoginToFolderResult.NoDecryptionKey);
                    return;

                default:     // Unknown result, but not successful
                    Tcs?.TrySetResult(LoginToFolderResult.Unknown);
                    return;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_QUERY_RECOVERY_LINK)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull change email link query
                    this.Email = request.getEmail();
                    Tcs?.TrySetResult(QueryChangeEmailLinkResult.Success);
                    return;

                case MErrorType.API_ENOENT:     // Invalid link
                    Tcs?.TrySetResult(QueryChangeEmailLinkResult.InvalidLink);
                    return;

                case MErrorType.API_EACCESS:     // No user is logged in
                    Tcs?.TrySetResult(QueryChangeEmailLinkResult.UserNotLoggedIn);
                    return;

                default:     // Unknown result, but not successful
                    Tcs?.TrySetResult(QueryChangeEmailLinkResult.Unknown);
                    return;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_CREATE_ACCOUNT)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull create account process
                    Tcs?.TrySetResult(CreateAccountResult.Success);
                    break;

                case MErrorType.API_EEXIST:     // Email already registered
                    Tcs?.TrySetResult(CreateAccountResult.AlreadyExists);
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(CreateAccountResult.Unknown);
                    break;
                }
            }
        }
Exemple #12
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_MOVE)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull move node process
                    if (Tcs != null)
                    {
                        Tcs.TrySetResult(true);
                    }
                    break;

                default:     // Default error processing
                    if (Tcs != null)
                    {
                        Tcs.TrySetResult(false);
                    }
                    break;
                }
            }
        }
Exemple #13
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_MULTI_FACTOR_AUTH_SET)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull set multi-factor authentication
                    if (Tcs != null)
                    {
                        Tcs.TrySetResult(true);
                    }
                    break;

                default:     // Default error processing
                    if (Tcs != null)
                    {
                        Tcs.TrySetResult(false);
                    }
                    break;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_GET_ATTR_USER &&
                request.getParamType() == (int)MUserAttrType.USER_ATTR_PWD_REMINDER)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull get user attribute process
                    Tcs?.TrySetResult(request.getAccess() == 1);
                    break;

                case MErrorType.API_ENOENT: // User attribute is not set yet
                default:                    // Default error processing
                    Tcs?.TrySetResult(false);
                    break;
                }
            }
        }
Exemple #15
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_GET_ATTR_USER)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:         // Successfull get user attribute process
                case MErrorType.API_ENOENT:     // Attribute not exists yet but the value still be valid
                    if (Tcs != null)
                    {
                        Tcs.TrySetResult(request.getFlag());
                    }
                    break;

                default:     // Default error processing
                    if (Tcs != null)
                    {
                        Tcs.TrySetResult(false);
                    }
                    break;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_LOGIN)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Login was successful
                    Tcs?.TrySetResult(true);
                    return;

                case MErrorType.API_ESID:     // Bad session ID
                    Tcs?.TrySetException(new BadSessionIdException());
                    Tcs?.TrySetResult(false);
                    return;

                default:     // Unknown result, but not successful
                    Tcs?.TrySetResult(false);
                    return;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_CHANGE_PW)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull change password process
                    Tcs?.TrySetResult(ChangePasswordResult.Success);
                    break;

                case MErrorType.API_EFAILED:     // Wrong MFA pin.
                case MErrorType.API_EEXPIRED:    // MFA pin is being re-used and is being denied to prevent a replay attack
                    Tcs?.TrySetResult(ChangePasswordResult.MultiFactorAuthInvalidCode);
                    return;

                default:     // Default error processing
                    Tcs?.TrySetResult(ChangePasswordResult.Unknown);
                    break;
                }
            }
        }
Exemple #18
0
 private void GenerateNetworkCredential()
 {
     if (IsReady)
     {
         var credential = new IdentityManager.Credential {
             Credentials = new NetworkCredential(UserName, Password)
         };
         Debug.Assert(Tcs != null);                 // due to test on IsReady
         Tcs.TrySetResult(credential);
         Tcs          = null;
         ErrorMessage = null;
     }
 }
Exemple #19
0
        public override async Task Initialize()
        {
            try
            {
                await AsyncConnection.CreateTableAsync <Host>();

                await AsyncConnection.CreateTableAsync <CommandSsh>();

                await Migrate();

                Tcs.TrySetResult(null);
            }
            catch (Exception e)
            {
                Tcs.TrySetException(e);
                throw;
            }
        }
Exemple #20
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_LOGIN)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Login was successful
                    Tcs?.TrySetResult(LoginResult.Success);
                    return;

                case MErrorType.API_ENOENT:     // Email unassociated with a MEGA account or Wrong password
                    Tcs?.TrySetResult(LoginResult.UnassociatedEmailOrWrongPassword);
                    return;

                case MErrorType.API_ETOOMANY:     // Too many failed login attempts. Wait one hour.
                    Tcs?.TrySetResult(LoginResult.TooManyLoginAttempts);
                    return;

                case MErrorType.API_EINCOMPLETE:     // Account not confirmed
                    Tcs?.TrySetResult(LoginResult.AccountNotConfirmed);
                    return;

                case MErrorType.API_EMFAREQUIRED:     // Multi-factor authentication required
                    Tcs?.TrySetResult(LoginResult.MultiFactorAuthRequired);
                    return;

                case MErrorType.API_EFAILED:     // Wrong MFA pin.
                case MErrorType.API_EEXPIRED:    // MFA pin is being re-used and is being denied to prevent a replay attack
                    Tcs?.TrySetResult(LoginResult.MultiFactorAuthInvalidCode);
                    return;

                default:     // Unknown result, but not successful
                    Tcs?.TrySetResult(LoginResult.Unknown);
                    return;
                }
            }
        }
Exemple #21
0
        private async void GenerateToken()
        {
            if (!IsReady)
            {
                return;
            }

            IsBusy       = true;
            ErrorMessage = null;

            long      requestID = ++_requestID;
            Exception error     = null;

            IdentityManager.Credential credential = null;
            try
            {
                credential = await IdentityManager.Current.GenerateCredentialAsync(_credentialRequestInfo.ServiceUri, UserName, Password, _credentialRequestInfo.GenerateTokenOptions);
            }
            catch (Exception e)
            {
                error = e;
            }
            if (requestID != _requestID || Tcs == null)
            {
                return;                 // No more the current request
            }
            IsBusy = false;

            if (error == null)
            {
                Tcs.TrySetResult(credential);
                Tcs = null;
            }
            else
            {
                // Display the error message and let the user try again
                string message = error.Message;
                if (string.IsNullOrEmpty(message) && error.InnerException != null)
                {
                    message = error.InnerException.Message;
                }
                ErrorMessage = message;
            }
        }
Exemple #22
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_FETCH_NODES)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull fetch nodes process
                    //If getFlag() returns true, the folder link key is invalid.
                    if (request.getFlag())
                    {
                        Tcs?.TrySetResult(DecryptionAlert ?
                                          FetchNodesResult.InvalidDecryptionKey :         // No valid decryption key
                                          FetchNodesResult.InvalidHandleOrDecryptionKey); // Handle length or Key length no valid
                    }

                    AccountService.GetUserData();
                    AccountService.GetAccountDetails();
                    AccountService.GetAccountAchievements();
                    Tcs?.TrySetResult(FetchNodesResult.Success);
                    break;

                case MErrorType.API_ETOOMANY:     // Taken down link and the link owner's account is blocked
                    Tcs?.TrySetResult(FetchNodesResult.AssociatedUserAccountTerminated);
                    return;

                case MErrorType.API_ENOENT:     // Link not exists or has been deleted by user
                case MErrorType.API_EBLOCKED:   // Taken down link
                    Tcs?.TrySetResult(FetchNodesResult.UnavailableLink);
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(FetchNodesResult.Unknown);
                    break;
                }
            }
        }
Exemple #23
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_GET_RECOVERY_LINK)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successful reset
                    Tcs?.TrySetResult(true);
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(false);
                    break;
                }
            }
        }
Exemple #24
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_CLEAN_RUBBISH_BIN)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull clean rubbish bin process
                    Tcs?.TrySetResult(true);
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(false);
                    break;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_GET_USER_DATA)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successful get user avatar process
                    Tcs?.TrySetResult(null);
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(null);
                    break;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_CANCEL_TRANSFER)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull cancel transfer process
                    Tcs?.TrySetResult(true);
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(false);
                    break;
                }
            }
        }
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_GET_PAYMENT_METHODS)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull get payment methods process
                    Tcs?.TrySetResult(request.getNumber());
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(0);
                    break;
                }
            }
        }
Exemple #28
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_ACCOUNT_DETAILS)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Successfull get account details process
                    Tcs?.TrySetResult(request.getMAccountDetails());
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(null);
                    break;
                }
            }
        }
Exemple #29
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_PAUSE_TRANSFERS)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:
                    Tcs?.TrySetResult(true);
                    break;

                default:
                    Tcs?.TrySetResult(false);
                    break;
                }
            }
        }
Exemple #30
0
        public override void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            base.onRequestFinish(api, request, e);

            if (Tcs.Task.IsFaulted)
            {
                return;
            }

            if (request.getType() == MRequestType.TYPE_QUERY_SIGNUP_LINK)
            {
                switch (e.getErrorCode())
                {
                case MErrorType.API_OK:     // Valid and operative confirmation link.
                    this.EmailAddress = request.getEmail();
                    Tcs?.TrySetResult(request.getFlag() ?
                                      SignUpLinkType.AutoConfirmed : SignUpLinkType.Valid);
                    break;

                case MErrorType.API_EEXPIRED:     // Expired confirmation link.
                    Tcs?.TrySetResult(SignUpLinkType.Expired);
                    break;

                case MErrorType.API_ENOENT:     // Already confirmed account
                    Tcs?.TrySetResult(SignUpLinkType.AlreadyConfirmed);
                    break;

                case MErrorType.API_EINCOMPLETE:     // Incomplete confirmation link
                    Tcs?.TrySetResult(SignUpLinkType.Invalid);
                    break;

                default:     // Default error processing
                    Tcs?.TrySetResult(SignUpLinkType.Unknown);
                    break;
                }
            }
        }