AddSuperInterface() public method

Adds an interface the data type should inherit from
public AddSuperInterface ( Type interfaceType ) : void
interfaceType System.Type
return void
Esempio n. 1
0
        /// <summary>
        /// Clones the data type description.
        /// </summary>
        /// <returns>A clone</returns>
        public DataTypeDescriptor Clone()
        {
            var dataTypeDescriptor = new DataTypeDescriptor(this.DataTypeId, this.Namespace, this.Name, this.TypeManagerTypeName, this.IsCodeGenerated)
            {
                Title = this.Title,
                BuildNewHandlerTypeName = this.BuildNewHandlerTypeName,
                LabelFieldName          = this.LabelFieldName,
                InternalUrlPrefix       = this.InternalUrlPrefix,
                Searchable = this.Searchable
            };

            foreach (DataTypeAssociationDescriptor dataTypeAssociationDescriptor in this.DataAssociations)
            {
                dataTypeDescriptor.DataAssociations.Add(dataTypeAssociationDescriptor.Clone());
            }

            dataTypeDescriptor.DataScopes = new List <DataScopeIdentifier>(this.DataScopes);

            foreach (DataFieldDescriptor dataFieldDescriptor in this.Fields)
            {
                if (!dataFieldDescriptor.Inherited)
                {
                    dataTypeDescriptor.Fields.Add(dataFieldDescriptor.Clone());
                }
            }


            foreach (string keyPropertyName in this.KeyPropertyNames)
            {
                dataTypeDescriptor.KeyPropertyNames.Add(keyPropertyName, false);
            }

            foreach (string storeSortOrderFieldNames in this.StoreSortOrderFieldNames)
            {
                dataTypeDescriptor.StoreSortOrderFieldNames.Add(storeSortOrderFieldNames, false);
            }

            foreach (Type superInterface in this.SuperInterfaces)
            {
                dataTypeDescriptor.AddSuperInterface(superInterface);
            }

            return(dataTypeDescriptor);
        }
