예제 #1
0
        private IEnumerable <ChangesetViewModel> BuildQuery(ChangesetSearchOptions search)
        {
            try
            {
                var projectCollection = _tfsServer.GetCollection();
                if (projectCollection.HasAuthenticated == false)
                {
                    projectCollection.Authenticate();
                }

                // Get the Changeset list from the TFS API.
                _versionControlServer = projectCollection.GetService <VersionControlServer>();

                var qryHistroy = _versionControlServer.QueryHistory(search.ProjectSourcePath, VersionSpec.Latest, 0, RecursionType.Full,
                                                                    null, null, null, search.TopN,
                                                                    false, false, false, false)
                                 .OfType <Changeset>();

                if (search.IsSearchBasedOnRegex && !string.IsNullOrEmpty(search.SearchKeyword))
                {
                    var rx = new Regex(search.SearchKeyword, RegexOptions.IgnoreCase);
                    qryHistroy = qryHistroy.Where(p => rx.IsMatch(search.SearchKeyword));
                }
                else if (!search.IsSearchBasedOnRegex && !string.IsNullOrEmpty(search.SearchKeyword))
                {
                    if (search.SearchCommentType == Consts.SearchCommentType.Exact)
                    {
                        qryHistroy = qryHistroy.Where(c => c.Comment != null && c.Comment.Contains(search.SearchKeyword));
                    }
                    else if (search.SearchCommentType == Consts.SearchCommentType.Keyword)
                    {
                        qryHistroy = qryHistroy.Where(c => c.Comment != null && search.SearchKeywordSplitMode.Any(s => c.Comment.Contains(s)));
                    }
                }


                if (!string.IsNullOrEmpty(search.Committer))
                {
                    qryHistroy = qryHistroy.Where(c => c.CommitterDisplayName == search.Committer);
                }

                if (search.StartDate.HasValue)
                {
                    qryHistroy = qryHistroy.Where(c => c.CreationDate >= search.StartDate.Value);
                }

                if (search.EndDate.HasValue)
                {
                    qryHistroy = qryHistroy.Where(c => c.CreationDate <= search.EndDate.Value);
                }

                return(qryHistroy.AsQueryable().Paging(search.PagingInfo).Select(ToViewModel).Where(c => c != null));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
예제 #2
0
        public async Task <IEnumerable <ChangesetViewModel> > GetAsync(ChangesetSearchOptions search)
        {
            Task <IEnumerable <ChangesetViewModel> > qryHistory;

            try
            {
                qryHistory = Task.Factory.StartNew(() => {
                    try
                    {
                        return(BuildQuery(search));
                    }
                    catch (Exception ex)
                    {
                        InvokeErrorHandler(ex);
                        return(null);
                    }
                });

                return(await qryHistory);
            }
            catch (Exception)  {
                return(null);
            }
        }