/// <summary> /// Executes the workflow activity. /// </summary> /// <param name="executionContext">The execution context.</param> protected override void Execute(CodeActivityContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("Code Activity Context is null"); } var tracingService = executionContext.GetExtension <ITracingService>(); if (tracingService == null) { throw new InvalidPluginExecutionException("Failed to retrieve tracing service."); } var context = executionContext.GetExtension <IWorkflowContext>(); WorkflowContext = context; tracingService.Trace("In Base Execute"); if (context == null) { throw new InvalidPluginExecutionException("Failed to retrieve workflow context."); } var serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); var service = serviceFactory.CreateOrganizationService(context.UserId); OrganizationServiceFactory = serviceFactory; OrganizationService = service; OrganizationServiceContext = new OrganizationServiceContext(service); tracingService.Trace("Entered custom activity, Correlation Id: {0}, Initiating User: {1}", context.CorrelationId, context.InitiatingUserId); try { tracingService.Trace("Entering ExecuteActivity {0}. Correlation Id: {1}", GetType().FullName, context.CorrelationId); // setting true beforehand so it doesn't overwrite any custom behavior. Success.Set(executionContext, true); ExecuteActivity(executionContext); tracingService.Trace("Ending ExecuteActivity {0}. Correlation Id: {1}", GetType().FullName, context.CorrelationId); } catch (Exception e) { tracingService.Trace("Exception for {0}. Correlation Id: {1}, Error message: {2} . Stack trace: {3}", GetType().FullName, context.CorrelationId, e.Message, e.StackTrace); Success.Set(executionContext, false); Result.Set(executionContext, e.Message + e.StackTrace); if (FailOnException.Get <bool>(executionContext)) { throw new InvalidPluginExecutionException(e.Message, e); } } }
/// <summary> /// Executes the workflow activity. /// </summary> /// <param name="executionContext">The execution context.</param> protected override void Execute(CodeActivityContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("Code Activity Context is null"); } ITracingService tracingService = executionContext.GetExtension <ITracingService>(); DXTools.CRM.Solutions.CustomEmails.Common.TraceService.Initialise(tracingService); if (tracingService == null) { throw new InvalidPluginExecutionException("Failed to retrieve tracing service."); } IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); this.WorkflowContext = context; if (context == null) { throw new InvalidPluginExecutionException("Failed to retrieve workflow context."); } IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); OrganizationServiceFactory = serviceFactory; OrganizationService = service; tracingService.Trace("Entered custom activity, Correlation Id: {0}, Initiating User: {1}", context.CorrelationId, context.InitiatingUserId); try { TraceService.Trace("Entering ExecuteActivity {0}. Correlation Id: {1}", this.GetType().FullName, context.CorrelationId); this.ExecuteActivity(executionContext); TraceService.Trace("Ending ExecuteActivity {0}. Correlation Id: {1}", this.GetType().FullName, context.CorrelationId); } catch (Exception e) { ExceptionOccured.Set(executionContext, true); ExceptionMessage.Set(executionContext, e.Message); if (FailOnException.Get <bool>(executionContext)) { throw new InvalidPluginExecutionException(e.Message, e); } } }