Esempio n. 1
0
        public static Object ToOptimizedCachedAndSubscribedResult <TResponse>(this IRequest request, Q.Query <TResponse> query, ICacheClient cache, ISubscriptionManager manager, Func <R.Query <TResponse> > factory)
        {
            var key    = query.GetCacheKey();
            var cached = cache.GetOrCreate(key, () =>
            {
                return(factory());
            });

            // Send response to client, so our subscription stuff doesn't delay the client
            request.Response.ContentType = request.ResponseContentType;
            request.Response.WriteToResponse(request, cached);
            request.Response.EndRequest();

            var documentId = "";
            var idField    = typeof(TResponse).GetProperty("Id", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

            if (idField == null)
            {
                documentId = idField.GetValue(cached.Payload).ToString();
            }

            manager.Manage <TResponse>(key, documentId, query.SubscriptionId, request.GetPermanentSessionId());

            return(cached);
        }
Esempio n. 2
0
 public static Object ToOptimizedCachedAndSubscribedResult <TResponse>(this IRequest request, Q.Query <TResponse> query, ICacheClient cache, ISubscriptionManager manager, IQueryProcessor processor)
 {
     return(request.ToOptimizedCachedAndSubscribedResult(query, cache, manager, () =>
     {
         return processor.Process(query);
     }));
 }
 public static R.Query <T> ToQueryResponse <T>(this T dto, Q.Query <T> query) where T : class, R.IResponse, new()
 {
     return(new R.Query <T> {
         Payload = dto, Etag = Guid.Empty, SubscriptionId = query.SubscriptionId
     });
 }