Exemplo n.º 1
0
        public async Task <PagedList <BookResponse> > GetBooksAsync(QueryOptions options)
        {
            QueryProcessing <Book> processing = new QueryProcessing <Book>(options);

            IQueryable <Book> query = GetEntities()
                                      .Include(p => p.Publisher)
                                      .Include(c => c.Category)
                                      .ThenInclude(c => c.ParentCategory);

            IQueryable <BookResponse> processedBooks;

            if (options.SortPropertyName == $"{nameof(Publisher)}.{nameof(Publisher.Name)}" ||
                options.SortPropertyName == $"{nameof(Category)}.{nameof(Category.Name)}" ||
                options.SortPropertyName ==
                $"{nameof(Category)}.{nameof(Category.ParentCategory)}.{nameof(Category.Name)}")
            {
                processedBooks = options.DescendingOrder
                    ? processing.ProcessQuery(query.OrderByDescending(b => b.Title))
                                 .Select(e => e.MapBookResponse())
                    : processing.ProcessQuery(query.OrderBy(b => b.Title))
                                 .Select(e => e.MapBookResponse());
            }
            else
            {
                processedBooks = processing.ProcessQuery(query)
                                 .Select(e => e.MapBookResponse());
            }

            PagedList <BookResponse> books = await Task.Run(() =>
                                                            new PagedList <BookResponse>(processedBooks, options));

            return(books);
        }
Exemplo n.º 2
0
        private async Task <DisplayedTasks> GetWeekTasksAsync(IQueryable <TaskItem> processedTasks,
                                                              QueryProcessing queryProcessing)
        {
            processedTasks = processedTasks.Where(t => t.PlanningDate.HasValue && t.EffectiveDate == null);
            processedTasks = queryProcessing.SortTasks(processedTasks);

            int thisWeekRemainingDaysCount = DateTime.Today.DayOfWeek == 0
                ? 0
                : 7 - (int)DateTime.Today.DayOfWeek;
            DateTime thisWeekEndDate = DateTime.Today.AddDays(thisWeekRemainingDaysCount);

            Dictionary <string, IEnumerable <TaskItem> > tasks = await dbTasks
                                                                 .Where(t => t.PlanningDate <= thisWeekEndDate &&
                                                                        t.PlanningDate.HasValue &&
                                                                        t.EffectiveDate == null)
                                                                 .Select(t => new { t.PlanningDate })
                                                                 .Distinct()
                                                                 .OrderBy(t => t.PlanningDate)
                                                                 .GroupJoin(
                processedTasks,
                t1 => t1.PlanningDate,
                t2 => t2.PlanningDate,
                (t1, t2) => new { t1.PlanningDate, t2 })
                                                                 .ToDictionaryAsync(a => a.PlanningDate.Value.ToShortDateString(), a => a.t2);

            return(new DisplayedTasks
            {
                Week = tasks
            });
        }
Exemplo n.º 3
0
        public async Task <DisplayedTasks> ReceiveTasksAsync(QueryOptions options)
        {
            if (options.SelectedCategoryId == null)
            {
                options.SelectedCategoryId = dbCategories.Min(c => c.Id);
            }
            IQueryable <TaskItem> processedTasks = dbTasks;

            QueryProcessing queryProcessing = new QueryProcessing(options);

            processedTasks = queryProcessing.SearchTasks(processedTasks);
            processedTasks = queryProcessing.FilterTasks(processedTasks);

            if (options.SelectedCategoryId == 0)
            {
                return(await GetFoundTasksAsync(queryProcessing));
            }
            else if (options.SelectedCategoryId == (long)CategoryFilterType.Starred)
            {
                return(await GetStarredTasksAsync(processedTasks, queryProcessing));
            }
            else if (options.SelectedCategoryId == (long)CategoryFilterType.Today)
            {
                return(await GetTodayTasksAsync(processedTasks, queryProcessing));
            }
            else if (options.SelectedCategoryId == (long)CategoryFilterType.Week)
            {
                return(await GetWeekTasksAsync(processedTasks, queryProcessing));
            }
            else
            {
                return(await GetTasksAsync(processedTasks, queryProcessing));
            }
        }
