Exemplo n.º 1
0
        /// <summary>
        /// Print the entity rule
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        private TreeViewItem PrintEntityRule(EntityRule item)
        {
            TreeViewItem entityRuleItem = new TreeViewItem();

            entityRuleItem.Header = "EntityRule- " + item.entityName;
            if (item.cardinality != "")
            {
                entityRuleItem.Items.Add("Cardinality: " + item.cardinality);
            }

            List <AttributeRule> allAttributeRules = item.getAttributeRules();

            if (allAttributeRules.Any())
            {
                TreeViewItem AttributesItems = new TreeViewItem();
                AttributesItems.Header = "AttributesRules";

                foreach (var item1 in allAttributeRules)
                {
                    TreeViewItem treeViewItem1 = new TreeViewItem();
                    treeViewItem1 = PrintAttribute(item1);
                    AttributesItems.Items.Add(treeViewItem1);
                }
                entityRuleItem.Items.Add(AttributesItems);
            }
            return(entityRuleItem);
        }
Exemplo n.º 2
0
        private static object GenerateForEmbeddedRule(EntityRule rule, IActionConfiguration actionConfiguration,
                                                      Dictionary <string, List <string> > routeRelations, object originalObject)
        {
            var actionExecutedContext     = ActionCallContext.Get <HttpActionExecutedContext>();
            var entityActionConfiguration = HypermediaControllerConfiguration.Instance.GetcontrollerActionConfiguration(rule.ControllerType, rule.ControllerAction, actionExecutedContext.Request.Headers.Accept);

            if (entityActionConfiguration == null)
            {
                return(null);
            }

            var referencedObject = rule.GetReferencedObjectInstance(originalObject);

            if (referencedObject == null)
            {
                return(null);
            }

            var transformed = ActionResponseTransformer.TransformPayload(entityActionConfiguration, referencedObject);

            if (transformed == null)
            {
                return(null);
            }

            if (transformed is IEnumerable)
            {
                throw new Exception(string.Format("Unable to generate enumerable entity object from controller {0} action {1}. Consider using outer object.", actionConfiguration.ControllerType.FullName, actionConfiguration.ActionMethodInfo));
            }

            AssignRelName(transformed, rule.Rel);

            return(transformed);
        }
        private void FindAttributeRules(EntityRule EnRule)
        {
            //Console.WriteLine("EntityName: {0}, AttributeRules count: {1}", EnRule.entityName, EnRule.getAttributeRules().Count);
            List <AttributeRule> listAttRules = EnRule.getAttributeRules();

            foreach (AttributeRule at in listAttRules)
            {
                FindEntityRules(at);
            }
        }
Exemplo n.º 4
0
        private static object GenerateForRule(EntityRule rule, IActionConfiguration actionConfiguration,
                                              Dictionary <string, List <string> > routeRelations, object originalObject)
        {
            if (rule.EntityEmbeddingRule == EntityRule.EmbeddingRule.Embedded)
            {
                return(GenerateForEmbeddedRule(rule, actionConfiguration, routeRelations, originalObject));
            }

            return(GenerateForLinkedRule(rule, actionConfiguration, routeRelations, originalObject));
        }
Exemplo n.º 5
0
        private static object GenerateForLinkedRule(EntityRule rule,
                                                    IActionConfiguration actionConfiguration,
                                                    Dictionary <string, List <string> > routeRelations, object originalObject)
        {
            var actionExecutedContext     = ActionCallContext.Get <HttpActionExecutedContext>();
            var entityActionConfiguration = HypermediaControllerConfiguration.Instance.GetcontrollerActionConfiguration(rule.ControllerType, rule.ControllerAction, actionExecutedContext.Request.Headers.Accept);

            if (entityActionConfiguration == null)
            {
                return(null);
            }

            var referencedObject = rule.GetReferencedObjectInstance(originalObject);

            if (referencedObject == null)
            {
                return(null);
            }
            var selfRule = entityActionConfiguration.MappingRules.FirstOrDefault(r => r.Names.Contains("self"));

            if (selfRule == null)
            {
                throw new Exception(string.Format("Unable to generate link to entity object from controller {0} action {1}. Can't find self rel.", actionConfiguration.ControllerType.FullName, actionConfiguration.ActionMethodInfo));
            }

            var selfApi = selfRule.ApiDescriptions.OrderBy(d => d.RelativePath.Length).FirstOrDefault();

            if (selfApi == null)
            {
                throw new Exception(string.Format("Unable to generate link to entity object from controller {0} action {1}. Can't find self API.", actionConfiguration.ControllerType.FullName, actionConfiguration.ActionMethodInfo));
            }

            var routeNameSubstitution = new DefaultRouteValueSubstitution();

            var absolutePath =
                LinkHelper.MakeAbsolutePath(routeNameSubstitution.Substitute(selfApi.RelativePath, selfRule,
                                                                             referencedObject));

            return(new LinkedEntity()
            {
                Rels = rule.Rel,
                ClassName = entityActionConfiguration.Class,
                Href = absolutePath
            });
        }
