Ejemplo n.º 1
0
        public static List <ChangesetViewModel> GetChangesetHistory(ChangesetHistoryRequest request)
        {
            List <ChangesetViewModel> changesetList = new List <ChangesetViewModel>();

            using (TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(request.TFSUrl)))
            {
                tpc.EnsureAuthenticated();
                VersionControlServer vcs = tpc.GetService <VersionControlServer>();

                VersionSpec fromDateVersion = null;
                VersionSpec toDateVersion   = null;
                if (request.FromDate != DateTime.MinValue || request.ToDate != DateTime.MinValue)
                {
                    fromDateVersion = new DateVersionSpec(request.FromDate.AddDays(-1));
                    toDateVersion   = new DateVersionSpec(request.ToDate);
                }

                IEnumerable changesets = vcs.QueryHistory(request.ReleaseBranchUrl, VersionSpec.Latest,
                                                          0, RecursionType.Full, null, fromDateVersion, toDateVersion, int.MaxValue, true, true);

                var ignoreUsers = request.IgnoreFromUsers;
                foreach (Changeset changeset in changesets)
                {
                    if (!ignoreUsers.Any(n => changeset.Owner.ToLower().Contains(n) || changeset.OwnerDisplayName.ToLower().Contains(n)))
                    {
                        changesetList.Add(new ChangesetViewModel()
                        {
                            ChangesetId = changeset.ChangesetId, Owner = changeset.OwnerDisplayName ?? changeset.Owner, Comment = changeset.Comment, CheckInDateTime = changeset.CreationDate
                        });
                    }
                }
            }
            return(changesetList);
        }
Ejemplo n.º 2
0
        private static void ValidateRequest(ChangesetHistoryRequest request)
        {
            bool result = Uri.TryCreate(request.TFSUrl, UriKind.Absolute, out Uri uriResult) &&
                          (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

            if (result)
            {
                throw new ArgumentException("TFS URL is not valid");
            }

            if (string.IsNullOrEmpty(request.ReleaseBranchUrl))
            {
                throw new ArgumentNullException("Release Branch Url cannot be null");
            }
        }
Ejemplo n.º 3
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtRelBranch.Text))
            {
                MessageBox.Show("Enter release branch to continue", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (string.IsNullOrEmpty(txtTFSUrl.Text))
            {
                MessageBox.Show("Enter TFS URL to continue", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }


            ChangesetHistoryRequest request = new ChangesetHistoryRequest();

            request.TFSUrl                = txtTFSUrl.Text.Trim();
            request.ReleaseBranchUrl      = txtRelBranch.Text.Trim();
            request.IgnoreFromUsersString = txtIgnoreUsers.Text.Trim();
            request.FromDate              = fromDate.Value;
            request.ToDate                = toDate.Value;

            try
            {
                bindList.Clear();
                var response = ChangesetManager.GetChangesetHistory(request);
                foreach (var changeItem in response)
                {
                    bindList.Add(changeItem);
                }
            }
            catch (ArgumentException aex)
            {
                MessageBox.Show("Check your inputs and try again", "Valdiation error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Message: {0}; Stacktrace: {1}", ex.Message, ex.StackTrace), "Error occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 4
0
        private static ChangesetHistoryRequest ParseArgs(string[] args)
        {
            ChangesetHistoryRequest request = new ChangesetHistoryRequest();

            for (int index = 0; index < args.Length; index++)
            {
                switch (args[index])
                {
                case "-t":
                    index++;
                    if (args[index].Trim().StartsWith("-"))
                    {
                        throw new ArgumentException("Value for argument -t is missing");
                    }
                    request.TFSUrl = args[index];
                    break;

                case "-r":
                    index++;
                    if (args[index].Trim().StartsWith("-"))
                    {
                        throw new ArgumentException("Value for argument -r is missing");
                    }
                    request.ReleaseBranchUrl = args[index];
                    break;

                case "-from":
                    index++;
                    if (args[index].Trim().StartsWith("-"))
                    {
                        throw new ArgumentException("Value for argument -from is missing");
                    }
                    if (DateTime.TryParse(args[index], out DateTime fromDate))
                    {
                        request.FromDate = fromDate;
                        if (request.ToDate == DateTime.MinValue)
                        {
                            request.ToDate = new DateTime(2100, 1, 1);
                        }
                        ;
                    }
                    else
                    {
                        throw new ArgumentException("Value for argument -from is invalid");
                    }
                    break;

                case "-to":
                    index++;
                    if (args[index].Trim().StartsWith("-"))
                    {
                        throw new ArgumentException("Value for argument -to is missing");
                    }
                    if (DateTime.TryParse(args[index], out DateTime toDate))
                    {
                        request.ToDate = toDate;
                    }
                    else
                    {
                        throw new ArgumentException("Value for argument -from is invalid");
                    }
                    break;

                case "-i":
                    index++;
                    if (args[index].Trim().StartsWith("-"))
                    {
                        throw new ArgumentException("Value for argument -i is missing");
                    }
                    request.IgnoreFromUsersString = args[index];
                    break;
                }
            }

            return(request);
        }