예제 #1
0
        private PowerTablesData ProduceData(IQueryable <TSourceData> source, PowerTableRequest request)
        {
            try
            {
                //gather data
                var  filtered = _queryHandler.ApplyFiltering(source, request.Query);
                var  ordered  = _queryHandler.ApplyOrdering(filtered, request.Query);
                long count    = 0;
                int  page     = 0;


                var paged        = _queryHandler.ApplyPaging(ordered, request.Query, out count, out page);
                var mapped       = new Lazy <TTableData[]>(() => _queryHandler.ApplyMapping(paged, request.Query));
                var mappedObject =
                    new Lazy <object[]>(() => _queryHandler.ApplyMapping(paged, request.Query).Cast <object>().ToArray());

                var data = new PowerTablesData(source, filtered, ordered, paged, mappedObject, _configuration, request,
                                               count,
                                               page);
                data._OriginalLazy = mapped;
                return(data);
            }
            catch (InvalidOperationException ex)
            {
                throw new Exception(
                          String.Format(@"InvalidOperationException thrown.
We recommend to re-check filters configuration against filtering/mapping on nullable columns. 
Lattice does not throw InvalidOperationException itself, but we not always handle filtering of nullable columns 
because it is highly dependent on query provider.
Consider usage of null-coalescing operator (??) within your nullables.
Btw, original message was: {0}", ex.Message),
                          ex);
            }
        }
예제 #2
0
        /// <summary>
        /// Entirely handles request to table. This method will extract all needed data from ControllerContext. Not needed additional information.
        /// </summary>
        /// <param name="source">Source data set</param>
        /// <param name="context">Controller context</param>
        /// <returns>ActionResult that should be sent to client</returns>
        public async Task <ActionResult> HandleAsync(IQueryable <TSourceData> source, ControllerContext context)
        {
            try
            {
                PowerTableRequest request        = _queryHandler.ExtractRequest(context);
                ICommandHandler   commandHandler = ResolveCommandHandler(request.Command);

                if (!request.IsDeferred && commandHandler.IsDeferable)
                {
                    request.IsDeferred = true;
                    var token = TokenStorage.StoreRequest(request);
                    return(new ContentResult()
                    {
                        Content = TokenStorage.TokenPrefix + token, ContentEncoding = Encoding.UTF8, ContentType = "lattice/service"
                    });
                }
                var data = ProduceData(source, request);

                return(await commandHandler.HandleAsync(data, this));
            }
            catch (Exception ex)
            {
                return(ProduceError(ex));
            }
        }
예제 #3
0
 public PowerTablesData(IQueryable source, IQueryable filtered, IQueryable ordered, IQueryable paged, Lazy <object[]> mapped, IConfigurator configuration, PowerTableRequest request, long resultsCount, int currentPage)
 {
     Source        = source;
     Filtered      = filtered;
     Ordered       = ordered;
     Paged         = paged;
     Mapped        = mapped;
     Configuration = configuration;
     Request       = request;
     ResultsCount  = resultsCount;
     CurrentPage   = currentPage;
 }
예제 #4
0
        /// <summary>
        /// Looks up for request by specified token, returns it and cleans up tokens dictionary
        /// according to TTL or immediately in case of UseSingleRequestTokens enabled.
        /// </summary>
        /// <param name="token">Token</param>
        /// <returns>Request</returns>
        public static PowerTableRequest Lookup(string token)
        {
            PowerTableRequest result = null;

            if (UseSingleRequestTokens)
            {
                StoredRequests.TryRemove(token, out result);
            }
            else
            {
                StoredRequests.TryGetValue(token, out result);
                Cleanup();
            }
            return(result);
        }
예제 #5
0
        private static void Cleanup()
        {
            if (UseSingleRequestTokens)
            {
                return;
            }
            var cDate = DateTime.Now;

            lock (ExpirationTokens)
            {
                var tokensToClean = ExpirationTokens.Where(c => c.ExpireDate <= cDate).ToArray();
                foreach (var tk in tokensToClean)
                {
                    PowerTableRequest req = null;
                    StoredRequests.TryRemove(tk.Token, out req);
                    ExpirationTokens.Remove(tk);
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Stores tables request from POST request and returns token back
        /// </summary>
        /// <param name="request">Request to store</param>
        /// <returns>Token value</returns>
        public static string StoreRequest(PowerTableRequest request)
        {
            _isDirty = true;
            string token  = null;
            bool   result = false;

            while (!result)
            {
                token  = Guid.NewGuid().ToString();
                result = StoredRequests.TryAdd(token, request);
            }
            if (!UseSingleRequestTokens)
            {
                lock (ExpirationTokens)
                {
                    StoredRequest rq = new StoredRequest()
                    {
                        ExpireDate = DateTime.Now.Add(TokenTimeToLive), Token = token
                    };
                    ExpirationTokens.Add(rq);
                }
            }
            return(token);
        }
예제 #7
0
 /// <summary>
 /// Retrieves additional JSONed data from AdditionalData collection
 /// </summary>
 /// <typeparam name="T">Object type</typeparam>
 /// <param name="request">PowerTables request</param>
 ///  <param name="key">Key in additional data</param>
 /// <param name="serializerSettings">Serializer settings to be supplied to Json.Net</param>
 /// <returns>RetrieveAdditionalObject ViewModel</returns>
 public static T RetrieveAdditionalObject <T>(this PowerTableRequest request, string key, JsonSerializerSettings serializerSettings)
 {
     return(RetrieveAdditionalObject <T>(request.Query, key, serializerSettings));
 }
예제 #8
0
 /// <summary>
 /// Retrieves additional JSONed data from AdditionalData collection
 /// </summary>
 /// <typeparam name="T">Object type</typeparam>
 /// <param name="request">PowerTables request</param>
 /// <param name="key">Key in additional data</param>
 /// <param name="converters">Converters to be supplied to Json.Net</param>
 /// <returns>RetrieveAdditionalObject ViewModel</returns>
 public static T RetrieveAdditionalObject <T>(this PowerTableRequest request, string key, params JsonConverter[] converters)
 {
     return(RetrieveAdditionalObject <T>(request.Query, key, converters));
 }
예제 #9
0
 /// <summary>
 /// Retrieves additional JSONed data from AdditionalData collection
 /// </summary>
 /// <typeparam name="T">Object type</typeparam>
 /// <param name="key">Key in additional data</param>
 /// <param name="request">PowerTables request</param>
 /// <returns>Additional data object</returns>
 public static T RetrieveAdditionalObject <T>(this PowerTableRequest request, string key)
 {
     return(RetrieveAdditionalObject <T>(request.Query, key));
 }