private void Adopt(Binding binding, string bindingUrl)
 {
     binding.parent.bindings.Remove(binding);
     binding.parent = this;
     bindings.Add(binding);
     binding.bindingUrl = bindingUrl;
 }
 private void CreateControllersTreeFromBinding(ExplorerNode parent, Binding binding)
 {
     foreach (Bistro.Methods.Controller item in binding.Controllers)
     {
         new ControllerNode(parent, item.Type, ControllerNode.ControllerNodeType.None);
     }
 }
 private Binding(Binding parent, string verb, string bindingUrl)
 {
     this.parent = parent;
     engine = parent.engine;
     this.verb = verb;
     this.bindingUrl = bindingUrl;
     fullBindingUrl = parent.fullBindingUrl + bindingUrl;
     parent.bindings.Add(this);
 }
        internal void Validate(string parentUrl, Binding binding)
        {
            string fullUrl = parentUrl + bindingUrl;
            binding.Bindings.ForEach(child =>
                {
                    BindingTest test = null;
                    string lookup = (child.BindingUrl == child.FullBindingUrl) ? (child.Verb + " " + child.BindingUrl) : child.BindingUrl;

                    test.Validate(fullUrl, child);
                });
            
            SortedList<int, Controller> controllers = new SortedList<int,Controller>();
            binding.Controllers.ForEach(controller => controllers.Add(controller.SeqNumber, controller));

            for (int i = 0; i < this.controllers.Length && i < binding.Controllers.Count; i++)
                this.controllers[i].Validate(fullUrl, controllers.Values[binding.Controllers.Count - i - 1]);
        }
        private void CreateMethodsTreeFromBinding(ExplorerNode parent, Binding binding)
        {
            foreach (Bistro.Methods.Binding item in binding.Bindings)
            {
                BindingNode newParent = new BindingNode(parent, item.Verb, item.BindingUrl);
                if (item.Bindings.Count > 0)
                {
                    CreateMethodsTreeFromBinding(new BindingNode(parent, item.Verb, item.BindingUrl), item);

                }
                
                if (item.Controllers.Count > 0)
                {
                    CreateControllersTreeFromBinding(newParent, item);
                }

            }
        }
        public void Validate(string parentUrl, Binding binding)
        {
            string fullUrl = parentUrl + bindingUrl;
            binding.Bindings.ForEach(child =>
                {
                    BindingTest test;
                    string lookup = (child.BindingUrl == child.FullBindingUrl) ? (child.Verb + " " + child.BindingUrl) : child.BindingUrl;

                    Assert.IsTrue(children.TryGetValue(lookup, out test), "Binding " + fullUrl + " Unexpected binding " + child.BindingUrl);
                    test.Validate(fullUrl, child);
                });
            Assert.AreEqual(children.Count, binding.Bindings.Count, "Binding " + fullUrl + ": Invalid number of child bindings");
            
            SortedList<int, Controller> controllers = new SortedList<int,Controller>();
            binding.Controllers.ForEach(controller => controllers.Add(controller.SeqNumber, controller));

            for (int i = 0; i < this.controllers.Length && i < binding.Controllers.Count; i++)
                this.controllers[i].Validate(fullUrl, controllers.Values[binding.Controllers.Count - i - 1]);
            Assert.AreEqual(this.controllers.Length, binding.Controllers.Count, "Binding " + fullUrl + ": Invalid number of controllers");
        }
 private void CreateControllersTreeFromBinding(ExplorerNode parent, Binding binding)
 {
     foreach (Bistro.Methods.Controller item in binding.Controllers)
     {
         ControllerNode parent1 = new ControllerNode(parent, item.Type, ControllerNode.ControllerNodeType.None);
         
         if (parent1.Name.CompareTo("DataAccessControl")== 0){
             new ResourceNode(parent1, "Resource1", ControllerNode.ControllerNodeType.Consumer);
             new ResourceNode(parent1, "Resource2", ControllerNode.ControllerNodeType.Provider);
         }
         if (parent1.Name.CompareTo("AdDisplay") == 0)
         {
             new ResourceNode(parent1, "Resource3", ControllerNode.ControllerNodeType.Consumer);
             new ResourceNode(parent1, "Resource1", ControllerNode.ControllerNodeType.Provider);
         }
         if (parent1.Name.CompareTo("AdUpdate") == 0)
         {
             new ResourceNode(parent1, "Resource5", ControllerNode.ControllerNodeType.Consumer);
             new ResourceNode(parent1, "Resource1", ControllerNode.ControllerNodeType.Provider);
         }
     }
 }
 public BistroNode(ExplorerNode root, Binding binding)
     : base(root, BISTRO_NODE_NAME, BINDERS_ICON, OPEN_FOLDER_ICON)
 {
     methods = new MethodsNode(this);
     CreateMethodsTreeFromBinding(methods, binding);
 }
 public Controller(Binding binding, Controller source)
 {
     type = source.type;
     this.binding = binding;
 }
 public Controller(Binding binding, ControllerType type, string methodUrl)
 {
     this.type = type;
     this.binding = binding;
 }
 internal void Validate(Binding binding)
 {
     Validate("", binding);
 }
 public void Add(Binding binding) { dictionary.Add(buildKey(binding), binding); }
 public void Validate(Binding root)
 {
     //TODO: Check whether right controllers are returned.
 }
        //internal void Register(Controller controller)
        //{
        //    controllers.Add(controller);
        //    controller.Type.Register(controller);
        //    foreach (string resourceName in controller.Type.Provides)
        //        lookupResource(resourceName).AddProvider(controller.Type);
        //    foreach (string resourceName in controller.Type.Requires)
        //        lookupResource(resourceName).AddRequiredBy(controller.Type);
        //    foreach (string resourceName in controller.Type.DependsOn)
        //        lookupResource(resourceName).AddDependents(controller.Type);
        //}

        internal void Register(Binding binding,ControllerType ctrType, string methodUrl)
        {
            foreach (Controller ctr in controllers)
            {
                if (ctr.Type == ctrType)
                    return;
            }
            Controller controller = new Controller(binding, ctrType, methodUrl);
            controllers.Add(controller);
            ctrType.Register(controller);
            foreach (string resourceName in controller.Type.Provides)
                lookupResource(resourceName).AddProvider(controller.Type);
            foreach (string resourceName in controller.Type.Requires)
                lookupResource(resourceName).AddRequiredBy(controller.Type);
            foreach (string resourceName in controller.Type.DependsOn)
                lookupResource(resourceName).AddDependents(controller.Type);
        }
        /// <summary>
        /// Matches method to binding
        /// </summary>
        /// <param name="binding"></param>
        /// <returns></returns>
        /// <remarks>method binding is always treated literally, while binding binding is
        /// checked for wildcards</remarks>
        private static bool Match(Binding method, Binding binding)
        {
            string verb = method.verb;
            string methodUrl = method.fullBindingUrl;
            string bindingVerb = binding.verb;
            string bindingUrl = binding.fullBindingUrl;

            if (verb != bindingVerb && bindingVerb != "*")
                return false;

            string[] MethodTokens = methodUrl.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            string[] BindingTokens = bindingUrl.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            int i, j;
            for (i = 0, j = 0; i < BindingTokens.Length && j < MethodTokens.Length; i++, j++)
            {
                if (BindingTokens[i] == MethodTokens[j])
                    continue; // so far so good - keep going
                if (BindingTokens[i] == "*")
                {
                    if (MethodTokens[j] == "?")
                        return false; // cannot match /aaa/* to /aaa/?, because /aaa/? is wider.
                    else
                        continue; // it is a local wild card - anything goes
                }
                if (BindingTokens[i].StartsWith("{"))
                    continue; // this is a url parameter, which is for the purpose of matching as good as a local wild card
                // note, that it is sufficient to check just the first character. The presence of the last one
                // is ensured by the regular expression in binding parser  
                if (BindingTokens[i] == "?")
                {
                    // it is a global wild card  - we need to find a matching tail
                    if (++i >= BindingTokens.Length)
                        return true;  // there is no tail to match - we can report a match
                    bool found = false;
                    for (; j < MethodTokens.Length; j++)
                        if (BindingTokens[i] == MethodTokens[j])
                        {
                            found = true;
                            break;
                        }
                    if (found)
                        continue;
                }
                return false; // no match
            }

            if (i < BindingTokens.Length) // items left in the binding
                for (; i < BindingTokens.Length; i++) // if all of them are wild cards this is a match
                    if (BindingTokens[i] != "*" && BindingTokens[i] != "?" && !BindingTokens[i].StartsWith("{"))
                        return false;

            // There is an implicit /? in the end of every binding
            //if (j < MethodTokens.Length) // items left in the method url - no match
            //    return false;

            return true;
        }
        /// <summary>
        /// Matches the new binding to all methods
        /// </summary>
        /// <param name="binding"></param>
        /// <returns>a list of all <see cref="BindingNode"/> matching the url </returns>
        private IEnumerable<Binding> MatchMethodsToBinding(Binding binding)
        {
            List<Binding> result = new List<Binding>();
            foreach (Binding child in bindings)
            {
                result.AddRange(child.MatchMethodsToBinding(binding));

                if (child.isMethod && Match(child, binding))
                    result.Add(child);
            }
            return result;
        }
 /// <summary>
 /// Matches the new node to all existing methods. If a match found clone
 /// controllers from the matching method to the new method
 /// </summary>
 /// <param name="methodNode"></param>
 /// <remarks>
 /// this method is called for every method node when the node is created. <br/>
 /// It recursively traverses the node tree looking if any existing method node
 /// matches the new method node. It can only happen if the existing node
 /// has a wild card url, otherwise our method node would already have been created
 /// </remarks>
 private void MatchBindingsToMethod(Binding methodNode)
 {
     foreach (Binding child in bindings)
     {
         child.MatchBindingsToMethod(methodNode);
         // this is our node - we do not need to do it again
         if (child == methodNode)
             continue;
         // this is not a method - skip it
         if (!child.isMethod)
             continue;
         if (Match(methodNode, child))
             // it is a match - all controllers from this method
             // have to be cloned to our new method
             foreach (Controller controller in child.controllers)
                 //                        methodNode.Register(new Controller(methodNode, controller));
                 methodNode.Register(methodNode, controller.Type, null);
     }
 }
        private void RegisterBindings(Binding newBinding, Binding oldBinding)
        {
            foreach (KeyValuePair<string, Binding> binding in new List<KeyValuePair<string, Binding>>(partialUrls))
                if (binding.Value == oldBinding)
                    partialUrls.Remove(binding.Key);
            if (newBinding == null)
                return;

            string bindingUrl = newBinding.bindingUrl;
            while (true)
            {
                partialUrls.Add(newBinding.verb + ',' + bindingUrl, newBinding);
                if (bindingUrl.LastIndexOf('/') < 1)
                    break;
                bindingUrl = bindingUrl.Substring(0, bindingUrl.LastIndexOf('/'));
            }
        }
 public void Validate(Binding binding)
 {
     Validate("", binding);
 }
