コード例 #1
0
ファイル: Trace.cs プロジェクト: pengyancai/cs-util
 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));
 }
コード例 #2
0
        private IAsyncResult BeginProcessTransaction(IPopTransaction t, bool exceptionIfIncapable)
        {
            PreProcessTransaction(t, exceptionIfIncapable);

              var processTransaction = new ProcessTransactionDelegate(ProcessTransactionInternal);

              return new TransactionAsyncResult(t, processTransaction.BeginInvoke(t, null, null));
        }
コード例 #3
0
ファイル: Trace.cs プロジェクト: pengyancai/cs-util
        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);
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        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);
              }
              */
        }
コード例 #6
0
 public TransactionAsyncResult(IPopTransaction transaction, IAsyncResult processTransactionAsyncResult)
 {
     this.transaction = transaction;
     this.processTransactionAsyncResult = processTransactionAsyncResult;
 }
コード例 #7
0
        private IPopTransaction ProcessTransactionInternal(IPopTransaction t)
        {
            lock (transactionLockObject) {
            Trace.LogRequest(t);

            t.Process();

            Trace.LogResponse(t);

            return t;
              }
        }
コード例 #8
0
        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));
            }
              }
        }
コード例 #9
0
ファイル: Trace.cs プロジェクト: pengyancai/cs-util
 public static void LogResponse(IPopTransaction transaction)
 {
     Log(transaction,
       "{0} {1}",
       transaction.Result.Code,
       transaction.Result.ResultText);
 }