public async Task TransferOperationTest() { var op = new TransferOperation(User.Login, User.Login, new Asset(1, Config.SteemAssetNumSbd), "Hi, it`s test transfer from Ditch (https://github.com/Chainers/Ditch)."); var response = Post(User.ActiveKeys, false, op); Assert.IsFalse(response.IsError, response.GetErrorMessage()); }
private void Abort(TraceEventType traceEventType, string timeoutErrorString, TransferOperation transferOperation) { lock (this.ThisLock) { if (this.closeState == CloseState.Closed) { return; } this.timeoutErrorString = timeoutErrorString; this.timeoutErrorTransferOperation = transferOperation; this.aborted = true; this.closeState = CloseState.Closed; if (!this.asyncReadPending) { this.FreeOverlappedContextAndReturnBuffer(); } if (this.asyncReadPending) { this.CancelReceiveTimer(); } if (this.asyncWritePending) { this.CancelSendTimer(); } } if (DiagnosticUtility.ShouldTrace(traceEventType)) { TraceUtility.TraceEvent(traceEventType, 0x4001b, System.ServiceModel.SR.GetString("TraceCodeSocketConnectionAbort"), this); } this.socket.Close(0); }
public async Task TransferOperationTest() { var fromUser = User; var toUser = Api.GetAccountByNameAsync("ditchtest1", CancellationToken.None).Result.Result; var op = new TransferOperation { Fee = new Asset { Amount = 100, AssetId = new AssetIdType(1, 3, 0) }, From = fromUser.Account.Id, To = toUser.Id, Amount = new Asset { Amount = 100000, AssetId = new AssetIdType(1, 3, 0) }, Memo = new MemoData { From = fromUser.Account.Active.KeyAuths[0].Key, To = toUser.Active.KeyAuths[0].Key, Message = "", Nonce = 0 }, Extensions = new object[0], }; await Post(fromUser.ActiveKeys, false, op).ConfigureAwait(false); }
protected override void Abort(int traceEventType, string timeoutErrorString, TransferOperation transferOperation) { lock (ThisLock) { if (_closeState == CloseState.Closed) { return; } _timeoutErrorString = timeoutErrorString; _timeoutErrorTransferOperation = transferOperation; _aborted = true; _closeState = CloseState.Closed; if (!_asyncReadPending) { DisposeReadEventArgs(); } if (!_asyncWritePending) { DisposeWriteEventArgs(); } DisposeReceiveTimer(); DisposeSendTimer(); } _socket.LingerState = new LingerOption(true, 0); _socket.Shutdown(SocketShutdown.Both); _socket.Dispose(); }
protected override void Abort(int traceEventType, string timeoutErrorString, TransferOperation transferOperation) { lock (ThisLock) { if (_closeState == CloseState.Closed) { return; } _timeoutErrorString = timeoutErrorString; _timeoutErrorTransferOperation = transferOperation; _aborted = true; _closeState = CloseState.Closed; if (_asyncReadPending) { CancelReceiveTimer(); } else { this.ReturnReadBuffer(); } if (_asyncWritePending) { CancelSendTimer(); } } _socket.Dispose(); }
protected void Abort(string timeoutErrorString, TransferOperation transferOperation) { int traceEventType = 4; // TraceEventType.Warning; // we could be timing out a cached connection Abort(traceEventType, timeoutErrorString, transferOperation); }
private void Abort(string timeoutErrorString, TransferOperation transferOperation) { TraceEventType warning = TraceEventType.Warning; if (this.ExceptionEventType == TraceEventType.Information) { warning = this.ExceptionEventType; } this.Abort(warning, timeoutErrorString, transferOperation); }
private void Abort(string timeoutErrorString, TransferOperation transferOperation) { TraceEventType warning = TraceEventType.Warning; if (this.ExceptionEventType == TraceEventType.Information) { warning = this.ExceptionEventType; } this.Abort(warning, timeoutErrorString, transferOperation); }
public override async Task <OperationResult <VoidResponse> > Transfer(TransferModel model, CancellationToken ct) { var isConnected = await TryReconnectChain(ct); if (!isConnected) { return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.EnableConnectToBlockchain))); } var keys = ToKeyArr(model.ActiveKey); if (keys == null) { return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.WrongPrivateActimeKey))); } var result = new OperationResult <VoidResponse>(); Asset asset; switch (model.CurrencyType) { case CurrencyType.Golos: { asset = new Asset($"{model.Value} GOLOS"); break; } case CurrencyType.Gbg: { asset = new Asset($"{model.Value} GBG"); break; } default: { result.Exception = new ValidationException(LocalizationKeys.UnsupportedCurrency, model.CurrencyType.ToString()); return(result); } } var op = new TransferOperation(model.Login, model.Recipient, asset, model.Memo); var resp = await _operationManager.BroadcastOperationsSynchronous(keys, ct, op); if (resp.IsError) { result.Exception = new RequestException(resp); } else { result.Result = new VoidResponse(); } return(result); }
private static Exception ConvertTransferException(SocketException socketException, TimeSpan timeout, Exception originalException, TransferOperation transferOperation, bool aborted, string timeoutErrorString, TransferOperation timeoutErrorTransferOperation, SocketConnection socketConnection, TimeSpan remainingTime) { if ((int)socketException.SocketErrorCode == UnsafeNativeMethods.ERROR_INVALID_HANDLE) { return(new CommunicationObjectAbortedException(socketException.Message, socketException)); } if (timeoutErrorString != null) { return(ConvertTimeoutErrorException(originalException, transferOperation, timeoutErrorString, timeoutErrorTransferOperation)); } // 10053 can occur due to our timeout sockopt firing, so map to TimeoutException in that case if ((int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAECONNABORTED && remainingTime <= TimeSpan.Zero) { TimeoutException timeoutException = new TimeoutException(SR.Format(SR.TcpConnectionTimedOut, timeout), originalException); return(timeoutException); } if ((int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAENETRESET || (int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAECONNABORTED || (int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAECONNRESET) { if (aborted) { return(new CommunicationObjectAbortedException(SR.TcpLocalConnectionAborted, originalException)); } else { CommunicationException communicationException = new CommunicationException(SR.Format(SR.TcpConnectionResetError, timeout), originalException); return(communicationException); } } else if ((int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAETIMEDOUT) { TimeoutException timeoutException = new TimeoutException(SR.Format(SR.TcpConnectionTimedOut, timeout), originalException); return(timeoutException); } else { if (aborted) { return(new CommunicationObjectAbortedException(SR.Format(SR.TcpTransferError, (int)socketException.SocketErrorCode, socketException.Message), originalException)); } else { CommunicationException communicationException = new CommunicationException(SR.Format(SR.TcpTransferError, (int)socketException.SocketErrorCode, socketException.Message), originalException); return(communicationException); } } }
public async Task Transfer([FromBody] TransferOperation operation) { await _repository.Decrement(operation.AccountNumber, operation.Amount); await _repository.Decrement(operation.AccountNumber, operation.Rate); await _repository.Increment(operation.AccountToNumber, operation.Amount); await _operationRepository.Register(operation); Ok(); }
public BankTransaction InterbankTransfer(TransferOperation transferOperation) { var initiaterAccount = _accountRepository.GetBankAccountByLastToken(transferOperation.Token); if (initiaterAccount != null) { if (!IsIbanReal(transferOperation.ToIban)) { throw new Exception("Iban is not in the bank."); } var balance = GetBalanceOfAccount(initiaterAccount); if (balance < transferOperation.Money) { throw new Exception("Insuficient funds."); } var timeStamp = DateTime.UtcNow; var outTransaction = new BankTransaction() { Id = Guid.NewGuid().ToString(), Message = transferOperation.Message, Direction = TransactionDirection.Outgoing, Money = transferOperation.Money, OtherPartyIban = transferOperation.ToIban, Timestamp = timeStamp, TransactionType = TransactionType.InterbankTransaction }; var inTransaction = new BankTransaction() { Id = Guid.NewGuid().ToString(), Message = transferOperation.Message, Direction = TransactionDirection.Incoming, Money = transferOperation.Money, OtherPartyIban = initiaterAccount.Iban, Timestamp = timeStamp, TransactionType = TransactionType.InterbankTransaction }; var recepient = _accountRepository.GetBankAccountByIban(transferOperation.ToIban); _accountRepository.AddTransactionToAccount(initiaterAccount, outTransaction); _accountRepository.AddTransactionToAccount(recepient, inTransaction); return(outTransaction); } else { throw new Exception("UnAuth"); } }
private static Exception ConvertTimeoutErrorException(Exception originalException, TransferOperation transferOperation, string timeoutErrorString, TransferOperation timeoutErrorTransferOperation) { Contract.Assert(timeoutErrorString != null, "Argument timeoutErrorString must not be null."); if (transferOperation == timeoutErrorTransferOperation) { return(new TimeoutException(timeoutErrorString, originalException)); } else { return(new CommunicationException(timeoutErrorString, originalException)); } }
public override async Task <OperationResult <VoidResponse> > Transfer(TransferModel model, CancellationToken ct) { var isConnected = await TryReconnectChain(ct); if (!isConnected) { return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.EnableConnectToBlockchain))); } var keys = ToKeyArr(model.ActiveKey); if (keys == null) { return(new OperationResult <VoidResponse>(new ValidationException(LocalizationKeys.WrongPrivateActimeKey))); } var result = new OperationResult <VoidResponse>(); var asset = new Asset(); switch (model.CurrencyType) { case CurrencyType.Steem: { asset.FromOldFormat($"{model.Value} {Config.Steem}"); break; } case CurrencyType.Sbd: { asset.FromOldFormat($"{model.Value} {Config.Sbd}"); break; } default: { result.Exception = new ValidationException(LocalizationKeys.UnsupportedCurrency, model.CurrencyType.ToString()); return(result); } } var op = new TransferOperation(model.Login, model.Recipient, asset, model.Memo); return(await Broadcast(keys, new BaseOperation[] { op }, ct)); }
public override async Task Invoke(CancellationToken token) { var accountRepository = GetRepository <Account>(); var fromAccount = await accountRepository.FirstOrDefaultAsync(a => a.Id == Command.From && !a.IsDeleted, token) ?? throw new ArgumentException($"Can't found account by {Command.From}"); var toAccount = await accountRepository.FirstOrDefaultAsync(a => a.Id == Command.To && !a.IsDeleted, token) ?? throw new ArgumentException($"Can't found account by {Command.To}"); var operation = new TransferOperation { Amount = Command.Amount, Type = OperationType.Transfer, From = Command.From, To = Command.To, OperationDate = Command.OperationDate, CreatedOn = Command.CreatedOn, Comment = Command.Comment, CreatedBy = Command.CreatedBy }; fromAccount.ChangeBalance(-Command.Amount); toAccount.ChangeBalance(Command.Amount); accountRepository.UpdateRange(new[] { fromAccount, toAccount }); var result = await GetRepository <TransferOperation>().AddAsync(operation, token); await SaveAsync(); var entity = result.Entity; Result = new TransferDto { Id = entity.Id, Amount = entity.Amount, Comment = entity.Comment, Date = entity.OperationDate, Type = entity.Type, FromId = entity.From, ToId = entity.To }; }
protected Exception ConvertObjectDisposedException(ObjectDisposedException originalException, TransferOperation transferOperation) { if (_timeoutErrorString != null) { return(ConvertTimeoutErrorException(originalException, transferOperation, _timeoutErrorString, _timeoutErrorTransferOperation)); } else if (_aborted) { return(new CommunicationObjectAbortedException(SR.SocketConnectionDisposed, originalException)); } else { return(originalException); } }
public async Task TransferOperationTest() { var op = new TransferOperation(User.Login, User.Login, new Asset("0.001 GBG"), "Hi, it`s test transfer from Ditch (https://github.com/Chainers/Ditch)."); await Post(User.ActiveKeys, false, op); }
/// <summary> /// Initializes a new instance of the TransferCommandMessage class with specified client transaction identifier, transfer object and transfer operation /// </summary> /// <param name="clientTranId">Сlient transaction identifier</param> /// <param name="transfer">Transfer object</param> /// <param name="op">Transfer operation</param> public TransferCommandMessage(string clientTranId, TTransferArgs transfer, TransferOperation op) : base(CommandType.Transfer, clientTranId, new TransferCommand <TTransferArgs, TTransferResult>(transfer, op)) { }
public RunbookTransferJob(AutomationRunbook rb, TransferOperation t) { this.Runbook = rb; this.Operation = t; }
private static Exception ConvertTimeoutErrorException(Exception originalException, TransferOperation transferOperation, string timeoutErrorString, TransferOperation timeoutErrorTransferOperation) { Contract.Assert(timeoutErrorString != null, "Argument timeoutErrorString must not be null."); if (transferOperation == timeoutErrorTransferOperation) { return new TimeoutException(timeoutErrorString, originalException); } else { return new CommunicationException(timeoutErrorString, originalException); } }
private static Exception ConvertTimeoutErrorException(Exception originalException, TransferOperation transferOperation, string timeoutErrorString, TransferOperation timeoutErrorTransferOperation) { if (transferOperation == timeoutErrorTransferOperation) { return(new TimeoutException(timeoutErrorString, originalException)); } return(new CommunicationException(timeoutErrorString, originalException)); }
private Exception CreatePipeClosedException(TransferOperation transferOperation) { return this.ConvertPipeException(new PipeException(System.ServiceModel.SR.GetString("PipeClosed")), transferOperation); }
private Exception ConvertPipeException(string exceptionMessage, PipeException pipeException, TransferOperation transferOperation) { if (this.timeoutErrorString != null) { if (transferOperation == this.timeoutErrorTransferOperation) { return new TimeoutException(this.timeoutErrorString, pipeException); } return new CommunicationException(this.timeoutErrorString, pipeException); } if (this.aborted) { return new CommunicationObjectAbortedException(exceptionMessage, pipeException); } return new CommunicationException(exceptionMessage, pipeException); }
private Exception ConvertPipeException(PipeException pipeException, TransferOperation transferOperation) { return this.ConvertPipeException(pipeException.Message, pipeException, transferOperation); }
private void CloseHandle(bool abort, string timeoutErrorString, TransferOperation transferOperation) { lock (this.readLock) { lock (this.writeLock) { if (this.closeState == CloseState.HandleClosed) { return; } this.timeoutErrorString = timeoutErrorString; this.timeoutErrorTransferOperation = transferOperation; this.aborted = abort; this.closeState = CloseState.HandleClosed; this.pipe.Close(); this.readOverlapped.FreeOrDefer(); this.writeOverlapped.FreeOrDefer(); if (this.atEOFEvent != null) { this.atEOFEvent.Close(); } try { this.FinishPendingWrite(TimeSpan.Zero); } catch (TimeoutException exception) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information); } } catch (CommunicationException exception2) { if (DiagnosticUtility.ShouldTraceInformation) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception2, TraceEventType.Information); } } } } if (abort) { TraceEventType warning = TraceEventType.Warning; if (this.ExceptionEventType == TraceEventType.Information) { warning = this.ExceptionEventType; } if (DiagnosticUtility.ShouldTrace(warning)) { TraceUtility.TraceEvent(warning, 0x4001d, System.ServiceModel.SR.GetString("TraceCodePipeConnectionAbort"), this); } } }
/// <summary> /// Initializes a new instance of the TransferCommand class with specified transfer object and specified operation /// </summary> /// <param name="args">Transfer object</param> /// <param name="op">Transfer operation</param> public TransferCommand(TTransferArgs args, TransferOperation op) : base(args) { this.Operation = op; }
private static Exception ConvertTransferException(SocketException socketException, TimeSpan timeout, Exception originalException, TransferOperation transferOperation, bool aborted, string timeoutErrorString, TransferOperation timeoutErrorTransferOperation, TimeSpan remainingTime) { if (socketException.ErrorCode == 6) { return(new CommunicationObjectAbortedException(socketException.Message, socketException)); } if (timeoutErrorString != null) { return(ConvertTimeoutErrorException(originalException, transferOperation, timeoutErrorString, timeoutErrorTransferOperation)); } if ((socketException.ErrorCode == 0x2745) && (remainingTime <= TimeSpan.Zero)) { return(new TimeoutException(System.ServiceModel.SR.GetString("TcpConnectionTimedOut", new object[] { timeout }), originalException)); } if (((socketException.ErrorCode == 0x2744) || (socketException.ErrorCode == 0x2745)) || (socketException.ErrorCode == 0x2746)) { if (aborted) { return(new CommunicationObjectAbortedException(System.ServiceModel.SR.GetString("TcpLocalConnectionAborted"), originalException)); } return(new CommunicationException(System.ServiceModel.SR.GetString("TcpConnectionResetError", new object[] { timeout }), originalException)); } if (socketException.ErrorCode == 0x274c) { return(new TimeoutException(System.ServiceModel.SR.GetString("TcpConnectionTimedOut", new object[] { timeout }), originalException)); } if (aborted) { return(new CommunicationObjectAbortedException(System.ServiceModel.SR.GetString("TcpTransferError", new object[] { socketException.ErrorCode, socketException.Message }), originalException)); } return(new CommunicationException(System.ServiceModel.SR.GetString("TcpTransferError", new object[] { socketException.ErrorCode, socketException.Message }), originalException)); }
private void Abort(string timeoutErrorString, TransferOperation transferOperation) { this.CloseHandle(true, timeoutErrorString, transferOperation); }
protected override void Abort(int traceEventType, string timeoutErrorString, TransferOperation transferOperation) { lock (ThisLock) { if (_closeState == CloseState.Closed) { return; } _timeoutErrorString = timeoutErrorString; _timeoutErrorTransferOperation = transferOperation; _aborted = true; _closeState = CloseState.Closed; if (_asyncReadPending) { CancelReceiveTimer(); } else { this.ReturnReadBuffer(); } if (_asyncWritePending) { CancelSendTimer(); } } _socket.Dispose(); }
protected override void Abort(int traceEventType, string timeoutErrorString, TransferOperation transferOperation) { lock (ThisLock) { if (_closeState == CloseState.Closed) { return; } _timeoutErrorString = timeoutErrorString; _timeoutErrorTransferOperation = transferOperation; _aborted = true; _closeState = CloseState.Closed; if (!_asyncReadPending) { DisposeReadEventArgs(); } if (!_asyncWritePending) { DisposeWriteEventArgs(); } DisposeReceiveTimer(); DisposeSendTimer(); } _socket.LingerState = new LingerOption(true, 0); _socket.Shutdown(SocketShutdown.Both); _socket.Dispose(); }
private static Exception ConvertTransferException(SocketException socketException, TimeSpan timeout, Exception originalException, TransferOperation transferOperation, bool aborted, string timeoutErrorString, TransferOperation timeoutErrorTransferOperation, SocketConnection socketConnection, TimeSpan remainingTime) { if ((int)socketException.SocketErrorCode == UnsafeNativeMethods.ERROR_INVALID_HANDLE) { return new CommunicationObjectAbortedException(socketException.Message, socketException); } if (timeoutErrorString != null) { return ConvertTimeoutErrorException(originalException, transferOperation, timeoutErrorString, timeoutErrorTransferOperation); } // 10053 can occur due to our timeout sockopt firing, so map to TimeoutException in that case if ((int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAECONNABORTED && remainingTime <= TimeSpan.Zero) { TimeoutException timeoutException = new TimeoutException(SR.Format(SR.TcpConnectionTimedOut, timeout), originalException); return timeoutException; } if ((int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAENETRESET || (int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAECONNABORTED || (int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAECONNRESET) { if (aborted) { return new CommunicationObjectAbortedException(SR.TcpLocalConnectionAborted, originalException); } else { CommunicationException communicationException = new CommunicationException(SR.Format(SR.TcpConnectionResetError, timeout), originalException); return communicationException; } } else if ((int)socketException.SocketErrorCode == UnsafeNativeMethods.WSAETIMEDOUT) { TimeoutException timeoutException = new TimeoutException(SR.Format(SR.TcpConnectionTimedOut, timeout), originalException); return timeoutException; } else { if (aborted) { return new CommunicationObjectAbortedException(SR.Format(SR.TcpTransferError, (int)socketException.SocketErrorCode, socketException.Message), originalException); } else { CommunicationException communicationException = new CommunicationException(SR.Format(SR.TcpTransferError, (int)socketException.SocketErrorCode, socketException.Message), originalException); return communicationException; } } }
void Abort(string timeoutErrorString, TransferOperation transferOperation) { TraceEventType traceEventType = TraceEventType.Warning; // we could be timing out a cached connection if (this.ExceptionEventType == TraceEventType.Information) { traceEventType = this.ExceptionEventType; } Abort(traceEventType, timeoutErrorString, transferOperation); }
protected void Abort(string timeoutErrorString, TransferOperation transferOperation) { int traceEventType = 4; // TraceEventType.Warning; // we could be timing out a cached connection Abort(traceEventType, timeoutErrorString, transferOperation); }
public async Task TransferOperationTest() { var op = new TransferOperation(User.Login, User.Login, new Asset(1, Config.SteemAssetNumSbd), "Hi, it`s test transfer from Ditch (https://github.com/Chainers/Ditch)."); await Post(User.ActiveKeys, false, op).ConfigureAwait(false); }
public RunbookTransferJob(AutomationRunbook rb, TransferOperation t) { this.Runbook = rb; this.Operation = t; }
private static Exception ConvertTimeoutErrorException(Exception originalException, TransferOperation transferOperation, string timeoutErrorString, TransferOperation timeoutErrorTransferOperation) { if (transferOperation == timeoutErrorTransferOperation) { return new TimeoutException(timeoutErrorString, originalException); } return new CommunicationException(timeoutErrorString, originalException); }
/// <summary> /// Initializes a new instance of the TransferCommandMessage class with specified transfer object and transfer operation /// </summary> /// <param name="transfer">Transfer object</param> /// /// <param name="op">Transfer operation</param> public TransferCommandMessage(TTransferArgs transfer, TransferOperation op) : base(CommandType.Transfer, null, new TransferCommand <TTransferArgs, TTransferResult>(transfer, op)) { }
public static void StartCommandLoop(string credential) { var me = acManager.GetBankAccountByCredentials(new AuthenticatedOperation() { Token = credential }); Console.WriteLine($"Logged in! as :{me.HolderName}, cred:{credential}"); var cmd = ""; while (true) { try { cmd = Console.ReadLine(); var tokens = cmd.Split(" "); var command = tokens[0]; var arguments = tokens.ToList().GetRange(1, tokens.Length - 1); if (command == "quit") { break; } if (command == "deposit") { var to = arguments[0]; var am = long.Parse(arguments[1]); var depo = new CashOperation { ToIban = to, Money = new Currency() { Amount = am }, OperationType = CashOperationType.Deposit, Token = credential }; var tr = acManager.CashOperation(depo); Console.WriteLine($"Deposited to: {to}, am:{am}"); } if (command == "withdraw") { var to = me.Iban; var am = long.Parse(arguments[0]); var with = new CashOperation { ToIban = to, Money = new Currency() { Amount = am }, OperationType = CashOperationType.Withdraw, Token = credential }; var tr = acManager.CashOperation(with); Console.WriteLine($"Withdrawn am:{am}"); } if (command == "transfer") { var to = arguments[0]; var am = long.Parse(arguments[1]); var msg = arguments[2]; var tx = new TransferOperation() { ToIban = to, Money = new Currency() { Amount = am }, Message = msg, Token = credential }; var tr = acManager.InterbankTransfer(tx); Console.WriteLine($"Transfered to: {to}, am:{am} | {msg}"); } if (command == "balance") { var bal = acManager.GetBalanceByCredentials(new AuthenticatedOperation() { Token = credential }); Console.WriteLine($"Balance :{bal.Amount} HUF"); } if (command == "history") { var filterDate = DateTime.MinValue; var dir = TransactionDirection.Any; if (arguments.Count >= 1) { filterDate = DateTime.Parse(arguments[0]); if (arguments.Count >= 2) { dir = arguments[1].ToLower() == "in" ? TransactionDirection.Incoming : TransactionDirection.Outgoing; } } PrintHistory(credential, filterDate, dir); } } catch (Exception ex) { Console.WriteLine($"error: {ex.Message}"); } } }
public TransferTable(long blockNum, short trxNum, short opNum, DateTime timestamp, TransferOperation operation) : base(blockNum, trxNum, opNum, timestamp) { From = operation.From; To = operation.To; Quantity = operation.Amount.Amount; AssetNum = (int)operation.Amount.Symbol.AssetNum; OperationType = operation.Type; Memo = operation.Memo; }
Exception CreatePipeClosedException(TransferOperation transferOperation) { return ConvertPipeException(new PipeException(SR.GetString(SR.PipeClosed)), transferOperation); }
protected abstract void Abort(int traceEventType, string timeoutErrorString, TransferOperation transferOperation);
void CloseHandle(bool abort, string timeoutErrorString, TransferOperation transferOperation) { lock (readLock) { lock (writeLock) { if (this.closeState == CloseState.HandleClosed) { return; } this.timeoutErrorString = timeoutErrorString; this.timeoutErrorTransferOperation = transferOperation; this.aborted = abort; this.closeState = CloseState.HandleClosed; this.pipe.Close(); this.readOverlapped.FreeOrDefer(); this.writeOverlapped.FreeOrDefer(); if (this.atEOFEvent != null) { this.atEOFEvent.Close(); } // This should only do anything in the abort case. try { FinishPendingWrite(TimeSpan.Zero); } catch (TimeoutException exception) { if (TD.CloseTimeoutIsEnabled()) { TD.CloseTimeout(exception.Message); } DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information); } catch (CommunicationException exception) { DiagnosticUtility.TraceHandledException(exception, TraceEventType.Information); } } } if (abort) { TraceEventType traceEventType = TraceEventType.Warning; // we could be timing out a cached connection if (this.ExceptionEventType == TraceEventType.Information) { traceEventType = this.ExceptionEventType; } if (DiagnosticUtility.ShouldTrace(traceEventType)) { TraceUtility.TraceEvent(traceEventType, TraceCode.PipeConnectionAbort, SR.GetString(SR.TraceCodePipeConnectionAbort), this); } } }
private void Abort(TraceEventType traceEventType, string timeoutErrorString, TransferOperation transferOperation) { lock (this.ThisLock) { if (this.closeState == CloseState.Closed) { return; } this.timeoutErrorString = timeoutErrorString; this.timeoutErrorTransferOperation = transferOperation; this.aborted = true; this.closeState = CloseState.Closed; if (!this.asyncReadPending) { this.FreeOverlappedContextAndReturnBuffer(); } if (this.asyncReadPending) { this.CancelReceiveTimer(); } if (this.asyncWritePending) { this.CancelSendTimer(); } } if (DiagnosticUtility.ShouldTrace(traceEventType)) { TraceUtility.TraceEvent(traceEventType, 0x4001b, System.ServiceModel.SR.GetString("TraceCodeSocketConnectionAbort"), this); } this.socket.Close(0); }
protected abstract void Abort(int traceEventType, string timeoutErrorString, TransferOperation transferOperation);
private static Exception ConvertTransferException(SocketException socketException, TimeSpan timeout, Exception originalException, TransferOperation transferOperation, bool aborted, string timeoutErrorString, TransferOperation timeoutErrorTransferOperation, TimeSpan remainingTime) { if (socketException.ErrorCode == 6) { return new CommunicationObjectAbortedException(socketException.Message, socketException); } if (timeoutErrorString != null) { return ConvertTimeoutErrorException(originalException, transferOperation, timeoutErrorString, timeoutErrorTransferOperation); } if ((socketException.ErrorCode == 0x2745) && (remainingTime <= TimeSpan.Zero)) { return new TimeoutException(System.ServiceModel.SR.GetString("TcpConnectionTimedOut", new object[] { timeout }), originalException); } if (((socketException.ErrorCode == 0x2744) || (socketException.ErrorCode == 0x2745)) || (socketException.ErrorCode == 0x2746)) { if (aborted) { return new CommunicationObjectAbortedException(System.ServiceModel.SR.GetString("TcpLocalConnectionAborted"), originalException); } return new CommunicationException(System.ServiceModel.SR.GetString("TcpConnectionResetError", new object[] { timeout }), originalException); } if (socketException.ErrorCode == 0x274c) { return new TimeoutException(System.ServiceModel.SR.GetString("TcpConnectionTimedOut", new object[] { timeout }), originalException); } if (aborted) { return new CommunicationObjectAbortedException(System.ServiceModel.SR.GetString("TcpTransferError", new object[] { socketException.ErrorCode, socketException.Message }), originalException); } return new CommunicationException(System.ServiceModel.SR.GetString("TcpTransferError", new object[] { socketException.ErrorCode, socketException.Message }), originalException); }
protected Exception ConvertObjectDisposedException(ObjectDisposedException originalException, TransferOperation transferOperation) { if (_timeoutErrorString != null) { return ConvertTimeoutErrorException(originalException, transferOperation, _timeoutErrorString, _timeoutErrorTransferOperation); } else if (_aborted) { return new CommunicationObjectAbortedException(SR.SocketConnectionDisposed, originalException); } else { return originalException; } }
void Abort(TraceEventType traceEventType, string timeoutErrorString, TransferOperation transferOperation) { if (TD.SocketConnectionAbortIsEnabled()) { TD.SocketConnectionAbort(this.socket.GetHashCode()); } lock (ThisLock) { if (closeState == CloseState.Closed) { return; } this.timeoutErrorString = timeoutErrorString; this.timeoutErrorTransferOperation = transferOperation; aborted = true; closeState = CloseState.Closed; if (this.asyncReadPending) { CancelReceiveTimer(); } else { this.DisposeReadEventArgs(); } if (this.asyncWritePending) { CancelSendTimer(); } else { this.DisposeWriteEventArgs(); } } if (DiagnosticUtility.ShouldTrace(traceEventType)) { TraceUtility.TraceEvent(traceEventType, TraceCode.SocketConnectionAbort, SR.GetString(SR.TraceCodeSocketConnectionAbort), this); } socket.Close(0); }
private Exception ConvertObjectDisposedException(ObjectDisposedException originalException, TransferOperation transferOperation) { if (this.timeoutErrorString != null) { return(ConvertTimeoutErrorException(originalException, transferOperation, this.timeoutErrorString, this.timeoutErrorTransferOperation)); } if (this.aborted) { return(new CommunicationObjectAbortedException(System.ServiceModel.SR.GetString("SocketConnectionDisposed"), originalException)); } return(originalException); }
static Exception ConvertTransferException(SocketException socketException, TimeSpan timeout, Exception originalException, TransferOperation transferOperation, bool aborted, string timeoutErrorString, TransferOperation timeoutErrorTransferOperation, SocketConnection socketConnection, TimeSpan remainingTime) { if (socketException.ErrorCode == UnsafeNativeMethods.ERROR_INVALID_HANDLE) { return new CommunicationObjectAbortedException(socketException.Message, socketException); } if (timeoutErrorString != null) { return ConvertTimeoutErrorException(originalException, transferOperation, timeoutErrorString, timeoutErrorTransferOperation); } TraceEventType exceptionEventType = socketConnection == null ? TraceEventType.Error : socketConnection.ExceptionEventType; // 10053 can occur due to our timeout sockopt firing, so map to TimeoutException in that case if (socketException.ErrorCode == UnsafeNativeMethods.WSAECONNABORTED && remainingTime <= TimeSpan.Zero) { TimeoutException timeoutException = new TimeoutException(SR.GetString(SR.TcpConnectionTimedOut, timeout), originalException); if (TD.TcpConnectionTimedOutIsEnabled()) { if (socketConnection != null) { int socketid = (socketConnection != null && socketConnection.socket != null) ? socketConnection.socket.GetHashCode() : -1; TD.TcpConnectionTimedOut(socketid, socketConnection.RemoteEndpointAddress); } } if (DiagnosticUtility.ShouldTrace(exceptionEventType)) { TraceUtility.TraceEvent(exceptionEventType, TraceCode.TcpConnectionTimedOut, GetEndpointString(SR.TcpConnectionTimedOut, timeout, null, socketConnection), timeoutException, null); } return timeoutException; } if (socketException.ErrorCode == UnsafeNativeMethods.WSAENETRESET || socketException.ErrorCode == UnsafeNativeMethods.WSAECONNABORTED || socketException.ErrorCode == UnsafeNativeMethods.WSAECONNRESET) { if (aborted) { return new CommunicationObjectAbortedException(SR.GetString(SR.TcpLocalConnectionAborted), originalException); } else { CommunicationException communicationException = new CommunicationException(SR.GetString(SR.TcpConnectionResetError, timeout), originalException); if (TD.TcpConnectionResetErrorIsEnabled()) { if (socketConnection != null) { int socketId = (socketConnection.socket != null) ? socketConnection.socket.GetHashCode() : -1; TD.TcpConnectionResetError(socketId, socketConnection.RemoteEndpointAddress); } } if (DiagnosticUtility.ShouldTrace(exceptionEventType)) { TraceUtility.TraceEvent(exceptionEventType, TraceCode.TcpConnectionResetError, GetEndpointString(SR.TcpConnectionResetError, timeout, null, socketConnection), communicationException, null); } return communicationException; } } else if (socketException.ErrorCode == UnsafeNativeMethods.WSAETIMEDOUT) { TimeoutException timeoutException = new TimeoutException(SR.GetString(SR.TcpConnectionTimedOut, timeout), originalException); if (DiagnosticUtility.ShouldTrace(exceptionEventType)) { TraceUtility.TraceEvent(exceptionEventType, TraceCode.TcpConnectionTimedOut, GetEndpointString(SR.TcpConnectionTimedOut, timeout, null, socketConnection), timeoutException, null); } return timeoutException; } else { if (aborted) { return new CommunicationObjectAbortedException(SR.GetString(SR.TcpTransferError, socketException.ErrorCode, socketException.Message), originalException); } else { CommunicationException communicationException = new CommunicationException(SR.GetString(SR.TcpTransferError, socketException.ErrorCode, socketException.Message), originalException); if (DiagnosticUtility.ShouldTrace(exceptionEventType)) { TraceUtility.TraceEvent(exceptionEventType, TraceCode.TcpTransferError, GetEndpointString(SR.TcpTransferError, TimeSpan.MinValue, socketException, socketConnection), communicationException, null); } return communicationException; } } }
private Exception ConvertObjectDisposedException(ObjectDisposedException originalException, TransferOperation transferOperation) { if (this.timeoutErrorString != null) { return ConvertTimeoutErrorException(originalException, transferOperation, this.timeoutErrorString, this.timeoutErrorTransferOperation); } if (this.aborted) { return new CommunicationObjectAbortedException(System.ServiceModel.SR.GetString("SocketConnectionDisposed"), originalException); } return originalException; }