Exemplo n.º 4
0
        private async Task <DisplayedTasks> GetTodayTasksAsync(IQueryable <TaskItem> processedTasks,
                                                               QueryProcessing queryProcessing)
        {
            processedTasks = processedTasks.Where(t => t.EffectiveDate == null &&
                                                  t.PlanningDate.HasValue &&
                                                  t.PlanningDate <= DateTime.Today);
            processedTasks = queryProcessing.SortTasks(processedTasks);

            long minId = dbCategories.Min(c => c.Id);
            IQueryable <Category> secondCategories             = dbCategories.Where(c => c.Id > minId).OrderBy(c => c.Name);
            Dictionary <string, IEnumerable <TaskItem> > tasks = await dbCategories
                                                                 .Where(c => c.Id == minId)
                                                                 .Concat(secondCategories)
                                                                 .GroupJoin(
                processedTasks,
                c => c.Id,
                t => t.CategoryId,
                (c, ct) => new { c.Name, ct })
                                                                 .ToDictionaryAsync(anonymous => anonymous.Name, anonymous => anonymous.ct);

            return(new DisplayedTasks
            {
                Today = tasks
            });
        }
Exemplo n.º 5
0
        public async Task <PagedList <Publisher> > GetPublishersAsync(QueryOptions options)
        {
            QueryProcessing <Publisher> processing = new QueryProcessing <Publisher>(options);

            IQueryable <Publisher> query      = GetEntities();
            IQueryable <Publisher> publishers = processing.ProcessQuery(query);

            return(await Task.Run(() => new PagedList <Publisher>(publishers, options)));
        }
Exemplo n.º 6
0
        public async Task <ActionResult> QueryResult(QueryInfo queryInfo)
        {
            if (queryInfo == null)
            {
                return(BadRequest());
            }
            ViewData[nameof(SearchInfo)] = queryInfo;
            object results;

            try
            {
                /*** validation ***/
                queryInfo.Validate();

                /*** query preparation ***/
                SparqlRemoteEndpoint endpoint = SearchPreparing.CreateEndpoint(queryInfo.Endpoints[0], queryInfo.Timeout, queryInfo.DefaultGraph);
                SparqlQuery          query    = QueryParsing.ParseQuery(queryInfo.QueryString);

                /*** query processing ***/
                results = await QueryProcessing.ProcessQuery(query, endpoint);

                //ViewData["ExecutionTime"] = query.QueryExecutionTime;
            }
            catch (BrowserException e)
            {
                return(View("QueryResultError", e.Message));
            }
            catch (Exception)
            {
                //TODO: better text
                return(View("QueryResultError", "Unknown error..."));
            }

            /*** result processing ***/
            if (results is SparqlResultSet)
            {
                return(View("QueryResultSet", (SparqlResultSet)results));
            }
            else if (results is IGraph)
            {
                return(View("QueryResultGraph", (IGraph)results));
            }
            else if (results is AsyncError)
            {
                return(View("QueryResultError", ErrorProcessing.ProcessAsyncError((AsyncError)results)));
            }
            else
            {
                //TODO: better text
                return(View("QueryResultError", "Unknown error..."));
            }
        }
Exemplo n.º 7
0
        private async Task <DisplayedTasks> GetTasksAsync(IQueryable <TaskItem> processedTasks,
                                                          QueryProcessing queryProcessing)
        {
            processedTasks = queryProcessing.SortTasks(processedTasks);

            List <TaskItem> tasks = await processedTasks.ToListAsync();

            return(new DisplayedTasks
            {
                Active = tasks?.Where(t => t.IsCompleted == false).ToList(),
                Completed = tasks?.Where(t => t.IsCompleted == true).ToList()
            });
        }
Exemplo n.º 8
0
        private void RunButton_Click(object sender, EventArgs e)
        {
            var       typeId = GetQueryType();
            DataTable dataTable;
            var       queryProcessing = new QueryProcessing();
            var       connData        = GetConnectionInformation();

            if (typeId == 1)
            {
                dataTable = queryProcessing.ExecuteQuery(connData, QueryTextBox.Text);
            }
            else
            {
                dataTable = queryProcessing.ExecuteStoredProcedure(connData, QueryTextBox.Text);
            }

            dataGridView1.DataSource = dataTable;
        }
Exemplo n.º 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            var    typeId = GetQueryType();
            Result result;
            var    queryProcessing = new QueryProcessing();
            var    connData        = GetConnectionInformation();

            if (typeId == 1)
            {
                result = queryProcessing.ExecuteScript(connData, QueryTextBox.Text);
            }
            else
            {
                result = queryProcessing.ExecuteScript(connData, QueryTextBox.Text);
            }

            MessageBox.Show(result.Message);

            treeView1.Nodes.Clear();
            SetTreeValues(connData);
        }
