/// <summary> /// Executes the workflow activity. /// </summary> /// <param name="executionContext">The execution context.</param> protected override void Execute(CodeActivityContext executionContext) { // Create the tracing service ITracingService tracingService = executionContext.GetExtension <ITracingService>(); if (tracingService == null) { throw new InvalidPluginExecutionException("Failed to retrieve tracing service."); } tracingService.Trace("Entered " + _processName + ".Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}", executionContext.ActivityInstanceId, executionContext.WorkflowInstanceId); // Create the context IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); if (context == null) { throw new InvalidPluginExecutionException("Failed to retrieve workflow context."); } tracingService.Trace(_processName + ".Execute(), Correlation Id: {0}, Initiating User: {1}", context.CorrelationId, context.InitiatingUserId); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); try { //do the regex match Match match = Regex.Match(StringToValidate.Get(executionContext), MatchPattern.Get(executionContext), RegexOptions.IgnoreCase); //did we match anything? if (match.Success) { Valid.Set(executionContext, 1); } else { Valid.Set(executionContext, 0); } } catch (FaultException <OrganizationServiceFault> e) { tracingService.Trace("Exception: {0}", e.ToString()); // Handle the exception. throw; } catch (Exception e) { tracingService.Trace("Exception: {0}", e.ToString()); throw; } tracingService.Trace("Exiting " + _processName + ".Execute(), Correlation Id: {0}", context.CorrelationId); }
private void ExecuteWorkflow(CodeActivityContext executionContext, IWorkflowContext workflowContext, IOrganizationServiceFactory serviceFactory, IOrganizationService service, ITracingService tracing) { tracing.Trace("Begin Execute Workflow: WooowKoolWorkflowContact_ValidateRegex"); var stringToValidate = StringToValidate.Get(executionContext); var matchPattern = MatchPattern.Get(executionContext); if (ValidateString(stringToValidate, matchPattern)) { Valid.Set(executionContext, "1"); } else { Valid.Set(executionContext, "0"); } tracing.Trace("End Execute Workflow: WooowKoolWorkflowContact_ValidateRegex"); }
/// <summary> /// Executes the workflow activity. /// </summary> /// <param name="executionContext">The execution context.</param> protected override void Execute(CodeActivityContext executionContext) { // Create the tracing service ITracingService tracingService = executionContext.GetExtension <ITracingService>(); if (tracingService == null) { throw new InvalidPluginExecutionException("Failed to retrieve tracing service."); } tracingService.Trace("Entered " + _processName + ".Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}", executionContext.ActivityInstanceId, executionContext.WorkflowInstanceId); // Create the context IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); if (context == null) { throw new InvalidPluginExecutionException("Failed to retrieve workflow context."); } tracingService.Trace(_processName + ".Execute(), Correlation Id: {0}, Initiating User: {1}", context.CorrelationId, context.InitiatingUserId); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); //get all our inputs ready to work with //string to parse string parseString = StringToParse.Get(executionContext); //pattern to match string matchPattern = MatchPattern.Get(executionContext); //type of match to be returned - first match, last match or all matches ExtractionType extractType; switch (ReturnType.Get(executionContext).ToUpperInvariant()) { case "FIRST": extractType = ExtractionType.First; break; case "LAST": extractType = ExtractionType.Last; break; case "ALL": extractType = ExtractionType.All; break; default: //default will return first match only extractType = ExtractionType.First; break; } //separator to be used for an "all" match string stringSeparator = StringSeparator.Get(executionContext); //evaluate the regex and return the match(es) try { string extractedString = ExtractMatchingString(parseString, matchPattern, extractType, stringSeparator); ExtractedString.Set(executionContext, extractedString); } catch (Exception e) { tracingService.Trace("Exception: {0}", e.ToString()); throw; } tracingService.Trace("Exiting " + _processName + ".Execute(), Correlation Id: {0}", context.CorrelationId); }