예제 #1
0
 public static void StampCurrentDataContext(Exception exception)
 {
     ExecutionContext.DataContextHolder contextHolder = ExecutionContext.GetContextHolder(exception, true);
     if (contextHolder != null && ExecutionContext.currentContexts != null)
     {
         foreach (DataContext dataContext in ExecutionContext.currentContexts)
         {
             contextHolder.Contexts.Add(dataContext.ToString());
             if (contextHolder.Side == null)
             {
                 OperationSideDataContext operationSideDataContext = dataContext as OperationSideDataContext;
                 if (operationSideDataContext != null)
                 {
                     contextHolder.Side = new ExceptionSide?(operationSideDataContext.Side);
                 }
             }
             if (contextHolder.OperationType == OperationType.None)
             {
                 OperationDataContext operationDataContext = dataContext as OperationDataContext;
                 if (operationDataContext != null && operationDataContext.OperationType != OperationType.None)
                 {
                     contextHolder.OperationType = operationDataContext.OperationType;
                 }
             }
         }
     }
 }
예제 #2
0
        public static string GetDataContext(Exception exception)
        {
            StringBuilder stringBuilder = new StringBuilder();

            for (Exception ex = exception; ex != null; ex = ex.InnerException)
            {
                ExecutionContext.DataContextHolder contextHolder = ExecutionContext.GetContextHolder(ex, false);
                if (contextHolder != null && contextHolder.Contexts != null && contextHolder.Contexts.Count > 0)
                {
                    foreach (string text in contextHolder.Contexts)
                    {
                        if (stringBuilder.Length == 0)
                        {
                            stringBuilder.Append(text);
                        }
                        else
                        {
                            stringBuilder.AppendFormat(Environment.NewLine + "{0}", text);
                        }
                    }
                    return(stringBuilder.ToString());
                }
            }
            return(stringBuilder.ToString());
        }
예제 #3
0
 public static void SetExceptionSide(Exception exception, ExceptionSide?side)
 {
     ExecutionContext.DataContextHolder contextHolder = ExecutionContext.GetContextHolder(exception, true);
     if (contextHolder != null)
     {
         contextHolder.Side = side;
     }
 }
예제 #4
0
 public static OperationType GetOperationType(Exception exception)
 {
     for (Exception ex = exception; ex != null; ex = ex.InnerException)
     {
         ExecutionContext.DataContextHolder contextHolder = ExecutionContext.GetContextHolder(ex, false);
         if (contextHolder != null && contextHolder.OperationType != OperationType.None)
         {
             return(contextHolder.OperationType);
         }
     }
     return(OperationType.None);
 }
예제 #5
0
 public static ExceptionSide?GetExceptionSide(Exception exception)
 {
     for (Exception ex = exception; ex != null; ex = ex.InnerException)
     {
         ExecutionContext.DataContextHolder contextHolder = ExecutionContext.GetContextHolder(ex, false);
         if (contextHolder != null && contextHolder.Side != null)
         {
             return(contextHolder.Side);
         }
     }
     return(null);
 }
예제 #6
0
 private static ExecutionContext.DataContextHolder GetContextHolder(Exception exception, bool createIfMissing)
 {
     if (exception == null || exception.Data == null)
     {
         return(null);
     }
     ExecutionContext.DataContextHolder dataContextHolder;
     if (exception.Data.Contains("Microsoft.Exchange.MailboxReplicationService.DataContext"))
     {
         dataContextHolder = (ExecutionContext.DataContextHolder)exception.Data["Microsoft.Exchange.MailboxReplicationService.DataContext"];
     }
     else if (createIfMissing)
     {
         dataContextHolder = new ExecutionContext.DataContextHolder();
         exception.Data["Microsoft.Exchange.MailboxReplicationService.DataContext"] = dataContextHolder;
     }
     else
     {
         dataContextHolder = null;
     }
     return(dataContextHolder);
 }