public static void Log(IPopTransaction transaction, string format, params object[] args) { Verbose("CID:{0} {1}: {2}", transaction.Connection.Id, transaction.GetType().Name.Replace("Transaction", string.Empty), args == null ? format : string.Format(format, args)); }
private IAsyncResult BeginProcessTransaction(IPopTransaction t, bool exceptionIfIncapable) { PreProcessTransaction(t, exceptionIfIncapable); var processTransaction = new ProcessTransactionDelegate(ProcessTransactionInternal); return new TransactionAsyncResult(t, processTransaction.BeginInvoke(t, null, null)); }
public static void LogRequest(IPopTransaction transaction) { var args = new StringBuilder(); foreach (var p in transaction.RequestArguments) { args.AppendFormat("'{0}'=>'{1}'; ", p.Key, p.Value); } Log(transaction, args.ToString(), null); }
private PopCommandResult PostProcessTransaction(IPopTransaction t) { switch (t.Result.Code) { /* * disconnect without processing responses */ case PopCommandResultCode.InternalError: CloseConnection(); throw new PopException(t.Result.Description, t.Result.Exception); case PopCommandResultCode.SocketTimeout: CloseConnection(); throw new TimeoutException(string.Format("socket timeout in {0}", t.GetType().FullName), t.Result.Exception); case PopCommandResultCode.ConnectionError: case PopCommandResultCode.UpgradeError: CloseConnection(); throw t.Result.Exception; } return t.Result; }
private void PreProcessTransaction(IPopTransaction t, bool exceptionIfIncapable) { if (IsTransactionProceeding) throw new InvalidOperationException("another transaction proceesing"); // check capability if (!exceptionIfIncapable) return; CheckServerCapability(t as IPopExtension); /* foreach (var arg in t.Request.Arguments.Values) { if (arg is IPopExtension) CheckServerCapability(arg as IPopExtension); } */ }
public TransactionAsyncResult(IPopTransaction transaction, IAsyncResult processTransactionAsyncResult) { this.transaction = transaction; this.processTransactionAsyncResult = processTransactionAsyncResult; }
private IPopTransaction ProcessTransactionInternal(IPopTransaction t) { lock (transactionLockObject) { Trace.LogRequest(t); t.Process(); Trace.LogResponse(t); return t; } }
private PopCommandResult ProcessTransaction(IPopTransaction t) { if (transactionTimeout == Timeout.Infinite) { // no timeout PreProcessTransaction(t, handlesIncapableAsException); ProcessTransactionInternal(t); return PostProcessTransaction(t); } else { var async = BeginProcessTransaction(t, handlesIncapableAsException); if (async.AsyncWaitHandle.WaitOne(transactionTimeout, false)) { return EndProcessTransaction(async); } else { CloseConnection(); throw new TimeoutException(string.Format("transaction timeout ({0})", t.GetType().FullName)); } } }
public static void LogResponse(IPopTransaction transaction) { Log(transaction, "{0} {1}", transaction.Result.Code, transaction.Result.ResultText); }