Пример #1
0
        public override IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
        {
            AssociationInfo other = (AssociationInfo)otherAttribute;

            AssociationInfo mergedResult = new AssociationInfo();

            mergedResult.PairTo = this.PairTo.Merge(other.PairTo, mergeConflictAction);

            var onOwnerRemove       = GetDefaultableOnRemoveAction(true);
            var mergedOnOwnerRemove = onOwnerRemove.Merge(other.GetDefaultableOnRemoveAction(true), mergeConflictAction);

            mergedResult.OnOwnerRemove = mergedOnOwnerRemove.IsDefault()
                                             ? AssociationOnRemoveAction.Default
                                             : mergedOnOwnerRemove.Value;

            var onTargetRemove       = GetDefaultableOnRemoveAction(false);
            var mergedOnTargetRemove = onTargetRemove.Merge(other.GetDefaultableOnRemoveAction(false), mergeConflictAction);

            mergedResult.OnTargetRemove = mergedOnTargetRemove.IsDefault()
                                             ? AssociationOnRemoveAction.Default
                                             : mergedOnTargetRemove.Value;

            var mergedUseAssociationAttribute =
                this.GetDefaultableUseAssociationAttribute().Merge(other.GetDefaultableUseAssociationAttribute(),
                                                                   mergeConflictAction);

            mergedResult.UseAssociationAttribute = mergedUseAssociationAttribute.Value;

            return(mergedResult);
        }
Пример #2
0
        private void TestMergeChangesForOrmAttribute <T>(T sourceAttribute, T targetAttribute) where T : IOrmAttribute
        {
            var targetGroupItems = targetAttribute.GetAttributeGroupItems(AttributeGroupsListMode.All);

            foreach (var attributeGroupItem in targetGroupItems)
            {
                attributeGroupItem.SetAsDefault();
            }

            bool   toXml = false;
            string xmlSource;
            string xmlTarget;

            if (toXml)
            {
                xmlSource = sourceAttribute.SerializeToString();
                xmlTarget = targetAttribute.SerializeToString();
            }

            IOrmAttribute mergedAttribute = sourceAttribute.MergeChanges(targetAttribute, MergeConflictAction.TakeOther);

            foreach (var attributeGroupsListMode in EnumType <AttributeGroupsListMode> .Values)
            {
                var sourceGroupItems = sourceAttribute.GetAttributeGroupItems(attributeGroupsListMode);
                var mergedGroupItems = mergedAttribute.GetAttributeGroupItems(attributeGroupsListMode);

                for (int i = 0; i < mergedGroupItems.Count; i++)
                {
                    var mergedGroupItem = mergedGroupItems[i];
                    var sourceGroupItem = sourceGroupItems[i];

                    Assert.IsTrue(mergedGroupItem.EqualsTo(sourceGroupItem));
                }
            }
        }
Пример #3
0
        public IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
        {
            OrmHierarchyRootAttribute other        = (OrmHierarchyRootAttribute)otherAttribute;
            OrmHierarchyRootAttribute mergedResult = new OrmHierarchyRootAttribute();

            bool enabled = this.Enabled;

            //if (!other.Enabled && mergeConflictAction == MergeConflictAction.TakeOther)
            if (other.Enabled && !enabled && mergeConflictAction == MergeConflictAction.TakeOther)
            {
                enabled = other.Enabled;
            }

            mergedResult.Enabled = enabled;

            var mergedInheritanceSchema = this.GetDefInheritanceSchema().Merge(other.GetDefInheritanceSchema(),
                                                                               mergeConflictAction);

            mergedResult.InheritanceSchema = mergedInheritanceSchema.Value;

            mergedResult.IncludeTypeId = this.IncludeTypeId.Merge(other.IncludeTypeId, mergeConflictAction);
            mergedResult.MappingName   = this.MappingName.Merge(other.MappingName, mergeConflictAction);

            return(mergedResult);
        }
