コード例 #1
0
        /// <exclude />
        public bool Equals(DataTypeAssociationDescriptor dataTypeAssociationDescriptor)
        {
            if (dataTypeAssociationDescriptor == null)
            {
                return(false);
            }

            return
                (this.AssociatedInterfaceType == dataTypeAssociationDescriptor.AssociatedInterfaceType &&
                 this.ForeignKeyPropertyName == dataTypeAssociationDescriptor.ForeignKeyPropertyName &&
                 this.AssociationType == dataTypeAssociationDescriptor.AssociationType);
        }
コード例 #2
0
ファイル: DataTypeDescriptor.cs プロジェクト: wwl2013/C1-CMS
        internal static DataTypeDescriptor FromXml(XElement element, bool inheritedFieldsIncluded)
        {
            Verify.ArgumentNotNull(element, "element");
            if (element.Name != "DataTypeDescriptor")
            {
                throw new ArgumentException("The xml is not correctly formatted.");
            }


            Guid   dataTypeId = (Guid)element.GetRequiredAttribute("dataTypeId");
            string name       = element.GetRequiredAttributeValue("name");
            string @namespace = element.GetRequiredAttributeValue("namespace");

            // TODO: check why "hasCustomPhysicalSortOrder"  is not used
            bool hasCustomPhysicalSortOrder = (bool)element.GetRequiredAttribute("hasCustomPhysicalSortOrder");

            bool       isCodeGenerated   = (bool)element.GetRequiredAttribute("isCodeGenerated");
            XAttribute cachableAttribute = element.Attribute("cachable");
            XAttribute buildNewHandlerTypeNameAttribute = element.Attribute("buildNewHandlerTypeName");
            XElement   dataAssociationsElement          = element.GetRequiredElement("DataAssociations");
            XElement   dataScopesElement       = element.GetRequiredElement("DataScopes");
            XElement   keyPropertyNamesElement = element.GetRequiredElement("KeyPropertyNames");
            // TODO: check why "superInterfaceKeyPropertyNamesElement" is not used
            // XElement superInterfaceKeyPropertyNamesElement = element.Element("SuperInterfaceKeyPropertyNames");
            XElement superInterfacesElement = element.GetRequiredElement("SuperInterfaces");
            XElement fieldsElement          = element.GetRequiredElement("Fields");
            XElement indexesElement         = element.Element("Indexes");

            XAttribute titleAttribute             = element.Attribute("title");
            XAttribute labelFieldNameAttribute    = element.Attribute("labelFieldName");
            XAttribute internalUrlPrefixAttribute = element.Attribute("internalUrlPrefix");
            string     typeManagerTypeName        = (string)element.Attribute("typeManagerTypeName");

            bool cachable = cachableAttribute != null && (bool)cachableAttribute;

            var dataTypeDescriptor = new DataTypeDescriptor(dataTypeId, @namespace, name, isCodeGenerated)
            {
                Cachable = cachable
            };

            if (titleAttribute != null)
            {
                dataTypeDescriptor.Title = titleAttribute.Value;
            }
            if (labelFieldNameAttribute != null)
            {
                dataTypeDescriptor.LabelFieldName = labelFieldNameAttribute.Value;
            }
            if (internalUrlPrefixAttribute != null)
            {
                dataTypeDescriptor.InternalUrlPrefix = internalUrlPrefixAttribute.Value;
            }
            if (typeManagerTypeName != null)
            {
                typeManagerTypeName = TypeManager.FixLegasyTypeName(typeManagerTypeName);
                dataTypeDescriptor.TypeManagerTypeName = typeManagerTypeName;
            }
            if (buildNewHandlerTypeNameAttribute != null)
            {
                dataTypeDescriptor.BuildNewHandlerTypeName = buildNewHandlerTypeNameAttribute.Value;
            }


            foreach (XElement elm in dataAssociationsElement.Elements())
            {
                var dataTypeAssociationDescriptor = DataTypeAssociationDescriptor.FromXml(elm);

                dataTypeDescriptor.DataAssociations.Add(dataTypeAssociationDescriptor);
            }

            foreach (XElement elm in dataScopesElement.Elements("DataScopeIdentifier"))
            {
                string dataScopeName = elm.GetRequiredAttributeValue("name");
                if (DataScopeIdentifier.IsLegasyDataScope(dataScopeName))
                {
                    Log.LogWarning("DataTypeDescriptor", "Ignored legacy data scope '{0}' on type '{1}.{2}' while deserializing DataTypeDescriptor. The '{0}' data scope is no longer supported.".FormatWith(dataScopeName, @namespace, name));
                    continue;
                }

                DataScopeIdentifier dataScopeIdentifier = DataScopeIdentifier.Deserialize(dataScopeName);

                dataTypeDescriptor.DataScopes.Add(dataScopeIdentifier);
            }

            foreach (XElement elm in superInterfacesElement.Elements("SuperInterface"))
            {
                string superInterfaceTypeName = elm.GetRequiredAttributeValue("type");

                if (superInterfaceTypeName.StartsWith("Composite.Data.ProcessControlled.IDeleteControlled"))
                {
                    Log.LogWarning("DataTypeDescriptor", string.Format("Ignored legacy super interface '{0}' on type '{1}.{2}' while deserializing DataTypeDescriptor. This super interface is no longer supported.", superInterfaceTypeName, @namespace, name));
                    continue;
                }

                Type superInterface;

                try
                {
                    superInterface = TypeManager.GetType(superInterfaceTypeName);
                }
                catch (Exception ex)
                {
                    throw XmlConfigurationExtensionMethods.GetConfigurationException("Failed to load super interface '{0}'".FormatWith(superInterfaceTypeName), ex, elm);
                }

                dataTypeDescriptor.AddSuperInterface(superInterface, !inheritedFieldsIncluded);
            }

            foreach (XElement elm in fieldsElement.Elements())
            {
                var dataFieldDescriptor = DataFieldDescriptor.FromXml(elm);

                try
                {
                    dataTypeDescriptor.Fields.Add(dataFieldDescriptor);
                }
                catch (Exception ex)
                {
                    throw XmlConfigurationExtensionMethods.GetConfigurationException("Failed to add a data field: " + ex.Message, ex, elm);
                }
            }

            foreach (XElement elm in keyPropertyNamesElement.Elements("KeyPropertyName"))
            {
                var propertyName = elm.GetRequiredAttributeValue("name");

                bool isDefinedOnSuperInterface = dataTypeDescriptor.SuperInterfaces.Any(f => f.GetProperty(propertyName) != null);
                if (!isDefinedOnSuperInterface)
                {
                    dataTypeDescriptor.KeyPropertyNames.Add(propertyName);
                }
            }

            if (indexesElement != null)
            {
                dataTypeDescriptor.Indexes = indexesElement.Elements("Index").Select(DataTypeIndex.FromXml).ToList();
            }

            // Loading field rendering profiles for static data types
            if (!isCodeGenerated && typeManagerTypeName != null)
            {
                Type type = Type.GetType(typeManagerTypeName);
                if (type != null)
                {
                    foreach (var fieldDescriptor in dataTypeDescriptor.Fields)
                    {
                        var property = type.GetProperty(fieldDescriptor.Name);

                        if (property != null)
                        {
                            var formRenderingProfile = DynamicTypeReflectionFacade.GetFormRenderingProfile(property);
                            if (formRenderingProfile != null)
                            {
                                fieldDescriptor.FormRenderingProfile = formRenderingProfile;
                            }
                        }
                    }
                }
            }


            return(dataTypeDescriptor);
        }
