public static void AddSubscriptionToObject(string targetLocation, string subscriberLocation, string subscriptionType, string targetTypeName = null, string subscriberTypeName = null) { if(targetLocation == subscriberLocation) throw new InvalidDataException("Self-circular subscription targeting self attempted: " + targetLocation); var sub = GetSubscriptionToObject(targetLocation, subscriberLocation, subscriptionType, targetTypeName:targetTypeName, subscriberTypeName:subscriberTypeName); SubscriptionCollection subscriptionCollection = GetSubscriptions(targetLocation); if(subscriptionCollection == null) { subscriptionCollection = new SubscriptionCollection(); subscriptionCollection.SetRelativeLocationAsMetadataTo(targetLocation); } var alreadyExists = subscriptionCollection.CollectionContent.FirstOrDefault( existing => existing.SubscriberRelativeLocation == sub.SubscriberRelativeLocation && existing.SubscriptionType == sub.SubscriptionType); if(alreadyExists != null) { // If the values match, don't save when there are no changes if (alreadyExists.SubscriberInformationObjectType == sub.SubscriberInformationObjectType && alreadyExists.TargetInformationObjectType == sub.TargetInformationObjectType) return; // ... otherwise update the values alreadyExists.SubscriberInformationObjectType = sub.SubscriberInformationObjectType; alreadyExists.TargetInformationObjectType = sub.TargetInformationObjectType; } else { subscriptionCollection.CollectionContent.Add(sub); } StorageSupport.StoreInformation(subscriptionCollection); }
public static void AddSubscriptionToObject(string targetLocation, string subscriberLocation, string subscriptionType, string targetTypeName = null, string subscriberTypeName = null) { if (targetLocation == subscriberLocation) { throw new InvalidDataException("Self-circular subscription targeting self attempted: " + targetLocation); } var sub = GetSubscriptionToObject(targetLocation, subscriberLocation, subscriptionType, targetTypeName: targetTypeName, subscriberTypeName: subscriberTypeName); SubscriptionCollection subscriptionCollection = GetSubscriptions(targetLocation); if (subscriptionCollection == null) { subscriptionCollection = new SubscriptionCollection(); subscriptionCollection.SetRelativeLocationAsMetadataTo(targetLocation); } var alreadyExists = subscriptionCollection.CollectionContent.FirstOrDefault( existing => existing.SubscriberRelativeLocation == sub.SubscriberRelativeLocation && existing.SubscriptionType == sub.SubscriptionType); if (alreadyExists != null) { // If the values match, don't save when there are no changes if (alreadyExists.SubscriberInformationObjectType == sub.SubscriberInformationObjectType && alreadyExists.TargetInformationObjectType == sub.TargetInformationObjectType) { return; } // ... otherwise update the values alreadyExists.SubscriberInformationObjectType = sub.SubscriberInformationObjectType; alreadyExists.TargetInformationObjectType = sub.TargetInformationObjectType; } else { subscriptionCollection.CollectionContent.Add(sub); } StorageSupport.StoreInformation(subscriptionCollection); }