Пример #4
0
        public IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
        {
            OrmKeyGeneratorAttribute other        = (OrmKeyGeneratorAttribute)otherAttribute;
            OrmKeyGeneratorAttribute mergedResult = new OrmKeyGeneratorAttribute();

            bool enabled = this.Enabled;

            //if (!other.Enabled && mergeConflictAction == MergeConflictAction.TakeOther)
            if (other.Enabled && !enabled && mergeConflictAction == MergeConflictAction.TakeOther)
            {
                enabled = other.Enabled;
            }

            mergedResult.Enabled = enabled;

            var defaultableItems      = GetDefaultableItems();
            var otherDefaultableItems = other.GetDefaultableItems();

            var mergedKind = defaultableItems.Item1.Merge(otherDefaultableItems.Item1, mergeConflictAction);

            mergedResult.Kind = mergedKind.IsDefault() ? KeyGeneratorKind.Default : mergedKind.Value;

            var mergedName = defaultableItems.Item2.Merge(otherDefaultableItems.Item2, mergeConflictAction);

            mergedResult.Name = mergedName.Value;

            var mergedType = defaultableItems.Item3.Merge(otherDefaultableItems.Item3, mergeConflictAction);

            mergedResult.Type = mergedType.Value;

            return(mergedResult);
        }
Пример #5
0
        private void PreparePropertiesTypeAttributes()
        {
            mappingPropertiesTypeAttributes.Clear();
            foreach (var mapping in mappingProperties)
            {
                IPropertyBase sourceProperty    = mapping.Key;
                IPropertyBase inheritedProperty = mapping.Value;

                IOrmAttribute[] typeAttributes = null;
                if (sourceProperty == inheritedProperty)
                {
                    typeAttributes = sourceProperty.TypeAttributes;
                }
                else
                {
                    List <IOrmAttribute> mergedTypeAttributes = new List <IOrmAttribute>();

                    foreach (var typeAttribute in sourceProperty.TypeAttributes)
                    {
                        Type          typeOftypeAttribute    = typeAttribute.GetType();
                        IOrmAttribute inheritedTypeAttribute = inheritedProperty.TypeAttributes.Single(item => item.GetType() == typeOftypeAttribute);

                        IOrmAttribute mergedTypeAttribute = typeAttribute.MergeChanges(inheritedTypeAttribute, MergeConflictAction.TakeCurrent);
                        mergedTypeAttributes.Add(mergedTypeAttribute);
                    }

                    typeAttributes = mergedTypeAttributes.ToArray();
                }

                mappingPropertiesTypeAttributes.Add(sourceProperty, typeAttributes);
            }
        }
Пример #6
0
        protected override void Prefilter(IOrmAttribute attribute, Dictionary <string, Defaultable> attributeGroupItems)
        {
            switch (propertyOwner.PropertyKind)
            {
            case PropertyKind.Scalar:
            {
                IScalarProperty scalarProperty = (IScalarProperty)propertyOwner;
                InternalPrefilter(scalarProperty, attribute, attributeGroupItems);
                break;
            }

            case PropertyKind.Structure:
            {
                IStructureProperty structureProperty = (IStructureProperty)propertyOwner;
                InternalPrefilter(structureProperty, attribute, attributeGroupItems);
                break;
            }

            case PropertyKind.Navigation:
            {
                INavigationProperty navigationProperty = (INavigationProperty)propertyOwner;
                InternalPrefilter(navigationProperty, attribute, attributeGroupItems);
                break;
            }
            }
        }
Пример #7
0
        public override IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
        {
            OrmFieldAttribute other        = (OrmFieldAttribute)otherAttribute;
            OrmFieldAttribute mergedResult = new OrmFieldAttribute();


            Defaultable <ObjectValue> defaultValue =
                this.GetDefaultValueAsDefaultable().Merge(other.GetDefaultValueAsDefaultable(),
                                                          mergeConflictAction);

            mergedResult.DefaultValue         = new ObjectValueInfo();
            mergedResult.DefaultValue.Enabled = defaultValue.IsCustom();
            mergedResult.DefaultValue.Value   = defaultValue.Value;

            mergedResult.Indexed           = this.Indexed.Merge(other.Indexed, mergeConflictAction);
            mergedResult.Nullable          = this.Nullable.Merge(other.Nullable, mergeConflictAction);
            mergedResult.Precision         = this.Precision.Merge(other.Precision, mergeConflictAction);
            mergedResult.Scale             = this.Scale.Merge(other.Scale, mergeConflictAction);
            mergedResult.LazyLoad          = this.LazyLoad.Merge(other.LazyLoad, mergeConflictAction);
            mergedResult.Length            = this.Length.Merge(other.Length, mergeConflictAction);
            mergedResult.NullableOnUpgrade = this.NullableOnUpgrade.Merge(other.NullableOnUpgrade, mergeConflictAction);
            mergedResult.MappingName       = this.MappingName.Merge(other.MappingName, mergeConflictAction);
            mergedResult.Version           = this.Version.Merge(other.Version, mergeConflictAction);
            mergedResult.TypeDiscriminator = this.TypeDiscriminator.Merge(other.TypeDiscriminator, mergeConflictAction);

            //mergedResult.Constraints = this.Constraints.Merge(other.Constraints, mergeConflictAction);

            return(mergedResult);
        }
