Пример #1
0
        /// <summary>
        /// Determines the icon to show in a compartment entry, based on its properties.
        /// </summary>
        /// <param name="element">The configuration property being shown in the compartment.</param>
        /// <returns>The icon to use to represent the configuration property.</returns>
        protected virtual Image CompartmentImageProvider(ModelElement element)
        {
            Image propertyImage = Resources.Property;

            PropertyBase prop = (PropertyBase)element;

            if (prop is ScalarProperty)
            {
                ScalarProperty scalarProperty = (ScalarProperty)prop;
                var            nullable       = scalarProperty.FieldAttribute.Nullable;

                if (scalarProperty.KeyAttribute.Enabled)
                {
                    propertyImage = Resources.PropertyKey;
                }
                else if (!nullable.IsDefault() && nullable.Value)
                {
                    propertyImage = Resources.PropertyNullable;
                }
            }
            else if (prop is StructureProperty)
            {
                propertyImage = Resources.StructureProperty;
            }
            else if (prop is NavigationProperty)
            {
                var navigationProperty = prop as NavigationProperty;
                propertyImage = navigationProperty.KeyAttribute.Enabled
                    ? Resources.NavigationPropertyKey
                    : Resources.NavigationProperty;
            }

            return(propertyImage);
        }
Пример #2
0
        private PropertyBase CreateNewProperty(PersistentType ownerPersistentType, PropertyKind newPropertyKind)
        {
            int propertiesCount = 0;

            PropertyBase newProperty = null;

            switch (newPropertyKind)
            {
            case PropertyKind.Scalar:
                newProperty = new ScalarProperty(ownerPersistentType.Partition);
                ownerPersistentType.Properties.Add(newProperty);
                propertiesCount = ownerPersistentType.Properties.OfType <ScalarProperty>().Count();
                break;

            case PropertyKind.Structure:
                newProperty = new StructureProperty(ownerPersistentType.Partition);
                ownerPersistentType.Properties.Add(newProperty);
                propertiesCount = ownerPersistentType.Properties.OfType <StructureProperty>().Count();
                break;

            case PropertyKind.Navigation:
                newProperty = new NavigationProperty(ownerPersistentType.Partition);
                ownerPersistentType.NavigationProperties.Add((NavigationProperty)newProperty);
                propertiesCount = ownerPersistentType.NavigationProperties.OfType <NavigationProperty>().Count();
                break;
            }

            newProperty.Name = string.Format("{0}Property{1}", newPropertyKind, propertiesCount + 1);

            return(newProperty);
        }
Пример #3
0
        protected override void OnCopy(ModelElement sourceElement)
        {
            base.OnCopy(sourceElement);

            ScalarProperty sourceProperty = (ScalarProperty)sourceElement;

            this.KeyAttribute = Common.ExtensionMethods.Clone(sourceProperty.KeyAttribute);
            this.Type         = sourceProperty.Type;
        }
Пример #4
0
        public ScalarProperty AddScalarProperty(string name, DomainType type)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (this.GetScalarProperties().Any(item => Util.StringEqual(item.Name, name, true)))
            {
                throw new ApplicationException(string.Format("Scalar property with name '{0}' already exist.",
                                                             name));
            }

            ScalarProperty newProperty = new ScalarProperty(this.Partition);

            newProperty.Type = type;//SystemPrimitiveTypesConverter.GetDisplayName(type);
            this.Properties.Add(newProperty);
            return(newProperty);
        }
Пример #5
0
        private void CustomWritePropertiesAsAttributes(SerializationContext serializationContext, ModelElement element, XmlWriter writer)
        {
            // Always call the base class so any extensions are serialized
            base.WritePropertiesAsAttributes(serializationContext, element, writer);

            ScalarProperty instanceOfScalarProperty = element as ScalarProperty;

            global::System.Diagnostics.Debug.Assert(instanceOfScalarProperty != null, "Expecting an instance of ScalarProperty");

            // Type
            if (!serializationContext.Result.Failed)
            {
//                instanceOfScalarProperty.type
//                string clrName = SystemPrimitiveTypesConverter.GetClrName(propValue);

                IDomainType domainType = instanceOfScalarProperty.Type;
                Guid        typeId     = domainType.GetTypeId();

                DONetEntityModelDesignerSerializationHelper.Instance.WriteAttributeString(serializationContext, element,
                                                                                          writer, "typeId", typeId.ToString());
            }
        }
