private void Initialize() { if (_oldDataTypeDescriptor.DataAssociations.Count > 0) { DataTypeAssociationDescriptor dataTypeAssociationDescriptor = _oldDataTypeDescriptor.DataAssociations.Single(); _associatedType = dataTypeAssociationDescriptor.AssociatedInterfaceType; } foreach (DataFieldDescriptor dataFieldDescriptor in _oldDataTypeDescriptor.Fields) { if (dataFieldDescriptor.ForeignKeyReferenceTypeName != null) { if (_associatedType != null) { string associatedTypeTypeName = TypeManager.SerializeType(_associatedType); if (dataFieldDescriptor.ForeignKeyReferenceTypeName == associatedTypeTypeName) { _foreignKeyDataFieldDescriptor = dataFieldDescriptor; } } } if (dataFieldDescriptor.Name == CompositionDescriptionFieldName) { _pageMetaDataDescriptionForeignKeyDataFieldDescriptor = dataFieldDescriptor; } } _publishControlled = this.IsPublishControlled; _localizedControlled = this.IsLocalizedControlled; }
public static List <DataTypeAssociationDescriptor> GetDataTypeAssociationDescriptorsRecursively(Type interfaceType) { var result = new List <DataTypeAssociationDescriptor>(); List <DataAssociationAttribute> attributes = interfaceType.GetCustomAttributesRecursively <DataAssociationAttribute>().ToList(); foreach (DataAssociationAttribute attribute in attributes) { var dataTypeAssociationDescriptor = new DataTypeAssociationDescriptor(attribute.AssociatedInterfaceType, attribute.ForeignKeyPropertyName, attribute.AssociationType); if (!result.Contains(dataTypeAssociationDescriptor)) { result.Add(dataTypeAssociationDescriptor); } } return(result); }
private bool IsDataFieldBindable(DataTypeDescriptor dataTypeDescriptor, DataFieldDescriptor dataFieldDescriptor) { if (dataFieldDescriptor.Inherited) { Type superInterface = dataTypeDescriptor.SuperInterfaces.FirstOrDefault(type => type.GetProperty(dataFieldDescriptor.Name) != null); if (superInterface != null && superInterface.Assembly == typeof(IData).Assembly) { return(false); } } if ((dataFieldDescriptor.Name == IdFieldName || dataFieldDescriptor.Name == CompositionDescriptionFieldName) && dataTypeDescriptor.IsPageMetaDataType) { return(false); } if (PageFolderFacade.GetAllFolderTypes().Contains(this._oldType) && dataFieldDescriptor.Name == PageReferenceFieldName) { return(false); } if (dataFieldDescriptor.ForeignKeyReferenceTypeName != null) { DataTypeAssociationDescriptor dataTypeAssociationDescriptor = dataTypeDescriptor.DataAssociations.FirstOrDefault(); if (dataTypeAssociationDescriptor != null) { if (!this.AllowForeignKeyEditing && dataFieldDescriptor.Name == dataTypeAssociationDescriptor.ForeignKeyPropertyName) { return(false); } if (dataFieldDescriptor.Name == CompositionDescriptionFieldName && dataTypeDescriptor.IsPageMetaDataType) { return(false); } } } return(true); }
/// <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); } }
private DataTypeDescriptor CreateNewDataTypeDescriptor( string typeNamespace, string typeName, string typeTitle, string labelFieldName, string internalUrlPrefix, bool cachable, bool searchable, bool publishControlled, bool localizedControlled, IEnumerable <DataFieldDescriptor> dataFieldDescriptors, DataFieldDescriptor foreignKeyDataFieldDescriptor, DataTypeAssociationDescriptor dataTypeAssociationDescriptor, DataFieldDescriptor compositionRuleForeignKeyDataFieldDescriptor) { var id = Guid.NewGuid(); var dataTypeDescriptor = new DataTypeDescriptor(id, typeNamespace, typeName, true) { Cachable = cachable, Searchable = searchable, 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 (var dataFieldDescriptor in dataFieldDescriptors) { dataTypeDescriptor.Fields.Add(dataFieldDescriptor); } if (_newKeyFieldName != null) { dataTypeDescriptor.KeyPropertyNames.Add(_newKeyFieldName); } var position = 100; if (_foreignKeyDataFieldDescriptor != null) { _foreignKeyDataFieldDescriptor.Position = position++; if (foreignKeyDataFieldDescriptor.Name != PageReferenceFieldName) { dataTypeDescriptor.Fields.Add(foreignKeyDataFieldDescriptor); dataTypeDescriptor.DataAssociations.Add(dataTypeAssociationDescriptor); } } return(dataTypeDescriptor); }