Exemple #1
0
        public void ParsingTest()
        {
            string           exp       = "-1 + 28*sqrt(1314)/2^5";
            IStringSeparator separator = new StringSeparator();
            OperatorList     opList    = new OperatorList();

            opList.InitWithDefaultOperators();
            Assert.Equal("-;1;+;28;*;sqrt;(;1314;);/;2;^;5",
                         String.Join(";", separator.Separate(exp, opList).ToArray().Select(e => e.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);
        }
 /// <exception cref="ArgumentNullException"><paramref name="input" /> or <paramref name="separator" /> is null.</exception>
 public static string SeparateWords(this string input, string separator = " ")
 {
     return(StringSeparator.Separate(input, separator));
 }