public TagAdminPageViewModel(IServiceProvider serviceProvider, ITeamFoundationContext teamFoundationContext, ITagAdminContext tagAdminContext)
        {
            _serviceProvider       = serviceProvider;
            _teamFoundationContext = teamFoundationContext;
            _tagAdminContext       = tagAdminContext;
            _eventAggregator       = _tagAdminContext.EventAggregator;

            var logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                                       $"Tag Admin for Visual Studio 2017\\TagAdminForVisualStudio2017-{DateTime.Now:dd-MM-yyyy}.log");

            _log = new LoggerConfiguration().WriteTo.File(logPath, fileSizeLimitBytes: 5000000)
                   .CreateLogger();
            _log.Information("Initializing TagAdminPageViewModel - ServiceProvider: {serviceprovider}, TFSContext: {@tfs}, TagAdminContext: {@tagAdmin}",
                             _serviceProvider != null,
                             new
            {
                Collection = _teamFoundationContext.TeamProjectCollection.Name,
                User       = _teamFoundationContext.TeamProjectCollection.ConfigurationServer.AuthorizedIdentity.UniqueName,
                Project    = _teamFoundationContext.TeamProjectName,
            }, _tagAdminContext.EventAggregator != null);

            ShowBusy(true);

            Subscriptions();

            Triggers();
        }
        /// <summary>
        /// Retrieves the shelveset list for the current user
        /// </summary>
        /// <param name="userName">The user name </param>
        /// <param name="secondUsername">The second user name </param>
        /// <param name="context">The Team foundation server context</param>
        /// <param name="shelveSets">The shelveset list to be returned</param>
        private static void FetchShevlesets(string userName, string secondUsername, ITeamFoundationContext context, out ObservableCollection <Shelveset> shelveSets)
        {
            shelveSets = new ObservableCollection <Shelveset>();
            if (context != null && context.HasCollection && context.HasTeamProject)
            {
                var vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                if (vcs != null)
                {
                    string user = string.IsNullOrWhiteSpace(userName) ? vcs.AuthorizedUser : userName;
                    foreach (var shelveSet in vcs.QueryShelvesets(null, user).OrderByDescending(s => s.CreationDate))
                    {
                        shelveSets.Add(shelveSet);
                    }

                    if (!string.IsNullOrWhiteSpace(secondUsername) && secondUsername != userName)
                    {
                        user = string.IsNullOrWhiteSpace(secondUsername) ? vcs.AuthorizedUser : secondUsername;
                        foreach (var shelveSet in vcs.QueryShelvesets(null, user).OrderByDescending(s => s.CreationDate))
                        {
                            shelveSets.Add(shelveSet);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public Changeset GetChangeset(ITeamFoundationContext currentContext, int changesetId)
        {
            var versionControl = currentContext.TeamProjectCollection.GetService <VersionControlServer>();
            var changeset      = versionControl.GetChangeset(changesetId);

            return(changeset);
        }
Ejemplo n.º 4
0
        private void PerformSearch()
        {
            this.TextBoxSearch.Foreground = Brushes.Black;

            if (!string.IsNullOrWhiteSpace(this.TextBoxSearch.Text))
            {
                ITeamFoundationContext     context = this.ParentSection.GetContext();
                IIdentityManagementService ims     = context.TeamProjectCollection.GetService <IIdentityManagementService>();

                // First try search by AccountName
                TeamFoundationIdentity userIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName, this.TextBoxSearch.Text, MembershipQuery.None, ReadIdentityOptions.ExtendedProperties);
                if (userIdentity == null)
                {
                    // Next we try search by DisplayName
                    userIdentity = ims.ReadIdentity(IdentitySearchFactor.DisplayName, this.TextBoxSearch.Text, MembershipQuery.None, ReadIdentityOptions.ExtendedProperties);
                    if (userIdentity == null)
                    {
                        this.TextBoxSearch.Foreground = Brushes.DarkRed;
                        return;
                    }
                }

                this.ParentSection.UserAccountName = this.TextBoxSearch.Text;
                this.ParentSection.UserDisplayName = userIdentity.DisplayName;
            }
            else
            {
                this.ParentSection.UserAccountName = "@Me";
                this.ParentSection.UserDisplayName = string.Empty;
            }

            this.ParentSection.Refresh();
        }
Ejemplo n.º 5
0
        private async Task RefreshAsyncShelveSets()
        {
            try
            {
                // Set our busy flag and clear the previous data
                this.IsBusy = true;
                this.Shelvesets.Clear();

                ObservableCollection <Shelveset> lshelvesests = new ObservableCollection <Shelveset>();

                // Make the server call asynchronously to avoid blocking the UI
                await Task.Run(() =>
                {
                    ITeamFoundationContext context = this.CurrentContext;
                    if (context != null && context.HasCollection && context.HasTeamProject)
                    {
                        VersionControlServer vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                        if (vcs != null)
                        {
                            // Ask the derived section for the history parameters
                            string user;
                            GetShelvesetParameters(vcs, out user);
                            foreach (Shelveset shelveset in vcs.QueryShelvesets(null, user))
                            {
                                lshelvesests.Add(shelveset);
                            }
                        }
                    }
                });

                // The shelvesets are not in the right order, lets sort them by date
                var sortedShelvesets = (
                    from ss in lshelvesests
                    orderby ss.CreationDate descending
                    select ss).ToList();

                ObservableCollection <Shelveset> lshelvesests2 = new ObservableCollection <Shelveset>();
                foreach (var s in sortedShelvesets)
                {
                    lshelvesests2.Add(s);

                    // only bring back the last 15
                    if (lshelvesests2.Count >= 15)
                    {
                        break;
                    }
                }

                this.Shelvesets = lshelvesests2;
            }
            catch (Exception ex)
            {
                this.ShowNotification(ex.Message, NotificationType.Error);
            }
            finally
            {
                // Always clear our busy flag when done
                this.IsBusy = false;
            }
        }
        public AssociatedWorkitemsPageContent(IServiceProvider serviceProvider, ITeamFoundationContext teamFoundationContext, ITagAdminContext tagAdminContext, object context)
        {
            InitializeComponent();
            var tagsList = context as AsyncObservableCollection <Tag>;

            DataContext = new AssociatedWorkitemViewModel(serviceProvider, teamFoundationContext, tagAdminContext, tagsList?.ToList());
        }
        /// <summary>
        /// Retrieves the shelveset for pending change for the current user
        /// </summary>
        /// <param name="context">The Team foundation server context</param>
        internal Shelveset FetchPendingChangeShelveset(ITeamFoundationContext context)
        {
            if (context != null && context.HasCollection && context.HasTeamProject)
            {
                var vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                if (vcs != null)
                {
                    var machineName     = Environment.MachineName;
                    var currentUserName = Environment.UserName;

                    var workspace = vcs.GetWorkspace(machineName, currentUserName);

                    var changes = workspace.GetPendingChanges();//we want to shelve all pending changes in the workspace

                    if (changes.Length != 0)

                    {
                        var pendChange = new Shelveset(vcs, "Pending Changes", workspace.OwnerName);
                        workspace.Shelve(pendChange, changes, ShelvingOptions.Replace);//you can specify to replace existing shelveset, or to remove pending changes from the local workspace with ShelvingOptions
                        pendChange.CreationDate = DateTime.Now;

                        return(pendChange);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 8
0
        public void SetLastWorkItem(ITeamExplorer teamExplorer, ITeamFoundationContext context)
        {
            var lastChangeset = GetLastUserChangeSet(context.TeamProjectCollection, context.TeamProjectName);
            if (lastChangeset == null)
                return;

            SetLastWorkItem(teamExplorer, lastChangeset);
        }
 private void OnGetTags(ITeamFoundationContext context)
 {
     OnClearSelectionCommand(null);
     //if context has changed by user update our local context
     // also fixes issue: The project specified is not found in hierarchy issue
     _teamFoundationContext = context;
     GetTagsFromService(context);
 }
Ejemplo n.º 10
0
        private async Task RefreshAsyncWorkitems()
        {
            try
            {
                // Set our busy flag and clear the previous data
                this.IsBusy = true;
                this.WorkItems.Clear();

                ObservableCollection <WorkItem> lworkItems = new ObservableCollection <WorkItem>();

                // Make the server call asynchronously to avoid blocking the UI
                await Task.Run(() =>
                {
                    ITeamFoundationContext context = this.CurrentContext;
                    if (context != null && context.HasCollection && context.HasTeamProject)
                    {
                        WorkItemStore wis = context.TeamProjectCollection.GetService <WorkItemStore>();
                        if (wis != null)
                        {
                            WorkItemCollection wic;
                            if (!string.IsNullOrWhiteSpace(this.UserAccountName))
                            {
                                string user = "******" + this.UserDisplayName + "'";
                                wic         = wis.Query("SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.WorkItemType] <> ''  AND  [System.State] <> ''  AND  [System.AssignedTo] EVER " + user + " ORDER BY [System.ChangedDate] desc");
                            }
                            else
                            {
                                wic = wis.Query("SELECT [System.Id], [System.Title], [System.State] FROM WorkItems WHERE [System.WorkItemType] <> ''  AND  [System.State] <> '' AND [System.TeamProject] = '" + context.TeamProjectName + "'ORDER BY [System.ChangedDate] desc");
                            }

                            int i = 0;
                            foreach (WorkItem wi in wic)
                            {
                                lworkItems.Add(wi);
                                i++;
                                if (i >= 12)
                                {
                                    break;
                                }
                            }
                        }
                    }
                });

                // Now back on the UI thread, update the bound collection and section title
                this.WorkItems = lworkItems;
            }
            catch (Exception ex)
            {
                this.ShowNotification(ex.Message, NotificationType.Error);
            }
            finally
            {
                // Always clear our busy flag when done
                this.IsBusy = false;
            }
        }
        public static bool IsConnectedToTfsCollectionAndProject(ITeamFoundationContext context)
        {
            if (context != null)
            {
                return(context.HasCollection && context.HasTeamProject);
            }

            return(false);
        }
        public static bool IsConnectedToTfsCollectionAndProject(ITeamFoundationContext context)
        {
            if (context != null)
            {
                return context.HasCollection && context.HasTeamProject;
            }

            return false;
        }
        /// <summary>
        /// Associates a new version control server (child of a TeamProjectCollection)
        /// with this instance. Should be called when the TeamProjectCollection changes.
        /// </summary>
        private void SetVersionControlServer(ITeamFoundationContext tfContext)
        {
            RemoveVersionControlReferences();

            if (tfContext != null && tfContext.TeamProjectCollection != null)
            {
                m_vcServer = tfContext.TeamProjectCollection.GetService <VersionControlServer>();
                m_vcServer.CommitCheckin += VersionControlServer_CommitCheckin;
            }
        }
Ejemplo n.º 14
0
 private void UpdateText(ITeamFoundationContext teamFoundationContext)
 {
     if (teamFoundationContext == null || string.IsNullOrEmpty(teamFoundationContext.TeamProjectName))
     {
         Text = string.Empty;
     }
     else
     {
         Text = "Plugin connected to " + teamFoundationContext.TeamProjectName;
     }
 }
Ejemplo n.º 15
0
        public void SetLastWorkItems(ITeamExplorer teamExplorer, ITeamFoundationContext context)
        {
            var lastChangeset = GetLastUserChangeSet(context.TeamProjectCollection, context.TeamProjectName);

            if (lastChangeset == null)
            {
                return;
            }

            SetWorkItemsFromChangeset(teamExplorer, lastChangeset);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Refresh the changeset data asynchronously.
        /// </summary>
        private async Task RefreshAsync()
        {
            try
            {
                var pc = GetService <IPendingChangesExt>();
                var currentlyAssociatedWorkItems = pc.WorkItems;

                // Set our busy flag and clear the previous data
                this.IsBusy = true;
                this.RecentWorkItems.Clear();

                var workItems = new ObservableCollection <AssociatedWorkItemInfo>();

                // Make the server call asynchronously to avoid blocking the UI
                await Task.Run(() =>
                {
                    ITeamFoundationContext context = this.CurrentContext;
                    if (context != null && context.HasCollection && context.HasTeamProject)
                    {
                        var vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                        if (vcs != null)
                        {
                            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(wi);
                                    }
                                }
                            }
                        }
                    }
                });

                // Now back on the UI thread, update the bound collection and section title
                this.RecentWorkItems = new ObservableCollection <AssociatedWorkItemInfo>(workItems.Take(5));
                this.Title           = this.RecentWorkItems.Count > 0 ? String.Format(" {0} ({1})", SectionTitle, this.RecentWorkItems.Count)
                                                       : SectionTitle;
            }
            catch (Exception ex)
            {
                ShowNotification(ex.Message, NotificationType.Error);
            }
            finally
            {
                // Always clear our busy flag when done
                this.IsBusy = false;
            }
        }
Ejemplo n.º 17
0
        private string GetPath()
        {
            if (!string.IsNullOrEmpty(QueryPath))
            {
                return(QueryPath);
            }
            ITeamFoundationContext context = CurrentContext;

            if (context != null && context.HasCollection && context.HasTeamProject)
            {
                return("$/" + context.TeamProjectName);
            }
            return("$/");
        }
        /// <summary>
        /// Refresh the changeset data asynchronously.
        /// </summary>
        private async Task RefreshAsync()
        {
            try
            {
                // Set our busy flag and clear the previous data
                this.IsBusy = true;
                this.Changesets.Clear();

                ObservableCollection <Changeset> changesets = new ObservableCollection <Changeset>();

                // Make the server call asynchronously to avoid blocking the UI
                await Task.Run(() =>
                {
                    ITeamFoundationContext context = this.CurrentContext;
                    if (context != null && context.HasCollection && context.HasTeamProject)
                    {
                        VersionControlServer vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                        if (vcs != null)
                        {
                            // Ask the derived section for the history parameters
                            string user;
                            int maxCount;
                            GetHistoryParameters(vcs, out user, out maxCount);

                            string path = "$/" + context.TeamProjectName;
                            foreach (Changeset changeset in vcs.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full,
                                                                             user, null, null, maxCount, false, true))
                            {
                                changesets.Add(changeset);
                            }
                        }
                    }
                });

                // Now back on the UI thread, update the bound collection and section title
                this.Changesets = changesets;
                this.Title      = this.Changesets.Count > 0 ? String.Format("{0} ({1})", this.BaseTitle, this.Changesets.Count)
                                                       : this.BaseTitle;
            }
            catch (Exception ex)
            {
                ShowNotification(ex.Message, NotificationType.Error);
            }
            finally
            {
                // Always clear our busy flag when done
                this.IsBusy = false;
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Refresh the changeset data asynchronously.
        /// </summary>
        private async Task RefreshAsync()
        {
            if (!IsEnabled)
            {
                IsBusy = false;
                return;
            }
            try
            {
                IsBusy = true;
                Changesets.Clear();

                ObservableCollection <ChangesetInfo> changesets = new ObservableCollection <ChangesetInfo>();
                await Task.Run(() =>
                {
                    ITeamFoundationContext context = CurrentContext;
                    if (context != null && context.HasCollection && context.HasTeamProject)
                    {
                        VersionControlServer vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                        if (vcs != null)
                        {
                            // Ask the derived section for the history parameters
                            string user;
                            int maxCount;
                            GetHistoryParameters(vcs, out user, out maxCount);

                            string path = GetPath();
                            foreach (Changeset changeset in vcs.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full,
                                                                             user, null, null, maxCount, false, true))
                            {
                                changesets.Add(new ChangesetInfo(changeset, IsUserNameVisible ? null : string.Empty));
                            }
                        }
                    }
                });

                Changesets   = changesets;
                SectionTitle = Changesets.Count > 0 ? String.Format("{0} ({1})", BaseTitle, Changesets.Count)
                                                                                                           : BaseTitle;
            }
            catch (Exception ex)
            {
                Output.Exception(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Ejemplo n.º 20
0
        public WorkItemSearchReplaceViewModel(QueryItem queryItem, IServiceProvider provider)
            : base(provider)
        {
            this.queryItem = queryItem;
            context        = TfsContext.TfsContextManager.CurrentContext;

            PreviewCommand      = new DelegateCommand <object>(Preview, CanPreview);
            ExecuteCommand      = new DelegateCommand <object>(Execute, CanExecute);
            OpenWorkItemCommand = new DelegateCommand <Uri>(OpenWorkItem);


            WorkItemsListProvider = new WorkItemsListProvider();
            PreviewFields         = new ObservableCollection <string>();
            Initialize();
        }
Ejemplo n.º 21
0
        private List <string> GetRecentUsers()
        {
            List <string>          names   = new List <string>();
            ITeamFoundationContext context = this.ParentSection.GetContext();

            if (context != null && context.HasCollection && context.HasTeamProject)
            {
                // first we get the recent users who committed code changes
                VersionControlServer vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                if (vcs != null)
                {
                    // Ask the derived section for the history parameters
                    string path = "$/" + context.TeamProjectName;
                    foreach (Changeset changeset in vcs.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full, string.Empty, null, null, 250, false, true, false).Cast <Changeset>().Where(changeset => !names.Contains(changeset.CommitterDisplayName)))
                    {
                        names.Add(changeset.CommitterDisplayName);
                    }
                }

                // next we  get the users who recently committed work item changes
                WorkItemStore wis = context.TeamProjectCollection.GetService <WorkItemStore>();
                if (wis != null)
                {
                    WorkItemCollection wic = wis.Query("SELECT [System.Id] FROM WorkItems WHERE [System.WorkItemType] <> ''  AND  [System.State] <> '' AND [System.TeamProject] = '" + context.TeamProjectName + "' ORDER BY [System.ChangedDate] desc");

                    int i = 0;
                    foreach (WorkItem wi in wic)
                    {
                        if (!names.Contains(wi.ChangedBy))
                        {
                            names.Add(wi.ChangedBy);
                        }

                        i++;
                        if (i >= 250)
                        {
                            break;
                        }
                    }
                }

                names.Sort();
            }

            return(names);
        }
        /// <summary>
        /// Gets if the version control service is available or not.
        /// </summary>
        /// <returns></returns>
        protected override async Task <bool> GetIfVersionControlServiceIsAvailable()
        {
            // Make sure we have a connection to Team Foundation.
            ITeamFoundationContext context = this.CurrentContext;

            if (context == null || !context.HasCollection)
            {
                return(false);
            }

            // Make sure we can access the Version Control Server.
            VersionControlServer versionControlService = null;
            await Task.Run(() => versionControlService = context.TeamProjectCollection.GetService <VersionControlServer>());

            // Return if we could connect to the TFS Version Control or not.
            return(versionControlService != null);
        }
Ejemplo n.º 23
0
 public void ViewWorkItemDetails(int workItemId)
 {
     try
     {
         ITeamFoundationContext context = this.CurrentContext;
         EnvDTE80.DTE2          dte2    = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(DTE)) as EnvDTE80.DTE2;
         if (dte2 != null)
         {
             DocumentService witDocumentService = (DocumentService)dte2.DTE.GetObject("Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.DocumentService");
             var             widoc = witDocumentService.GetWorkItem(context.TeamProjectCollection, workItemId, this);
             witDocumentService.ShowWorkItem(widoc);
         }
     }
     catch (Exception ex)
     {
         this.ShowNotification(ex.Message, NotificationType.Error);
     }
 }
Ejemplo n.º 24
0
        public void ViewHistory()
        {
            ITeamFoundationContext context = this.CurrentContext;

            if (context != null && context.HasCollection && context.HasTeamProject)
            {
                VersionControlServer vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                if (vcs != null)
                {
                    string            path = "$/" + context.TeamProjectName;
                    VersionControlExt vc   = GetVersionControlExt(this.ServiceProvider);
                    if (vc != null)
                    {
                        vc.History.Show(path, VersionSpec.Latest, 0, RecursionType.Full, this.UserAccountName, null, null, 250, true);
                    }
                }
            }
        }
Ejemplo n.º 25
0
        public MainView(ITeamFoundationContext tfsContext, ITeamExplorer iTeamExplorer)
        {
            InitializeComponent();
            _teamFoundationContext = tfsContext;
            itfs = iTeamExplorer;

            bs = tfs.GetService <IBuildServer>();

            var dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

            if (dte != null)
            {
                var fi = new FileInfo(dte.FileName);
                IdePath = fi.DirectoryName;
            }

            LoadcbBuildDef();
        }
        /// <summary>
        /// Returns whether the user identity of the given account name or display name exists or not
        /// </summary>
        /// <param name="userDisplayNameOrAccount">The given account name or display name</param>
        /// <returns>True if the given user account or display name exists. False otherwise</returns>
        private bool UserIdentityExists(string userDisplayNameOrAccount)
        {
            ITeamFoundationContext     context = this.ParentSection.Context;
            IIdentityManagementService ims     = context.TeamProjectCollection.GetService <IIdentityManagementService>();

            // First try search by AccountName
            TeamFoundationIdentity userIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName, userDisplayNameOrAccount, MembershipQuery.None, ReadIdentityOptions.ExtendedProperties);

            if (userIdentity == null)
            {
                // Next we try search by DisplayName
                userIdentity = ims.ReadIdentity(IdentitySearchFactor.DisplayName, userDisplayNameOrAccount, MembershipQuery.None, ReadIdentityOptions.ExtendedProperties);
                if (userIdentity == null)
                {
                    return(false);
                }
            }

            return(true);
        }
        private async Task RefreshAsync()
        {
            try
            {
                this.IsBusy = true;
                this.Builds.Clear();

                var buildRefresh = new ObservableCollection <BuildDefinitionViewModel>();

                await Task.Run(() =>
                {
                    ITeamFoundationContext context = this.CurrentContext;
                    if (context != null && context.HasCollection && context.HasTeamProject)
                    {
                        var buildServer = context.TeamProjectCollection.GetService <IBuildServer>();
                        if (buildServer != null)
                        {
                            var buildDefinitions   = buildServer.QueryBuildDefinitions(context.TeamProjectName);
                            var builDefinitionTree = BuildDefinitionTreeBuilder.Build(buildDefinitions,
                                                                                      _optionsViewModel.OptionsModel.SplitCharacter.HasValue
                                                ? _optionsViewModel.OptionsModel.SplitCharacter.Value
                                                : '.');
                            foreach (var rootNode in builDefinitionTree)
                            {
                                buildRefresh.Add(new BuildDefinitionViewModel(rootNode));
                            }
                        }
                    }
                });

                this.Builds = buildRefresh;
            }
            catch (Exception ex)
            {
                this.ShowNotification(ex.Message, NotificationType.Error);
            }
            finally
            {
                this.IsBusy = false;
            }
        }
Ejemplo n.º 28
0
        private async Task RefreshAsyncChangesets()
        {
            try
            {
                // Set our busy flag and clear the previous data
                this.IsBusy = true;
                this.Changesets.Clear();

                ObservableCollection <Changeset> lchangesets = new ObservableCollection <Changeset>();

                // Make the server call asynchronously to avoid blocking the UI
                await Task.Run(() =>
                {
                    ITeamFoundationContext context = this.CurrentContext;
                    if (context != null && context.HasCollection && context.HasTeamProject)
                    {
                        VersionControlServer vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                        if (vcs != null)
                        {
                            string path = "$/" + context.TeamProjectName;
                            foreach (Changeset changeset in vcs.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full, this.UserAccountName, null, null, 12, false, true))
                            {
                                lchangesets.Add(changeset);
                            }
                        }
                    }
                });

                // Now back on the UI thread, update the bound collection and section title
                this.Changesets = lchangesets;
            }
            catch (Exception ex)
            {
                this.ShowNotification(ex.Message, NotificationType.Error);
            }
            finally
            {
                // Always clear our busy flag when done
                this.IsBusy = false;
            }
        }
Ejemplo n.º 29
0
        public void ViewHistory()
        {
            ITeamFoundationContext context = this.CurrentContext;

            if (context != null && context.HasCollection && context.HasTeamProject)
            {
                VersionControlServer vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                if (vcs != null)
                {
                    // Ask the derived section for the history parameters
                    string user;
                    int    maxCount;
                    this.GetHistoryParameters(vcs, out user, out maxCount);
                    string            path = "$/" + context.TeamProjectName;
                    VersionControlExt vc   = GetVersionControlExt(this.ServiceProvider);
                    if (vc != null)
                    {
                        vc.History.Show(path, VersionSpec.Latest, 0, RecursionType.Full, user, null, null, int.MaxValue, true);
                    }
                }
            }
        }
Ejemplo n.º 30
0
        public MergeInfo GetMergeInfo(ITeamExplorer teamExplorer, ITeamFoundationContext context, Changeset changeset)
        {
            var        branchInfos     = GetBranches(teamExplorer, context);
            BranchInfo currentBranch   = null;
            var        serverItemPaths = (from Change change in changeset.Changes select change.Item.ServerItem).ToArray();

            foreach (var branchInfo in branchInfos)
            {
                if (serverItemPaths.All(x => x.StartsWith(branchInfo.BranchServerPath)))
                {
                    currentBranch = branchInfo;
                    break;
                }
            }
            return(new MergeInfo
            {
                ChangesetId = changeset.ChangesetId,
                VersionSpec = new ChangesetVersionSpec(changeset.ChangesetId),
                FromPath = currentBranch.BranchServerPath,
                ToPath = currentBranch.ParentServerPath
            });
        }
        public AssociatedWorkitemViewModel(IServiceProvider serviceProvider, ITeamFoundationContext teamFoundationContext, ITagAdminContext tagAdminContext, List <Tag> tagsList)
        {
            _serviceProvider       = serviceProvider;
            _teamFoundationContext = teamFoundationContext;
            _tagAdminContext       = tagAdminContext;
            _tagsList        = tagsList;
            _eventAggregator = _tagAdminContext.EventAggregator;

            var logPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), string.Format("Tag Admin for Visual Studio 2015\\TagAdminForVisualStudio2015-{0}.log", DateTime.Now.ToString("dd-MM-yyyy")));

            _log = new LoggerConfiguration().WriteTo.File(logPath, fileSizeLimitBytes: 5000000)
                   .CreateLogger();
            _log.Information("Initializing AssociatedWorkitemViewModel - ServiceProvider: {serviceprovider}, TFSContext: {@tfs}, TagsCount: {tagsCount}",
                             _serviceProvider != null,
                             new
            {
                Collection = _teamFoundationContext.TeamProjectCollection.Name,
                User       = _teamFoundationContext.TeamProjectCollection.ConfigurationServer.AuthorizedIdentity.UniqueName,
                Project    = _teamFoundationContext.TeamProjectName,
            }, tagsList.Count);

            Subscriptions();
            Triggers();
        }
Ejemplo n.º 32
0
        private ObservableCollection<MergeInfoViewModel> GetBranches(ITeamFoundationContext context, ChangesetViewModel changesetViewModel)
        {
            if (context == null)
                return new ObservableCollection<MergeInfoViewModel>();
            var tfs = context.TeamProjectCollection;
            var versionControl = tfs.GetService<VersionControlServer>();

            var result = new ObservableCollection<MergeInfoViewModel>();

            var workspace = _workspace;

            var changesetService = _changesetService;

            var changes = changesetService.GetChanges(changesetViewModel.ChangesetId);

            var sourceTopFolder = CalculateTopFolder(changes);
            var mergesRelationships = GetMergesRelationships(sourceTopFolder, versionControl);



            if (mergesRelationships.Count > 0)
            {
                var sourceBranchIdentifier = changesetViewModel.Branches.Select(b => new ItemIdentifier(b)).First();

                var sourceBranch = sourceBranchIdentifier.Item;

                var trackMerges = versionControl.TrackMerges(new[] { changesetViewModel.ChangesetId },
                    new ItemIdentifier(sourceTopFolder),
                    mergesRelationships.ToArray(),
                    null);

                var changesetVersionSpec = new ChangesetVersionSpec(changesetViewModel.ChangesetId);

                var branchValidator = new BranchValidator(workspace, trackMerges);
                var branchFactory = new BranchFactory(sourceBranch, sourceTopFolder,
                    changesetVersionSpec, branchValidator,
                    _eventAggregator, _settings);

                var sourceBranchInfo = versionControl.QueryBranchObjects(sourceBranchIdentifier, RecursionType.None)[0];
                if (sourceBranchInfo.Properties != null && sourceBranchInfo.Properties.ParentBranch != null
                    && !sourceBranchInfo.Properties.ParentBranch.IsDeleted)
                {
                    var targetBranch = sourceBranchInfo.Properties.ParentBranch;
                    var targetPath = GetTargetPath(mergesRelationships, targetBranch);
                    if (targetPath != null)
                    {
                        var mergeInfo = branchFactory.CreateTargetBranchInfo(targetBranch, targetPath);
                        mergeInfo._checked = mergeInfo.ValidationResult == BranchValidationResult.Success;

                        result.Add(mergeInfo);
                    }
                }

                var currentBranchInfo = branchFactory.CreateSourceBranch();
                result.Add(currentBranchInfo);

                if (sourceBranchInfo.ChildBranches != null)
                {
                    var childBranches = sourceBranchInfo.ChildBranches.Where(b => !b.IsDeleted)
                        .Reverse();
                    foreach (var childBranch in childBranches)
                    {
                        var targetBranch = childBranch;
                        var targetPath = GetTargetPath(mergesRelationships, targetBranch);
                        if (targetPath != null)
                        {
                            var mergeInfo = branchFactory.CreateTargetBranchInfo(targetBranch, targetPath);
                            result.Add(mergeInfo);
                        }
                    }
                }

                // Feature branch
                if (mergesRelationships.Count > 0)
                {
                    var changetIds =
                        mergesRelationships.Select(r => r.Version).Cast<ChangesetVersionSpec>().Select(c => c.ChangesetId)
                        .Distinct()
                        .ToArray();
                    var branches = _changesetService.GetAssociatedBranches(changetIds);

                    foreach (var mergesRelationship in mergesRelationships)
                    {
                        var targetBranch = branches.FirstOrDefault(b => IsTargetPath(mergesRelationship, b));
                        if (targetBranch != null)
                        {
                            var mergeInfo = branchFactory.CreateTargetBranchInfo(targetBranch, mergesRelationship);
                            result.Add(mergeInfo);
                        }
                    }
                }
            }

            return result;
        }
        /// <summary>
        /// Retrieves the shelveset list for the current user 
        /// </summary>
        /// <param name="userName">The user name </param>
        /// <param name="secondUsername">The second user name </param>
        /// <param name="context">The Team foundation server context</param>
        /// <param name="shelveSets">The shelveset list to be returned</param>
        private static void FetchShevlesets(string userName, string secondUsername, ITeamFoundationContext context, out ObservableCollection<Shelveset> shelveSets)
        {
            shelveSets = new ObservableCollection<Shelveset>();
            if (context != null && context.HasCollection && context.HasTeamProject)
            {
                var vcs = context.TeamProjectCollection.GetService<VersionControlServer>();
                if (vcs != null)
                {
                    string user = string.IsNullOrWhiteSpace(userName) ? vcs.AuthorizedUser : userName;
                    foreach (var shelveSet in vcs.QueryShelvesets(null, user).OrderByDescending(s => s.CreationDate))
                    {
                        shelveSets.Add(shelveSet);
                    }

                    if (!string.IsNullOrWhiteSpace(secondUsername) && secondUsername != userName)
                    {
                        user = string.IsNullOrWhiteSpace(secondUsername) ? vcs.AuthorizedUser : secondUsername;
                        foreach (var shelveSet in vcs.QueryShelvesets(null, user).OrderByDescending(s => s.CreationDate))
                        {
                            shelveSets.Add(shelveSet);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Refresh the changeset data asynchronously.
        /// </summary>
        public async Task RefreshAsync()
        {
            try
            {
                var pc = GetService <IPendingChangesExt>();
                var currentlyAssociatedWorkItems = pc.WorkItems;

                // Set our busy flag and clear the previous data
                this.IsBusy = true;
                this.RecentWorkItems.Clear();

                var workItems = new ObservableCollection <RecentWorkItem>();

                var activeWorkItems = new ObservableCollection <ActiveWorkItem>();

                try
                {
                    var service = GetService <SActiveWiService>() as IActiveWiService;
                    if (service != null)
                    {
                        activeWorkItems = service.GetActiveWorkItems(string.Empty);
                    }
                }
                catch
                {
                }

                // Make the server call asynchronously to avoid blocking the UI
                await Task.Run(() =>
                {
                    ITeamFoundationContext context = this.CurrentContext;
                    if (context != null && context.HasCollection && context.HasTeamProject)
                    {
                        var vcs = context.TeamProjectCollection.GetService <VersionControlServer>();
                        if (vcs != null)
                        {
                            string path = "$/" + context.TeamProjectName;
                            foreach (Changeset changeset in vcs.QueryHistory(path, VersionSpec.Latest, 0, RecursionType.Full,
                                                                             vcs.AuthorizedUser, null, null, 10, false, true))
                            {
                                foreach (AssociatedWorkItemInfo wi in changeset.AssociatedWorkItems.Where(i => string.IsNullOrEmpty(this.SearchTerm) ||
                                                                                                          i.State.ToLower().Contains(this.SearchTerm.ToLower()) ||
                                                                                                          i.Id.ToString().ToLower().Contains(this.SearchTerm.ToLower()) ||
                                                                                                          i.Title.ToLower().Contains(this.SearchTerm.ToLower()) ||
                                                                                                          i.AssignedTo.ToLower().Contains(this.SearchTerm.ToLower()) ||
                                                                                                          i.WorkItemType.ToLower().Contains(this.SearchTerm.ToLower())))
                                {
                                    if (
                                        workItems.All(w => w.Id != wi.Id) &&
                                        currentlyAssociatedWorkItems.All(w => w.WorkItem.Id != wi.Id) &&
                                        activeWorkItems.All(w => w.Id != wi.Id)
                                        )
                                    {
                                        workItems.Add(new RecentWorkItem(wi));
                                    }
                                }
                            }
                        }
                    }
                });

                // Now back on the UI thread, update the bound collection and section title
                this.RecentWorkItems = new ObservableCollection <RecentWorkItem>(workItems.Take(5));
                this.Title           = this.RecentWorkItems.Count > 0 ? String.Format("{0} ({1})", SectionTitle, this.RecentWorkItems.Count)
                                                       : SectionTitle;
            }
            catch (Exception ex)
            {
                ShowNotification(ex.Message, NotificationType.Error);
            }
            finally
            {
                // Always clear our busy flag when done
                this.IsBusy = false;
            }
        }