コード例 #3
0
        private DataTypeDescriptor CreateNewDataTypeDescriptor(
            string typeNamespace,
            string typeName,
            string typeTitle,
            string labelFieldName,
            string internalUrlPrefix,
            bool cachable,
            bool publishControlled,
            bool localizedControlled,
            IEnumerable<DataFieldDescriptor> dataFieldDescriptors,
            DataFieldDescriptor foreignKeyDataFieldDescriptor,
            DataTypeAssociationDescriptor dataTypeAssociationDescriptor,
            DataFieldDescriptor compositionRuleForeignKeyDataFieldDescriptor)
        {
            Guid id = Guid.NewGuid();
            var dataTypeDescriptor = new DataTypeDescriptor(id, typeNamespace, typeName, true)
            {
                Cachable = cachable,
                Title = typeTitle,
                LabelFieldName = labelFieldName,
                InternalUrlPrefix = internalUrlPrefix
            };

            dataTypeDescriptor.DataScopes.Add(DataScopeIdentifier.Public);

            if (publishControlled && _dataAssociationType != DataAssociationType.Composition)
            {
                dataTypeDescriptor.AddSuperInterface(typeof(IPublishControlled));
            }

            if (localizedControlled)
            {
                dataTypeDescriptor.AddSuperInterface(typeof(ILocalizedControlled));
            }

            //bool addKeyField = true;
            if (_dataAssociationType == DataAssociationType.Aggregation)
            {
                dataTypeDescriptor.AddSuperInterface(typeof(IPageDataFolder));
            }
            else if (_dataAssociationType == DataAssociationType.Composition)
            {
                //addKeyField = false;
                dataTypeDescriptor.AddSuperInterface(typeof(IPageData));
                dataTypeDescriptor.AddSuperInterface(typeof(IPageRelatedData));
                dataTypeDescriptor.AddSuperInterface(typeof(IPageMetaData));
            }

            //if (addKeyField)
            //{
            //    var idDataFieldDescriptor = BuildKeyFieldDescriptor();

            //    dataTypeDescriptor.Fields.Add(idDataFieldDescriptor);
            //    dataTypeDescriptor.KeyPropertyNames.Add(IdFieldName);
            //}

            foreach (DataFieldDescriptor dataFieldDescriptor in dataFieldDescriptors)
            {
                dataTypeDescriptor.Fields.Add(dataFieldDescriptor);
            }

            if (_newKeyFieldName != null)
            {
                dataTypeDescriptor.KeyPropertyNames.Add(_newKeyFieldName);
            }

            int position = 100;
            if (_foreignKeyDataFieldDescriptor != null)
            {
                _foreignKeyDataFieldDescriptor.Position = position++;

                if (foreignKeyDataFieldDescriptor.Name != PageReferenceFieldName)
                {
                    dataTypeDescriptor.Fields.Add(foreignKeyDataFieldDescriptor);
                    dataTypeDescriptor.DataAssociations.Add(dataTypeAssociationDescriptor);
                }
            }


            return dataTypeDescriptor;
        }
