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; } } }
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_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_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; } } }
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; } } }
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 void Run(float frameTime) { switch (Status) { case DoAfterStatus.Running: break; case DoAfterStatus.Cancelled: case DoAfterStatus.Finished: return; default: throw new ArgumentOutOfRangeException(); } Elapsed += frameTime; if (IsFinished()) { Tcs.SetResult(DoAfterStatus.Finished); return; } if (IsCancelled()) { Tcs.SetResult(DoAfterStatus.Cancelled); } }
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; } } }
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; } } }
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 void Run(float frameTime, IEntityManager entityManager) { switch (Status) { case DoAfterStatus.Running: break; case DoAfterStatus.Cancelled: case DoAfterStatus.Finished: return; default: throw new ArgumentOutOfRangeException(); } Elapsed += frameTime; if (IsFinished()) { // Do the final checks here if (!TryPostCheck()) { Tcs.SetResult(DoAfterStatus.Cancelled); } else { Tcs.SetResult(DoAfterStatus.Finished); } return; } if (IsCancelled(entityManager)) { Tcs.SetResult(DoAfterStatus.Cancelled); } }
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; } } }
/// <summary> /// Accept this stream /// </summary> /// <param name="ct"></param> /// <returns></returns> public Task <IMessageStream> OpenAsync(CancellationToken ct) { ct.Register(() => { Tcs.TrySetCanceled(); }); return(Tcs.Task); }
/// <summary> /// Close stream /// </summary> /// <returns></returns> public Task CloseAsync() { Task pumps; lock (this) { // Set close state _open.Cancel(); _receive.Complete(); _send.Complete(); // Remove ourselves from the listener... Close(); // Fail any in progress open if (!Tcs.Task.IsCompleted) { Tcs.TrySetException(new SocketException(SocketError.Closed)); } if (_pumps == null) { return(TaskEx.Completed); } pumps = _pumps; _pumps = null; return(pumps); } }
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; } } }
/// <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); } }
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_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 void Cancel() { if (Status == DoAfterStatus.Running) { Tcs.SetResult(DoAfterStatus.Cancelled); } }
public DiscordClientSharder( IOptions <DiscordClientSharderConfiguration> options, ILogger <DiscordClientSharder> logger, IRestClient restClient, IGatewayClient gatewayClient, IEnumerable <DiscordClientExtension> extensions, IShardFactory shardFactory, IServiceProvider services) : base(logger, restClient, gatewayClient, extensions) { if (GatewayClient.Shards is not ISynchronizedDictionary <ShardId, IGatewayApiClient> ) { throw new InvalidOperationException("The gateway client instance is expected to return a synchronized dictionary of shards."); } if (GatewayClient.Dispatcher is not DefaultGatewayDispatcher dispatcher || dispatcher["READY"] is not ReadyHandler) { throw new InvalidOperationException("The gateway dispatcher must be the default implementation."); } var configuration = options.Value; _configuredShardCount = configuration.ShardCount; _configuredShardIds = configuration.ShardIds?.ToArray(); _shardFactory = shardFactory; _services = services; _initialReadyTcs = new Tcs(); }
/// <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); }
public void OnNext(int value) { Sum += value; //if(value % 1000 == 0) Console.WriteLine(value); if (value == _count) { Tcs.SetResult(Sum); } }
private void Cancel() { IsBusy = false; if (Tcs != null) { Tcs.TrySetCanceled(); Tcs = null; } }
public DefaultRestRequest(FormattedRoute route, IRestRequestContent content = null, IRestRequestOptions options = null) { Guard.IsNotNull(route); Route = route; Content = content; Options = options; _tcs = new Tcs <IRestResponse>(); }
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; } }
new public void onSuccess(object result) { Debug.Log("Callback onSuccess"); List <T> outList = new List <T>(); int size = ((AndroidJavaObject)result).Call <int>("size"); System.Type type = wrapper.GetType(); for (int i = 0; i < size; i++) { T instance = (T)System.Activator.CreateInstance(type); ((IKilnObjectWrapper)instance).JavaInst = ((AndroidJavaObject)result).Call <AndroidJavaObject>("get", i); outList.Add(instance); } Tcs.SetResult(outList); }
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; } }
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; } } }