public static List <Type> GetAssociationTypes(Type associatedType, DataAssociationType dataAssociationType) { if (associatedType == null) { throw new ArgumentNullException("associatedType"); } if (dataAssociationType == DataAssociationType.None) { throw new ArgumentException(string.Format("dataAssociationType may not be '{0}", DataAssociationType.None)); } using (GlobalInitializerFacade.CoreIsInitializedScope) { List <Type> associationTypes; if (!_associatedTypes.TryGetValue(associatedType, out associationTypes)) { return(new List <Type>()); } return ((from t1 in associationTypes from info in _dataAssociations[t1].Values where info.AssociationType == dataAssociationType select t1).ToList()); } }
/// <summary> /// Defines an object association. /// </summary> /// <param name="name">Name of forward association to create.</param> /// <param name="type">Type of this association.</param> /// <param name="info1">Describes object identifier 1 in an association.</param> /// <param name="info2">Describes object identifier 2 in an association.</param> /// <param name="inverse">(Optional) Name of backward association, if this is a two-way asymmetric one.</param> public void DefineAssociation(string name, DataAssociationType type, DataAssociationInfo info1, DataAssociationInfo info2, string inverse) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } string info1Alias = info1.Alias; string info2Alias = info2.Alias; CheckDataName(ref name); CheckDataName(ref info1Alias); CheckDataName(ref info2Alias); var info1Prop = new Dictionary<string, string> {{"alias", info1Alias}}; AddParameter(info1Prop, "object_type", info1.ObjectType); if (info1.Unique) info1Prop.Add("unique", info1.Unique.ToString().ToLowerInvariant()); var info2Prop = new Dictionary<string, string> {{"alias", info2Alias}}; AddParameter(info2Prop, "object_type", info2.ObjectType); if (info2.Unique) info2Prop.Add("unique", info2.Unique.ToString().ToLowerInvariant()); var query = new Dictionary<string, string>(6) { {"method", "facebook.data.defineAssociation"}, {"name", name}, {"assoc_type", ((int) type).ToString()}, {"assoc_info1", ToJsonAssociativeArray(info1Prop)}, {"assoc_info2", ToJsonAssociativeArray(info2Prop)} }; AddParameter(query, "inverse ", inverse); ExecuteApiCall(query, true); }
/// <exclude /> public void SetForeignKeyReference(Type targetDataType, DataAssociationType dataAssociationType) { if (dataAssociationType == DataAssociationType.None) throw new ArgumentException("dataAssociationType"); DataTypeDescriptor targetDataTypeDescriptor = DynamicTypeManager.GetDataTypeDescriptor(targetDataType); SetForeignKeyReference(targetDataTypeDescriptor, dataAssociationType); }
/// <summary> /// Defines an object association. /// </summary> /// <param name="name">Name of forward association to create.</param> /// <param name="type">Type of this association.</param> /// <param name="info1">Describes object identifier 1 in an association.</param> /// <param name="info2">Describes object identifier 2 in an association.</param> /// <param name="inverse">(Optional) Name of backward association, if this is a two-way asymmetric one.</param> public void DefineAssociation(string name, DataAssociationType type, DataAssociationInfo info1, DataAssociationInfo info2, string inverse) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } string info1Alias = info1.Alias; string info2Alias = info2.Alias; CheckDataName(ref name); CheckDataName(ref info1Alias); CheckDataName(ref info2Alias); var info1Prop = new Dictionary <string, string> { { "alias", info1Alias } }; AddParameter(info1Prop, "object_type", info1.ObjectType); if (info1.Unique) { info1Prop.Add("unique", info1.Unique.ToString().ToLowerInvariant()); } var info2Prop = new Dictionary <string, string> { { "alias", info2Alias } }; AddParameter(info2Prop, "object_type", info2.ObjectType); if (info2.Unique) { info2Prop.Add("unique", info2.Unique.ToString().ToLowerInvariant()); } var query = new Dictionary <string, string>(6) { { "method", "facebook.data.defineAssociation" }, { "name", name }, { "assoc_type", ((int)type).ToString() }, { "assoc_info1", ToJsonAssociativeArray(info1Prop) }, { "assoc_info2", ToJsonAssociativeArray(info2Prop) } }; AddParameter(query, "inverse ", inverse); ExecuteApiCall(query, true); }
public static IEnumerable<string> GetForeignKeyPropertyNames(this Type associationType, DataAssociationType dataAssociationType) { Verify.ArgumentNotNull(associationType, "associationType"); using (GlobalInitializerFacade.CoreIsInitializedScope) { Dictionary<Type, DataAssociationInfo> dataAssociationInfos; if (!_dataAssociations.TryGetValue(associationType, out dataAssociationInfos)) { return Enumerable.Empty<string>(); } return from info in dataAssociationInfos.Values where info.AssociationType == dataAssociationType select info.ForeignKeyPropertyName; } }
/// <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); } }
/// <exclude /> public static DataTypeAssociationDescriptor FromXml(XElement element) { if (element.Name != "DataTypeAssociationDescriptor") { throw new ArgumentException("The xml is not correctly formattet"); } XAttribute associatedInterfaceTypeAttribute = element.Attribute("associatedInterfaceType"); XAttribute foreignKeyPropertyNameAttribute = element.Attribute("foreignKeyPropertyName"); XAttribute associationTypeAttribute = element.Attribute("associationType"); if ((associatedInterfaceTypeAttribute == null) || (foreignKeyPropertyNameAttribute == null) || (associatedInterfaceTypeAttribute == null)) { throw new ArgumentException("The xml is not correctly formattet"); } Type associatedInterfaceType = TypeManager.GetType(associatedInterfaceTypeAttribute.Value); string foreignKeyPropertyName = foreignKeyPropertyNameAttribute.Value; DataAssociationType dataAssociationType = (DataAssociationType)Enum.Parse(typeof(DataAssociationType), associationTypeAttribute.Value); return(new DataTypeAssociationDescriptor(associatedInterfaceType, foreignKeyPropertyName, dataAssociationType)); }
public static List <Type> GetAssociatedTypes(Type associationType, DataAssociationType dataAssociationType) { Verify.ArgumentNotNull(associationType, "associationType"); if (dataAssociationType == DataAssociationType.None) { throw new ArgumentException(string.Format("dataAssociationType may not be '{0}", DataAssociationType.None)); } using (GlobalInitializerFacade.CoreIsInitializedScope) { Dictionary <Type, DataAssociationInfo> dataAssociations; if (!_dataAssociations.TryGetValue(associationType, out dataAssociations)) { throw new InvalidOperationException(string.Format("Type type '{0}' is not an association type", associationType)); } return ((from info in dataAssociations where info.Value.AssociationType == dataAssociationType select info.Key).ToList()); } }
/// <exclude /> public DataAssociationAttribute(Type associatedInterfaceType, string foreignKeyPropertyName, DataAssociationType dataAssociationType) { this.AssociatedInterfaceType = associatedInterfaceType; this.ForeignKeyPropertyName = foreignKeyPropertyName; this.AssociationType = dataAssociationType; }
/// <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); } }
public static List<Type> GetAssociationTypes(Type associatedType, DataAssociationType dataAssociationType) { if (associatedType == null) throw new ArgumentNullException("associatedType"); if (dataAssociationType == DataAssociationType.None) throw new ArgumentException(string.Format("dataAssociationType may not be '{0}", DataAssociationType.None)); using (GlobalInitializerFacade.CoreIsInitializedScope) { List<Type> associationTypes; if (!_associatedTypes.TryGetValue(associatedType, out associationTypes)) { return new List<Type>(); } return (from t1 in associationTypes from info in _dataAssociations[t1].Values where info.AssociationType == dataAssociationType select t1).ToList(); } }
public static IEnumerable <string> GetForeignKeyPropertyNames(this Type associationType, DataAssociationType dataAssociationType) { Verify.ArgumentNotNull(associationType, "associationType"); using (GlobalInitializerFacade.CoreIsInitializedScope) { Dictionary <Type, DataAssociationInfo> dataAssociationInfos; if (!_dataAssociations.TryGetValue(associationType, out dataAssociationInfos)) { return(Enumerable.Empty <string>()); } return(from info in dataAssociationInfos.Values where info.AssociationType == dataAssociationType select info.ForeignKeyPropertyName); } }
public static List<Type> GetAssociatedTypes(Type associationType, DataAssociationType dataAssociationType) { Verify.ArgumentNotNull(associationType, "associationType"); if (dataAssociationType == DataAssociationType.None) throw new ArgumentException(string.Format("dataAssociationType may not be '{0}", DataAssociationType.None)); using (GlobalInitializerFacade.CoreIsInitializedScope) { Dictionary<Type, DataAssociationInfo> dataAssociations; if (!_dataAssociations.TryGetValue(associationType, out dataAssociations)) { throw new InvalidOperationException(string.Format("Type type '{0}' is not an association type", associationType)); } return (from info in dataAssociations where info.Value.AssociationType == dataAssociationType select info.Key).ToList(); } }
/// <exclude /> public DataTypeAssociationDescriptor(Type associatedInterfaceType, string foreignKeyPropertyName, DataAssociationType dataAssociationType) { this.AssociatedInterfaceType = associatedInterfaceType; this.ForeignKeyPropertyName = foreignKeyPropertyName; this.AssociationType = dataAssociationType; }