Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GenBindingTuple"/> class.
        /// </summary>
        /// <param name="_verbNormalizedUrl">The bind url with verb in form verb/url (i.e. GET/a/b/c/).</param>
        /// <param name="_engine">The methods engine.</param>
        internal MethodBindingTuple(string _verbNormalizedUrl ,EngineControllerDispatcher _engine)
        {
            PositiveBind = new MethodBinding(_verbNormalizedUrl, true, _engine);
            NegativeBind = new MethodBinding(_verbNormalizedUrl, false, _engine);
            Processed = false;

            engine = _engine;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodUrlsSubset"/> class. 
        /// Copies contents of the old bindings list and adds new to the new list GenBinding.
        /// </summary>
        /// <param name="_engine">The engine.</param>
        /// <param name="oldBindingsList">Old bindings list.</param>
        /// <param name="newBinding">The new binding.</param>
        private BistroMethod(EngineControllerDispatcher _engine, List<MethodBinding> oldBindingsList, MethodBinding newBinding)
        {
            engine = _engine;
            
            bindingsList = new List<MethodBinding>(oldBindingsList);
            bindingsList.Add(newBinding);


        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method is called for each binding and returns newly-constructed Bistro method, consisting of matching/not matching GenBindings.
        /// </summary>
        /// <param name="newBinding">new binding</param>
        /// <returns>newly-created method.</returns>
        internal BistroMethod ApplyBinding(MethodBinding newBinding)
        {

            if (newBinding.MatchWithSubset(this))
            {
                return new BistroMethod(engine, bindingsList, newBinding);
            }

            return null;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Compares two GenBindings with different match statuses for intersection
        /// </summary>
        /// <param name="matchBind">The match bind object.</param>
        /// <param name="noMatchBind">The no match bind object.</param>
        /// <returns>Result of the evaluation. true/false</returns>
        private static bool CompareMatchAndNoMatch(MethodBinding matchBind, MethodBinding 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]) && !(wildCardOnlyRegex.IsMatch(firstPartOfThis[i]) && (i< firstPart.Count) &&  paramsRegex.IsMatch(firstPart[i])))  || (firstPart[i] == firstPartOfThis[i]))
                    continue;

                firstItemMatchImpossible = true;
                break;
            }

            if (firstItemMatchImpossible)
                return true;

            var currentNoMatchPartEnum = noMatchBind.items.GetEnumerator();
            currentNoMatchPartEnum.MoveNext();
            var currentMatchPartEnum = matchBind.items.GetEnumerator();

            int positionInMatchPart = (currentNoMatchPartEnum.Current == null) ? 0 : currentNoMatchPartEnum.Current.Count;

            List<string> currentNoMatchPart = (currentNoMatchPartEnum.MoveNext()) ? currentNoMatchPartEnum.Current : null;
            List<string> currentMatchPart = (currentMatchPartEnum.MoveNext()) ? currentMatchPartEnum.Current : null;



            #endregion

            while ((currentNoMatchPart != null) && (currentMatchPart != null))
            {
                //try to place it.
                if (positionInMatchPart + currentNoMatchPart.Count <= currentMatchPart.Count)
                {
                    bool placed = true;
                    for (int i = 0; i < currentNoMatchPart.Count; i++)
                    {
                        if (wildCardRegex.IsMatch(currentNoMatchPart[i]) && !(wildCardOnlyRegex.IsMatch(currentNoMatchPart[i]) && ((i + positionInMatchPart)< currentMatchPart.Count) &&  paramsRegex.IsMatch(currentMatchPart[i+positionInMatchPart])))
                            continue;
                        if (currentNoMatchPart[i] == currentMatchPart[i + positionInMatchPart])
                            continue;

                        placed = false;
                        break;
                    }

                    if (placed)
                    {
                        positionInMatchPart = positionInMatchPart + currentNoMatchPart.Count;
                        currentNoMatchPartEnum.MoveNext();
                        currentNoMatchPart = currentNoMatchPartEnum.Current;
                    }
                    else
                        positionInMatchPart++;

                }
                else
                {
                    currentMatchPartEnum.MoveNext();
                    currentMatchPart = currentMatchPartEnum.Current;
                    positionInMatchPart = 0;
                }

            }

            if ((currentNoMatchPart == null) && (currentMatchPart != null))
            {
                // noMatch binding completely matches with one of the match bindings.
                return false;
            }


            return true;

        }
Ejemplo n.º 5
0
        /// <summary>
        /// Compares this Genbinding with another GenBinding for intersection. Both must have match status set to true 
        /// for this part of algorithm to work properly
        /// </summary>
        /// <param name="matchBind">Another GenBinding object.</param>
        /// <returns>Result of the evaluation. true/false</returns>
        private bool CompareWithMatch(MethodBinding 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;
        }
 /// <summary>
 /// This method should be used by SubSetsProcessor to retrieve Bind Points associated with GenBindings
 /// </summary>
 /// <param name="binding">binding to use for search</param>
 /// <returns>List of associated bind points found in the map</returns>
 internal List<IMethodsBindPointDesc> GetTypesByBinding(MethodBinding binding)
 {
     if (map.ContainsKey(binding.InitialUrl))
     {
         return map[binding.InitialUrl];
     }
     Logger.Report(Errors.BindingNotFound, binding.InitialUrl);
     throw new ApplicationException("Binding not found");
     
 }