예제 #1
0
        private static IModelRoot GetEntityModel(ITypeDescriptorContext context)
        {
            ModelElement element     = context.Instance as ModelElement;
            IModelRoot   entityModel = element.Store.GetEntityModel();

            return(entityModel);
        }
예제 #2
0
        private void Build(IModelRoot modelRoot)
        {
            var inheritanceTrees = InheritanceTreeCache.Get(modelRoot.TopHierarchyTypes.ToArray());

            foreach (var tree in inheritanceTrees)
            {
                if (!tree.TreeRebuilded)
                {
                    tree.RebuildTree(true);
                }
            }
            var mergePaths = InheritanceTree.MergePaths(inheritanceTrees);
            var dependencyImplementationFlatList = InheritanceTree.GetDependencyImplementationFlatList(mergePaths);

            foreach (var @interface in dependencyImplementationFlatList)
            {
                IPropertiesBuilder propertiesBuilder = PropertiesBuilder.Build(@interface);
                lock (sync)
                {
                    propertiesBuilders.Add(@interface, propertiesBuilder);
                }
            }

            // process rest types (e.g. with no inheritance defined)
            foreach (var @interface in modelRoot.PersistentTypes.Except(dependencyImplementationFlatList))
            {
                IPropertiesBuilder propertiesBuilder = PropertiesBuilder.Build(@interface);
                lock (sync)
                {
                    propertiesBuilders.Add(@interface, propertiesBuilder);
                }
            }
        }
예제 #3
0
        private bool ScalarProperty_ReadPropertiesFromAttributes(SerializationContext serializationContext,
                                                                 ScalarProperty scalarProperty, XmlReader reader)
        {
            // Type
            if (!serializationContext.Result.Failed)
            {
                string attribType = DONetEntityModelDesignerSerializationHelper.Instance.ReadAttribute(serializationContext, scalarProperty, 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 = scalarProperty.Store.GetEntityModel();
                        IDomainType domainType  = entityModel.GetDomainType(typeId);
                        if (domainType == null)
                        {
                            domainType =
                                entityModel.BuildInDomainTypes.SingleOrDefault(type => type.FullName == "System.String");
                        }

                        scalarProperty.Type = (DomainType)domainType;

                        return(true);
                    }
                    else
                    {   // Invalid property value, ignored.
                        EntityModelDesignerSerializationBehaviorSerializationMessages.IgnoredPropertyValue(serializationContext, reader, "type", typeof(global::System.String), attribType);
                    }
                }
            }

            return(false);
        }
예제 #4
0
        public ScalarProperty AddScalarProperty(string name, Type type)
        {
            Guid        typeId      = SystemPrimitiveTypesConverter.GetTypeId(type);
            IDomainType domainType  = null;
            IModelRoot  entityModel = this.Store.GetEntityModel();

            if (typeId != default(Guid))
            {
                domainType = entityModel.GetDomainType(typeId);
            }
            else
            {
                domainType = entityModel.DomainTypes.SingleOrDefault(item => item.FullName == type.FullName);
            }

            if (domainType != null)
            {
                return(AddScalarProperty(name, (DomainType)domainType));
            }

            throw new ArgumentOutOfRangeException("type is not registered as Domain Type!");
        }
예제 #5
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;
                }
            }
        }
예제 #6
0
 public static void Initialize(IModelRoot modelRoot)
 {
     current = new PropertiesBuilderContext();
     current.Build(modelRoot);
 }