public void LoadItemsTest()
        {
            const int        startRow = 1;
            const int        rowCount = 2;
            List <ICoreItem> items    = _client.LoadItems(typeof(Market), null, null, startRow, rowCount);

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual("Market1", items[0].Name);
            Assert.AreEqual("Market2", items[1].Name);
        }
Exemple #2
0
        // 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);
        }