protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (localContext == null) { throw new ArgumentNullException(nameof(localContext)); } string stringToParse = StringToParse.Get(context); int startPosition = StartPosition.Get(context); int length = Length.Get(context); if (startPosition < 0) { startPosition = 0; } if (startPosition > stringToParse.Length) { localContext.TracingService.Trace("Specified start position [" + startPosition + "] is after end is string [" + stringToParse + "]"); PartialString.Set(context, null); } if (length > stringToParse.Length) { length = stringToParse.Length - startPosition; } string partialString = (length == 0) ? stringToParse.Substring(startPosition) : stringToParse.Substring(startPosition, length); PartialString.Set(context, partialString); }
protected override void Execute(CodeActivityContext executionContext) { ITracingService tracer = executionContext.GetExtension <ITracingService>(); try { string stringToParse = StringToParse.Get(executionContext); int startPosition = StartPosition.Get(executionContext); int length = Length.Get(executionContext); if (startPosition < 0) { startPosition = 0; } if (startPosition > stringToParse.Length) { tracer.Trace("Specified start position [" + startPosition + "] is after end is string [" + stringToParse + "]"); PartialString.Set(executionContext, null); } if (length > stringToParse.Length) { length = stringToParse.Length - startPosition; } string partialString = (length == 0) ? stringToParse.Substring(startPosition) : stringToParse.Substring(startPosition, length); PartialString.Set(executionContext, partialString); } catch (Exception ex) { tracer.Trace("Exception: {0}", ex.ToString()); } }
/// <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); }
public List <Command> parseCommandString() { List <Command> listOfCommands = new List <Command>(); bool badcmd = false; var charsToRemove = new string[] { "(", ")", " ", "." }; foreach (var c in charsToRemove) { StringToParse = StringToParse.Replace(c, string.Empty); } string[] separatedCommands = StringToParse.Split(','); // for (int i = 0; i < separatedCommands.Length; i++) { StringBuilder sb = new StringBuilder(); string dir = null; badcmd = false; for (int j = 0; j < separatedCommands[i].Length; j++) { if (Char.IsLetter(separatedCommands[i][j]) && j == 0) { if (separatedCommands[i][j] == 'l') { dir = "left"; } else if (separatedCommands[i][j] == 'r') { dir = "right"; } else if (separatedCommands[i][j] == 'u') { dir = "up"; } else if (separatedCommands[i][j] == 'd') { dir = "down"; } else { BadCommand bc = new BadCommand(separatedCommands[i], "Invalid command for direction"); //ListOfInvalidCommands.Add(separatedCommands[i]); Console.WriteLine(bc.ToString()); badcmd = true; break; } } else if (Char.IsNumber(separatedCommands[i][j]) && j > 0) { sb.Append(separatedCommands[i][j]); } else { BadCommand bc = new BadCommand(separatedCommands[i], "Invalid distance"); //ListOfInvalidCommands.Add(separatedCommands[i]); Console.WriteLine(bc.ToString()); badcmd = true; break; } } if (!badcmd) { int dis = Int32.Parse(sb.ToString()); Command com = new Command(dir, dis); listOfCommands.Add(com); } } //// //foreach (var substring in separatedCommands) { // string dir = substring[0].ToString(); // int dis = Int32.Parse(substring.Substring(1)); // if (dir.Equals("l")) // dir = "left"; // else if (dir.Equals("r")) // dir = "right"; // else if (dir.Equals("u")) // dir = "up"; // else if (dir.Equals("d")) // dir = "down"; // else { // badCommand = true; // } // Command com = new Command(dir, dis); // listOfCommands.Add(com); //} return(listOfCommands); }