/// <summary> /// Tries to get the <see cref="EtpSupportedDataObject"/> matching the specified <see cref="IDataObjectType"/>. /// </summary> /// <param name="dataObjectType">The type to try to get the matching <see cref="EtpSupportedDataObject"/> for.</param> /// <returns> /// If there is a specific type matching the specified data object type, it is returned. /// Otherwise, if there is a family that matches the specified data object type, it is returned. /// Otherwise, <c>null</c> is returned. /// </returns> public EtpSupportedDataObject TryGetMatchingDataObject(IDataObjectType dataObjectType) { if (dataObjectType == null || !dataObjectType.IsValid || dataObjectType.IsBaseType) { return(null); } EtpSupportedDataObject sessionDataObject; if (!dataObjectType.IsWildcard) { if (SupportedDataObjectsByType.TryGetValue(dataObjectType.Key, out sessionDataObject)) { return(sessionDataObject); } dataObjectType = dataObjectType.ToWildCard(); } if (SupportedDataObjectsByFamily.TryGetValue(dataObjectType.Key, out sessionDataObject)) { return(sessionDataObject); } return(null); }
/// <summary> /// Gets a consistent, version-specific key for this data object type. /// </summary> /// <param name="dataObjectType">The data object type to get the key for.</param> /// <param name="version">The ETP version to get the key for.</param> /// <returns>The version-specific key.</returns> public static string ToVersionKey(this IDataObjectType dataObjectType, EtpVersion version) { switch (version) { case EtpVersion.v11: return(dataObjectType.ContentType.ToString()); case EtpVersion.v12: return(dataObjectType.DataObjectType.ToString()); default: return(null); } }
/// <summary> /// Converts a data object type to a wildcard matching its entire family. /// </summary> /// <param name="dataObjectType">The data object type to convert.</param> /// <returns>The converted data object type.</returns> public static IDataObjectType ToWildCard(this IDataObjectType dataObjectType) { if (dataObjectType == null || !dataObjectType.IsValid || string.IsNullOrEmpty(dataObjectType.Family) || string.IsNullOrEmpty(dataObjectType.Version)) { return(null); } if (dataObjectType.IsWildcard) { return(dataObjectType); } return(new EtpDataObjectType(dataObjectType.Family, dataObjectType.Version, "*")); }
/// <summary> /// Checks if the specified data object types have matching families and versions. /// </summary> /// <param name="dataObjectType">The data object type to compare.</param> /// <param name="otherDataObjectType">The data object type to compare against.</param> /// <returns><c>true</c> if the data object type matches the other data object type; <c>false</c> otherwise.</returns> public static bool MatchesFamilyAndVersion(this IDataObjectType dataObjectType, IDataObjectType otherDataObjectType) { if (dataObjectType == null && otherDataObjectType == null) { return(true); } if (dataObjectType == null || otherDataObjectType == null) { return(false); } var familyMatches = StringMatches(dataObjectType.Family, otherDataObjectType.Family); var versionMatches = StringMatches(dataObjectType.Version, otherDataObjectType.Version); return(familyMatches && versionMatches); }
/// <summary> /// Checks if the specified data object type exactly matches the other data object type. With exact matches, wildcards /// only match other wildcards, not specific data object types. /// </summary> /// <param name="dataObjectType">The data object type to compare.</param> /// <param name="otherDataObjectType">The data object type to compare against.</param> /// <returns><c>true</c> if the data object type matches the other data object type; <c>false</c> otherwise.</returns> public static bool MatchesExact(this IDataObjectType dataObjectType, IDataObjectType otherDataObjectType) { if (dataObjectType == null && otherDataObjectType == null) { return(true); } if (dataObjectType == null || otherDataObjectType == null) { return(false); } var familyMatches = StringMatches(dataObjectType.Family, otherDataObjectType.Family); var versionMatches = StringMatches(dataObjectType.Version, otherDataObjectType.Version); if (!familyMatches || !versionMatches) { return(false); } return(StringMatches(dataObjectType.ObjectType, otherDataObjectType.ObjectType)); }
/// <summary> /// Tries to get the <see cref="ISessionSupportedDataObject"/> matching the specified <see cref="IDataObjectType"/>. /// </summary> /// <param name="dataObjectType">The type to try to get the matching <see cref="ISessionSupportedDataObject"/> for.</param> /// <returns> /// If there is a specific type matching the specified data object type, it is returned. /// Otherwise, if there is a family that matches the specified data object type, it is returned. /// Otherwise, <c>null</c> is returned. /// </returns> ISessionSupportedDataObject ISessionSupportedDataObjectCollection.TryGetMatchingDataObject(IDataObjectType dataObjectType) => TryGetMatchingDataObject(dataObjectType);
/// <summary> /// Checks whether or not the specificied <see cref="IDataObjectType"/> is supported or not. /// </summary> /// <param name="dataObjectType">The type to check.</param> /// <returns><c>true</c> if the data object type is supported; <c>false</c> otherwise.</returns> public bool IsSupported(IDataObjectType dataObjectType) { return(TryGetMatchingDataObject(dataObjectType) != null); }
public static IEnumerable <IDataObjectType> FilterByFamilyAndVersion(this IEnumerable <IDataObjectType> dataObjectTypes, IDataObjectType dataObjectType) { return(dataObjectTypes.Where(dt => dt.MatchesFamilyAndVersion(dataObjectType))); }
public static IEnumerable <MockObject> FilterByFamilyAndVersion(this IEnumerable <MockObject> objects, IDataObjectType dataObjectType) { return(objects.Where(o => o.DataObjectType.MatchesFamilyAndVersion(dataObjectType))); }
/// <summary> /// Initializes a new <see cref="EtpSupportedDataObject"/> instance. /// </summary> /// <param name="qualifiedType">The data object's qualified type.</param> public EtpSupportedDataObject(IDataObjectType qualifiedType) { QualifiedType = qualifiedType; Capabilities = new EtpDataObjectCapabilities(); }
/// <summary> /// Initializes a new <see cref="EtpSupportedDataObject"/> instance. /// </summary> /// <param name="qualifiedType">The data object's qualified type.</param> /// <param name="capabilities">The data object's capabilities</param> public EtpSupportedDataObject(IDataObjectType qualifiedType, IReadOnlyCapabilities capabilities) { QualifiedType = qualifiedType; Capabilities = capabilities == null ? new EtpDataObjectCapabilities() : new EtpDataObjectCapabilities(capabilities); }
/// <summary> /// Appends the specified object type and optional object identifier to the <see cref="EtpUri" />. /// </summary> /// <param name="dataObjecType">The data object type.</param> /// <param name="objectId">The object identifier.</param> /// <param name="objectVersion">The object version.</param> /// <param name="encode">if set to <c>true</c> encode the object identifier value.</param> /// <returns>A new <see cref="EtpUri" /> instance.</returns> public EtpUri Append(IDataObjectType dataObjecType, string objectId = null, string objectVersion = null, bool encode = false) { return(Append(dataObjecType?.Family, dataObjecType?.Version, dataObjecType?.ObjectType, objectId: objectId, objectVersion: objectVersion, encode: encode)); }
/// <summary> /// Creates a URI for the specified data object type, object ID and object version. /// </summary> /// <param name="version">The ETP version.</param> /// <param name="dataspace">The dataspace.</param> /// <param name="dataObjectType">The data object type.</param> /// <param name="objectId">The object ID.</param> /// <param name="objectVersion">The object version.</param> public EtpUri(EtpVersion version, string dataspace, IDataObjectType dataObjectType, string objectId = null, string objectVersion = null) : this(new EtpUri(CreateBaseUri(version, dataObjectType?.Family, dataObjectType?.Version, dataspace)).Append(dataObjectType?.Family, dataObjectType?.Version, dataObjectType?.ObjectType, objectId : objectId, objectVersion : objectVersion)) { }