public static string GetCacheKey <TResponse>(this QueriesPaged <TResponse> query)
        {
            var properties = query.GetType()
                             .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                             .Select(x =>
            {
                var val = x.GetValue(query);
                if (val == null)
                {
                    return(null);
                }
                return(x.Name + ":" + val.ToString());
            }).Where(x => x != null);

            return("urn:{0}:{1}".Fmt(query.GetType().FullName, properties.Join(":")));
        }
Esempio n. 2
0
        public async Task Manage<TResponse>(QueriesPaged<TResponse> query, string subscriptionId, ChangeType subscriptionType, TimeSpan subscriptionTime, string session)
        {
            var key = query.GetCacheKey();
            var subscription = new Subscription
            {
                SerializedQuery = query.SerializeToString(),
                SerializedQueryType = query.GetType().AssemblyQualifiedName,
                SubscriptionId = subscriptionId,
                Document = typeof(TResponse).FullName,
                DocumentId = "",
                CacheKey = key,
                Expires = DateTime.UtcNow.Add(subscriptionTime),
                Session = session,
                Type = subscriptionType
            };

            await _storage.Store(subscription).ConfigureAwait(false);
        }