Exemple #1
0
 /// <summary>
 /// Replaces the matched elements of item for the specified value</summary>
 /// <param name="matchList">List of elements that matched a query</param>
 /// <param name="replaceValue">Object that designates which data is replaced in each matchList entry</param>
 public void Replace(IList <IQueryMatch> matchList, object replaceValue)
 {
     foreach (IQueryMatch matchCandidate in matchList)
     {
         MatchPattern.Replace(matchCandidate, replaceValue);
     }
 }
Exemple #2
0
        /// <summary>
        /// Tests the predicate on an item</summary>
        /// <param name="searchItem">Item in which searchable elements should be queried</param>
        /// <param name="matchList">Resulting list of matching elements from within searchItem</param>
        /// <returns>True iff the item matches the predicate</returns>
        public bool Test(object searchItem, out IList <IQueryMatch> matchList)
        {
            matchList = null;
            IQueryable query = GetQueryable(searchItem);

            if (query != null)
            {
                // execute the query against domNode's Properties - foreach statement will iterate for each match
                foreach (object queryMatch in query)
                {
                    // The tests below are NOT the match test...each queryMatch *is* a bona-fide match.
                    // Rather, the if statement below confirms a valid 'match pattern' was created, which
                    // can be used later to perform a replace operation.
                    IQueryMatch candidate = CreatePredicateMatch(searchItem, queryMatch);
                    if (MatchPattern == null || MatchPattern.Matches(candidate))
                    {
                        if (matchList == null)
                        {
                            matchList = new List <IQueryMatch>();
                        }
                        matchList.Add(candidate);
                    }
                }
            }

            // success based on whether a match list was created or not
            return(matchList != null);
        }
Exemple #3
0
        public bool Matches(HttpRequestMessage request, string paramTemplate)
        {
            var result = MatchPattern.Match(paramTemplate);

            if (!result.Success)
            {
                return(false);
            }


            var parameterValues = new Dictionary <string, object>();

            for (int i = 1; i < result.Groups.Count; i++)
            {
                var name  = MatchPattern.GroupNameFromNumber(i);
                var value = result.Groups[i].Value;
                parameterValues.Add(name, value);
            }

            foreach (var constraint in _Constraints)
            {
                var match = constraint.Value.Match(request, null, constraint.Key, parameterValues, HttpRouteDirection.UriResolution);
                if (match == false)
                {
                    return(false);
                }
            }

            return(true);
        }
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.Append('"');
            sb.Append(MatchPattern.ToString());
            sb.Append('"');
            sb.Append(" -> ");
            sb.Append('"');
            sb.Append(SubstitutionPattern);
            sb.Append('"');
            if (PathPattern != null)
            {
                sb.Append(" on files ");
                sb.Append('"');
                sb.Append(PathPattern.ToString());
                sb.Append('"');
            }
            if (MaximumRepeatCount > 0)
            {
                if (MaximumRepeatCount >= int.MaxValue)
                {
                    sb.Append(" repeated forever");
                }
                else
                {
                    sb.Append(" repeated up to ");
                    sb.Append(MaximumRepeatCount);
                    sb.Append(" times");
                }
            }
            return(sb.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);

            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);
        }
Exemple #6
0
 public void HighlightAllMatchingTurns()
 {
     if (!isHighlighted)
     {
         isHighlighted   = true;
         highlightedGems = new List <Gem> ();
         MatchPattern p = MatchPattern.Empty;
         for (int i = 0; i < Size; i++)
         {
             for (int j = 0; j < Size; j++)
             {
                 if (TryFindMatchingTurns(i, j, out p))
                 {
                     highlightedGems.Add(board [i, j]);
                     highlightedGems.Add(board [p.offset1.x + i, p.offset1.y + j]);
                     highlightedGems.Add(board [p.offset2.x + i, p.offset2.y + j]);
                 }
             }
         }
         foreach (var o in highlightedGems)
         {
             o.Throb();
         }
     }
 }
Exemple #7
0
    public void HighlightMatchingTurns(int number)
    {
        if (!isHighlighted)
        {
            isHighlighted   = true;
            highlightedGems = new List <Gem> ();
            MatchPattern p = MatchPattern.Empty;
            for (int i = 0; i < Size; i++)
            {
                for (int j = 0; j < Size; j++)
                {
                    if (TryFindMatchingTurns(i, j, out p))
                    {
                        highlightedGems.Add(board [i, j]);
                        highlightedGems.Add(board [p.offset1.x + i, p.offset1.y + j]);
                        highlightedGems.Add(board [p.offset2.x + i, p.offset2.y + j]);
                    }
                }
            }

            while (number > 0)
            {
                if (highlightedGems.Count > 0)
                {
                    int random = Random.Range(0, highlightedGems.Count / 3);
                    highlightedGems [random * 3].Throb();
                    highlightedGems [random * 3 + 1].Throb();
                    highlightedGems [random * 3 + 2].Throb();
                }
                number--;
            }
        }
    }