Exemplo n.º 10
0
        private async Task <DisplayedTasks> GetFoundTasksAsync(QueryProcessing queryProcessing)
        {
            IQueryable <TaskItem> processedTasks = queryProcessing.SearchTasks(dbTasks);

            processedTasks = processedTasks.Where(t => t.EffectiveDate == null);
            processedTasks = queryProcessing.SortTasks(processedTasks);

            long minId = dbCategories.Min(c => c.Id);
            IQueryable <Category> secondCategories             = dbCategories.Where(c => c.Id > minId).OrderBy(c => c.Name);
            Dictionary <string, IEnumerable <TaskItem> > tasks = await dbCategories
                                                                 .Where(c => c.Id == minId)
                                                                 .Concat(secondCategories).GroupJoin(
                processedTasks,
                c => c.Id,
                t => t.CategoryId,
                (c, ct) => new { c.Name, ct })
                                                                 .Where(a => a.ct.Count() > 0)
                                                                 .ToDictionaryAsync(anonymous => anonymous.Name, anonymous => anonymous.ct);

            return(new DisplayedTasks
            {
                Found = tasks
            });
        }
Exemplo n.º 11
0
        private static async Task <Dictionary <string, int> > RetrievePopularPropertiesFromEndpoint()
        {
            string errorMessage = "";
            object results      = null;

            try
            {
                SparqlQuery          query    = QueryParsing.ParseQuery(QueryCreating.GetQueryTemplateCopy(QueryTemplates.SelectPopularProperties));
                SparqlRemoteEndpoint endpoint = SearchPreparing.CreateEndpoint(Config.LOV_SPARQL_ENDPOINT, Config.LOV_PREDICATES_SEARCH_TIMEOUT);
                results = await QueryProcessing.ProcessQuery(query, endpoint);
            }
            catch (BrowserException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new BrowserException("An unexpected error occured while retrieving the list of popular predicates.", e);
            }

            if (results is SparqlResultSet)
            {
                return(ResultSetToDictionary((SparqlResultSet)results));
            }
            else if (results is AsyncError)
            { /*TODO: remove exceptions */
                throw ((AsyncError)results).Error.InnerException;
                //errorMessage += ResultProcessing.ProcessAsyncError((AsyncError)results);
                //return null;
            }
            /*TODO: remove exceptions*/
            throw new Exception(errorMessage);

            //otherwise it should be null and errorMessage should be already set
            //return null;
        }
Exemplo n.º 12
0
        public async Task <PagedList <CategoryResponse> > GetCategoriesAsync(QueryOptions options)
        {
            if (string.IsNullOrEmpty(options.SortPropertyName))
            {
                options.SortPropertyName = nameof(Category.Name);
            }

            QueryProcessing <Category> processing = new QueryProcessing <Category>(options);

            IQueryable <Category> entities = GetEntities();
            IQueryable <Category> query    = entities
                                             .GroupJoin(entities, subcategory => subcategory.ParentCategoryID,
                                                        category => category.Id, (Category subcategory, IEnumerable <Category> categories) =>
                                                        new
            {
                subcategory,
                categories
            })
                                             .SelectMany(newCategory => newCategory.categories.DefaultIfEmpty(),
                                                         (temp0, categoryWithDisplayedName) =>
                                                         new Category
            {
                Id               = temp0.subcategory.Id,
                Name             = temp0.subcategory.Name,
                ParentCategoryID = temp0.subcategory.ParentCategoryID,
                DisplayedName    = (temp0.subcategory.ParentCategoryID == null)
                         ? temp0.subcategory.Name
                         : ((temp0.subcategory.ParentCategory.Name + " <=> ") + temp0.subcategory.Name)
            }
                                                         );
            //from subcategories in entities
            //join categories in entities
            //on subcategories.ParentCategoryID equals categories.Id into categoriesWithParent
            //from cwp in categoriesWithParent.DefaultIfEmpty()
            //select new Category
            //{
            //    Id = subcategories.Id,
            //    Name = subcategories.Name,
            //    ParentCategoryID = subcategories.ParentCategoryID,
            //    DisplayedName = subcategories.ParentCategoryID == null
            //        ? subcategories.Name
            //        : subcategories.ParentCategory.Name + " <=> " + subcategories.Name
            //};

            IQueryable <CategoryResponse> processedCategories;

            if (options.SortPropertyName == $"{nameof(Category.Name)}")
            {
                options.SortPropertyName = $"{nameof(Category.DisplayedName)}";
                processedCategories      = processing.ProcessQuery(query)
                                           .Select(e => e.MapCategoryResponse());
            }
            else
            {
                processedCategories = processing.ProcessQuery(query)
                                      .Select(e => e.MapCategoryResponse());
            }

            PagedList <CategoryResponse> pagedList = await Task.Run(() =>
                                                                    new PagedList <CategoryResponse>(processedCategories, options));

            return(pagedList);
        }