protected override void Execute(CodeActivityContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            try
            {
                CodeActivityContext = context;
                Initialize();
                Trace(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.StartTracing, SystemTypeName, Stopwatch.ElapsedMilliseconds));
                Trace(TraceHelper.Trace(WorkflowContext));
                Trace(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.ExecutionContextTracingCompleted, SystemTypeName, Stopwatch.ElapsedMilliseconds));
                Validate();
                Execute();
            }
            catch (InvalidPluginExecutionException ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.InvalidPluginExecution, SystemTypeName, ex.Message, ex.StackTrace));

                Action <Exception> le = null;
                le = (n) => { sb.AppendLine(n.Message); sb.AppendLine(n.StackTrace); if (n.InnerException != null)
                              {
                                  le(n.InnerException);
                              }
                };
                le(ex);

                Trace(sb.ToString());

                ExceptionJson ej = new ExceptionJson
                {
                    Details = sb.ToString(),
                    Message = ex.Message,
                    Source  = ex.Source,
                };
                Exception.Set(CodeActivityContext, ej.Message);
                ExceptionJson.Set(CodeActivityContext, SerializationHelper.SerializeJson(ej));

                if (ThrowsException.Value)
                {
                    throw;
                }
            }
            catch (FaultException <OrganizationServiceFault> ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.OrganizationServiceFault, SystemTypeName, ex.Message, ex.StackTrace));

                if (ex.Detail == null)
                {
                    Trace(sb.ToString());

                    ExceptionJson ej = new ExceptionJson
                    {
                        Details = sb.ToString(),
                        Message = ex.Message,
                        Source  = ex.Source,
                    };
                    Exception.Set(CodeActivityContext, ej.Message);
                    ExceptionJson.Set(CodeActivityContext, SerializationHelper.SerializeJson(ej));

                    if (ThrowsException.Value)
                    {
                        throw new InvalidPluginExecutionException(ex.Message, ex);
                    }
                }
                else
                {
                    sb.AppendLine(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.ExceptionErrorCode, ex.Detail.ErrorCode));
                    sb.AppendLine(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.ExceptionMessage, ex.Detail.Message));
                    sb.AppendLine(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.ExceptionTrace, ex.Detail.TraceText));
                    foreach (var errorDetail in ex.Detail.ErrorDetails)
                    {
                        sb.AppendLine(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.ExceptionDetailKey, errorDetail.Key, errorDetail.Value));
                    }

                    Trace(sb.ToString());

                    ExceptionJson ej = new ExceptionJson
                    {
                        Details = sb.ToString(),
                        Message = ex.Detail.Message,
                        Source  = ex.Source,
                    };
                    Exception.Set(CodeActivityContext, ej.Message);
                    ExceptionJson.Set(CodeActivityContext, SerializationHelper.SerializeJson(ej));

                    if (ThrowsException.Value)
                    {
                        throw new InvalidPluginExecutionException(ex.Detail.Message, ex);
                    }
                }
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.UndefinedFault, SystemTypeName, ex.Message, ex.StackTrace));

                Action <Exception> le = null;
                le = (n) => { sb.AppendLine(n.Message); sb.AppendLine(n.StackTrace); if (n.InnerException != null)
                              {
                                  le(n.InnerException);
                              }
                };
                le(ex);

                Trace(sb.ToString());

                ExceptionJson ej = new ExceptionJson
                {
                    Details = sb.ToString(),
                    Message = ex.Message,
                    Source  = ex.Source,
                };
                Exception.Set(CodeActivityContext, ej.Message);
                ExceptionJson.Set(CodeActivityContext, SerializationHelper.SerializeJson(ej));

                if (ThrowsException.Value)
                {
                    throw new InvalidPluginExecutionException(ex.Message, ex);
                }
            }
            finally
            {
                if (Stopwatch != null)
                {
                    Trace(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.ExecutionContextTracingCompleted, SystemTypeName, Stopwatch.Elapsed.TotalMilliseconds));
                    Stopwatch.Stop();
                    Stopwatch = null;
                }
                Trace(string.Format(CultureInfo.InvariantCulture, TraceMessageHelper.StopTracing, SystemTypeName));
            }
        }
 /// <summary>
 /// Tracks an exception
 /// </summary>
 /// <param name="ApplicationException">
 /// The exception object to be tracked
 /// </param>
 public void TrackException(Exception ApplicationException)
 {
     lock (ObjectLock)
     {
         if (Started && ApplicationException != null)
         {
             CheckApplicationCorrectness();
             var json = new ExceptionJson(ApplicationException, GetFlowNumber());
             JSON.Add(JsonBuilder.GetJsonFromHashTable(json.GetJsonHashTable()));
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// Tracks an exception
        /// </summary>
        /// <param name="exception">
        /// The exception object to be tracked
        /// </param>
        public void TrackException(Exception exception)
        {
            if (exception == null)
                throw new ArgumentNullException("exception");

            lock (_objectLock)
            {
                if (Started)
                {
                    CheckIfEnabled();
                    var json = new ExceptionJson(_sessionGUID, exception, GetFlowNumber());
                    _json.Add(JsonBuilder.GetJsonFromHashTable(json.GetJsonHashTable()));
                }
            }
        }