public SimpleDocType()
            {
                var root = new TypedEntityVertex().SetupRoot();

                this.SetupTypeDefinition("SimpleDocType", "Simple DocType", root);

                // Create a new tab group
                var textGroup = EntityFactory.Create <AttributeGroupDefinition>("textdata", "Text Data");

                this.AttributeSchema.AttributeGroupDefinitions.Add(textGroup);

                // Create a data type
                var textInputField = EntityFactory.Create <AttributeTypeDefinition>("textInputField", "Text Input Field");

                // Create a serialization type for persisting this to the repository
                var stringSerializer = EntityFactory.Create <StringSerializationType>("string", "String");

                stringSerializer.DataSerializationType = DataSerializationTypes.String;

                // Create a new property with that data type in our tab group
                var bodyText = EntityFactory.CreateAttributeIn <AttributeDefinition>("bodyText", "Body Text", textInputField,
                                                                                     stringSerializer, textGroup);

                // Specify that tis type is allowed under itself
                this.GraphSchema.PermittedDescendentTypes.Add(this);
            }
Пример #2
0
        public ArticleDocType()
        {
            // Mock-up a fake root
            var root = new TypedEntityVertex().SetupRoot();

            // Define a name and an alias for the doctype
            // Setup<TAllowedType> is an extension method declared on EntityFactory)
            this.SetupTypeDefinition("article", "Article", root);

            // Create a new tab group
            var textGroup = EntityFactory.Create <AttributeGroupDefinition>("textdata", "Text Data");

            base.AttributeSchema.AttributeGroupDefinitions.Add(textGroup);

            // Create a data type
            var textInputField = EntityFactory.Create <AttributeTypeDefinition>("textInputField", "Text Input Field");

            // Create a serialization type for persisting this to the repository
            var stringSerializer = EntityFactory.Create <StringSerializationType>("string", "String");

            stringSerializer.DataSerializationType = DataSerializationTypes.String;

            // Create a new property with that data type in our tab group
            var bodyText = EntityFactory.CreateAttributeIn <AttributeDefinition>("bodyText", "Body Text", textInputField,
                                                                                 stringSerializer, textGroup);

            // Specify that an Article can be a child of an Article
            base.GraphSchema.PermittedDescendentTypes.Add(this);
        }
        public IEntityGraph <IEntityTypeDefinition> GetAll()
        {
            var elements = PackageXml.Element("umbPackage").Element("DocumentTypes").Elements("DocumentType");

            var returnVal = new EntityGraph <IEntityTypeDefinition>();

            foreach (var xElement in elements)
            {
                var xml = xElement;
                var id  = new StringIdentifier((string)xml.Element("Info").Element("Alias"), this.GetType().FullName);
                returnVal.Add(id, new Lazy <IEntityTypeDefinition>(() =>
                {
                    var info = xml.Element("Info");
                    var entityTypeDefinition = new DocType();
                    var root = new TypedEntityVertex().SetupRoot();
                    entityTypeDefinition.SetupTypeDefinition((string)info.Element("Alias"), (string)info.Element("Name"), root);
                    entityTypeDefinition.Id = id;

                    //find all the tabs so we can get the ID's off them
                    var tabs = xml.Element("Tabs").Elements("Tab");
                    foreach (var tab in tabs)
                    {
                        //get the repo to create the ID
                        var groupId = attributeGroupRepository.ResolveIdentifier((string)tab.Element("Caption"));
                        //resolve the group from the repo based on the ID schema
                        var group = attributeGroupRepository.Get(groupId);

                        //add the group to the attribute schema
                        entityTypeDefinition.AttributeSchema.AttributeGroupDefinitions.Add(group);
                    }

                    var properties = xml.Element("GenericProperties").Elements("GenericProperty");
                    foreach (var property in properties)
                    {
                        //TODO: Make this lazy, currently we're resolving all the attributes (and all its sub-graph) immediately...

                        //get the ID of the property using the repo to generate it
                        var attributeId = attributeRepository.ResolveIdentifier(entityTypeDefinition.Alias + "/" + (string)property.Element("Alias"));
                        //resolve the attribute
                        var attribute = attributeRepository.Get(attributeId);
                        //find the group that this attribute is associated with
                        var groupId = attributeGroupRepository.ResolveIdentifier((string)property.Element("Tab"));
                        var group   = attributeGroupRepository.Get(groupId);
                        //add this attribute to the group

                        group.AttributeDefinitions.Add(attribute);
                    }

                    return(entityTypeDefinition);
                }));
            }

            return(returnVal);
        }