/// <summary> /// Returns a new <see cref="EtpSupportedDataObjectCollection"/> that representes the intersection of supported data objects between this instance and the other instance. /// </summary> /// <param name="instanceSupportedDataObjects">The ETP endpoint's supported data objects.</param> /// <param name="counterpartSupportedDataObjects">The ETP endpoint's counterpart's supported data objects.</param> /// <param name="intersection">If <c>true</c>, the collection is the intersection of data objects supported by the instance and its counterpart; if <c>false</c> it is the union.</param> /// <returns>The new collection representing the intersection of the supported data objects.</returns> public static EtpSupportedDataObjectCollection GetSupportedDataObjectCollection(IEnumerable <EtpSupportedDataObject> instanceSupportedDataObjects, IEnumerable <EtpSupportedDataObject> counterpartSupportedDataObjects, bool intersection) { var instanceCollection = new EtpSupportedDataObjectCollection(instanceSupportedDataObjects); var counterpartCollection = new EtpSupportedDataObjectCollection(counterpartSupportedDataObjects); var supportedDataObjects = new List <EtpSupportedDataObject>(); // First handle wildcards found in both sets foreach (var instanceFamily in instanceCollection.SupportedFamilies) { var counterpartFamily = counterpartCollection.TryGetMatchingDataObject(instanceFamily.QualifiedType); if (!intersection || counterpartFamily != null) { supportedDataObjects.Add(instanceFamily); instanceFamily.CounterpartCapabilities = counterpartFamily?.Capabilities ?? new EtpDataObjectCapabilities(); } } if (!intersection) { foreach (var counterpartFamily in counterpartCollection.SupportedFamilies) { var instanceFamily = instanceCollection.TryGetMatchingDataObject(counterpartFamily.QualifiedType); if (instanceFamily == null) { var supportedDataObject = new EtpSupportedDataObject(counterpartFamily.QualifiedType, null); supportedDataObject.CounterpartCapabilities = counterpartFamily.Capabilities; supportedDataObjects.Add(supportedDataObject); } } } // Next handle explicit types from instance found in counterpart as either an explicit type or a family foreach (var instanceType in instanceCollection.SupportedTypes) { var counterpartDataObject = counterpartCollection.TryGetMatchingDataObject(instanceType.QualifiedType); if (!intersection || counterpartDataObject != null) { supportedDataObjects.Add(instanceType); instanceType.CounterpartCapabilities = counterpartDataObject?.Capabilities ?? new EtpDataObjectCapabilities(); } } // Last handle explicit types from counterpart foreach (var counterpartType in counterpartCollection.SupportedTypes) { var instanceDataObject = instanceCollection.TryGetMatchingDataObject(counterpartType.QualifiedType); if ((!intersection && (instanceDataObject == null || instanceDataObject.QualifiedType.IsWildcard)) || (intersection && instanceDataObject != null && instanceDataObject.QualifiedType.IsWildcard)) { var supportedDataObject = new EtpSupportedDataObject(counterpartType.QualifiedType, instanceDataObject?.Capabilities); supportedDataObject.CounterpartCapabilities = counterpartType.Capabilities; supportedDataObjects.Add(supportedDataObject); } } return(new EtpSupportedDataObjectCollection(supportedDataObjects)); }
/// <summary> /// Adds a supported data object to this collection. /// </summary> /// <param name="supportedDataObject">The supported data object to add.</param> /// <returns><c>true</c> if the supported data object was successfully added; <c>false</c> otherwise.</returns> public bool AddSupportedDataObject(EtpSupportedDataObject supportedDataObject) { if (!supportedDataObject.QualifiedType.IsValid || supportedDataObject.QualifiedType.IsBaseType) { return(false); } AllDataObjects.Add(supportedDataObject); if (supportedDataObject.QualifiedType.IsWildcard) { SupportedDataObjectsByFamily[supportedDataObject.Key] = supportedDataObject; } else { SupportedDataObjectsByType[supportedDataObject.Key] = supportedDataObject; } return(true); }