コード例 #4
0
        /// <exclude />
        public void SetForeignKeyReference(DataTypeDescriptor targetDataTypeDescriptor, DataAssociationType dataAssociationType)
        {
            if (dataAssociationType == DataAssociationType.None) throw new ArgumentException("dataAssociationType");

            if ((dataAssociationType == DataAssociationType.Aggregation || dataAssociationType == DataAssociationType.Composition)
                && _pageMetaDataDescriptionForeignKeyDataFieldDescriptor != null)
            {
                throw new InvalidOperationException("The type already has a foreign key reference");
            }


            Type targetType = TypeManager.GetType(targetDataTypeDescriptor.TypeManagerTypeName);
            string fieldName = null;
            if (targetType == typeof(IPage))
            {
                fieldName = PageReferenceFieldName;
                _dataAssociationType = dataAssociationType;
            }

            string foreignKeyFieldName;
            _foreignKeyDataFieldDescriptor = CreateReferenceDataFieldDescriptor(targetDataTypeDescriptor, out foreignKeyFieldName, fieldName);

            if (dataAssociationType != DataAssociationType.None)
            {
                _dataTypeAssociationDescriptor = new DataTypeAssociationDescriptor(
                        targetType,
                        foreignKeyFieldName,
                        dataAssociationType
                    );
            }

            if (dataAssociationType == DataAssociationType.Composition)
            {
                DataTypeDescriptor compositionRuleDataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(typeof(IPageMetaDataDefinition));

                _pageMetaDataDescriptionForeignKeyDataFieldDescriptor = CreateWeakReferenceDataFieldDescriptor(compositionRuleDataTypeDescriptor, compositionRuleDataTypeDescriptor.Fields["Name"], CompositionDescriptionFieldName);
            }
        }
コード例 #5
0
        /// <exclude />
        public bool Equals(DataTypeAssociationDescriptor dataTypeAssociationDescriptor)
        {
            if (dataTypeAssociationDescriptor == null) return false;

            return
                this.AssociatedInterfaceType == dataTypeAssociationDescriptor.AssociatedInterfaceType &&
                this.ForeignKeyPropertyName == dataTypeAssociationDescriptor.ForeignKeyPropertyName &&
                this.AssociationType == dataTypeAssociationDescriptor.AssociationType;
        }