示例#1
0
        public static WXMLModel LoadFromXml(XmlReader reader, XmlResolver xmlResolver)
        {
            WXMLModel odef = WXMLModelReader.Parse(reader, xmlResolver);

            odef.CreateSystemComments();
            return(odef);
        }
示例#2
0
 public void Merge(WXMLModel mergeWith)
 {
     MergeTypes(mergeWith);
     MergeTables(mergeWith);
     MergeEntities(mergeWith);
     MergeExtensions(Extensions, mergeWith.Extensions);
 }
示例#3
0
        internal static WXMLDocumentSet Generate(WXMLModel schema, WXMLModelWriterSettings settings)
        {
            WXMLModelWriter generator = new WXMLModelWriter(schema, settings);

            generator.GenerateXmlDocumentInternal();

            return(generator._wxmlDocumentSet);
        }
示例#4
0
 internal WXMLModelWriter(WXMLModel model, WXMLModelWriterSettings settings)
 {
     _model     = model;
     _nametable = new NameTable();
     _nsMgr     = new XmlNamespaceManager(_nametable);
     _nsMgr.AddNamespace(WXMLModel.NS_PREFIX, WXMLModel.NS_URI);
     _wxmlDocumentSet = new WXMLDocumentSet();
     _settings        = settings;
 }
示例#5
0
 private void MergeTypes(WXMLModel model)
 {
     foreach (TypeDefinition newType in model.GetTypes())
     {
         string         newTypeIdentifier = newType.Identifier;
         TypeDefinition type = GetTypes().SingleOrDefault(item => item.Identifier == newTypeIdentifier);
         if (type != null)
         {
             if (type.ToString() != newType.ToString())
             {
                 throw new NotSupportedException(string.Format("Type with identifier {0} already exists.", newTypeIdentifier));
             }
         }
         else
         {
             AddType(newType);
         }
     }
 }
示例#6
0
 private static string GetIncludeFileName(WXMLModel model, WXMLModel model2include, WXMLModelWriterSettings settings)
 {
     if (string.IsNullOrEmpty(model2include.FileName))
     {
         string filename =
             settings.IncludeFileNamePattern.Replace("%MAIN_FILENAME%", GetFilename(model, settings)).
             Replace(
                 "%INCLUDE_NAME%", GetFilename(model2include, settings)) +
             model.Includes.IndexOf(model2include);
         return
             ((((settings.IncludeBehaviour & IncludeGenerationBehaviour.PlaceInFolder) ==
                IncludeGenerationBehaviour.PlaceInFolder)
                  ? settings.IncludeFolderName + System.IO.Path.DirectorySeparatorChar
                  : string.Empty) + filename);
     }
     else
     {
         return(model2include.FileName);
     }
 }
示例#7
0
        private void MergeTables(WXMLModel mergeWith)
        {
            foreach (SourceFragmentDefinition newsf in mergeWith.GetSourceFragments())
            {
                string newsfIdentifier      = newsf.Identifier;
                SourceFragmentDefinition sf = GetSourceFragments().SingleOrDefault(item => item.Identifier == newsfIdentifier);
                if (sf != null)
                {
                    if (!string.IsNullOrEmpty(newsf.Name))
                    {
                        sf.Name = newsf.Name;
                    }

                    if (!string.IsNullOrEmpty(newsf.Selector))
                    {
                        sf.Selector = newsf.Selector;
                    }
                }
                else
                {
                    AddSourceFragment(newsf);
                }
            }
        }
示例#8
0
 private static string GetFilename(WXMLModel model, WXMLModelWriterSettings settings)
 {
     return(string.IsNullOrEmpty(model.FileName)
                ? settings.DefaultMainFileName
                : model.FileName);
 }