Exemple #8
0
            public Rule(string ruleRow)
            {
                var ruleSplit = ruleRow.Split(new string[] { " => " }, StringSplitOptions.RemoveEmptyEntries);

                this.MatchPattern = new List <string>();
                this.ArrayPattern = ruleSplit[1].Trim();
                this.Size         = ruleSplit[0].Where(x => x == '/').Count() + 1;

                // Add all flipped / rotated arrays to MatchPattern
                char[,] tArray = GetMatrixFromString(ruleSplit[0]);

                for (int i = 0; i < 4; i++)
                {
                    // Add tArray
                    MatchPattern.Add(GetStringFromMatrix(tArray));

                    // Flip & add horizontal
                    var fArray = FlipMatrix(tArray, true);
                    MatchPattern.Add(GetStringFromMatrix(fArray));

                    // Flip & add vertical
                    fArray = FlipMatrix(tArray, false);
                    MatchPattern.Add(GetStringFromMatrix(fArray));

                    // Rotate
                    tArray = RotateMatrix(tArray);
                }
            }
 public HexagonRule(int priority, MatchType type, Tuple <int, int> modularCondition, MatchPattern pattern, List <Tuple <int, int> > offsets)
 {
     this.priority         = priority;
     this.pattern          = pattern;
     this.modularCondition = modularCondition;
     this.type             = type;
     this.offsets          = offsets;
 }
Exemple #10
0
            /// <summary>
            ///     Initializes a new instance of the <see cref="AssemblyVersion"/> class.
            /// </summary>
            /// <exception cref="EvolveCoreDriverException"></exception>
            public AssemblyVersion(string version)
            {
                Version = Check.NotNullOrEmpty(version, nameof(version));

                if (!MatchPattern.IsMatch(Version))
                {
                    throw new EvolveCoreDriverException(string.Format(InvalidVersionPatternMatching, Version));
                }

                VersionParts = Version.Split('.').Select(long.Parse).ToList();
            }
Exemple #11
0
        /// <summary>
        ///     Constructor.
        /// </summary>
        /// <param name="version"> Version of the script. Example: 1_1_0_11 </param>
        /// <exception cref="EvolveConfigurationException"> Thrown when the format of the version is invalid. </exception>
        public MigrationVersion(string version)
        {
            Check.NotNullOrEmpty(version, nameof(version));

            Label = version.Replace('_', '.');
            if (!MatchPattern.IsMatch(Label))
            {
                throw new EvolveConfigurationException(string.Format(InvalidVersionPatternMatching, Label));
            }

            VersionParts = Label.Split('.').Select(long.Parse).ToList();
        }
Exemple #12
0
 bool CheckMatchPattern(int x, int y, MatchPattern pattern)
 {
     if ((x + pattern.offset1.x < Size && x + pattern.offset1.x >= 0) &&
         (y + pattern.offset1.y < Size && y + pattern.offset1.y >= 0) &&
         (x + pattern.offset2.x < Size && x + pattern.offset2.x >= 0) &&
         (y + pattern.offset2.y < Size && y + pattern.offset2.y >= 0) &&
         (x + pattern.offset3.x < Size && x + pattern.offset3.x >= 0) &&
         (y + pattern.offset3.y < Size && y + pattern.offset3.y >= 0))
     {
         return(boardData [x, y] == boardData [x + pattern.offset1.x, y + pattern.offset1.y] &&
                boardData [x, y] == boardData [x + pattern.offset2.x, y + pattern.offset2.y]);
     }
     return(false);
 }
        private MatchPattern GetPatternAndHighlightError()
        {
            var pattern = MatchPattern.TryCreate(patternTextbox.Text);

            if (pattern == null)
            {
                patternTextbox.BackColor = Color.Pink;
                patternTextbox.Focus();
            }
            else
            {
                patternTextbox.BackColor = Color.Empty;
            }

            return(pattern);
        }
