Ejemplo n.º 1
0
        /// <summary>
        /// Loads table items from DynamoDb
        /// - Filter property is used to query against DynamoDb table
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public IEnumerable <T> LoadTableItems <T>(LoadTableItemsRequest request)
        {
            //LambdaLogger.Log($"Entering: LoadTableItems({ JsonConvert.SerializeObject(request) }");

            var response = new List <T>();

            try
            {
                //SearchDocumentsRequest searchDocumentsRequest = CreateSearchDocumentsRequest(request);

                //var tableItems = DynamoDbHelper.SearchDocuments(searchDocumentsRequest);

                //TODOING: build conditions from request filter

                var tableItems = DynamoDbHelper.Scan <T>(request.Conditions);

                //TODO: Handle order by expression and record cap here

                //Use request to hit dynamodb
                //If has an id, then can use dynamodb GetItem, else need to query based on filter
                response = tableItems.ToList();
            }
            catch (Exception exp)
            {
                LambdaLogger.Log($"Error: { exp }");

                //LambdaLogger.Log($"Leaving: LoadTableItems({ JsonConvert.SerializeObject(response) }");
                return(response);
            }

            //LambdaLogger.Log($"Leaving: LoadTableItems({ JsonConvert.SerializeObject(response) }");
            return(response);
        }
Ejemplo n.º 2
0
        public IEnumerable <T> FindAll(string filter, List <ScanCondition> conditions, string orderByExpression, int recordCap)
        {
            LambdaLogger.Log($"Entering: FindAll({JsonConvert.SerializeObject(conditions)})");

            var request = new LoadTableItemsRequest
            {
                Filter            = filter,
                OrderByExpression = orderByExpression,
                RecordCap         = recordCap,
                Table             = typeof(T).Name, //Name of table will be name of model
                Properties        = typeof(T).GetProperties().Select(x => x.Name).ToList(),
                Type       = typeof(T),
                Conditions = conditions
            };

            var response = _daoContext.LoadTableItems <T>(request);

            LambdaLogger.Log($"Load Table Items response: { JsonConvert.SerializeObject(response) }");

            return(response);

            //if (response != null)
            //{
            //    foreach(var tableItem in response.TableItems)
            //    {
            //        yield return ContextResponseEntity(tableItem);
            //    }
            //
        }
Ejemplo n.º 3
0
        private static SearchDocumentsRequest CreateSearchDocumentsRequest(LoadTableItemsRequest request)
        {
            LambdaLogger.Log($"Entering: CreateSearchDocumentsRequest({ JsonConvert.SerializeObject(request) })");

            SearchDocumentsRequest searchDocumentsRequest = new SearchDocumentsRequest
            {
                TableName = request.Table
            };

            try
            {
                //Enter the Regex
                // - goal here is to map request.Filter to Dictionary<string, List<string>>
                request.Filter = request.Filter.ToLower();

                List <string> tokens = request.Filter
                                       .Split(new char[] { ' ', ',' })
                                       .ToList();

                //Example Case #2
                //tokens = ["attr1", "=", "value1", "and", "attr2", "=", "value2"]
                //keyFilters = [{"attr1", ["=", "value1"]}, {"attr2", ["=", "value2"]}]
                if (tokens.Contains("&&"))
                {
                    var subFilters = request.Filter.Split("&&");

                    foreach (var subFilter in subFilters)
                    {
                        var subTokens = subFilter.Split(new char[] { ' ', ',' })
                                        .ToList();

                        //TODO: Will check later for ORs ("||") here
                        ParseBaseQuery(searchDocumentsRequest, subTokens);
                    }
                }
            } catch (Exception exp) {
                LambdaLogger.Log($"Error: { exp }");

                LambdaLogger.Log($"Leaving: CreateSearchDocumentsRequest({ JsonConvert.SerializeObject(searchDocumentsRequest) })");
                throw exp;
            }

            LambdaLogger.Log($"Leaving: CreateSearchDocumentsRequest({ JsonConvert.SerializeObject(searchDocumentsRequest) })");
            return(searchDocumentsRequest);
        }