Ejemplo n.º 1
0
        internal static void ValidateProperties <T>(T persistentType, InheritanceTree inheritanceTree, ValidationContext context) where T : PersistentType
        {
            if (persistentType is IInterface)
            {
                // validate 'IsInheritedProperty' properties, each property marked with this must have property with same name in its inheritance tree path
                IEnumerable <IPropertyBase> properties = persistentType.AllProperties.Where(property => property.IsInherited);

                if (properties.Count() > 0)
                {
                    IInterface @interface = (IInterface)persistentType;
                    if (inheritanceTree == null)
                    {
                        inheritanceTree = @interface.GetInheritanceTree();
                        inheritanceTree.RebuildTree(true);
                    }

                    foreach (var property in properties)
                    {
                        bool foundProperty = false;

                        inheritanceTree.IterateTree(false,
                                                    delegate(GenericTreeIterationArgs <InheritanceNode> args)
                        {
                            IInterface currentType = args.Current.Interface;
                            foundProperty          = currentType != persistentType &&
                                                     currentType.AllProperties.Any(item => Util.StringEqual(item.Name, property.Name, true) &&
                                                                                   item.PropertyKind == property.PropertyKind);

                            args.Cancel = foundProperty;
                        });

                        if (!foundProperty)
                        {
                            context.LogError(
                                string.Format(
                                    ERROR_INVALID_IS_INHERITED_PROPERTY,
                                    persistentType.TypeKind, persistentType.Name, property.PropertyKind, property.Name),
                                CODE_INVALID_IS_INHERITED_PROPERTY,
                                new[] { property as ModelElement });
                        }
                    }
                }
            }

            ValidateOrmAttributes(persistentType, context);
        }
Ejemplo n.º 2
0
        public static InheritanceTree Get(IInterface @interface)
        {
            InheritanceTree result;

            lock (sync)
            {
                if (cache.ContainsKey(@interface))
                {
                    result = cache[@interface];
                }
                else
                {
                    result = @interface.GetInheritanceTree();
                    cache.Add(@interface, result);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        internal static DuplicatedPropertiesInfo FindDuplicatedPropertieInInheritanceTree(IInterface thisInterface, InheritanceTree inheritanceTree)
        {
            if (inheritanceTree == null)
            {
                inheritanceTree = thisInterface.GetInheritanceTree();
                inheritanceTree.RebuildTree(true);
            }

            var inheritanceTreeList = inheritanceTree.GetFlatList(InheritanceListMode.WholeTree).Select(node => node.Interface);

            List <IPropertyBase> scalarPropertiesWithDifferentType = new List <IPropertyBase>();
            List <IPropertyBase> scalarPropertiesWithSameType      = new List <IPropertyBase>();

            List <IPropertyBase> structurePropertiesWithDifferentType = new List <IPropertyBase>();
            List <IPropertyBase> structurePropertiesWithSameType      = new List <IPropertyBase>();

            List <IPropertyBase> navigationPropertiesWithDifferentType = new List <IPropertyBase>();
            List <IPropertyBase> navigationPropertiesWithSameType      = new List <IPropertyBase>();

            // iterate scalar properties
            foreach (var scalarProperty in thisInterface.GetScalarProperties())
            {
                if (scalarProperty.IsInherited)
                {
                    continue;
                }

                var query = from childInterface in inheritanceTreeList
                            let childScalarProperties =
                    childInterface.Properties.Where(item => item.PropertyKind == PropertyKind.Scalar).Cast
                    <IScalarProperty>()
                    where childScalarProperties.Any(childScalarProperty
                                                    =>
                                                    Util.StringEqual(childScalarProperty.Name, scalarProperty.Name, true))
                    select new
                {
                    PropertiesWithDifferentType = childScalarProperties
                                                  .Where(childScalarProperty => !childScalarProperty.Type.EqualsTo(scalarProperty.Type)),
                    PropertiesWithSameType = childScalarProperties
                                             .Where(childScalarProperty => childScalarProperty.Type.EqualsTo(scalarProperty.Type))
                };


                scalarPropertiesWithDifferentType.AddRange(
                    query.SelectMany(arg => arg.PropertiesWithDifferentType).Cast <IPropertyBase>().ToList());

                scalarPropertiesWithSameType.AddRange(
                    query.SelectMany(arg => arg.PropertiesWithSameType).Cast <IPropertyBase>().ToList());
            }


            // iterate structures properties
            foreach (var structureProperty in thisInterface.GetStructureProperties())
            {
                if (structureProperty.IsInherited)
                {
                    continue;
                }

                var query = from childInterface in inheritanceTreeList
                            let childStructureProperties =
                    childInterface.Properties.Where(item => item.PropertyKind == PropertyKind.Structure).Cast
                    <IStructureProperty>()
                    where childStructureProperties.Any(childStructureProperty
                                                       =>
                                                       Util.StringEqual(childStructureProperty.Name, structureProperty.Name, true))
                    select new
                {
                    PropertiesWithDifferentType = childStructureProperties
                                                  .Where(childScalarProperty => childScalarProperty.TypeOf != structureProperty.TypeOf),
                    PropertiesWithSameType = childStructureProperties
                                             .Where(childScalarProperty => childScalarProperty.TypeOf == structureProperty.TypeOf)
                };

                structurePropertiesWithDifferentType.AddRange(
                    query.SelectMany(arg => arg.PropertiesWithDifferentType).Cast <IPropertyBase>().ToList());

                structurePropertiesWithSameType.AddRange(
                    query.SelectMany(arg => arg.PropertiesWithSameType).Cast <IPropertyBase>().ToList());
            }

            // iterate navigation properties
            foreach (var navigationProperty in thisInterface.NavigationProperties)
            {
                if (navigationProperty.IsInherited)
                {
                    continue;
                }

                var query = from childInterface in inheritanceTreeList
                            let childNavigationProperties = childInterface.NavigationProperties
                                                            where childNavigationProperties.Any(childStructureProperty
                                                                                                =>
                                                                                                Util.StringEqual(childStructureProperty.Name, navigationProperty.Name, true))
                                                            select new
                {
                    PropertiesWithDifferentType = childNavigationProperties
                                                  .Where(childScalarProperty => !childScalarProperty.PersistentTypeHasAssociations.EqualAssociationLinkTo(navigationProperty.PersistentTypeHasAssociations)),
                    PropertiesWithSameType = childNavigationProperties
                                             .Where(childScalarProperty => childScalarProperty.PersistentTypeHasAssociations.EqualAssociationLinkTo(navigationProperty.PersistentTypeHasAssociations))
                };

                navigationPropertiesWithDifferentType.AddRange(
                    query.SelectMany(arg => arg.PropertiesWithDifferentType).Cast <IPropertyBase>().ToList());

                navigationPropertiesWithSameType.AddRange(
                    query.SelectMany(arg => arg.PropertiesWithSameType).Cast <IPropertyBase>().ToList());
            }

            var propertiesWithDifferentType =
                scalarPropertiesWithDifferentType.Concat(structurePropertiesWithDifferentType).Concat(
                    navigationPropertiesWithDifferentType);

            var propertiesWithSameType =
                scalarPropertiesWithSameType.Concat(structurePropertiesWithSameType).Concat(
                    navigationPropertiesWithSameType);

            int inheritancePathsCount = inheritanceTree.GetUniquePathsSuperRoots().Count();

            DuplicatedPropertiesInfo info = new DuplicatedPropertiesInfo(propertiesWithDifferentType, propertiesWithSameType,
                                                                         inheritancePathsCount);

            return(info);
        }