/// <summary> /// This method is called for each binding and returns newly-constructed SubSet, consists of matching groups /// </summary> /// <param name="newBinding"></param> /// <returns></returns> internal MethodUrlsSubset ApplyBinding(GenBinding newBinding) { if (!newBinding.MatchWithSubset(this)) { return null; } return new MethodUrlsSubset(bindingsList, newBinding); }
internal MatchResult Match(MethodUrlsSubset group, GenBinding newBinding) { #region MatchPart #endregion #region NoMatchPart #endregion return MatchResult.BothOptions; }
private static bool CompareMatchAndNoMatch(GenBinding matchBind, GenBinding noMatchBind) { if (!matchBind.MatchStatus && noMatchBind.MatchStatus) throw new ApplicationException("improper usage of CompareMatchAndNoMatch"); List<string> firstPart = matchBind.items.Count == 0 ? new List<string>() : new List<string>(matchBind.items[0]); List<string> firstPartOfThis = noMatchBind.items.Count == 0 ? new List<string>() : new List<string>(noMatchBind.items[0]); #region Get the start point firstPartOfThis - B; firstPart - A if (firstPartOfThis.Count > firstPart.Count) return true; bool firstItemMatchImpossible = false; for (int i = 0; i < firstPartOfThis.Count; i++) { if ((wildCardRegex.IsMatch(firstPartOfThis[i])) || (firstPart[i] == firstPartOfThis[i])) continue; firstItemMatchImpossible = true; break; } if (firstItemMatchImpossible) return true; var currentPartEnum = noMatchBind.items.GetEnumerator(); currentPartEnum.MoveNext(); var currentMatchPartEnum = matchBind.items.GetEnumerator(); int positionInMatchPart = (currentPartEnum.Current == null) ? 0 : currentPartEnum.Current.Count; List<string> currentPart = (currentPartEnum.MoveNext()) ? currentPartEnum.Current : null; List<string> currentMatchPart = (currentMatchPartEnum.MoveNext()) ? currentMatchPartEnum.Current : null; #endregion while ((currentPart != null) && (currentMatchPart != null)) { //try to place it. if (positionInMatchPart + currentPart.Count <= currentMatchPart.Count) { bool placed = true; for (int i = 0; i < currentPart.Count; i++) { if (wildCardRegex.IsMatch(currentPart[i])) continue; if (currentPart[i] == currentMatchPart[i + positionInMatchPart]) continue; placed = false; break; } if (placed) { positionInMatchPart = positionInMatchPart + currentPart.Count; currentPartEnum.MoveNext(); currentPart = currentPartEnum.Current; } else positionInMatchPart++; } else { currentMatchPartEnum.MoveNext(); currentMatchPart = currentMatchPartEnum.Current; positionInMatchPart = 0; } } if ((currentPart == null) && (currentMatchPart != null)) { // noMatch binding completely matches with one of the match bindings. return false; } return true; }
private bool CompareWithMatch(GenBinding matchBind) { if (!matchBind.MatchStatus || !this.MatchStatus) throw new ApplicationException("improper usage of CompareWithMatch"); List<string> firstPartOfThis = this.items.Count == 0 ? new List<string>() : new List<string>(this.items[0]); List<string> firstPart = matchBind.items.Count == 0 ? new List<string>() : new List<string>(matchBind.items[0]); #region Check for different beginning int smallestSize = firstPartOfThis.Count < firstPart.Count ? firstPartOfThis.Count : firstPart.Count; for (int i = 0; i < smallestSize; i++) { if ((wildCardRegex.IsMatch(firstPart[i])) || (wildCardRegex.IsMatch(firstPartOfThis[i])) || (firstPartOfThis[i] == firstPart[i])) continue; return false; } #endregion return true; }
private MethodUrlsSubset(List<GenBinding> oldBindingsList, GenBinding newBinding) { bindingsList = new List<GenBinding>(oldBindingsList); bindingsList.Add(newBinding); }