public bool TryCheckin(Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote = null, WorkItemCheckinInfo[] workItemChanges = null, PolicyOverrideInfo policyOverride = null)
        {
            try
            {
                _teamPilgrimTfsService.WorkspaceCheckin(workspace, changes, comment, checkinNote, workItemChanges, policyOverride);
                return true;
            }
            catch (Exception ex)
            {
                this.Logger().DebugException(ex);
                LastException = ex;
            }

            return false;
        }
Ejemplo n.º 2
0
        public static int CheckInWithPolicyOverride(this Workspace workspace, string comment, PendingChange[] pendingChanges, string policyOverrideMessage = "")
        {
            PolicyOverrideInfo policyOverride = null;

            if (!string.IsNullOrEmpty(policyOverrideMessage))
            {
                var evaluationResult = workspace.EvaluateCheckin(CheckinEvaluationOptions.Policies,
                                                                 pendingChanges,
                                                                 pendingChanges,
                                                                 comment,
                                                                 null,
                                                                 new WorkItemCheckinInfo[0]);

                policyOverride = new PolicyOverrideInfo(policyOverrideMessage, evaluationResult.PolicyFailures);
            }

#warning Associate workitem
            return(workspace.CheckIn(pendingChanges,
                                     comment,
                                     null,
                                     null,
                                     policyOverride));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Performs a check-in of the specified item.
        /// </summary>
        /// <param name="item">The path of the file to check in.</param>
        /// <param name="comment">Check-in comment.</param>
        /// <param name="checkinNotes">Check-in notes.</param>
        /// <param name="recursive">Recurse to the last child.</param>
        /// <returns>The result of the evaluation.</returns>
        public static CheckinEvaluationResult CheckIn(string item, string comment = null, CheckinNote checkinNotes = null, bool recursive = false, bool overridePolicyFailures = true)
        {
            var checkinChanges = Workspace.GetPendingChangesEnumerable(item, recursive ? RecursionType.Full : RecursionType.None);

            if (PendingChange.IsIEnumerableEmpty(checkinChanges))
            {
                throw new InvalidOperationException("There are no pending changes!");
            }

            var checkinOptions   = CheckinEvaluationOptions.Notes | CheckinEvaluationOptions.Policies;
            var checkedWorkItems = new WorkItemCheckinInfo[0];

            var result = Workspace.EvaluateCheckin2(checkinOptions, null, checkinChanges, comment, checkinNotes, checkedWorkItems);

            if (result.Conflicts.Length > 0 || result.NoteFailures.Length > 0 || result.PolicyEvaluationException != null ||
                (result.PolicyFailures.Length > 0 && !overridePolicyFailures))
            {
                return(result);
            }

            PolicyOverrideInfo policyOverrideInfo = null;

            if (result.PolicyFailures.Length > 0)
            {
                policyOverrideInfo = new PolicyOverrideInfo("PolicyFailures override!", result.PolicyFailures);
            }

            var checkInParameters = new WorkspaceCheckInParameters(checkinChanges, comment);

            checkInParameters.CheckinNotes        = checkinNotes;
            checkInParameters.AssociatedWorkItems = checkedWorkItems;
            checkInParameters.PolicyOverride      = policyOverrideInfo;
            Workspace.CheckIn(checkInParameters);

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks the in.
        /// </summary>
        /// <remarks>Documented by CFI, 2010-06-27</remarks>
        public void CheckIn()
        {
            foreach (ITabbedDocument document in PluginBase.MainForm.Documents)
            {
                if (document.IsModified)
                {
                    document.Save();
                }
            }

            List <PendingChange> changes = GetSelectedChanges();

            if (pendingChanges.Count <= 0 || changes.Count <= 0)
            {
                MessageBox.Show("Nothing to Check In!", "Nothing to Check In", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            CheckinNote note = GetCurrentCheckinNotes();

            WorkItemCheckinInfo[] workItemsArray = GetSelectedWorkItems();

            PolicyOverrideInfo policyInfo = null;

            CheckinEvaluationResult result = Manager.CurrentWorkspace.EvaluateCheckin(CheckinEvaluationOptions.Conflicts, PendingChanges.ToArray(), changes.ToArray(), textBoxComment.Text, note, workItemsArray);

            if (result.Conflicts.Length > 0)
            {
                MessageBox.Show("Checkin cannot proceed because there are some conflicts.", "Conflict Failure", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ShowConfilcts();

                return;
            }

            result = Manager.CurrentWorkspace.EvaluateCheckin(CheckinEvaluationOptions.Notes, PendingChanges.ToArray(), changes.ToArray(), textBoxComment.Text, note, workItemsArray);
            if (result.NoteFailures.Length > 0)
            {
                MessageBox.Show("Checkin cannot proceed because there are errors in the Check-in Notes.", "Check-in Notes Failure", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                ShowCheckInNotes();

                return;
            }

            result = Manager.CurrentWorkspace.EvaluateCheckin(CheckinEvaluationOptions.Policies, PendingChanges.ToArray(), changes.ToArray(), textBoxComment.Text, note, workItemsArray);
            if (result.PolicyEvaluationException != null || result.PolicyFailures.Length > 0)
            {
                string errors = string.Empty;
                foreach (PolicyFailure failure in result.PolicyFailures)
                {
                    if (failure.Message.Contains("CheckForComments.cs"))
                    {
                        if (string.IsNullOrEmpty(textBoxComment.Text))
                        {
                            errors += Environment.NewLine + " - " + "Please provide comments for your check-in.";
                        }
                    }
                    else
                    {
                        errors += Environment.NewLine + " - " + failure.Message;
                    }
                }
                if (result.PolicyEvaluationException != null)
                {
                    errors += Environment.NewLine + " - " + result.PolicyEvaluationException.Message;
                }

                if (errors != string.Empty)
                {
                    DialogResult boxResult = MessageBox.Show("Checkin cannot proceed because the policy requirements have not been satisfied." + Environment.NewLine + errors, "Policy Failure", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
                    if (boxResult == DialogResult.Abort)
                    {
                        ShowPolicyWarnings();
                        return;
                    }
                    else if (boxResult == DialogResult.Retry)
                    {
                        CheckIn();
                        return;
                    }
                }
            }

            Manager.CurrentWorkspace.CheckIn(changes.ToArray(), textBoxComment.Text, note, workItemsArray, policyInfo);
            CheckedInChanges = changes;

            textBoxComment.Text             = string.Empty;
            textBoxCodeReviewer.Text        = string.Empty;
            textBoxSecurityReviewer.Text    = string.Empty;
            textBoxPerformanceReviewer.Text = string.Empty;

            foreach (ITabbedDocument document in PluginBase.MainForm.Documents)
            {
                if (changes.FirstOrDefault(c => c.LocalItem == document.FileName) != null)
                {
                    document.Reload(false);
                }
            }

            UpdatePendingChanges();

            OnCheckedIn(EventArgs.Empty);
        }
        private void CheckIn()
        {
            this.Logger().Trace("CheckIn");

            var pendingChanges = PendingChanges
                .Where(model => model.IncludeChange)
                .Select(model => model.Change)
                .ToArray();

            var workItemChanges =
                WorkItems.Where(model => model.IsSelected)
                .Select(model => new WorkItemCheckinInfo(model.WorkItem, model.WorkItemCheckinAction.ToWorkItemCheckinAction())).ToArray();

            var missingCheckinNotes = CheckinNotes
                .Where(model => model.CheckinNoteFieldDefinition.Required && string.IsNullOrWhiteSpace(model.Value))
                .Select(model => model.CheckinNoteFieldDefinition.Name).ToArray();

            if (missingCheckinNotes.Any())
            {
                OnShowPendingChangesItem(ShowPendingChangesTabItemEnum.CheckinNotes);

                MessageBox.Show("Check-in Validation\r\n\r\nEnter a value for " + string.Join(", ", missingCheckinNotes), "Team Pilgrim", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var checkinNoteFieldValues =
                CheckinNotes
                .Where(model => !string.IsNullOrWhiteSpace(model.Value))
                .Select(model => new CheckinNoteFieldValue(model.CheckinNoteFieldDefinition.Name, model.Value))
                .ToArray();

            var checkinNote = new CheckinNote(checkinNoteFieldValues);

            CheckinEvaluationResult checkinEvaluationResult;
            if (teamPilgrimServiceModelProvider.TryEvaluateCheckin(out checkinEvaluationResult, Workspace, pendingChanges, Comment, checkinNote, workItemChanges))
            {
                this.Logger().Debug("CheckIn EvaluateCheckin: Valid:{0}", checkinEvaluationResult.IsValid());

                PolicyOverrideInfo policyOverrideInfo = null;

                if (!checkinEvaluationResult.IsValid())
                {
                    if (checkinEvaluationResult.Conflicts.Any())
                    {
                        MessageBox.Show(
                            "Check In\r\n\r\nNo files checked in due to conflicting changes. Please use Conflicts Manager to resolve conflicts and try again.",
                            "Team Pilgrim", MessageBoxButton.OK, MessageBoxImage.Exclamation);

                        var conflictedServerItems = checkinEvaluationResult.Conflicts.Select(conflict => conflict.ServerItem).ToArray();
                        teamPilgrimVsService.ResolveConflicts(Workspace, conflictedServerItems, false, false);

                        return;
                    }

                    if (checkinEvaluationResult.PolicyFailures.Any())
                    {
                        OnShowPendingChangesItem(ShowPendingChangesTabItemEnum.PolicyWarnings);

                        var policyFailureModel = new PolicyFailureModel();
                        var policyFailureDialog = new PolicyFailureDialog()
                            {
                                DataContext = policyFailureModel
                            };

                        var dialogResult = policyFailureDialog.ShowDialog();
                        if (!dialogResult.HasValue || !dialogResult.Value || !policyFailureModel.Override)
                        {
                            CheckinEvaluationResult = checkinEvaluationResult;
                            return;
                        }

                        policyOverrideInfo = new PolicyOverrideInfo(policyFailureModel.Reason, checkinEvaluationResult.PolicyFailures);
                    }
                }

                if (teamPilgrimServiceModelProvider.TryCheckin(Workspace, pendingChanges, Comment, checkinNote, workItemChanges, policyOverrideInfo))
                {
                    Comment = string.Empty;
                    RefreshPendingChanges();

                    foreach (var workItem in WorkItems.Where(model => model.IsSelected))
                    {
                        workItem.IsSelected = false;
                    }

                    RefreshPendingChangesCommand.Execute(null);
                    RefreshSelectedDefinitionWorkItemsCommand.Execute(null);
                }
            }
        }
        public bool TryCheckin(Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote = null, WorkItemCheckinInfo[] workItemChanges = null, PolicyOverrideInfo policyOverride = null)
        {
            try
            {
                _teamPilgrimTfsService.WorkspaceCheckin(workspace, changes, comment, checkinNote, workItemChanges, policyOverride);
                return(true);
            }
            catch (Exception ex)
            {
                this.Logger().DebugException(ex);
                LastException = ex;
            }

            return(false);
        }
        private void CheckIn()
        {
            this.Logger().Trace("CheckIn");

            var pendingChanges = PendingChanges
                                 .Where(model => model.IncludeChange)
                                 .Select(model => model.Change)
                                 .ToArray();

            var workItemChanges =
                WorkItems.Where(model => model.IsSelected)
                .Select(model => new WorkItemCheckinInfo(model.WorkItem, model.WorkItemCheckinAction.ToWorkItemCheckinAction())).ToArray();

            var missingCheckinNotes = CheckinNotes
                                      .Where(model => model.CheckinNoteFieldDefinition.Required && string.IsNullOrWhiteSpace(model.Value))
                                      .Select(model => model.CheckinNoteFieldDefinition.Name).ToArray();

            if (missingCheckinNotes.Any())
            {
                OnShowPendingChangesItem(ShowPendingChangesTabItemEnum.CheckinNotes);

                MessageBox.Show("Check-in Validation\r\n\r\nEnter a value for " + string.Join(", ", missingCheckinNotes), "Team Pilgrim", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var checkinNoteFieldValues =
                CheckinNotes
                .Where(model => !string.IsNullOrWhiteSpace(model.Value))
                .Select(model => new CheckinNoteFieldValue(model.CheckinNoteFieldDefinition.Name, model.Value))
                .ToArray();

            var checkinNote = new CheckinNote(checkinNoteFieldValues);

            CheckinEvaluationResult checkinEvaluationResult;

            if (teamPilgrimServiceModelProvider.TryEvaluateCheckin(out checkinEvaluationResult, Workspace, pendingChanges, Comment, checkinNote, workItemChanges))
            {
                this.Logger().Debug("CheckIn EvaluateCheckin: Valid:{0}", checkinEvaluationResult.IsValid());

                PolicyOverrideInfo policyOverrideInfo = null;

                if (!checkinEvaluationResult.IsValid())
                {
                    if (checkinEvaluationResult.Conflicts.Any())
                    {
                        MessageBox.Show(
                            "Check In\r\n\r\nNo files checked in due to conflicting changes. Please use Conflicts Manager to resolve conflicts and try again.",
                            "Team Pilgrim", MessageBoxButton.OK, MessageBoxImage.Exclamation);

                        var conflictedServerItems = checkinEvaluationResult.Conflicts.Select(conflict => conflict.ServerItem).ToArray();
                        teamPilgrimVsService.ResolveConflicts(Workspace, conflictedServerItems, false, false);

                        return;
                    }

                    if (checkinEvaluationResult.PolicyFailures.Any())
                    {
                        OnShowPendingChangesItem(ShowPendingChangesTabItemEnum.PolicyWarnings);

                        var policyFailureModel  = new PolicyFailureModel();
                        var policyFailureDialog = new PolicyFailureDialog()
                        {
                            DataContext = policyFailureModel
                        };

                        var dialogResult = policyFailureDialog.ShowDialog();
                        if (!dialogResult.HasValue || !dialogResult.Value || !policyFailureModel.Override)
                        {
                            CheckinEvaluationResult = checkinEvaluationResult;
                            return;
                        }

                        policyOverrideInfo = new PolicyOverrideInfo(policyFailureModel.Reason, checkinEvaluationResult.PolicyFailures);
                    }
                }

                if (teamPilgrimServiceModelProvider.TryCheckin(Workspace, pendingChanges, Comment, checkinNote, workItemChanges, policyOverrideInfo))
                {
                    Comment = string.Empty;
                    RefreshPendingChanges();

                    foreach (var workItem in WorkItems.Where(model => model.IsSelected))
                    {
                        workItem.IsSelected = false;
                    }

                    RefreshPendingChangesCommand.Execute(null);
                    RefreshSelectedDefinitionWorkItemsCommand.Execute(null);
                }
            }
        }
Ejemplo n.º 8
0
        private static CheckInResult CheckIn(IReadOnlyCollection<PendingChange> targetPendingChanges, string comment,
            Workspace workspace, IReadOnlyCollection<int> workItemIds, PolicyOverrideInfo policyOverride, WorkItemStore workItemStore)
        {
            var result = new CheckInResult();

            // Another user can update workitem. Need re-read before update.
            var workItems = GetWorkItemCheckinInfo(workItemIds, workItemStore);

            var evaluateCheckIn = workspace.EvaluateCheckin2(CheckinEvaluationOptions.All,
                targetPendingChanges,
                comment,
                null,
                workItems);

            var skipPolicyValidate = !policyOverride.PolicyFailures.IsNullOrEmpty();
            if (!CanCheckIn(evaluateCheckIn, skipPolicyValidate))
            {
                result.CheckinResult = MergeResult.CheckInEvaluateFail;
            }

            var changesetId = workspace.CheckIn(targetPendingChanges.ToArray(), null, comment,
                null, workItems, policyOverride);
            if (changesetId > 0)
            {
                result.ChangesetId = changesetId;
                result.CheckinResult = MergeResult.CheckIn;
            }
            else
            {
                result.CheckinResult = MergeResult.CheckInFail;
            }
            return result;
        }
Ejemplo n.º 9
0
        public void WorkspaceCheckin(Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote, WorkItemCheckinInfo[] workItemChanges, PolicyOverrideInfo policyOverride)
        {
            this.Logger().Trace("WorkspaceCheckin");

            workspace.CheckIn(changes, comment, checkinNote, workItemChanges, policyOverride);
        }
        public void WorkspaceCheckin(Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote, WorkItemCheckinInfo[] workItemChanges, PolicyOverrideInfo policyOverride)
        {
            this.Logger().Trace("WorkspaceCheckin");

            workspace.CheckIn(changes, comment, checkinNote, workItemChanges, policyOverride);
        }
Ejemplo n.º 11
0
        public bool ShowDialog(Workspace workSpace  = null,
                               int pageToSelect     = 0,
                               bool?closeButtonOnly = null)
        {
            if (closeButtonOnly == null)
            {
                closeButtonOnly = pageToSelect == 4;
            }


            if (workSpace == null)
            {
                workSpace = versionControlServer.GetWorkspace(Environment.MachineName, versionControlServer.AuthorizedUser);
            }

            workSpace.Refresh();
            //Thread.Sleep(2000);
            PendingChange[] pendingChange = workSpace.GetPendingChanges();
            PendingChange[] checkedinPendingChange;
            if (workingFolder != null)
            {
                checkedinPendingChange = workSpace.GetPendingChanges(workingFolder.ServerItem, RecursionType.Full);
            }
            else if (changes != null && changes.Any())
            {
                checkedinPendingChange = changes;
            }
            else
            {
                checkedinPendingChange = pendingChange;
            }
            //PendingChange[] checkedinPendingChange = pendingChange.Where(c => c.ServerItem.Contains(workingFolder.ServerItem)).ToArray();
            //Assembly controlsAssembly = Assembly.LoadFile(controlsAssemblyPath);
            Assembly controlsAssembly    = typeof(Microsoft.TeamFoundation.VersionControl.Controls.LocalPathLinkBox).Assembly;
            Type     vcCheckinDialogType = controlsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogCheckin");


            ConstructorInfo ci = vcCheckinDialogType.GetConstructor(
                BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                new Type[] { typeof(Workspace), typeof(PendingChange[]), typeof(PendingChange[]),
                             typeof(string), typeof(CheckinNote), typeof(WorkItemCheckedInfo[]), typeof(string) },
                null);

            checkInDialog = (Form)ci.Invoke(new object[] { workSpace, pendingChange, checkedinPendingChange, "", null, null, "" });

            checkedPendingChanges = vcCheckinDialogType.GetProperty("CheckedChanges", BindingFlags.Instance | BindingFlags.NonPublic);
            checkedWorkItems      = vcCheckinDialogType.GetProperty("CheckedWorkItems", BindingFlags.Instance | BindingFlags.NonPublic);
            checkinNotes          = vcCheckinDialogType.GetProperty("CheckinNotes", BindingFlags.Instance | BindingFlags.NonPublic);
            comment = vcCheckinDialogType.GetProperty("Comment", BindingFlags.Instance | BindingFlags.NonPublic);
            policyFailureOverrideReason = vcCheckinDialogType.GetProperty("PolicyFailureOverrideReason", BindingFlags.Instance | BindingFlags.NonPublic);
            policyFailures = vcCheckinDialogType.GetProperty("PolicyFailures", BindingFlags.Instance | BindingFlags.NonPublic);

            if (Application.OpenForms.Count > 0 && Application.OpenForms[0] != null)
            {
                checkInDialog.Owner         = Application.OpenForms[0];
                checkInDialog.StartPosition = FormStartPosition.CenterParent;
            }

            dynamic dynamicForm            = ExposedObject.From(checkInDialog);
            dynamic checkinsChannelControl = ExposedObject.From(dynamicForm.m_channelControl);             // PendingCheckinsChannelControl

            //dynamic conflictsChannel = ExposedObject.From(((dynamic)checkinsChannelControl).ConflictsControl);
            //dynamic conflictsPresenter = ExposedObject.From(((dynamic)conflictsChannel).m_conflictPresenter);
            //dynamic conflictStore = ExposedObject.From(((dynamic)conflictsPresenter).m_store);

            if (pageToSelect != 0)
            {
                checkinsChannelControl.SelectedChannel = pageToSelect;
                var channel = checkinsChannelControl.SelectedChannel;
            }

            if (closeButtonOnly == true)
            {
                try
                {
                    dynamicForm.buttonOK.Visible  = false;
                    dynamicForm.buttonCancel.Text = "Close";
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            checkInDialog.ShowDialog();
            this.DialogResult = checkInDialog.DialogResult;
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

            if (DialogResult != DialogResult.Cancel)
            {
                PendingChange[]       selectedPendingChange = (PendingChange[])checkedPendingChanges.GetValue(checkInDialog, null);
                WorkItemCheckinInfo[] checkedWorkItemInfo   = (WorkItemCheckinInfo[])checkedWorkItems.GetValue(checkInDialog, null);
                string          comments     = (string)comment.GetValue(checkInDialog, null);
                string          policyReason = (string)policyFailureOverrideReason.GetValue(checkInDialog, null);
                CheckinNote     notes        = (CheckinNote)checkinNotes.GetValue(checkInDialog, null);
                PolicyFailure[] failures     = (PolicyFailure[])policyFailures.GetValue(checkInDialog, null);

                PolicyOverrideInfo overrideinfo = new PolicyOverrideInfo(policyReason, failures);

                try
                {
                    workSpace.CheckIn(selectedPendingChange,
                                      comments,
                                      notes,
                                      checkedWorkItemInfo,
                                      overrideinfo);
                }
                catch (Exception exp)
                {
                    System.Windows.Forms.MessageBox.Show("Check in Failed due to " + exp.Message);
                    return(false);
                }
            }
            else
            {
                return(true);
            }


            return(true);
        }