Exemplo n.º 6
0
        private static Templates DisplayTemplates(XmlNode node, ConceptTemplate conceptTemplate, Templates templates, bool subTemplates, bool rules, AttributeRule attributeRule, EntityRule entityRule)
        {
            //Print the node type, node name and node value of the node
            if (node.Name == "ConceptTemplate")
            {
                conceptTemplate = new ConceptTemplate();
                if (node.Attributes != null)
                {
                    XmlAttributeCollection attrs = node.Attributes;
                    foreach (XmlAttribute attr in attrs)
                    {
                        switch (attr.Name)
                        {
                        case "uuid":
                            conceptTemplate.setUUID(attr.Value);
                            break;

                        case "name":
                            conceptTemplate.name = attr.Value;
                            break;

                        case "code":
                            conceptTemplate.code = attr.Value;
                            break;

                        case "status":
                            break;

                        case "applicableSchema":
                            conceptTemplate.applicableSchema = attr.Value;
                            break;

                        case "applicableEntity":
                            conceptTemplate.applicableEntity = attr.Value;
                            break;
                        }
                    }
                }
                templates.addConceptTemplate(conceptTemplate.getUUID(), conceptTemplate);
            }
            else if (node.Name == "Definition")
            {
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    Definition definition = new Definition();
                    definition.setBody(childNode.InnerText);
                    conceptTemplate.addDefinition(definition);
                }
            }
            else if (node.Name == "SubTemplates")
            {
                templates = new Templates();
                conceptTemplate.addTemplates(templates);
            }
            else if (node.Name == "Rules")
            {
                rules = true;
            }

            else if (node.Name == "AttributeRule")
            {
                attributeRule = new AttributeRule();

                if (node.Attributes != null)
                {
                    XmlAttributeCollection attrs = node.Attributes;
                    foreach (XmlAttribute attr in attrs)
                    {
                        if (attr.Name == "AttributeName")
                        {
                            attributeRule.attributeName = attr.Value;
                        }
                        else if (attr.Name == "Cardinality")
                        {
                            attributeRule.cardinality = attr.Value;
                        }
                    }
                }
                if (rules == true)
                {
                    conceptTemplate.addAttributeRule(attributeRule);
                }
                else
                {
                    entityRule.addAttributeRule(attributeRule);
                }
            }
            else if (node.Name == "EntityRule")
            {
                rules      = false;
                entityRule = new EntityRule();
                string attributeName = attributeRule.attributeName;
                if (!String.IsNullOrEmpty(attributeName))
                {
                    if (node.Attributes != null)
                    {
                        XmlAttributeCollection attrs = node.Attributes;
                        foreach (XmlAttribute attr in attrs)
                        {
                            if (attr.Name == "EntityName")
                            {
                                entityRule.entityName = attr.Value;
                            }
                            else if (attr.Name == "Cardinality")
                            {
                                entityRule.cardinality = attr.Value;
                            }
                        }
                    }
                    attributeRule.addEntityRule(entityRule);
                }
            }
            else
            {
                Console.WriteLine("Type = [" + node.NodeType + "] Name = " + node.Name);
            }

            //Print attributes of the node
            if (node.Attributes != null)
            {
                XmlAttributeCollection attrs = node.Attributes;
                foreach (XmlAttribute attr in attrs)
                {
                    Console.WriteLine("Attribute Name = " + attr.Name + "; Attribute Value = " + attr.Value);
                }
            }

            //Print individual children of the node, gets only direct children of the node
            XmlNodeList children = node.ChildNodes;

            foreach (XmlNode child in children)
            {
                DisplayTemplates(child, conceptTemplate, templates, subTemplates, rules, attributeRule, entityRule);
            }
            return(templates);
        }