Esempio n. 1
0
        private static void CustomReadPropertiesFromElements(SerializationContext serializationContext, ScalarProperty element, XmlReader reader)
        {
            while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == XmlNodeType.Element)
            {
                switch (reader.LocalName)
                {
                case "key":                                  // key
                    if (reader.IsEmptyElement)
                    {                                        // No serialized value, must be default one.
                        SerializationUtilities.Skip(reader); // Skip this tag.
                    }
                    else
                    {
                        OrmKeyAttribute keyAttribute = new OrmKeyAttribute();
                        keyAttribute.DeserializeFromXml(reader);
                        element.KeyAttribute = keyAttribute;

                        SerializationUtilities.SkipToNextElement(reader);
                        reader.SkipToNextElementFix();
                    }
                    break;

                default:
                    return;      // Don't know this element.
                }
            }
        }
Esempio n. 2
0
        private OrmKeyAttribute CreateOrmKeyAttribute(TestAttributeValuesType valuesType)
        {
            OrmKeyAttribute originalAttribute = new OrmKeyAttribute();
            bool            isValues1         = valuesType == TestAttributeValuesType.Values1;

            originalAttribute.Enabled = isValues1 ? true : false;
            originalAttribute.Direction.SetAsCustom(isValues1 ? KeyDirection.Negative : KeyDirection.Positive);
            originalAttribute.Position.SetAsCustom(isValues1 ? 45 : 54);
            return(originalAttribute);
        }
        private static void CustomReadPropertiesFromElements(SerializationContext serializationContext, NavigationProperty element, XmlReader reader)
        {
            while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
            {
                switch (reader.LocalName)
                {
                case "key":                                  // key
                    if (reader.IsEmptyElement)
                    {                                        // No serialized value, must be default one.
                        SerializationUtilities.Skip(reader); // Skip this tag.
                    }
                    else
                    {
                        OrmKeyAttribute keyAttribute = new OrmKeyAttribute();
                        keyAttribute.DeserializeFromXml(reader);
                        element.KeyAttribute = keyAttribute;

                        SerializationUtilities.SkipToNextElement(reader);
                        reader.SkipToNextElementFix();
                    }
                    break;

                case "multiplicity":                         // Multiplicity
                    if (reader.IsEmptyElement)
                    {                                        // No serialized value, must be default one.
                        SerializationUtilities.Skip(reader); // Skip this tag.
                    }
                    else
                    {
                        string           strMultiplicity = DONetEntityModelDesignerSerializationHelper.Instance.ReadElementContentAsString(serializationContext, element, reader);
                        MultiplicityKind valueOfMultiplicity;
                        if (Enum.TryParse(strMultiplicity, true, out valueOfMultiplicity))
                        {
                            element.Multiplicity = valueOfMultiplicity;
                        }
                        else
                        {       // Invalid property value, ignored.
                            EntityModelDesignerSerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "multiplicity", typeof(global::TXSoftware.DataObjectsNetEntityModel.Common.MultiplicityKind), strMultiplicity);
                        }

                        SerializationUtilities.SkipToNextElement(reader);
                    }
                    break;

                default:
                    return;      // Don't know this element.
                }
            }
        }
Esempio n. 4
0
    public string ForSetter(IPropertyBase property, IPropertiesBuilder propertiesBuilder)
    {
        string result = string.Empty;

        if (this.ActiveDTOStage)
        {
            return(result);
        }

        switch (property.PropertyKind)
        {
        case PropertyKind.Scalar:
        {
            IOrmAttribute[] typeAttributes = propertiesBuilder.GetPropertyTypeAttributes(property);
            OrmKeyAttribute keyAttribute   = (OrmKeyAttribute)typeAttributes.Single(item => item is OrmKeyAttribute);

            result = keyAttribute.Enabled ? VISIBILITY_PRIVATE : string.Empty;
            break;
        }

        case PropertyKind.Navigation:
        {
            IOrmAttribute[] typeAttributes = propertiesBuilder.GetPropertyTypeAttributes(property);
            OrmKeyAttribute keyAttribute   = (OrmKeyAttribute)typeAttributes.Single(item => item is OrmKeyAttribute);

            INavigationProperty navigationProperty = (INavigationProperty)property;
            if (navigationProperty.Multiplicity == MultiplicityKind.Many || keyAttribute.Enabled)
            {
                result = VISIBILITY_PRIVATE;
            }

            break;
        }
        }

        // only when result is not directly 'private' because of business rules we can adjust it from settings
        if (string.IsNullOrEmpty(result))
        {
            PropertyAccessModifier higherModifier = property.PropertyAccess.GetHigherModifier();

            if (property.PropertyAccess.Setter != PropertyAccessModifier.Public && property.PropertyAccess.Setter != higherModifier)
            {
                result = GetPropertyAccessModifierString(property.PropertyAccess.Setter);
            }
        }

        return(result);
    }
Esempio n. 5
0
        private void TestSerializationForOrmKeyAttribute()
        {
            const string referentialXml =
                "<key valueType=\"Enabled\"><direction valueType=\"Custom\"><value>Negative</value></direction><position valueType=\"Custom\" value=\"45\" /></key>";

            OrmKeyAttribute originalAttribute = CreateOrmKeyAttribute(TestAttributeValuesType.Values1);

            string xml = originalAttribute.SerializeToString();

            Assert.IsTrue(Util.StringEqual(xml, referentialXml, true),
                          "Serialized xml form of 'OrmKeyAttribute' type differs from referential xml.");

            OrmKeyAttribute clonedAttribute = null;

            Action cloneAttribute = () => clonedAttribute = (OrmKeyAttribute)originalAttribute.Clone();

            cloneAttribute();
            Assert.IsTrue(originalAttribute.EqualsTo(clonedAttribute));

            Action testClonedNotEquals = () => Assert.IsFalse(originalAttribute.EqualsTo(clonedAttribute));

            cloneAttribute();
            clonedAttribute.Enabled = false;
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Direction.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Direction.SetAsCustom(KeyDirection.Positive);
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Position.SetAsDefault();
            testClonedNotEquals();

            cloneAttribute();
            clonedAttribute.Position.SetAsCustom(int.MinValue);
            testClonedNotEquals();
        }