protected override IEnumerable<WorkItemInfo> GetWorkItems(WorkItemCheckinInfo[] currentlyAssociatedWorkItems)
        {
            var context = CurrentContext;
            if (context == null || !context.HasCollection || !context.HasTeamProject)
                return Enumerable.Empty<WorkItemInfo>();

            var store = context.TeamProjectCollection.GetService<WorkItemStore>();
            if (store == null)
                return Enumerable.Empty<WorkItemInfo>();

            var workItems = new List<WorkItemInfo>();

            var results = store.Query(@"
            Select [ID], [Title]
            From WorkItems
            Where [System.TeamProject] = '" + context.TeamProjectName + @"' AND [Assigned to] = @Me
            Order By [Created Date] desc");

            foreach (WorkItem workItem in results)
            {
                if (currentlyAssociatedWorkItems.All(w => w.WorkItem.Id != workItem.Id))
                {
                    workItems.Add(new WorkItemInfo(workItem.Id, workItem.Title, workItem.Type.Name, workItem.State, "@Me"));

                    if (workItems.Count == 5)
                        break;
                }
            }

            return workItems;
        }
Esempio n. 2
0
        public bool AddToTFVC(string[] _files, WorkItem _wi, Workspace _ws)
        {
            try
             {
                 _ws.Get();
                 // Now add everything.
                 _ws.PendAdd(_files, false);
                 WorkItemCheckinInfo[] _wici = new WorkItemCheckinInfo[1];

                 _wici[0] = new WorkItemCheckinInfo(_wi, WorkItemCheckinAction.Associate);

                 if (_ws.CheckIn(_ws.GetPendingChanges(), null, null, _wici, null) > 0)
                 {
                     _ws.Delete();
                     return true;

                 }
                 else
                 {
                     return false;
                 }

             }
             catch
             {
                 return false;
             }
        }
        protected override IEnumerable<WorkItemInfo> GetWorkItems(WorkItemCheckinInfo[] currentlyAssociatedWorkItems)
        {
            var context = CurrentContext;
            if (context == null || !context.HasCollection || !context.HasTeamProject)
                return Enumerable.Empty<WorkItemInfo>();

            var vcs = context.TeamProjectCollection.GetService<VersionControlServer>();
            if (vcs == null)
                return Enumerable.Empty<WorkItemInfo>();

            var workItems = new List<WorkItemInfo>();

            string path = "$/" + context.TeamProjectName;
            foreach (Changeset changeset in vcs.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full, vcs.AuthorizedUser, null, null, 10, false, true))
            {
                foreach (var wi in changeset.AssociatedWorkItems)
                {
                    if (workItems.All(w => w.Id != wi.Id) && currentlyAssociatedWorkItems.All(w => w.WorkItem.Id != wi.Id))
                    {
                        workItems.Add(new WorkItemInfo(wi.Id, wi.Title, wi.WorkItemType, wi.State, wi.AssignedTo));
                    }
                }
            }

            return workItems;
        }
Esempio n. 4
0
        /// <summary>
        /// Determines whether the <paramref name="value"/> should be excluded from the policy.
        /// </summary>
        /// <param name="value">An <see cref="System.Object"/> to evaluate.</param>
        /// <returns><b>true</b> if the exclusion is successful; otherwise, <b>false</b>.</returns>
        public override bool Evaluate(object value)
        {
            bool retval = false;

            if (value != null)
            {
                WorkItemCheckinInfo item = (WorkItemCheckinInfo)value;
                retval = item.WorkItem != null && item.WorkItem.Id == this.WorkItemId;
            }

            return(retval);
        }
        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;
        }
        /// <summary>
        /// Determines whether the <paramref name="value"/> should be excluded from the policy.
        /// </summary>
        /// <param name="value">An <see cref="System.Object"/> to evaluate.</param>
        /// <returns><b>true</b> if the exclusion is successful; otherwise, <b>false</b>.</returns>
        public override bool Evaluate(object value)
        {
            bool retval = false;

            if (value != null && !string.IsNullOrEmpty(this.FieldName))
            {
                WorkItemCheckinInfo item = (WorkItemCheckinInfo)value;
                if (item != null && item.WorkItem.Fields.Contains(this.FieldName))
                {
                    Field field = item.WorkItem.Fields[this.FieldName];
                    if (field != null && field.IsValid)
                    {
                        retval = this.FieldValue == field.Value.ToString();
                    }
                }
            }

            return(retval);
        }
Esempio n. 7
0
        /// <summary>
        /// Associate Work Item to our shelveset
        /// </summary>
        public static void AssociateWorkItemToShelveset()
        {
            WorkItemCheckinInfo work = new WorkItemCheckinInfo(workItemReviewCode, WorkItemCheckinAction.Associate);

            work.CheckinAction = WorkItemCheckinAction.Associate;
            List <WorkItemCheckinInfo> workCollection = new List <WorkItemCheckinInfo>();

            workCollection.Add(work);

            shelveset.WorkItemInfo = workCollection.ToArray();
            if (shelvesetExist)
            {
                //TODO Ne pas remplacer le ShelveSet mais Creér un id Unique
                workspace.Shelve(shelveset, changes, ShelvingOptions.Replace);
            }
            else
            {
                workspace.Shelve(shelveset, changes, ShelvingOptions.None);
                wiStore.SyncToCache();
                wiStore.RefreshCache();
            }
        }
