private CheckinNote GetCurrentCheckinNotes() { List <CheckinNoteFieldValue> notes = new List <CheckinNoteFieldValue>(); if (textBoxCodeReviewer.Text.Length > 0) { notes.Add(new CheckinNoteFieldValue("Code Reviewer", textBoxCodeReviewer.Text)); } if (textBoxSecurityReviewer.Text.Length > 0) { notes.Add(new CheckinNoteFieldValue("Security Reviewer", textBoxSecurityReviewer.Text)); } if (textBoxPerformanceReviewer.Text.Length > 0) { notes.Add(new CheckinNoteFieldValue("Performance Reviewer", textBoxPerformanceReviewer.Text)); } CheckinNote note = notes.Count > 0 ? new CheckinNote(notes.ToArray()) : null; return(note); }
/// <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); }
public bool TryEvaluateCheckin(out CheckinEvaluationResult checkinEvaluationResult, Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote = null, WorkItemCheckinInfo[] workItemChanges = null) { try { checkinEvaluationResult = _teamPilgrimTfsService.EvaluateCheckin(workspace, changes, comment, checkinNote, workItemChanges); return(true); } catch (Exception ex) { this.Logger().DebugException(ex); LastException = ex; } checkinEvaluationResult = null; return(false); }
/// <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); }
private void EvaluateCheckIn() { this.Logger().Trace("EvaluateCheckIn"); var pendingChanges = PendingChanges .Where(model => model.IncludeChange) .Select(model => model.Change) .ToArray(); if (!pendingChanges.Any()) { CheckinEvaluationResult = null; CheckinNotes.Clear(); return; } var currentCheckinNoteDefinitions = checkinNotesCacheWrapper.GetCheckinNotes(pendingChanges); var equalityComparer = CheckinNoteFieldDefinition.NameComparer.ToGenericComparer <CheckinNoteFieldDefinition>().ToEqualityComparer(); var modelIntersection = CheckinNotes .Join(currentCheckinNoteDefinitions, model => model.CheckinNoteFieldDefinition, checkinNoteFieldDefinition => checkinNoteFieldDefinition, (model, change) => model, equalityComparer) .ToArray(); var modelsToRemove = CheckinNotes.Where(model => !modelIntersection.Contains(model)).ToArray(); var modelsToAdd = currentCheckinNoteDefinitions .Where(checkinNoteFieldDefinition => !modelIntersection.Select(model => model.CheckinNoteFieldDefinition).Contains(checkinNoteFieldDefinition, equalityComparer)) .Select(checkinNoteFieldDefinition => new CheckinNoteModel(checkinNoteFieldDefinition)).ToArray(); foreach (var checkinNoteModel in modelsToAdd) { CheckinNotes.Add(checkinNoteModel); } foreach (var modelToRemove in modelsToRemove) { CheckinNotes.Remove(modelToRemove); } CheckinEvaluationResult checkinEvaluationResult; var workItemChanges = WorkItems .Where(model => model.IsSelected) .Select(model => new WorkItemCheckinInfo(model.WorkItem, model.WorkItemCheckinAction.ToWorkItemCheckinAction())).ToArray(); var checkinNoteFieldValues = CheckinNotes .Where(model => !string.IsNullOrWhiteSpace(model.Value)) .Select(model => new CheckinNoteFieldValue(model.CheckinNoteFieldDefinition.Name, model.Value)) .ToArray(); var checkinNote = new CheckinNote(checkinNoteFieldValues); if (teamPilgrimServiceModelProvider.TryEvaluateCheckin(out checkinEvaluationResult, Workspace, pendingChanges, Comment, checkinNote, workItemChanges)) { CheckinEvaluationResult = checkinEvaluationResult; } }
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); } } }
private void Shelve() { var pendingChanges = PendingChanges .Where(model => model.IncludeChange) .Select(model => model.Change) .ToArray(); if (EvaluatePoliciesAndCheckinNotes) { 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( string.Format("Check-in Validation\r\n\r\nEnter a value for {0}", string.Join(", ", missingCheckinNotes)), "Team Pilgrim", MessageBoxButton.OK, MessageBoxImage.Error); return; } } var workItemInfo = WorkItems .Where(model => model.IsSelected) .Select(model => new WorkItemCheckinInfo(model.WorkItem, model.WorkItemCheckinAction.ToWorkItemCheckinAction())) .ToArray(); var checkinNoteFieldValues = CheckinNotes .Where(model => !string.IsNullOrWhiteSpace(model.Value)) .Select(model => new CheckinNoteFieldValue(model.CheckinNoteFieldDefinition.Name, model.Value)) .ToArray(); var checkinNote = new CheckinNote(checkinNoteFieldValues); string policyOverrideComment = null; if (EvaluatePoliciesAndCheckinNotes) { CheckinEvaluationResult checkinEvaluationResult; if (teamPilgrimServiceModelProvider.TryEvaluateCheckin(out checkinEvaluationResult, _workspaceServiceModel.Workspace, pendingChanges, Comment, checkinNote, workItemInfo)) { if (!checkinEvaluationResult.IsValid()) { 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; } policyOverrideComment = policyFailureModel.Reason; } } else { return; } } var versionControlServer = _projectCollectionServiceModel.TfsTeamProjectCollection.GetVersionControlServer(); var shelveset = new Shelveset(versionControlServer, ShelvesetName, _projectCollectionServiceModel.TfsTeamProjectCollection.AuthorizedIdentity.UniqueName) { Comment = Comment, ChangesExcluded = PendingChanges.Count() != pendingChanges.Count(), WorkItemInfo = workItemInfo, CheckinNote = checkinNote, PolicyOverrideComment = policyOverrideComment }; PendingSet[] pendingSets; if (teamPilgrimServiceModelProvider.TryWorkspaceQueryShelvedChanges(_workspaceServiceModel.Workspace, out pendingSets, ShelvesetName, _projectCollectionServiceModel.TfsTeamProjectCollection.AuthorizedIdentity.UniqueName, null)) { bool overwrite = false; if (pendingSets != null && pendingSets.Any()) { if (MessageBox.Show(string.Format("Replace shelveset\r\n\r\nThe shelveset {0} already exists. Replace?", ShelvesetName), "Team Pilgrim", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { overwrite = true; } else { return; } } var shelvingOptions = ShelvingOptions.None; if (!PreservePendingChangesLocally) { shelvingOptions |= ShelvingOptions.Move; } if (overwrite) { shelvingOptions |= ShelvingOptions.Replace; } if (teamPilgrimServiceModelProvider.TryShelve(_workspaceServiceModel.Workspace, shelveset, pendingChanges, shelvingOptions)) { } } OnDismiss(true); }
public CheckinEvaluationResult EvaluateCheckin(Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote, WorkItemCheckinInfo[] workItemChanges) { this.Logger().Trace("EvaluateCheckin"); return(workspace.EvaluateCheckin(CheckinEvaluationOptions.All, changes, changes, comment, checkinNote, workItemChanges)); }
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 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); }