Пример #8
0
        public IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
        {
            OrmTypeDiscriminatorValueAttribute other        = (OrmTypeDiscriminatorValueAttribute)otherAttribute;
            OrmTypeDiscriminatorValueAttribute mergedResult = new OrmTypeDiscriminatorValueAttribute();

            bool enabled = this.Enabled;

            //if (!other.Enabled && mergeConflictAction == MergeConflictAction.TakeOther)
            if (other.Enabled && !enabled && mergeConflictAction == MergeConflictAction.TakeOther)
            {
                enabled = other.Enabled;
            }

            mergedResult.Enabled = enabled;

            Defaultable <bool> mergedDefault = GetDefaultAsDefaultable().Merge(other.GetDefaultAsDefaultable(), mergeConflictAction);

            mergedResult.Default = mergedDefault.Value;

            ObjectValue value = this.Value;

            if (!this.Value.EqualsTo(other.Value) && other.Enabled && mergeConflictAction == MergeConflictAction.TakeOther)
            {
                value = other.Value;
            }

            mergedResult.Value = value;

            return(mergedResult);
        }
Пример #9
0
        public OrmAttributeGroup[] GetAttributeGroups(IOrmAttribute attribute)
        {
            if (attributeItems.ContainsKey(attribute))
            {
                return(attributeItems[attribute].AttributeGroups);
            }

            return(new OrmAttributeGroup[0]);
        }
Пример #10
0
        private void InternalPrefilter(INavigationProperty property, IOrmAttribute attribute, Dictionary <string, Defaultable> attributeGroupItems)
        {
            OrmFieldAttribute fieldAttribute = attribute as OrmFieldAttribute;

            if (fieldAttribute != null)
            {
                Prefilter(property, fieldAttribute, attributeGroupItems);
            }
        }
Пример #11
0
        public IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
        {
            PropertyConstraint mergedConstraint = CreateInstance(this.ConstrainType);
            PropertyConstraint other            = (PropertyConstraint)otherAttribute;

            string mergedValueType;
            PropertyConstrainMode mergedMode;
            string mergedErrorMessage;

            if ((this.Used && other.Used) || (!this.Used && !other.Used))
            {
                if (mergeConflictAction == MergeConflictAction.TakeOther)
                {
                    mergedValueType    = other.ValueType;
                    mergedMode         = other.Mode;
                    mergedErrorMessage = other.ErrorMessage;
                }
                else
                {
                    mergedValueType    = this.ValueType;
                    mergedMode         = this.Mode;
                    mergedErrorMessage = this.ErrorMessage;
                }
            }
            else
            {
                if (this.Used)
                {
                    mergedValueType    = this.ValueType;
                    mergedMode         = this.Mode;
                    mergedErrorMessage = this.ErrorMessage;
                }
                else // other.IsCustom()
                {
                    mergedValueType    = other.ValueType;
                    mergedMode         = other.Mode;
                    mergedErrorMessage = other.ErrorMessage;
                }
            }

            mergedConstraint.Mode         = mergedMode;
            mergedConstraint.ErrorMessage = mergedErrorMessage;
            mergedConstraint.ValueType    = mergedValueType;
            if (mergedConstraint.Used)
            {
                InternalMergeChanges(ref mergedConstraint, other, mergeConflictAction);
            }

            return(mergedConstraint);
        }
Пример #12
0
        public Dictionary <string, Defaultable> GetAttributeGroupItems(IOrmAttribute attribute,
                                                                       OrmAttributeGroup attributeGroup)
        {
            if (attributeItems.ContainsKey(attribute))
            {
                var attributeGroupItems = attributeItems[attribute].AttributeGroupItems;
                if (attributeGroupItems.ContainsGroup(attributeGroup))
                {
                    return(attributeGroupItems[attributeGroup]);
                }
            }

            return(new Dictionary <string, Defaultable>());
        }