Esempio n. 8
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);
        }
 /// <summary>
 /// Indicates whether the work item has been excluded from the policy.
 /// </summary>
 /// <param name="selectedWorkItem">The work item to check.</param>
 /// <returns><b>true</b> if the work item is excluded; otherwise, <b>false</b>.</returns>
 private bool IsWorkItemExcluded(WorkItemCheckinInfo selectedWorkItem)
 {
     return(this.IsItemExcluded(selectedWorkItem, PolicyExclusionType.WorkItemId) || this.IsItemExcluded(selectedWorkItem, PolicyExclusionType.WorkItemField));
 }
        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;
        }
        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);
        }
Esempio n. 12
0
        public bool Checkin(string element, string wsname, string owner, string comment, string witype, int winum, string project)
        {
            TeamFoundationServer tfs = GetTfs();
            WorkItemStore store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
            WorkItemTypeCollection workItemTypes = store.Projects[project].WorkItemTypes;
            Workspace ws = this.GetWorkSpace(wsname, owner);
            PendingChange[] pendingChanges = ws.GetPendingChanges(element);
            WorkItemType wi = workItemTypes[witype];
            WorkItemCheckinInfo[] wici= new WorkItemCheckinInfo[1];

            wici[0] = new WorkItemCheckinInfo( wi.Store.GetWorkItem(winum),
                                               WorkItemCheckinAction.Associate);

            int changesetNumber = ws.CheckIn(pendingChanges, comment, null, wici, null);
            return true;
        }
 protected abstract IEnumerable<WorkItemInfo> GetWorkItems(WorkItemCheckinInfo[] currentlyAssociatedWorkItems);
Esempio n. 14
0
 public IWorkItemCheckinInfo Wrap(WorkItemCheckinInfo workItemCheckinInfo)
 {
     return new WrapperForWorkItemCheckinInfo(workItemCheckinInfo);
 }
Esempio n. 15
0
        private static WorkItemCheckinInfo[] GetWorkItemCheckinInfo(IReadOnlyCollection<int> workItemIds, WorkItemStore workItemStore)
        {

            var result = new List<WorkItemCheckinInfo>(workItemIds.Count);
            foreach (var workItemId in workItemIds)
            {
                var workItem = workItemStore.GetWorkItem(workItemId);
                var workItemCheckinInfo = new WorkItemCheckinInfo(workItem, WorkItemCheckinAction.Associate);
                result.Add(workItemCheckinInfo);
            }

            return result.ToArray();
        }
Esempio n. 16
0
        public void MergeByWorkItem()
        {
            var tuples = GetLinkAndChangesetPairs(_workitemID, _source);

            if (tuples == null || tuples.Count() == 0)
            {
                _log.InfoFormat("There is no applicable changeset to merge to target branch '{0}' linked to workitem {1}.", _target, _workitemID);
                return;
            }

            var sourceResult = GetLatest(_source);

            if (sourceResult == false)
            {
                return;
            }

            var targetResult = GetLatest(_target);

            if (targetResult == false)
            {
                return;
            }

            var workitem = _workitemStore.GetWorkItem(_workitemID);

            // *** ENSURE list is sorted by Changeset ID's in order not to chekin to target in wrong order ***
            tuples.Sort((a, b) => a.Item2.ChangesetId.CompareTo(b.Item2.ChangesetId));

            foreach (var tuple in tuples)
            {
                var changeset = tuple.Item2;
                var link      = tuple.Item1;

                var version = VersionSpec.ParseSingleSpec(changeset.ChangesetId.ToString(), _sourceControl.AuthorizedUser);
                _log.InfoFormat("Merge process for changeset {0} is starting... Source: {1} - Target: {2}", changeset.ChangesetId, _source, _target);
                var status = _workspace.Merge(_source, _target, version, version);
                var result = ValidateStatus(status);

                workitem.Links.Remove(link);
                workitem.Save();

                if (result == false)
                {
                    _log.InfoFormat("Link of changeset {0} removed from workitem {1}", changeset.ChangesetId, _workitemID);
                    _log.InfoFormat("Please copy the comment of Changeset {0}: '{1}'", changeset.ChangesetId, changeset.Comment);
                    return;
                }

                // Get pending changes of files ONLY related to this changeset
                var serverItems    = changeset.Changes.Select(c => c.Item.ServerItem).ToArray();
                var pendingChanges = _workspace.GetPendingChanges(serverItems);

                // If the set of pending changes for checkin is null, the server will attempt to check in all changes in the workspace, but this operation
                // is not valid if any pending changes in the workspace are edits or adds, as content will not have been uploaded to the server.
                if (pendingChanges == null || pendingChanges.Count() == 0)
                {
                    continue;
                }

                var workitemRelation = new WorkItemCheckinInfo(workitem, WorkItemCheckinAction.Associate);
                var newChangesetID   = _workspace.CheckIn(pendingChanges, changeset.Comment, null, new WorkItemCheckinInfo[] { workitemRelation }, null);

                _log.InfoFormat("Changeset {0} checked in under WorkItem: {1}", newChangesetID, _workitemID);
            }
        }
Esempio n. 17
0
        public bool CheckinAll(string wsname, string owner, string comment, int winum)
        {
            TeamFoundationServer tfs = GetTfs();
             WorkItemStore store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
             Workspace ws = this.GetWorkSpace(wsname, owner);
             PendingChange[] pendingChanges = ws.GetPendingChanges();
             WorkItemCheckinInfo[] wici = new WorkItemCheckinInfo[1];
             wici[0] = new WorkItemCheckinInfo(store.GetWorkItem(winum), WorkItemCheckinAction.Associate);

             if (pendingChanges.Length > 0)
             {
                 int changesetNumber = ws.CheckIn(pendingChanges, comment, null, wici, null);
                 return true;
             }
             else
             {
                 return false;
             }
        }
        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);
        }