Пример #6
0
        private void CustomReadPropertiesFromAttributes(SerializationContext serializationContext, ModelElement element, XmlReader reader)
        {
            // Always call the base class so any extensions are deserialized
            base.ReadPropertiesFromAttributes(serializationContext, element, reader);

            ScalarProperty instanceOfScalarProperty = element as ScalarProperty;

            global::System.Diagnostics.Debug.Assert(instanceOfScalarProperty != null, "Expecting an instance of ScalarProperty");

            ModelUpgrader.Instance.RequestSerializationUpgrade(
                upgrader => upgrader.ReadPropertiesFromAttributes(serializationContext, instanceOfScalarProperty, reader));

            // Type

/*
 *          if (!serializationContext.Result.Failed)
 *          {
 *              string attribType = DONetEntityModelDesignerSerializationHelper.Instance.ReadAttribute(serializationContext, element, reader, "type");
 *              if (!string.IsNullOrEmpty(attribType))
 *              {
 *                  string typeDisplayName = SystemPrimitiveTypesConverter.GetDisplayName(attribType);
 *                  if (!string.IsNullOrEmpty(typeDisplayName))
 *                  {
 *                      Type clrType = SystemPrimitiveTypesConverter.GetClrType(typeDisplayName);
 *                      Guid typeId = SystemPrimitiveTypesConverter.GetTypeId(clrType);
 *                      IModelRoot entityModel = element.Store.GetEntityModel();
 *                      IDomainType domainType = entityModel.GetDomainType(typeId);
 *                      if (domainType == null)
 *                      {
 *                          domainType =
 *                              entityModel.BuildInDomainTypes.SingleOrDefault(type => type.FullName == "System.String");
 *                      }
 *
 *                      instanceOfScalarProperty.Type = (DomainType) domainType;
 *
 *                      element.Store.PropertyBag["@@OldModelConversions"] = true;
 *                  }
 *                  else
 *                  {	// Invalid property value, ignored.
 *                      EntityModelDesignerSerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "type", typeof(global::System.String), attribType);
 *                  }
 *              }
 *          }
 */

            // typeId
            if (!serializationContext.Result.Failed)
            {
                string attribType = DONetEntityModelDesignerSerializationHelper.Instance.ReadAttribute(serializationContext, element, reader, "typeId");
                if (!string.IsNullOrEmpty(attribType))
                {
                    Guid        typeId      = new Guid(attribType);
                    IModelRoot  entityModel = element.Store.GetEntityModel();
                    IDomainType domainType  = entityModel.GetDomainType(typeId);
                    if (domainType == null)
                    {
                        domainType =
                            entityModel.BuildInDomainTypes.SingleOrDefault(type => type.FullName == "System.String");
                    }

                    instanceOfScalarProperty.Type = (DomainType)domainType;
                }
            }
        }
Пример #7
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.
                }
            }
        }
Пример #8
0
 private static void CustomWritePropertiesAsElements(SerializationContext context, ScalarProperty element, XmlWriter writer)
 {
     if (!context.Result.Failed)
     {
         element.KeyAttribute.SerializeToXml(writer);
     }
 }
Пример #9
0
        public override void ExecCommand(MenuCommand menuCommand)
        {
            CurrentModelSelection modelSelection = GetCurrentSelectedPersistentType();
            EntityDiagram         entityDiagram  = modelSelection.GetFromSelection <EntityDiagram>(false).Single();

            EntityModel entityModel = entityDiagram.Store.ElementDirectory.FindElements <EntityModel>().Single();

            IEnumerable <Tuple <string, EntityKind> > existingTypeNames =
                entityDiagram.Store.ElementDirectory.FindElements <PersistentType>()
                .Where(item => item.TypeKind.In(PersistentTypeKind.Entity, PersistentTypeKind.Interface, PersistentTypeKind.Structure))
                .Select(item => new Tuple <string, EntityKind>(item.Name, ConvertTypeKind(item.TypeKind)));

            Func <string, EntityKind, PersistentType> findTypeFunc =
                (typeName, typeKind) => entityDiagram.Store.ElementDirectory
                .FindElements <PersistentType>()
                .Where(item => item.Name == typeName && ConvertTypeKind(item.TypeKind) == typeKind)
                .SingleOrDefault();

            FormAddPersistentType.ResultData resultData;
            if (FormAddPersistentType.DialogShow(existingTypeNames, out resultData))
            {
                modelSelection.MakeActionWithinTransaction(string.Format("Add new {0} with name '{1}'", resultData.TypeKind, resultData.TypeName),
                                                           delegate
                {
                    PersistentType newEntity = null;

                    switch (resultData.TypeKind)
                    {
                    case EntityKind.Entity:
                        {
                            newEntity = new Entity(entityModel.Partition);
                            if (resultData.BaseTypeInfo.Item1.HasValue)
                            {
                                Entity entity   = (Entity)newEntity;
                                entity.BaseType = findTypeFunc(resultData.BaseTypeInfo.Item2, resultData.BaseTypeInfo.Item1.Value) as EntityBase;
                            }
                            break;
                        }

                    case EntityKind.Structure:
                        {
                            newEntity = new Structure(entityModel.Partition);
                            if (resultData.BaseTypeInfo.Item1.HasValue)
                            {
                                Structure structure = (Structure)newEntity;
                                structure.BaseType  = findTypeFunc(resultData.BaseTypeInfo.Item2, resultData.BaseTypeInfo.Item1.Value) as EntityBase;
                            }
                            break;
                        }

                    case EntityKind.Interface:
                        {
                            newEntity = new Interface(entityModel.Partition);
                            if (resultData.BaseTypeInfo.Item1.HasValue)
                            {
                                Interface @interface    = (Interface)newEntity;
                                Interface baseInterface = findTypeFunc(resultData.BaseTypeInfo.Item2, resultData.BaseTypeInfo.Item1.Value) as Interface;
                                @interface.InheritedInterfaces.Add(baseInterface);
                            }
                            break;
                        }
                    }

                    newEntity.Name = resultData.TypeName;
                    entityModel.PersistentTypes.Add(newEntity);

                    // create key property
                    if (resultData.KeyPropertyInfo.Item1)
                    {
                        var newProperty  = new ScalarProperty(newEntity.Partition);
                        newProperty.Name = resultData.KeyPropertyInfo.Item2;
                        newProperty.KeyAttribute.Enabled = true;
                        Guid typeId      = SystemPrimitiveTypesConverter.GetTypeId(resultData.KeyPropertyInfo.Item3);
                        newProperty.Type = (DomainType)entityModel.GetDomainType(typeId);
                        newEntity.Properties.Add(newProperty);
                    }

                    Owner.SelectModelElement((ModelElement)newEntity);
                });
            }
        }