Пример #13
0
        public IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
        {
            EntityIndex other = (EntityIndex)otherAttribute;

            EntityIndex mergedResult = new EntityIndex((Store)null);

            mergedResult.Unique     = this.Unique.Merge(other.Unique, mergeConflictAction);
            mergedResult.FillFactor = this.FillFactor.Merge(other.FillFactor, mergeConflictAction);
            mergedResult.IndexName  = this.IndexName.Merge(other.IndexName, mergeConflictAction);

            mergedResult.Fields = this.Fields.MergeChanges(other.Fields, mergeConflictAction);

            return(mergedResult);
        }
Пример #14
0
        private void InternalPrefilter(IScalarProperty property, IOrmAttribute attribute, Dictionary <string, Defaultable> attributeGroupItems)
        {
            OrmFieldAttribute fieldAttribute = attribute as OrmFieldAttribute;

            if (fieldAttribute != null)
            {
                Prefilter(property, fieldAttribute, attributeGroupItems);
            }

            IAssociationInfo associationInfo = attribute as IAssociationInfo;

            if (associationInfo != null)
            {
                // No prefiltering at now...
            }
        }
Пример #15
0
        protected void Build()
        {
            foreach (var pair in attributeItems)
            {
                IOrmAttribute attribute     = pair.Key;
                AttrData      attributeData = pair.Value;

                foreach (var attributeGroup in attributeData.AttributeGroups)
                {
                    Dictionary <string, Defaultable> attributeGroupItems =
                        attribute.GetAttributeGroupItems(attributeGroup);

                    Prefilter(attribute, attributeGroupItems);

                    attributeData.AttributeGroupItems[attributeGroup] = attributeGroupItems;
                }
            }
        }
Пример #16
0
        private void TestMergeChangesForAssociationInfo()
        {
            var sourceAttribute = CreateAssociationInfo(TestAttributeValuesType.Values1);
            var targetAttribute = CreateAssociationInfo(TestAttributeValuesType.Values2);

            targetAttribute.OnTargetRemove = AssociationOnRemoveAction.Default;

            IOrmAttribute mergedAttribute   = sourceAttribute.MergeChanges(targetAttribute, MergeConflictAction.TakeOther);
            string        expectedMergedXml =
                "<end multiplicity=\"ZeroOrOne\" onOwnerRemove=\"Deny\" onTargetRemove=\"Deny\"><pairTo valueType=\"Custom\"><value>RevertedItems</value></pairTo></end>";
            string mergedAttributeXml = mergedAttribute.SerializeToString();

            Action testMergedXml =
                () =>
                Assert.IsTrue(Util.StringEqual(expectedMergedXml, mergedAttributeXml, true),
                              "Merged xml and expected xml is not equal!");

            testMergedXml();
        }
Пример #17
0
        public IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
        {
            OrmKeyAttribute other        = (OrmKeyAttribute)otherAttribute;
            OrmKeyAttribute mergedResult = new OrmKeyAttribute();

            bool enabled = this.Enabled;

            //if (!other.Enabled && mergeConflictAction == MergeConflictAction.TakeOther)
            if (other.Enabled && !enabled && mergeConflictAction == MergeConflictAction.TakeOther)
            {
                enabled = other.Enabled;
            }

            mergedResult.Enabled = enabled;

            mergedResult.Direction = this.Direction.Merge(other.Direction, mergeConflictAction);
            mergedResult.Position  = this.Position.Merge(other.Position, mergeConflictAction);

            return(mergedResult);
        }
Пример #18
0
 public IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction)
 {
     return
         ((ContractDescriptorBase)
          InternalMergeChanges(otherAttribute as ContractDescriptorBase, mergeConflictAction));
 }
Пример #19
0
 protected PropertyBase(string name)
 {
     Name           = name;
     TypeAttributes = new IOrmAttribute[0];
 }
Пример #20
0
 protected PersistentType(ModelRoot modelRoot, string name)
 {
     modelRoot.AddPersistentType(this);
     Name           = name;
     TypeAttributes = new IOrmAttribute[0];
 }
Пример #21
0
 public string[] CreateTypeAttributesCommon(IOrmAttribute attribute)
 {
     return(CreateTypeAttributesCommon(new[] { attribute }));
 }
Пример #22
0
 public abstract IOrmAttribute MergeChanges(IOrmAttribute otherAttribute, MergeConflictAction mergeConflictAction);
Пример #23
0
 protected virtual void Prefilter(IOrmAttribute attribute, Dictionary <string, Defaultable> attributeGroupItems)
 {
 }