Пример #1
0
        /// <summary>
        /// Tracks the complete outstanding operation.
        /// </summary>
        /// <param name="asyncEvent">The asynchronous event.</param>
        /// <param name="result">The result.</param>
        /// <param name="executionStarted">if set to <c>true</c> [execution started].</param>
        internal void TrackCompleteOutstandingOperation(AsyncEvent asyncEvent, AsyncHandlerResult result, bool executionStarted)
        {
            lock (_outstandingOperations)
            {
                if (result is AsyncInProgressResult) return;
                if (!_outstandingOperations.Remove(asyncEvent)) return;

                Counters.TrackCompleteOutstandingOperation(asyncEvent.OperationType, result, asyncEvent.ExecutionTime);
                if (executionStarted)
                {
                    _startThreadHandler();
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Determines whether this instance [can remove event] the specified asynchronous event.
 /// </summary>
 /// <param name="asyncEvent">The asynchronous event.</param>
 /// <param name="result">The result.</param>
 /// <returns></returns>
 private bool CanRemoveEvent(AsyncEvent asyncEvent, AsyncHandlerResult result)
 {
     var asyncRemoveEventResult = result as AsyncRemoveEventResult;
     return asyncRemoveEventResult != null;
 }
Пример #3
0
 /// <summary>
 /// Ends the asynchronous event processing.
 /// </summary>
 /// <param name="asyncEvent">The asynchronous event.</param>
 /// <param name="result">The result.</param>
 public void EndAsynchronousEventProcessing(AsyncEvent asyncEvent, AsyncHandlerResult result)
 {
     UpdateEventState(asyncEvent, result);
     TrackCompleteExecutingOperation(asyncEvent, result);
     TrackCompleteOutstandingOperation(asyncEvent, result, true);
 }
Пример #4
0
        /// <summary>
        /// Tracks the complete executing operation.
        /// </summary>
        /// <param name="asyncEvent">The asynchronous event.</param>
        /// <param name="result">The result.</param>
        internal void TrackCompleteExecutingOperation(AsyncEvent asyncEvent, AsyncHandlerResult result)
        {
            lock (_executingOperations)
            {
                if (result is AsyncInProgressResult) return;

                if (_executingOperations.Remove(asyncEvent))
                {
                    Counters.TrackCompleteExecutingOperation(asyncEvent.OperationType);
                    SemaphoreSlim semaphoreSlim = null;
                    if (Configuration.OperationTypeThrottle.TryGetValue(asyncEvent.OperationType, out semaphoreSlim))
                    {
                        semaphoreSlim.Release();
                    }
                }
                if (_shutdownEvent != null && _executingOperations.Count == 0)
                {
                    _shutdownEvent.Set();
                }
            }
        }
Пример #5
0
 /// <summary>
 /// Ends the asynchronous event processing.
 /// </summary>
 /// <param name="asyncEvent">The asynchronous event.</param>
 /// <param name="result">The result.</param>
 internal void EndAsynchronousEventProcessing(AsyncEvent asyncEvent, AsyncHandlerResult result)
 {
     _queueManager.EndAsynchronousEventProcessing(asyncEvent, result);
 }
Пример #6
0
 /// <summary>
 /// Updates the state of the event.
 /// </summary>
 /// <param name="asyncEvent">The asynchronous event.</param>
 /// <param name="result">The result.</param>
 private void UpdateEventState(AsyncEvent asyncEvent, AsyncHandlerResult result)
 {
     var instance = this._dataAccessFactory.CreateInstance(this, Configuration.OrganizationConfiguration);
     var newStatus = result.ResultCode;
     int newState = 3;
     int errorCode = 0;
     string errorMessage = null;
     string friendlyMessage = null;
     bool retryOperation = false;
     var handlerResultWithError = result as AsyncHandlerResultWithError;
     if (handlerResultWithError != null)
     {
         errorCode = handlerResultWithError.ErrorCode;
         errorMessage = handlerResultWithError.ErrorMessage;
         friendlyMessage = handlerResultWithError.FriendlyMessage;
     }
     else
     {
         var resultWithMessage = result as AsyncHandlerResultWithMessage;
         if (resultWithMessage != null)
             friendlyMessage = resultWithMessage.Message;
     }
     var nextOccurrence = DateTime.MinValue;
     if (result is AsyncRetryResult)
     {
         if (asyncEvent.RetryCount < this.Configuration.MaximumRetries || errorCode == -2147180543) // -2147180543 = The server is busy and the request was not completed. Try again later.
         {
             retryOperation = true;
         }
         else
         {
             nextOccurrence = DateTime.MaxValue;
             LogEvent(EventLogEntryType.Error, 3221242897L, Environment.MachineName, asyncEvent.OperationType, errorCode.ToString("x", (IFormatProvider)CultureInfo.InvariantCulture),
                 errorMessage);
         }
     }
     var asyncPausedResult = result as AsyncPausedResult;
     if (asyncPausedResult != null && asyncPausedResult.PostponeUntil != DateTime.MinValue)
         nextOccurrence = asyncPausedResult.PostponeUntil;
     switch (newStatus)
     {
         case 20:
             return;
         case 21:
         case 10:
             if (retryOperation && this.HandleSpecialTransition(asyncEvent) != null)
                 return;
             newState = 1;
             newStatus = 10;
             break;
         case 22:
         case 32:
             newState = 3;
             newStatus = 32;
             break;
         case 0:
             AsyncServiceException.Assert(false, "错误状态: " + newStatus);
             break;
     }
     if (result is AsyncSystemPausedResult)
         nextOccurrence = DateTime.MaxValue;
     if (asyncEvent.IsRecurrenceEvent)
     {
         nextOccurrence = NextOccurrence(asyncEvent);
         if (nextOccurrence == DateTime.MinValue)
         {
             newState = 3;
             newStatus = 30;
         }
         else
         {
             newState = 1;
             newStatus = 10;
         }
     }
     if (newState == 1 && newStatus == 10 && asyncEvent.AutoResumeFromPause)
         nextOccurrence = DateTime.Now.AddMinutes(1.0);
     var newEventState = new AsyncEventState()
     {
         EventId = asyncEvent.EventId,
         NewState = newState,
         NewStatus = newStatus,
         NextOccurrence = nextOccurrence,
         RetryOperation = retryOperation,
         CurrentRetryCount = asyncEvent.RetryCount,
         ErrorCode = errorCode,
         ErrorMessage = errorMessage,
         FriendlyMessage = friendlyMessage,
         ClearData = this.CanClearData(newState, asyncEvent),
         ExecutionTime = asyncEvent.ExecutionTimeSeconds,
         CanRemoveEvent = this.CanRemoveEvent(asyncEvent, result),
         HandlerResult = result
     };
     instance.UpdateStateAndStatus(newEventState);
     RemoveSpecialTransition(asyncEvent.EventId);
 }
Пример #7
0
 /// <summary>
 /// Ends the asynchronous event processing.
 /// </summary>
 /// <param name="result">The result.</param>
 public void EndAsynchronousEventProcessing(AsyncHandlerResult result)
 {
     this._queueManager.EndAsynchronousEventProcessing(this, result);
 }
Пример #8
0
 /// <summary>
 /// Tracks the complete outstanding operation.
 /// </summary>
 /// <param name="result">The result.</param>
 /// <param name="completionTime">The completion time.</param>
 public void TrackCompleteOutstandingOperation(AsyncHandlerResult result, System.TimeSpan completionTime)
 {
     this._itemsOutstanding.Decrement();
     long num = this._itemsCompleted.Increment();
     this._itemsCompletedThroughput.Increment();
     if (num < 1L)
     {
         num = 1L;
     }
     if (result is AsyncFailedResult)
     {
         this._itemsFailedWithException.Increment();
     }
     else if (result is AsyncRetryResult)
     {
         this._itemsFailedWithRetry.Increment();
     }
     this._rateFailedWithException.RawValue =
         (long) (this._itemsFailedWithException.RawValue/(double) num*100.0);
     this._rateFailedWithRetry.RawValue =
         (long) (this._itemsFailedWithRetry.RawValue/(double) num*100.0);
     if (completionTime != System.TimeSpan.MinValue)
     {
         long value = System.Convert.ToInt64(completionTime.TotalSeconds);
         long num2 = System.Threading.Interlocked.Add(ref this._totalTime, value);
         long num3 = System.Threading.Interlocked.Increment(ref this._totalCount);
         if (num2 < 0L || num3 <= 0L)
         {
             num3 = 1L;
             num2 = this._averageTime.RawValue;
             System.Threading.Interlocked.Exchange(ref this._totalCount, num3);
             System.Threading.Interlocked.Exchange(ref this._totalTime, num2);
         }
         this._averageTime.RawValue = num2/num3;
     }
 }
Пример #9
0
 /// <summary>
 /// Tracks the complete outstanding operation.
 /// </summary>
 /// <param name="operationType">Type of the operation.</param>
 /// <param name="result">The result.</param>
 /// <param name="completionTime">The completion time.</param>
 public void TrackCompleteOutstandingOperation(Guid operationType, AsyncHandlerResult result,
     System.TimeSpan completionTime)
 {
     this._totalCounters.TrackCompleteOutstandingOperation(result, completionTime);
 }
Пример #10
0
 public void TrackCompleteOutstandingOperation(Guid operationType, AsyncHandlerResult result,
                                               System.TimeSpan completionTime)
 {
 }
Пример #11
0
 public void TrackCompleteOutstandingOperation(Guid operationType, AsyncHandlerResult result)
 {
 }