Ejemplo n.º 1
0
        private void PopulateSelectedPendingChangesSummary()
        {
            if (_backgroundFunctionPreventDataUpdate)
            {
                return;
            }

            this.Logger().Trace("PopulateSelectedPendingChangesSummary");

            if (PendingChanges.Count == 0)
            {
                PendingChangesSummary = CollectionSelectionSummaryEnum.None;
                return;
            }

            var includedCount = PendingChanges.Count(model => model.IncludeChange);

            if (includedCount == 0)
            {
                PendingChangesSummary = CollectionSelectionSummaryEnum.None;
                return;
            }

            PendingChangesSummary = PendingChanges.Count == includedCount
                                        ? CollectionSelectionSummaryEnum.All
                                        : CollectionSelectionSummaryEnum.Some;
        }
Ejemplo n.º 2
0
        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);
        }