Exemple #14
0
 public bool TryFindMatchingTurns(int x, int y, out MatchPattern pattern)
 {
     if (boardData [x, y] > 0)
     {
         foreach (MatchPattern p in matchPatterns)
         {
             if (CheckMatchPattern(x, y, p))
             {
                 pattern = p;
                 return(true);
             }
         }
     }
     pattern = MatchPattern.Empty;
     return(false);
 }
        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");
        }
Exemple #16
0
    public int Find(string target, MatchPattern pattern = MatchPattern.Equals, bool foward = true)
    {
        int i = _mCursor;

        while (i >= 0 && i < _mLines.Count)
        {
            if (pattern == MatchPattern.Equals && _mLines [i].Trim().Equals(target) ||
                pattern == MatchPattern.Contains && _mLines [i].Trim().Contains(target) ||
                pattern == MatchPattern.StartsWith && _mLines [i].Trim().StartsWith(target))
            {
                _mCursor = i;
                return(_mCursor);
            }

            i = foward ? i + 1 : i - 1;
        }

        return(-1);
    }
Exemple #17
0
    public void MakeTurn()
    {
        MatchPattern p = MatchPattern.Empty;

        for (int i = 0; i < Size; i++)
        {
            for (int j = 0; j < Size; j++)
            {
                if (TryFindMatchingTurns(i, j, out p))
                {
                    turn++;
                    Swap(new Vector2i(i + p.offset2.x, j + p.offset2.y), new Vector2i(i + p.offset3.x, j + p.offset3.y));
                    return;
                }
            }
        }
        //Debug.Log ("NO MORE TURNS: already made: " + turn + " turns");
        //Application.LoadLevel (0);
    }
Exemple #18
0
 public MatchMethod(MatchPattern pattern, int row_index, int col_index)
 {
     MatchPattern    = pattern;
     LeftTopRowIndex = row_index;
     LeftTopColIndex = col_index;
 }
 public void OverrideMatchPatternOptions(RegexOptions options, TimeSpan matchTimeout) => MatchPattern = MatchPattern.OverrideOptions(options, matchTimeout);
Exemple #20
0
        protected override System.Threading.Tasks.Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            PathRouteData pathRouteData;

            // Message handlers cause this method to be re-entrant.  Determine if this is the first time in or not.
            var beforeMessageHandler = IsBeforeMessageHandler(request, _MessageHandler);

            if (beforeMessageHandler || _MessageHandler == null)
            {
                pathRouteData = RetrieveRouteData(request);

                // Parse Parameters from URL and add them to the PathRouteData
                var result = MatchPattern.Match(pathRouteData.CurrentSegment);

                for (int i = 1; i < result.Groups.Count; i++)
                {
                    var name  = MatchPattern.GroupNameFromNumber(i);
                    var value = result.Groups[i].Value;
                    pathRouteData.SetParameter(name, value);
                }
            }
            else
            {
                pathRouteData = (PathRouteData)GetRouteData(request);
            }



            if (beforeMessageHandler)
            {
                return(base.SendAsync(request, cancellationToken));  // Call message handler, which will call back into here.
            }

            pathRouteData.AddRouter(this); // Track ApiRouters used to resolve path

            if (pathRouteData.EndOfPath())
            {
                if (HasController)
                {
                    return(Dispatch(request, cancellationToken));
                }
                else
                {
                    var tcs = new TaskCompletionSource <HttpResponseMessage>();
                    tcs.SetResult(new HttpResponseMessage(HttpStatusCode.NotFound));
                    return(tcs.Task);
                }
            }
            else
            {
                pathRouteData.MoveToNext();

                var nextRouter = GetMatchingRouter(request, pathRouteData.CurrentSegment);

                if (nextRouter != null)
                {
                    return(nextRouter.SendAsync(request, cancellationToken));
                }

                var tcs = new TaskCompletionSource <HttpResponseMessage>();
                tcs.SetResult(new HttpResponseMessage(HttpStatusCode.NotFound));
                return(tcs.Task);
            }
        }
Exemple #21
0
    public static List <Transform> FindDeepChildren(this Transform aParent, string aName, MatchPattern matchFunction)
    {
        List <Transform> children = new List <Transform>();

        foreach (Transform child in aParent)
        {
            if (matchFunction(aName, child.name))
            {
                children.Add(child);
            }
            List <Transform> result = child.FindDeepChildren(aName, matchFunction);
            children.AddRange(result);
        }
        return(children);
    }
Exemple #22
0
 public ExplodeElement(MatchType type, MatchPattern explosion, List <Vector2> positions)
 {
     this.type      = type;
     this.explosion = explosion;
     this.positions = positions;
 }
        /// <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);
        }