Пример #1
0
        public override IDesignModel GenerateDesignModel(IXmlElement xmlElement, DesignModelParseContext context)
        {
            var projectConfiguration = new ProjectConfiguration(
                CoreConstants.DesignModelType_ProjectConfiguration,
                context.Namespace,
                xmlElement,
                _projectCollection
                );
            var configFileDir   = Path.GetFullPath(Path.GetDirectoryName(xmlElement.ParseLocation.File.GetSourcePath()));
            var solutionElement = xmlElement.FindChildElement("Solution");
            var solutionPath    = solutionElement.GetAttribute("path").Value;

            solutionPath = Path.GetFullPath(Path.Combine(configFileDir, solutionPath));

            foreach (var projectElement in solutionElement.Children.Where(x => x.Definition.Name.LocalName == "Project"))
            {
                var project = new Project(
                    projectElement.GetAttribute("name").Value,
                    projectElement.GetAttribute("type").Value,
                    Path.Combine(solutionPath, projectElement.GetAttribute("path").Value)
                    );

                project.SetDesignModelsFolder("DesignModels,Plugins/*/DesignModels");

                projectConfiguration.Projects.AddProject(project);
            }

            return(projectConfiguration);
        }
Пример #2
0
        private void ParseDesignModelElements(DesignModelParseContext context)
        {
            var designModelConverter = this._designModelConverterFactory.GetGenerator(context.XmlElement.Definition);
            var designModel          = designModelConverter?.GenerateDesignModel(context.XmlElement, context);

            if (designModel != null)
            {
                context.XmlElement.DesignModel = designModel;
                context.DesignModel            = designModel;
                context.Namespace.AddDesignModel(designModel);
                context.Collection.AddDesignModel(designModel);

                foreach (var attribute in context.XmlElement.Attributes)
                {
                    ParseProperty(designModel, attribute);
                }
            }

            foreach (var childElement in context.XmlElement.Children)
            {
                var childContext = new DesignModelParseContext(context)
                {
                    XmlElement = childElement
                };

                this.ParseDesignModelElements(childContext);
            }
        }
Пример #3
0
        public override IDesignModel GenerateDesignModel(IXmlElement xmlElement, DesignModelParseContext context)
        {
            var sourceDesignModelName  = xmlElement.GetStringAttributeValue("src");
            var destinationDesingModel = context.DesignModel;

            if (!(destinationDesingModel is IClassModel destinationClassDesignModel))
            {
                throw new ParseException(xmlElement.ParseLocation, $"Mapping destination model '{destinationDesingModel.FullyQualifiedName}' must be a class-like design model.");
            }

            var ns        = destinationDesingModel.Namespace;
            var classData = new ClassDerivation
            {
                Source        = _designModelCollection.CreateClassModelReference(ns, xmlElement.ParseLocation, sourceDesignModelName),
                Destination   = destinationClassDesignModel.CreateClassModelReference(xmlElement.ParseLocation),
                ParseLocation = xmlElement.ParseLocation
            };

            foreach (var attributeElement in xmlElement.GetChildElments("Attribute"))
            {
                var attributeData = new AttributeDerivation
                {
                    Source        = new ClassAttributeReference(attributeElement.GetStringAttributeValue("src"), attributeElement.ParseLocation),
                    Destination   = new ClassAttributeReference(attributeElement.GetStringAttributeValue("dest"), attributeElement.ParseLocation),
                    ParseLocation = attributeElement.ParseLocation
                };

                classData.AttributeDerivations.Add(attributeData);
            }

            foreach (var relationElement in xmlElement.GetChildElments("Relation"))
            {
                var relationData = new RelationDerivation
                {
                    Source        = new ClassRelationReference(relationElement.GetStringAttributeValue("src"), relationElement.ParseLocation),
                    Destination   = new ClassRelationReference(relationElement.GetStringAttributeValue("dest"), relationElement.ParseLocation),
                    MapAttributes = relationElement.GetBoolAttributeValue("attributes", true),
                    ParseLocation = relationElement.ParseLocation
                };

                foreach (var attributeElement in relationElement.GetChildElments("Attribute"))
                {
                    var relationAttributeData = new AttributeDerivation
                    {
                        Source        = new ClassAttributeReference(attributeElement.GetStringAttributeValue("src"), attributeElement.ParseLocation),
                        Destination   = new ClassAttributeReference(attributeElement.GetStringAttributeValue("dest"), attributeElement.ParseLocation),
                        ParseLocation = attributeElement.ParseLocation
                    };

                    relationData.AttributeDerivations.Add(relationAttributeData);
                }

                classData.RelationDerivations.Add(relationData);
            }

            destinationClassDesignModel.SetClassDerivationData(classData);

            return(null);
        }
Пример #4
0
        public void Parse(IXmlElement rootElement, IDesignModelCollection collection)
        {
            var context = new DesignModelParseContext(collection)
            {
                Namespace  = collection.RootNamespace,
                XmlElement = rootElement
            };

            this.ParseDesignModelElements(context);
        }
Пример #5
0
        public override IDesignModel GenerateDesignModel(IXmlElement xmlElement, DesignModelParseContext context)
        {
            var entity    = (Entity)context.DesignModel;
            var name      = xmlElement.GetStringAttributeValue("name");
            var type      = _dataTypeRegistry.Get(xmlElement.GetStringAttributeValue("type"));
            var attribute = new EntityAttribute(name, type, xmlElement, xmlElement.ParseLocation);

            entity.AddAttribute(attribute);

            // Don't register this design model globally.
            return(null);
        }