示例#9
0
        private void MergeEntities(WXMLModel mergeWith)
        {
            foreach (EntityDefinition newEntity in mergeWith.GetEntities())
            {
                string newEntityIdentifier = newEntity.Identifier;

                EntityDefinition entity = GetEntities().SingleOrDefault(item => item.Identifier == newEntityIdentifier);
                if (entity != null)
                {
                    if (!string.IsNullOrEmpty(newEntity.Name))
                    {
                        entity.Name = newEntity.Name;
                    }

                    entity.Namespace          = newEntity.Namespace;
                    entity.BaseEntity         = newEntity.BaseEntity;
                    entity.Behaviour          = newEntity.Behaviour;
                    entity.CacheCheckRequired = newEntity.CacheCheckRequired;
                    entity.Description        = newEntity.Description;
                    entity.Disabled           = newEntity.Disabled;
                    entity.InheritsBaseTables = newEntity.InheritsBaseTables;
                    entity.AutoInterface      = newEntity.AutoInterface;
                    entity.UseGenerics        = newEntity.UseGenerics;
                    entity.FamilyName         = newEntity.FamilyName;
                    foreach (var @interface in newEntity.Interfaces)
                    {
                        if (!entity.Interfaces.ContainsKey(@interface.Key))
                        {
                            entity.Interfaces.Add(@interface.Key, @interface.Value);
                        }
                    }

                    entity.ClearSourceFragments();
                    foreach (SourceFragmentRefDefinition newsf in newEntity.OwnSourceFragments)
                    {
                        //string newsfId = newsf.Identifier;
                        //SourceFragmentRefDefinition sf =
                        //    entity.GetSourceFragments().SingleOrDefault(item => item.Identifier == newsfId);

                        //foreach (PropertyDefinition rp in entity.GetProperties()
                        //    .Where(item=>item.SourceFragment == sf))
                        //{
                        //    if (rp is ScalarPropertyDefinition)
                        //    {
                        //        ScalarPropertyDefinition property = rp as ScalarPropertyDefinition;
                        //        property.SourceField.SourceFragment = newsf;
                        //    }
                        //    else if (rp is EntityPropertyDefinition)
                        //    {
                        //        EntityPropertyDefinition property = rp as EntityPropertyDefinition;
                        //        property.SourceFragment = newsf;
                        //    }
                        //}

                        //entity.RemoveSourceFragment(sf);
                        entity.AddSourceFragment(newsf);
                    }
                    //List<SourceFragmentRefDefinition> torem = new List<SourceFragmentRefDefinition>();
                    //foreach (SourceFragmentRefDefinition newsf in newEntity.GetSourceFragments())
                    //{
                    //    string newsfId = newsf.Identifier;
                    //    SourceFragmentRefDefinition sf =
                    //        entity.GetSourceFragments().SingleOrDefault(item => item.Identifier == newsfId);

                    //    if (sf != null)
                    //    {
                    //        if (newsf.Action == MergeAction.Delete)
                    //        {
                    //            entity.RemoveSourceFragment(sf);
                    //            torem.Add(newsf);
                    //        }
                    //        else if (newsf.AnchorTable != null)
                    //        {
                    //            sf.AnchorTable = newsf.AnchorTable;
                    //            sf.JoinType = newsf.JoinType;
                    //            if (newsf.Conditions.Count > 0)
                    //            {
                    //                foreach (SourceFragmentRefDefinition.Condition c in newsf.Conditions)
                    //                {
                    //                    SourceFragmentRefDefinition.Condition ec =
                    //                        sf.Conditions.SingleOrDefault(item =>
                    //                            item.LeftColumn == c.LeftColumn &&
                    //                            item.RightColumn == c.RightColumn
                    //                        );
                    //                    if (ec != null)
                    //                    {
                    //                        if (c.Action == MergeAction.Delete)
                    //                            sf.Conditions.Remove(ec);
                    //                    }
                    //                    else
                    //                        sf.Conditions.Add(c);
                    //                }
                    //            }
                    //        }
                    //    }
                    //    else
                    //        entity.AddSourceFragment(newsf);
                    //}

                    //foreach (SourceFragmentRefDefinition newsf in torem)
                    //{
                    //    newEntity.RemoveSourceFragment(newsf);
                    //}

                    foreach (PropertyDefinition newProperty in newEntity.GetProperties())
                    {
                        string newPropertyName = newProperty.PropertyAlias;

                        PropertyDefinition rp =
                            entity.GetProperties().SingleOrDefault(item => item.PropertyAlias == newPropertyName);

                        if (rp != null)
                        {
                            if (newProperty.Action == MergeAction.Delete)
                            {
                                entity.RemoveProperty(rp);
                            }
                            else
                            {
                                rp.Name = MergeString(rp, newProperty, item => item.Name);
                                rp.ObsoleteDescripton = MergeString(rp, newProperty, item => item.ObsoleteDescripton);
                                rp.DefferedLoadGroup  = MergeString(rp, newProperty, item => item.DefferedLoadGroup);
                                rp.GenerateAttribute  = newProperty.GenerateAttribute;
                                rp.AvailableFrom      = MergeString(rp, newProperty, item => item.AvailableFrom);
                                rp.AvailableTo        = MergeString(rp, newProperty, item => item.AvailableTo);
                                rp.Description        = MergeString(rp, newProperty, item => item.Description);
                                if (newProperty.Attributes != Field2DbRelations.None)
                                {
                                    rp.Attributes = newProperty.Attributes;
                                }
                                rp.Feature               = MergeString(rp, newProperty, item => item.Feature);
                                rp.Group                 = newProperty.Group ?? rp.Group;
                                rp.PropertyType          = newProperty.PropertyType ?? rp.PropertyType;
                                rp.Disabled              = newProperty.Disabled;
                                rp.EnablePropertyChanged = newProperty.EnablePropertyChanged;
                                rp.SourceFragment        = newProperty.SourceFragment ?? rp.SourceFragment;

                                if (newProperty.FieldAccessLevel != default(AccessLevel))
                                {
                                    rp.FieldAccessLevel = newProperty.FieldAccessLevel;
                                }

                                if (newProperty.PropertyAccessLevel != default(AccessLevel))
                                {
                                    rp.PropertyAccessLevel = newProperty.PropertyAccessLevel;
                                }

                                if (newProperty.Obsolete != default(ObsoleteType))
                                {
                                    rp.Obsolete = newProperty.Obsolete;
                                }

                                if (rp.GetType() != newProperty.GetType())
                                {
                                    PropertyDefinition newProp = null;
                                    if (rp is EntityPropertyDefinition && newProperty is ScalarPropertyDefinition)
                                    {
                                        newProp = new ScalarPropertyDefinition(entity, newPropertyName);
                                        rp.CopyTo(newProp);
                                    }
                                    else if (rp is ScalarPropertyDefinition && newProperty is EntityPropertyDefinition)
                                    {
                                        newProp = new EntityPropertyDefinition(rp as ScalarPropertyDefinition);
                                    }
                                    entity.RemoveProperty(rp);
                                    entity.AddProperty(newProp);
                                    rp = newProp;
                                }

                                if (rp is ScalarPropertyDefinition)
                                {
                                    ScalarPropertyDefinition property = rp as ScalarPropertyDefinition;
                                    property.SourceField.SourceType            = MergeString(property, newProperty as ScalarPropertyDefinition, item => item.SourceType);
                                    property.SourceFieldAlias                  = MergeString(property, newProperty as ScalarPropertyDefinition, item => item.SourceFieldAlias);
                                    property.SourceField.SourceFieldExpression = MergeString(property, newProperty as ScalarPropertyDefinition, item => item.SourceFieldExpression);
                                    property.SourceField.IsNullable            = ((ScalarPropertyDefinition)newProperty).IsNullable;
                                    property.SourceField.SourceTypeSize        = ((ScalarPropertyDefinition)newProperty).SourceTypeSize ?? property.SourceTypeSize;
                                }
                            }
                        }
                        else
                        {
                            entity.AddProperty(newProperty);
                        }
                    }

                    MergeExtensions(entity.Extensions, newEntity.Extensions);
                }
                else
                {
                    AddEntity(newEntity);
                }
            }
        }