Exemplo n.º 1
0
 public CacheSubscription(ISubscription subscription, CoreItemCacheParams cacheParams, SubscriptionCallback userCallback, object userContext)
 {
     Subscription = subscription;
     CacheParams  = cacheParams;
     UserCallback = userCallback;
     UserContext  = userContext;
 }
Exemplo n.º 2
0
        // ------------------------------ load single item methods ------------------------------
        private ICoreItem LoadItem(string itemName, CoreItemCacheParams cacheParams)
        {
            ICoreItem result = Cache.Get(itemName, LoadSaveType.Default, cacheParams);

            if (result != null)
            {
                if (!result.IsCurrent())
                {
                    result = null;
                }
            }
            NotifyUserDataChange(Cache.GetUpdates());
            return(result);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        // ------------------------------ load multiple items methods ------------------------------
        public List <ICoreItem> LoadItems <T>(IEnumerable <string> itemNames)
        {
            var cacheParams = new CoreItemCacheParams(typeof(T), Guid.Empty);

            return(itemNames.Select(itemName => LoadItem(itemName, cacheParams)).Where(item => item != null).ToList());
        }