Esempio n. 2
0
        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");

            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");
            XElement versionKeyPropertyNamesElement = element.Element("VersionKeyPropertyNames");
            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(LogTitle, "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(LogTitle, $"Ignored legacy super interface '{superInterfaceTypeName}' on type '{@namespace}.{name}' while deserializing DataTypeDescriptor. This super interface is no longer supported.");
                    continue;
                }
                
                Type superInterface;

                try
                {
                    superInterface = TypeManager.GetType(superInterfaceTypeName);
                }
                catch (Exception ex)
                {
                    throw XmlConfigurationExtensionMethods.GetConfigurationException($"Failed to load super interface '{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 (versionKeyPropertyNamesElement != null)
            {
                foreach (XElement elm in versionKeyPropertyNamesElement.Elements("VersionKeyPropertyName"))
                {
                    var propertyName = elm.GetRequiredAttributeValue("name");

                    dataTypeDescriptor.VersionKeyPropertyNames.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;
        }
Esempio n. 3
0
        /// <summary>
        /// Clones the data type description.
        /// </summary>
        /// <returns>A clone</returns>
        public DataTypeDescriptor Clone()
        {
            var dataTypeDescriptor = new DataTypeDescriptor(this.DataTypeId, this.Namespace, this.Name, this.TypeManagerTypeName, this.IsCodeGenerated)
            {
                Title = this.Title,
                BuildNewHandlerTypeName = this.BuildNewHandlerTypeName,
                LabelFieldName = this.LabelFieldName,
                InternalUrlPrefix = this.InternalUrlPrefix,
            };

            foreach (DataTypeAssociationDescriptor dataTypeAssociationDescriptor in this.DataAssociations)
            {
                dataTypeDescriptor.DataAssociations.Add(dataTypeAssociationDescriptor.Clone());
            }

            dataTypeDescriptor.DataScopes = new List<DataScopeIdentifier>(this.DataScopes);

            foreach (DataFieldDescriptor dataFieldDescriptor in this.Fields)
            {
                if (!dataFieldDescriptor.Inherited)
                {
                    dataTypeDescriptor.Fields.Add(dataFieldDescriptor.Clone());
                }
            }


            foreach (string keyPropertyName in this.KeyPropertyNames)
            {
                dataTypeDescriptor.KeyPropertyNames.Add(keyPropertyName, false);
            }

            foreach (string storeSortOrderFieldNames in this.StoreSortOrderFieldNames)
            {
                dataTypeDescriptor.StoreSortOrderFieldNames.Add(storeSortOrderFieldNames, false);
            }

            foreach (Type superInterface in this.SuperInterfaces)
            {
                dataTypeDescriptor.AddSuperInterface(superInterface);
            }

            return dataTypeDescriptor;
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        //private DataFieldDescriptor BuildKeyFieldDescriptor()
        //{
        //    DataFieldDescriptor result;

        //    switch (_keyFieldType)
        //    {
        //        case KeyFieldType.Guid:
        //            result = BuildIdField();
        //            break;
        //        case KeyFieldType.RandomString4:
        //            result = new DataFieldDescriptor(Guid.NewGuid(), IdFieldName, StoreFieldType.String(22), typeof (string))
        //            {
        //                DefaultValue = DefaultValue.RandomString(4, true)
        //            };
        //            break;
        //        case KeyFieldType.RandomString8:
        //            result = new DataFieldDescriptor(Guid.NewGuid(), IdFieldName, StoreFieldType.String(22), typeof (string))
        //            {
        //                DefaultValue = DefaultValue.RandomString(8, false)
        //            };
        //            break;
        //        default: throw new InvalidOperationException("Not supported key field type value");
        //    }

        //    result.Position = -1;

        //    return result;
        //}


        private DataTypeDescriptor CreateUpdatedDataTypeDescriptor()
        {
            var dataTypeDescriptor = new DataTypeDescriptor(_oldDataTypeDescriptor.DataTypeId, _newTypeNamespace, _newTypeName, true);

            dataTypeDescriptor.DataScopes.Add(DataScopeIdentifier.Public);

            dataTypeDescriptor.Cachable = _cachable;


            Type[] indirectlyInheritedInterfaces =
            {
                typeof(IPublishControlled), typeof(ILocalizedControlled), 
                typeof(IPageData), typeof(IPageFolderData), typeof(IPageMetaData)
            };

            // Foreign interfaces should stay inherited
            foreach (var superInterface in _oldDataTypeDescriptor.SuperInterfaces)
            {
                if (!indirectlyInheritedInterfaces.Contains(superInterface))
                {
                    dataTypeDescriptor.AddSuperInterface(superInterface);
                }
            }


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

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


            if (_oldDataTypeDescriptor.SuperInterfaces.Contains(typeof(IPageFolderData)))
            {
                dataTypeDescriptor.AddSuperInterface(typeof(IPageData));
                dataTypeDescriptor.AddSuperInterface(typeof(IPageFolderData));
            }
            else if (_oldDataTypeDescriptor.SuperInterfaces.Contains(typeof(IPageMetaData)))
            {
                dataTypeDescriptor.AddSuperInterface(typeof(IPageData));
                dataTypeDescriptor.AddSuperInterface(typeof(IPageMetaData));
            }
            else
            {
                //DataFieldDescriptor idDataFieldDescriptor =
                //    (from dfd in _oldDataTypeDescriptor.Fields
                //     where dfd.Name == KeyFieldName
                //     select dfd).Single();

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

            dataTypeDescriptor.Title = _newTypeTitle;

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

            if (KeyFieldName != null && !dataTypeDescriptor.KeyPropertyNames.Contains(KeyFieldName))
            {
                dataTypeDescriptor.KeyPropertyNames.Add(KeyFieldName);
            }


            dataTypeDescriptor.LabelFieldName = _newLabelFieldName;
            dataTypeDescriptor.InternalUrlPrefix = _newInternalUrlPrefix;

            dataTypeDescriptor.DataAssociations.AddRange(_oldDataTypeDescriptor.DataAssociations);

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

                if (_foreignKeyDataFieldDescriptor.Name != PageReferenceFieldName)
                {
                    dataTypeDescriptor.Fields.Add(_foreignKeyDataFieldDescriptor);
                }
            }

            return dataTypeDescriptor;
        }
Esempio n. 6
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;
        }