예제 #1
0
        async Task <object[]> GetTotalSummariesAsync(GetSummariesAsyncEventArgs e)
        {
            IssueFilter filter        = IssuesHelper.MakeIssueFilter(e.Filter);
            var         summaryValues = await IssuesService.GetSummariesAsync(filter);

            return(e.Summaries.Select(x => {
                if (x.SummaryType == SummaryType.Count)
                {
                    return (object)summaryValues.Count;
                }
                throw new InvalidOperationException();
            }).ToArray());
        }
예제 #2
0
        async Task <FetchRowsResult> FetchRowsAsync(FetchRowsAsyncEventArgs e)
        {
            IssueSortOrder sortOrder = IssuesHelper.GetIssueSortOrder(e);
            IssueFilter    filter    = IssuesHelper.MakeIssueFilter(e.Filter);
            const int      pageSize  = 30;
            var            issues    = await IssuesService.GetIssuesAsync(
                page : e.Skip / pageSize,
                pageSize : pageSize,
                sortOrder : sortOrder,
                filter : filter);

            return(new FetchRowsResult(issues, hasMoreRows: issues.Length == pageSize));
        }
예제 #3
0
 public static IEnumerable <IssueData> FilterIssues(IssueFilter filter, IEnumerable <IssueData> issues)
 {
     if (filter == null)
     {
         return(issues);
     }
     issues = issues.Where(x => {
         return((!filter.CreatedFrom.HasValue || x.Created >= filter.CreatedFrom.Value) &&
                (!filter.CreatedTo.HasValue || x.Created <= filter.CreatedTo.Value) &&
                (!filter.MinVotes.HasValue || x.Votes >= filter.MinVotes.Value) &&
                (!filter.MaxVotes.HasValue || x.Votes <= filter.MaxVotes.Value) &&
                (!filter.Priority.HasValue || x.Priority == filter.Priority.Value) &&
                (filter.User == null || x.User == filter.User));
     });
     return(issues);
 }
예제 #4
0
 public async static Task <IssuesSummaries> GetSummariesAsync(IssueFilter filter)
 {
     return(await Task.Run(() => {
         return new IssuesSummaries(count: IssuesHelper.FilterIssues(filter, AllIssues.Value).Count());
     }));
 }
예제 #5
0
 public async static Task <IssueData[]> GetIssuesAsync(int page, int pageSize, IssueSortOrder sortOrder, IssueFilter filter)
 {
     return(await Task.Run(() => {
         var issues = IssuesHelper.SortIssues(sortOrder, AllIssues.Value);
         if (filter != null)
         {
             issues = IssuesHelper.FilterIssues(filter, issues);
         }
         issues = issues.Skip(page *pageSize).Take(pageSize);
         return issues.ToArray();
     }));
 }
예제 #6
0
        public static IssueFilter MakeIssueFilter(CriteriaOperator filter)
        {
            return(filter.Match(
                       binary: (propertyName, value, type) => {
                if (propertyName == "Votes")
                {
                    int?_value = null;
                    if (value != null)
                    {
                        double v;
                        if (double.TryParse(value.ToString(), out v))
                        {
                            _value = (int)v;
                        }
                    }
                    switch (type)
                    {
                    case BinaryOperatorType.Greater:
                        return new IssueFilter(minVotes: _value == null ? 0 : (int)(double)_value + 1);

                    case BinaryOperatorType.GreaterOrEqual:
                        return new IssueFilter(minVotes: _value == null ? 0 : (int)(double)_value);

                    case BinaryOperatorType.Less:
                        return new IssueFilter(maxVotes: _value == null || (double)_value < 0 ? int.MaxValue : (int)(double)_value - 1);

                    case BinaryOperatorType.LessOrEqual:
                        return new IssueFilter(maxVotes: _value == null || (double)_value < 0 ? int.MaxValue : (int)(double)_value);
                    }
                }
                if (propertyName == "Created")
                {
                    switch (type)
                    {
                    case BinaryOperatorType.Greater:
                        return new IssueFilter(createdFrom: value == null ? DateTime.MinValue : ((DateTime)value).AddTicks(1));

                    case BinaryOperatorType.GreaterOrEqual:
                        return new IssueFilter(createdFrom: value == null ? DateTime.MinValue : (DateTime)value);

                    case BinaryOperatorType.Less:
                        return new IssueFilter(createdTo: value == null ? DateTime.MaxValue : ((DateTime)value).AddTicks(-1));

                    case BinaryOperatorType.LessOrEqual:
                        return new IssueFilter(createdTo: value == null ? DateTime.MaxValue : (DateTime)value);
                    }
                }
                if (propertyName == "Priority" && type == BinaryOperatorType.Equal)
                {
                    return new IssueFilter(priority: (Priority)value);
                }
                if (propertyName == "User" && type == BinaryOperatorType.Equal)
                {
                    return new IssueFilter(user: (string)value);
                }

                throw new InvalidOperationException(string.Format("Can't convert '{0}' FilterCriteria to IssueFilter (type = '{1}', value = '{2}')", propertyName, type, value));
            },
                       and: filters => {
                var result = new IssueFilter(
                    priority: filters.Select(x => x.Priority).SingleOrDefault(x => x != null),
                    createdFrom: filters.Select(x => x.CreatedFrom).SingleOrDefault(x => x != null),
                    createdTo: filters.Select(x => x.CreatedTo).SingleOrDefault(x => x != null),
                    minVotes: filters.Select(x => x.MinVotes).SingleOrDefault(x => x != null),
                    maxVotes: filters.Select(x => x.MaxVotes).SingleOrDefault(x => x != null),
                    user: filters.Select(x => x.User).SingleOrDefault(x => x != null)
                    );
                return result;
            },
                       @null: default(IssueFilter)
                       ));
        }