Example #1
0
        /// <summary>
        /// Load projects from certain user
        /// </summary>
        /// <param name="username">The name of the user which Shelvesets should be fetched</param>
        /// <returns>State if fetching Projects was succesfull</returns>
        public FetchState FetchProjects(string username = "")
        {
            if (m_TfsConfigurationServer == null)
            {
                return(FetchState.UserNotLoggedIn);
            }
            var configurationServerNode = m_TfsConfigurationServer.CatalogNode;

            if (configurationServerNode == null)
            {
                return(FetchState.NoProject);
            }
            IReadOnlyCollection <CatalogNode> tfsTeamProjectNodes = configurationServerNode.QueryChildren(
                new Guid[] { CatalogResourceTypes.ProjectCollection },
                false,
                CatalogQueryOptions.None);


            foreach (CatalogNode projectNode in tfsTeamProjectNodes)
            {
                var tfsTeamProjectCollection = m_TfsConfigurationServer.GetTeamProjectCollection(
                    new Guid(projectNode.Resource.Properties[s_TeamConfigServerIdProperty]));
                m_VersionControl = tfsTeamProjectCollection.GetService <VersionControlServer>();
                PendingSet[] allSets;

                // at start up or context change use authenticated user and on search the given username
                if (string.IsNullOrEmpty(username))
                {
                    TeamFoundationIdentity identity;

                    m_TfsConfigurationServer.GetAuthenticatedIdentity(out identity);
                    allSets = m_VersionControl.QueryShelvedChanges(
                        null,
                        identity.DisplayName);
                    username = identity.DisplayName;
                }
                else
                {
                    try
                    {
                        allSets = m_VersionControl.QueryShelvedChanges(
                            null,
                            username);
                    }
                    catch (Microsoft.TeamFoundation.VersionControl.Client.IdentityNotFoundException)
                    {
                        return(FetchState.UserNotFound);
                        //nothing to do here
                        //m_VersionControl.QueryShelvedChanges throws an exception if the given username is not valid
                    }
                }

                IList <PendingSetWrapper> wrapper = new List <PendingSetWrapper>();

                //get Shelveset from PendingSet.
                //need the CreatedDate from the Shelveset to order the PndingSets
                foreach (PendingSet set in allSets)
                {
                    Shelveset[] shelvesets = m_VersionControl.QueryShelvesets(set.Name, username);
                    wrapper.Add(new PendingSetWrapper(set, shelvesets[0].CreationDate));
                }
                var orderedWrapper = wrapper.OrderByDescending(d => d.CreationDate.Date);

                Project = new ProjectData(projectNode.Resource.DisplayName, orderedWrapper.ToArray());
            }

            OnSetUsername(username);
            OnChanged(Project);

            return(FetchState.Successful);
        }
Example #2
0
 // ProjectList Changed
 protected void OnChanged(
     ProjectData project)
 {
     ContextChanged?.Invoke(project);
 }