// subscriptions private ISubscription SubscribePrivate( Type dataType, IExpression filter, bool excludeExisting, bool waitForExisting, bool excludeDataBody, SubscriptionCallback userCallback, object userContext) { if (dataType == null) { throw new ArgumentNullException(nameof(dataType)); } if (filter == null) { throw new ArgumentNullException(nameof(filter)); } // create subscription ISubscription subscription = Client.CreateTypedSubscription(dataType, filter); subscription.UserCallback = SubscriptionCallback; subscription.UserContext = null; subscription.ItemKind = ItemKind.Object; subscription.ExcludeExisting = excludeExisting; subscription.WaitForExisting = waitForExisting; subscription.ExcludeDataBody = excludeDataBody; var userParams = new CoreItemCacheParams(dataType, subscription.Id); _Subscriptions.Set(subscription.Id, new CacheSubscription(subscription, userParams, userCallback, userContext)); // hack - todo - do initial load if required (remove when server supports waitForExisting) const long minimumUSN = 0; if (!excludeExisting) { List <ICoreItem> items = Client.LoadItems(dataType, ItemKind.Object, filter, 0, true); foreach (var newItem in items) { Cache.Put(newItem.Name, newItem, LoadSaveType.Avoid, userParams, TimeSpan.MaxValue); } // notify user NotifyUserDataChange(Cache.GetUpdates()); } // start subscription subscription.MinimumUSN = minimumUSN; //_Logger.LogDebug("Cache: Creating subscription[{0}]: <{1}> {2} ({3})", // filter.GetHashCode(), dataType.FullName, // filter.DisplayString(), subscription.Id); subscription.Start(); return(subscription); }