Пример #6
0
        public override IDesignModel GenerateDesignModel(IXmlElement xmlElement, DesignModelParseContext context)
        {
            var namespaceName = xmlElement.GetAttribute("name")?.Value;

            if (string.IsNullOrWhiteSpace(namespaceName))
            {
                throw new DesignModelException(context.DesignModel, "Namespace name not set");
            }

            var ns = context.Collection.DefineNamespace(namespaceName);

            context.Namespace = ns;

            return(null);
        }
Пример #7
0
        public override IDesignModel GenerateDesignModel(IXmlElement xmlElement, DesignModelParseContext context)
        {
            var sourceEntity = (Entity)context.DesignModel;
            var name         = xmlElement.GetStringAttributeValue("name");
            var relation     = new EntityRelation(name, xmlElement, xmlElement.ParseLocation)
            {
                Source = sourceEntity,
                DestinationReference = new ClassModelReference(xmlElement.GetStringAttributeValue("destination"),
                                                               sourceEntity.Namespace, sourceEntity.Type, xmlElement.ParseLocation)
            };

            sourceEntity.AddOutgoingRelation(relation);

            // Don't register this design model globally.
            return(null);
        }
 public IDesignModel GenerateDesignModel(IXmlElement xmlElement, DesignModelParseContext context)
 {
     return(_fn(xmlElement, context));
 }
Пример #9
0
        public override IDesignModel GenerateDesignModel(IXmlElement xmlElement, DesignModelParseContext context)
        {
            var sourceDesignModelName         = xmlElement.GetStringAttributeValue("src");
            var sourceDesignModelNameSet      = !string.IsNullOrWhiteSpace(sourceDesignModelName);
            var destinationDesignModelName    = xmlElement.GetStringAttributeValue("dest");
            var destinationDesignModelNameSet = !string.IsNullOrWhiteSpace(destinationDesignModelName);

            if (sourceDesignModelNameSet && destinationDesignModelNameSet)
            {
                throw new ParseException(xmlElement.ParseLocation, $"Both 'src' and 'dest' attributes cannot be set.");
            }

            if (!sourceDesignModelNameSet && !destinationDesignModelNameSet)
            {
                throw new ParseException(xmlElement.ParseLocation, $"Either 'src' or 'dest' attribute must be set.");
            }

            var currentDesignModel = context.DesignModel;

            if (!(currentDesignModel is IClassModel currentClassModel))
            {
                throw new ParseException(xmlElement.ParseLocation, $"Mapping model '{currentDesignModel.FullyQualifiedName}' must be a class-like design model.");
            }

            var ns = currentDesignModel.Namespace;
            var sourceReference = sourceDesignModelNameSet
                ? _designModelCollection.CreateClassModelReference(ns, xmlElement.ParseLocation, sourceDesignModelName)
                : currentClassModel.CreateClassModelReference(xmlElement.ParseLocation);
            var destinationReference = destinationDesignModelNameSet
                ? _designModelCollection.CreateClassModelReference(ns, xmlElement.ParseLocation, destinationDesignModelName)
                : currentClassModel.CreateClassModelReference(xmlElement.ParseLocation);

            var classMapping = new ClassMapping
            {
                Name          = xmlElement.GetStringAttributeValue("name", null),
                Source        = sourceReference,
                Destination   = destinationReference,
                MapAttributes = xmlElement.GetBoolAttributeValue("attributes", true),
                MapRelations  = xmlElement.GetBoolAttributeValue("relations", true),
                AddMissing    = xmlElement.GetBoolAttributeValue("add-missing", true),
                TwoWay        = xmlElement.GetBoolAttributeValue("two-way", true),
                ParseLocation = xmlElement.ParseLocation
            };

            foreach (var attributeElement in xmlElement.GetChildElments("Attribute"))
            {
                var mapping = new AttributeMapping
                {
                    Source        = new ClassAttributeReference(attributeElement.GetStringAttributeValue("src"), attributeElement.ParseLocation),
                    Destination   = new ClassAttributeReference(attributeElement.GetStringAttributeValue("dest"), attributeElement.ParseLocation),
                    ParseLocation = attributeElement.ParseLocation
                };

                classMapping.AttributeMappings.Add(mapping);
            }

            foreach (var relationElement in xmlElement.GetChildElments("Relation"))
            {
                var relationMapping = new RelationMapping
                {
                    Source        = new ClassRelationReference(relationElement.GetStringAttributeValue("src"), relationElement.ParseLocation),
                    Destination   = new ClassRelationReference(relationElement.GetStringAttributeValue("dest"), relationElement.ParseLocation),
                    MapAttributes = relationElement.GetBoolAttributeValue("attributes", true),
                    AddMissing    = relationElement.GetBoolAttributeValue("add-missing", true),
                    TwoWay        = relationElement.GetBoolAttributeValue("two-way", true),
                    ParseLocation = relationElement.ParseLocation
                };

                foreach (var attributeElement in relationElement.GetChildElments("Attribute"))
                {
                    var relationAttributeMapping = new AttributeMapping
                    {
                        Source        = new ClassAttributeReference(attributeElement.GetStringAttributeValue("src"), attributeElement.ParseLocation),
                        Destination   = new ClassAttributeReference(attributeElement.GetStringAttributeValue("dest"), attributeElement.ParseLocation),
                        ParseLocation = attributeElement.ParseLocation
                    };

                    relationMapping.AttributeMappings.Add(relationAttributeMapping);
                }

                classMapping.RelationMappings.Add(relationMapping);
            }

            currentClassModel.SetClassMappingData(classMapping);

            return(null);
        }
Пример #10
0
 public override IDesignModel GenerateDesignModel(IXmlElement xmlElement, DesignModelParseContext context)
 {
     return(new Entity(xmlElement.GetStringAttributeValue("name"), context.Namespace, xmlElement));
 }