Beispiel #20
0
 public Engine()
 {
     root = new Binding(this);
 }
 internal Resource(Engine engine, Binding binding, string name)
 {
     this.name = name;
     this.engine = engine;
     this.binding = binding;
 }
 private void Adopt(Binding node, string newName)
 {
    
 }
 private string buildKey(Binding binding) {return binding.Verb + ';' + binding.BindingUrl;}
Beispiel #24
0
 private string GetTreeRecursive(string spacer, Binding leaf)
 {
     string result = String.Format("{1}{2} {0} \r\n",leaf.BindingUrl,spacer,leaf.Verb);
     foreach (Controller ctrlr in leaf.Controllers)
     {
         result += String.Format("{1}    Controller: {0} \r\n", ctrlr.Type.Name,spacer);
     }
     foreach (Binding bnd in leaf.Bindings)
     {
         result += GetTreeRecursive(spacer + "   ",bnd);
     }
     return result;
 }
 public void Remove(Binding binding) { dictionary.Remove(buildKey(binding)); }
Beispiel #26
0
        private string GetTreeResultText(string spacer, Binding leaf)
        {
            string result = String.Format("{1}Node(\"{2}{0}\",Controllers( \r\n", leaf.BindingUrl, spacer, spacer == "   " ?  leaf.Verb+" ":"");
            bool first = false;
            foreach (Controller ctrlr in (leaf.Controllers.OrderByDescending(ctrlr => ctrlr.SeqNumber)))
            {
                result += String.Format("{1}    {2}\"{0}\" \r\n", ctrlr.Type.Name, spacer, (first ? "," : ""));
                first = true;
            }

            result += String.Format("{0}){1}\r\n", spacer,(leaf.Bindings.Count>0? ",":"" ));
            bool first1 = false;
            foreach (Binding bnd in leaf.Bindings)
            {
                result += (first1 ? String.Format("{0},\r\n",spacer) : "") + GetTreeResultText(spacer + "   ", bnd);
                first1 = true;
            }
            result += String.Format("{0})\r\n", spacer);


            return result;
        }