Ejemplo n.º 1
0
        protected override void InternalExecute()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            //////////////////////////////////////////////////
            // Retrieve the project URI. Needed to enumerate teams.
            var         css4        = Engine.Target.GetService <ICommonStructureService4>();
            ProjectInfo projectInfo = css4.GetProjectFromName(Engine.Target.Config.AsTeamProjectConfig().Project);
            // Retrieve a list of all teams on the project.
            TfsTeamService teamService = Engine.Target.GetService <TfsTeamService>();
            TfsConnection  connection  = (TfsConnection)Engine.Target.InternalCollection;

            foreach (ProjectInfo p in css4.ListAllProjects())
            {
                var allTeams = teamService.QueryTeams(p.Uri);

                foreach (TeamFoundationTeam team in allTeams)
                {
                    Log.LogInformation("Team name: {0}", team.Name);
                    Log.LogInformation("Team ID: {0}", team.Identity.TeamFoundationId.ToString());
                    Log.LogInformation("Description: {0}", team.Description, p.Name);
                    var members = team.GetMembers(connection, MembershipQuery.Direct);
                    Log.LogInformation("Team Accounts: {0}", String.Join(";", (from member in team.GetMembers(connection, MembershipQuery.Direct) select member.UniqueName)));
                    Log.LogInformation("Team names: {0}", String.Join(";", (from member in team.GetMembers(connection, MembershipQuery.Direct) select member.DisplayName)));
                }
            }

            //////////////////////////////////////////////////
            stopwatch.Stop();

            Log.LogInformation("DONE in {Elapsed} ", stopwatch.Elapsed.ToString("c"));
        }
Ejemplo n.º 2
0
        internal override void InternalExecute()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            //////////////////////////////////////////////////
            // Retrieve the project URI. Needed to enumerate teams.
            var         css4        = me.Target.Collection.GetService <ICommonStructureService4>();
            ProjectInfo projectInfo = css4.GetProjectFromName(me.Target.Config.Project);
            // Retrieve a list of all teams on the project.
            TfsTeamService teamService = me.Target.Collection.GetService <TfsTeamService>();

            foreach (ProjectInfo p in css4.ListAllProjects())
            {
                var allTeams = teamService.QueryTeams(p.Uri);

                foreach (TeamFoundationTeam team in allTeams)
                {
                    Trace.WriteLine(string.Format("Team name: {0}", team.Name), p.Name);
                    Trace.WriteLine(string.Format("Team ID: {0}", team.Identity.TeamFoundationId.ToString()), p.Name);
                    Trace.WriteLine(string.Format("Description: {0}", team.Description), p.Name);
                    var members = team.GetMembers(me.Target.Collection, MembershipQuery.Direct);
                    Trace.WriteLine(string.Format("Team Accounts: {0}", String.Join(";", (from member in team.GetMembers(me.Target.Collection, MembershipQuery.Direct) select member.UniqueName))), p.Name);
                    Trace.WriteLine(string.Format("Team names: {0}", String.Join(";", (from member in team.GetMembers(me.Target.Collection, MembershipQuery.Direct) select member.DisplayName))), p.Name);
                }
            }



            //////////////////////////////////////////////////
            stopwatch.Stop();

            Console.WriteLine(@"DONE in {0:%h} hours {0:%m} minutes {0:s\:fff} seconds", stopwatch.Elapsed);
        }
Ejemplo n.º 3
0
        static List <TeamFoundationTeam> ListTeams(TfsTeamProjectCollection pTpc, Project pProject)
        {
            TfsTeamService _teamService = pTpc.GetService <TfsTeamService>();
            var            _teams       = _teamService.QueryTeams(pProject.Uri.ToString());

            return((from t in _teams select t).ToList());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create TFS Team if not exists
        /// </summary>
        /// <returns></returns>
        public TeamFoundationTeam CreateTeam()
        {
            // Check team already exists
            var teams        = _tfsTeamService.QueryTeams(_projectInfo.Uri.ToString());
            var existingTeam = teams.FirstOrDefault(t => t.Name == _softwareProjectName);

            if (existingTeam != null)
            {
                Console.WriteLine($"Team '{existingTeam.Name}' already exists.");
                return(existingTeam);
            }

            //Create TFS Team
            TeamFoundationTeam team = _tfsTeamService.CreateTeam(
                _projectInfo.Uri.ToString(), _softwareProjectName, _softwareProjectDescription, null);

            //Set the IterationPaths and BacklogIterationPath for the TFS Team
            var teamConfiguration     = _teamSettingsConfigurationService.GetTeamConfigurations(new[] { team.Identity.TeamFoundationId });
            TeamConfiguration tconfig = teamConfiguration.FirstOrDefault();
            TeamSettings      ts      = tconfig.TeamSettings;

            ts.IterationPaths       = new string[] { $"{_projectInfo.Name}\\{_softwareProjectName}\\Sprint 1" };
            ts.BacklogIterationPath = $"{_projectInfo.Name}\\{_softwareProjectName}";
            TeamFieldValue tfv = new TeamFieldValue();

            tfv.IncludeChildren = true;
            tfv.Value           = ts.BacklogIterationPath;
            ts.TeamFieldValues  = new TeamFieldValue[] { tfv };
            _teamSettingsConfigurationService.SetTeamSettings(tconfig.TeamId, ts);

            Console.WriteLine($"Team '{team.Name}' created.");

            return(team);
        }
        internal override void InternalExecute()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            //////////////////////////////////////////////////
            WorkItemStoreContext targetStore = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules);

            TfsQueryContext tfsqc = new TfsQueryContext(targetStore);

            TfsTeamService            teamService = me.Target.Collection.GetService <TfsTeamService>();
            QueryHierarchy            qh          = targetStore.Store.Projects[me.Target.Config.Project].QueryHierarchy;
            List <TeamFoundationTeam> teamList    = teamService.QueryTeams(me.Target.Config.Project).ToList();

            Trace.WriteLine(string.Format("Found {0} teams?", teamList.Count));
            //////////////////////////////////////////////////
            int  current   = teamList.Count;
            int  count     = 0;
            long elapsedms = 0;

            foreach (TeamFoundationTeam team in teamList)
            {
                Stopwatch witstopwatch = Stopwatch.StartNew();

                Trace.Write(string.Format("Processing team {0}", team.Name));
                Regex  r = new Regex(@"^Project - ([a-zA-Z ]*)");
                string path;
                if (r.IsMatch(team.Name))
                {
                    Trace.Write(string.Format(" is a Project"));
                    path = string.Format(@"Projects\{0}", r.Match(team.Name).Groups[1].Value.Replace(" ", "-"));
                }
                else
                {
                    Trace.Write(string.Format(" is a Team"));
                    path = string.Format(@"Teams\{0}", team.Name.Replace(" ", "-"));
                }
                Trace.Write(string.Format(" and new path is {0}", path));
                //me.AddFieldMap("*", new RegexFieldMap("KM.Simulation.Team", "System.AreaPath", @"^Project - ([a-zA-Z ]*)", @"Nemo\Projects\$1"));

                string[] bits = path.Split(char.Parse(@"\"));

                CreateFolderHyerarchy(bits, qh["Shared Queries"]);

                //_me.ApplyFieldMappings(workitem);
                qh.Save();


                witstopwatch.Stop();
                elapsedms = elapsedms + witstopwatch.ElapsedMilliseconds;
                current--;
                count++;
                TimeSpan average   = new TimeSpan(0, 0, 0, 0, (int)(elapsedms / count));
                TimeSpan remaining = new TimeSpan(0, 0, 0, 0, (int)(average.TotalMilliseconds * current));
                Trace.WriteLine("");
                //Trace.WriteLine(string.Format("Average time of {0} per work item and {1} estimated to completion", string.Format(@"{0:s\:fff} seconds", average), string.Format(@"{0:%h} hours {0:%m} minutes {0:s\:fff} seconds", remaining)));
            }
            //////////////////////////////////////////////////
            stopwatch.Stop();
            Console.WriteLine(@"DONE in {0:%h} hours {0:%m} minutes {0:s\:fff} seconds", stopwatch.Elapsed);
        }
Ejemplo n.º 6
0
        public List <TeamFoundationTeam> GetTeams(Project project)
        {
            TfsTeamService _teamService             = tfs.GetService <TfsTeamService>();
            IEnumerable <TeamFoundationTeam> _teams = _teamService.QueryTeams(project.Uri.ToString());



            return(_teams.ToList());
        }
        protected override void InternalExecute()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            //////////////////////////////////////////////////
            TfsTeamService            teamService = Engine.Target.GetService <TfsTeamService>();
            QueryHierarchy            qh          = ((TfsWorkItemMigrationClient)Engine.Target.WorkItems).Store.Projects[Engine.Target.Config.AsTeamProjectConfig().Project].QueryHierarchy;
            List <TeamFoundationTeam> teamList    = teamService.QueryTeams(Engine.Target.Config.AsTeamProjectConfig().Project).ToList();

            Log.LogInformation("Found {0} teams?", teamList.Count);
            //////////////////////////////////////////////////
            int  current   = teamList.Count;
            int  count     = 0;
            long elapsedms = 0;

            foreach (TeamFoundationTeam team in teamList)
            {
                Stopwatch witstopwatch = Stopwatch.StartNew();

                Log.LogTrace("Processing team {0}", team.Name);
                Regex  r = new Regex(@"^Project - ([a-zA-Z ]*)");
                string path;
                if (r.IsMatch(team.Name))
                {
                    Log.LogInformation("{0} is a Project", team.Name);
                    path = string.Format(@"Projects\{0}", r.Match(team.Name).Groups[1].Value.Replace(" ", "-"));
                }
                else
                {
                    Log.LogInformation("{0} is a Team", team.Name);
                    path = string.Format(@"Teams\{0}", team.Name.Replace(" ", "-"));
                }
                Log.LogInformation(" and new path is {0}", path);
                //me.AddFieldMap("*", new RegexFieldMap("KM.Simulation.Team", "System.AreaPath", @"^Project - ([a-zA-Z ]*)", @"Nemo\Projects\$1"));

                string[] bits = path.Split(char.Parse(@"\"));

                CreateFolderHyerarchy(bits, qh["Shared Queries"]);

                //_me.ApplyFieldMappings(workitem);
                qh.Save();

                witstopwatch.Stop();
                elapsedms = elapsedms + witstopwatch.ElapsedMilliseconds;
                current--;
                count++;
                TimeSpan average   = new TimeSpan(0, 0, 0, 0, (int)(elapsedms / count));
                TimeSpan remaining = new TimeSpan(0, 0, 0, 0, (int)(average.TotalMilliseconds * current));
                Log.LogInformation("Average time of {average} per work item and {remaining} estimated to completion", average.ToString("c"), remaining.ToString("c"));
            }
            //////////////////////////////////////////////////
            stopwatch.Stop();
            Log.LogInformation("DONE in {Elapsed} ", stopwatch.Elapsed.ToString("c"));
        }
Ejemplo n.º 8
0
        public IEnumerable <TeamFoundationIdentity> GetAllUsersInTFSBasedOnProjectCollection()
        {
            var            css4        = Collection.GetService <Microsoft.TeamFoundation.Server.ICommonStructureService4>();
            TfsTeamService teamService = Collection.GetService <TfsTeamService>();

            return(from p in css4.ListProjects()
                   let allTeams = teamService.QueryTeams(p.Uri)
                                  from a in allTeams
                                  let ppls = a.GetMembers(Collection, MembershipQuery.Direct)
                                             from ppl in ppls
                                             select ppl);
        }
 private IEnumerable <ITeamFoundationTeamViewModel> PopulateTeams()
 {
     if (this.RawPolicyEditArg != null)
     {
         TfsTeamService tfsts = this.RawPolicyEditArg.TeamProject.TeamProjectCollection.GetService <TfsTeamService>();
         IEnumerable <TeamFoundationTeam> teams = tfsts.QueryTeams(this.RawPolicyEditArg.TeamProject.Name);
         return(from t in teams select new TeamFoundationTeamViewModel(t));
     }
     else
     {
         List <ITeamFoundationTeamViewModel> fakeTeams = new List <ITeamFoundationTeamViewModel>();
         fakeTeams.Add(new TeamFoundationTeamFakeViewModel("Team A"));
         fakeTeams.Add(new TeamFoundationTeamFakeViewModel("Team B"));
         return(fakeTeams);
     }
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Indicates wich TFS version we work with
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public static TfsVersion GetVersion(this TfsTeamProjectCollection collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            try
            {
                IBuildServer buildserver   = collection.GetService <IBuildServer>();
                string       ServerVersion = Convert.ToString(buildserver.BuildServerVersion);

                switch (ServerVersion)
                {
                case "V5":
                {
                    return(TfsVersion.Tfs2011);

                    break;
                }

                case "V4":
                {
                    return(TfsVersion.Tfs2011);

                    break;
                }

                case "V3":
                {
                    return(TfsVersion.Tfs2010);

                    break;
                }
                }
                ITestManagementService testService = collection.GetService <ITestManagementService>();
                TfsTeamService         teamService = collection.GetService <TfsTeamService>();
                teamService.QueryTeams(string.Empty);
                return(TfsVersion.Tfs2011);
            }
            catch
            {
                return(TfsVersion.Tfs2010);
            }
        }
Ejemplo n.º 11
0
        public IEnumerable <TeamFoundationIdentity> GetAllUsersInTfsBasedOnProjectCollection()
        {
            try
            {
                var            css4        = _tfsServer.GetCollection().GetService <ICommonStructureService4>();
                TfsTeamService teamService = _tfsServer.GetCollection().GetService <TfsTeamService>();

                return(from p in css4.ListProjects()
                       let allTeams = teamService.QueryTeams(p.Uri)
                                      from a in allTeams
                                      let ppls = a.GetMembers(_tfsServer.GetCollection(), MembershipQuery.Direct)
                                                 from ppl in ppls
                                                 select ppl);
            }
            catch (Exception)
            {
                return(EnumerableExtensions.Empty <TeamFoundationIdentity>());
            }
        }
Ejemplo n.º 12
0
        private List <TeamFoundationTeam> GetMyTeams(TfsTeamService teamService, Project project)
        {
            try
            {
                var properties = new List <string>();

                var teamGroups = teamService.QueryTeams(project.Uri.ToString());

                var allTeams = teamGroups
                               .Select(x => teamService.ReadTeam(x.Identity.Descriptor, properties))
                               .AsParallel()
                               .ToList();

                return(allTeams);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e);
                return(new List <TeamFoundationTeam>());
            }
        }
        internal override void InternalExecute()
        {
            if (_config == null)
            {
                throw new Exception("You must call Configure() first");
            }
            Stopwatch stopwatch = Stopwatch.StartNew();
            //////////////////////////////////////////////////
            WorkItemStoreContext sourceStore = new WorkItemStoreContext(me.Source, WorkItemStoreFlags.BypassRules, Telemetry);
            TfsTeamService sourceTS = me.Source.Collection.GetService<TfsTeamService>();
            List<TeamFoundationTeam> sourceTL = sourceTS.QueryTeams(me.Source.Config.Project).ToList();
            Trace.WriteLine(string.Format("Found {0} teams in Source?", sourceTL.Count));
            var sourceTSCS = me.Source.Collection.GetService<TeamSettingsConfigurationService>();
            //////////////////////////////////////////////////
            WorkItemStoreContext targetStore = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules, Telemetry);
            Project targetProject = targetStore.GetProject();
            Trace.WriteLine(string.Format("Found target project as {0}", targetProject.Name));
            TfsTeamService targetTS = me.Target.Collection.GetService<TfsTeamService>();
            List<TeamFoundationTeam> targetTL = targetTS.QueryTeams(me.Target.Config.Project).ToList();
            Trace.WriteLine(string.Format("Found {0} teams in Target?", targetTL.Count));
            var targetTSCS = me.Target.Collection.GetService<TeamSettingsConfigurationService>();
            //////////////////////////////////////////////////
            int current = sourceTL.Count;
            int count = 0;
            long elapsedms = 0;

            /// Create teams
            /// 
            foreach (TeamFoundationTeam sourceTeam in sourceTL)
            {
                Stopwatch witstopwatch = Stopwatch.StartNew();
                var foundTargetTeam = (from x in targetTL where x.Name == sourceTeam.Name select x).SingleOrDefault();
                if (foundTargetTeam == null)
                {
                    Trace.WriteLine(string.Format("Processing team '{0}':", sourceTeam.Name));
                    TeamFoundationTeam newTeam = targetTS.CreateTeam(targetProject.Uri.ToString(), sourceTeam.Name, sourceTeam.Description, null);
                    Trace.WriteLine(string.Format("-> Team '{0}' created", sourceTeam.Name));

                    if (_config.EnableTeamSettingsMigration)
                    {
                        /// Duplicate settings
                        Trace.WriteLine(string.Format("-> Processing team '{0}' settings:", sourceTeam.Name));
                        var sourceConfigurations = sourceTSCS.GetTeamConfigurations(new List<Guid> { sourceTeam.Identity.TeamFoundationId });
                        var targetConfigurations = targetTSCS.GetTeamConfigurations(new List<Guid> { newTeam.Identity.TeamFoundationId });

                        foreach (var sourceConfig in sourceConfigurations)
                        {
                            var targetConfig = targetConfigurations.FirstOrDefault(t => t.TeamName == sourceConfig.TeamName);
                            if (targetConfig == null)
                            {
                                Trace.WriteLine(string.Format("-> Settings for team '{0}'.. not found", sourceTeam.Name));
                                continue;
                            }

                            Trace.WriteLine(string.Format("-> Settings found for team '{0}'..", sourceTeam.Name));
                            if (_config.PrefixProjectToNodes)
                            {
                                targetConfig.TeamSettings.BacklogIterationPath = 
                                    string.Format("{0}\\{1}", me.Target.Config.Project, sourceConfig.TeamSettings.BacklogIterationPath);
                                targetConfig.TeamSettings.IterationPaths = sourceConfig.TeamSettings.IterationPaths
                                    .Select(path => string.Format("{0}\\{1}", me.Target.Config.Project, path))
                                    .ToArray();
                                targetConfig.TeamSettings.TeamFieldValues = sourceConfig.TeamSettings.TeamFieldValues
                                    .Select(field => new TeamFieldValue
                                    {
                                        IncludeChildren = field.IncludeChildren,
                                        Value = string.Format("{0}\\{1}", me.Target.Config.Project, field.Value)
                                    })
                                    .ToArray();
                            }
                            else
                            {
                                targetConfig.TeamSettings.BacklogIterationPath = sourceConfig.TeamSettings.BacklogIterationPath;
                                targetConfig.TeamSettings.IterationPaths = sourceConfig.TeamSettings.IterationPaths;
                                targetConfig.TeamSettings.TeamFieldValues = sourceConfig.TeamSettings.TeamFieldValues;
                            }

                            targetTSCS.SetTeamSettings(targetConfig.TeamId, targetConfig.TeamSettings);
                            Trace.WriteLine(string.Format("-> Team '{0}' settings... applied", targetConfig.TeamName));
                        }
                    }
                }
                else
                {
                    Trace.WriteLine(string.Format("Team '{0}' found.. skipping", sourceTeam.Name));
                }

                witstopwatch.Stop();
                elapsedms = elapsedms + witstopwatch.ElapsedMilliseconds;
                current--;
                count++;
                TimeSpan average = new TimeSpan(0, 0, 0, 0, (int)(elapsedms / count));
                TimeSpan remaining = new TimeSpan(0, 0, 0, 0, (int)(average.TotalMilliseconds * current));
                Trace.WriteLine("");
                //Trace.WriteLine(string.Format("Average time of {0} per work item and {1} estimated to completion", string.Format(@"{0:s\:fff} seconds", average), string.Format(@"{0:%h} hours {0:%m} minutes {0:s\:fff} seconds", remaining)));
            }
            // Set Team Settings
            //foreach (TeamFoundationTeam sourceTeam in sourceTL)
            //{
            //    Stopwatch witstopwatch = new Stopwatch();
            //    witstopwatch.Start();
            //    var foundTargetTeam = (from x in targetTL where x.Name == sourceTeam.Name select x).SingleOrDefault();
            //    if (foundTargetTeam == null)
            //    {
            //        Trace.WriteLine(string.Format("Processing team {0}", sourceTeam.Name));
            //        var sourceTCfU = sourceTSCS.GetTeamConfigurations((new[] { sourceTeam.Identity.TeamFoundationId })).SingleOrDefault();
            //        TeamSettings newTeamSettings = CreateTargetTeamSettings(sourceTCfU);
            //        TeamFoundationTeam newTeam = targetTS.CreateTeam(targetProject.Uri.ToString(), sourceTeam.Name, sourceTeam.Description, null);
            //        targetTSCS.SetTeamSettings(newTeam.Identity.TeamFoundationId, newTeamSettings);
            //    }
            //    else
            //    {
            //        Trace.WriteLine(string.Format("Team found.. skipping"));
            //    }

            //    witstopwatch.Stop();
            //    elapsedms = elapsedms + witstopwatch.ElapsedMilliseconds;
            //    current--;
            //    count++;
            //    TimeSpan average = new TimeSpan(0, 0, 0, 0, (int)(elapsedms / count));
            //    TimeSpan remaining = new TimeSpan(0, 0, 0, 0, (int)(average.TotalMilliseconds * current));
            //    Trace.WriteLine("");
            //    //Trace.WriteLine(string.Format("Average time of {0} per work item and {1} estimated to completion", string.Format(@"{0:s\:fff} seconds", average), string.Format(@"{0:%h} hours {0:%m} minutes {0:s\:fff} seconds", remaining)));

            //}
            //////////////////////////////////////////////////
            stopwatch.Stop();
            Console.WriteLine(@"DONE in {0:%h} hours {0:%m} minutes {0:s\:fff} seconds", stopwatch.Elapsed);
        }
Ejemplo n.º 14
0
        public async Task <IdentityViewModel[]> GetAllUsersInTfsBasedOnIdentityAsync()
        {
            try
            {
                var readUsersTask = Task.Factory.StartNew(() =>
                {
                    try
                    {
                        _tfsServer.GetCollection().EnsureAuthenticated();


                        var css4 = _tfsServer.GetCollection().GetService <ICommonStructureService4>();
                        TfsTeamService teamService = _tfsServer.GetCollection().GetService <TfsTeamService>();

#pragma warning disable 618
                        var gss = _tfsServer.GetCollection().GetService <IGroupSecurityService>();
#pragma warning restore 618
                        var teamProjectCollections = _tfsServer.GetCollection().CatalogNode.QueryChildren(
                            new[] { CatalogResourceTypes.TeamProject },
                            false,
                            CatalogQueryOptions.None);

                        if (teamProjectCollections.Any())
                        {
                            var sids = gss.ReadIdentity(SearchFactor.AccountName,
                                                        teamProjectCollections.FirstOrDefault().Resource.DisplayName + " Team",
                                                        QueryMembership.Expanded);

                            var identities = gss.ReadIdentities(SearchFactor.Sid, sids.Members, QueryMembership.None)
                                             .Where(u => u != null)
                                             .OrderBy(u => u.DisplayName)
                                             .Select(u => u.ToIdentityViewModel());

                            var tidentities = from p in css4.ListProjects()
                                              let allTeams = teamService.QueryTeams(p.Uri)
                                                             from a in allTeams
                                                             let ppls = a.GetMembers(_tfsServer.GetCollection(), MembershipQuery.Direct)
                                                                        from ppl in ppls
                                                                        select new IdentityViewModel {
                                DisplayName = ppl.DisplayName
                            };

                            var p1 = GetAllUsersInTfsBasedOnIdentity();
                            var q  = GetAllUsersInTfsBasedOnProjectCollection().Select(u => new IdentityViewModel {
                                DisplayName = u.DisplayName
                            });

                            return(p1.Union(q).Union(identities).Union(tidentities).DistinctBy(u => u.DisplayName).OrderBy(u => u.DisplayName).ToArray());
                        }
                        return(EnumerableExtensions.Empty <IdentityViewModel>().ToArray());
                    }
                    catch (Exception ex)
                    {
                        InvokeErrorHandler(ex);
                        return(null);
                    }
                });

                return(await readUsersTask);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        internal override void InternalExecute()
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            //////////////////////////////////////////////////
            WorkItemStoreContext      sourceStore = new WorkItemStoreContext(me.Source, WorkItemStoreFlags.BypassRules);
            TfsTeamService            sourceTS    = me.Source.Collection.GetService <TfsTeamService>();
            List <TeamFoundationTeam> sourceTL    = sourceTS.QueryTeams(me.Source.Name).ToList();

            Trace.WriteLine(string.Format("Found {0} teams in Source?", sourceTL.Count));
            var sourceTSCS = me.Source.Collection.GetService <TeamSettingsConfigurationService>();
            //////////////////////////////////////////////////
            WorkItemStoreContext targetStore = new WorkItemStoreContext(me.Target, WorkItemStoreFlags.BypassRules);
            Project targetProject            = targetStore.GetProject();

            Trace.WriteLine(string.Format("Found target project as {0}", targetProject.Name));
            TfsTeamService            targetTS = me.Target.Collection.GetService <TfsTeamService>();
            List <TeamFoundationTeam> targetTL = targetTS.QueryTeams(me.Target.Name).ToList();

            Trace.WriteLine(string.Format("Found {0} teams in Target?", targetTL.Count));
            var targetTSCS = me.Target.Collection.GetService <TeamSettingsConfigurationService>();
            //////////////////////////////////////////////////
            int  current   = sourceTL.Count;
            int  count     = 0;
            long elapsedms = 0;

            /// Create teams
            ///
            foreach (TeamFoundationTeam sourceTeam in sourceTL)
            {
                Stopwatch witstopwatch    = Stopwatch.StartNew();
                var       foundTargetTeam = (from x in targetTL where x.Name == sourceTeam.Name select x).SingleOrDefault();
                if (foundTargetTeam == null)
                {
                    Trace.WriteLine(string.Format("Processing team {0}", sourceTeam.Name));
                    TeamFoundationTeam newTeam = targetTS.CreateTeam(targetProject.Uri.ToString(), sourceTeam.Name, sourceTeam.Description, null);
                }
                else
                {
                    Trace.WriteLine(string.Format("Team found.. skipping"));
                }

                witstopwatch.Stop();
                elapsedms = elapsedms + witstopwatch.ElapsedMilliseconds;
                current--;
                count++;
                TimeSpan average   = new TimeSpan(0, 0, 0, 0, (int)(elapsedms / count));
                TimeSpan remaining = new TimeSpan(0, 0, 0, 0, (int)(average.TotalMilliseconds * current));
                Trace.WriteLine("");
                //Trace.WriteLine(string.Format("Average time of {0} per work item and {1} estimated to completion", string.Format(@"{0:s\:fff} seconds", average), string.Format(@"{0:%h} hours {0:%m} minutes {0:s\:fff} seconds", remaining)));
            }
            // Set Team Settings
            //foreach (TeamFoundationTeam sourceTeam in sourceTL)
            //{
            //    Stopwatch witstopwatch = new Stopwatch();
            //    witstopwatch.Start();
            //    var foundTargetTeam = (from x in targetTL where x.Name == sourceTeam.Name select x).SingleOrDefault();
            //    if (foundTargetTeam == null)
            //    {
            //        Trace.WriteLine(string.Format("Processing team {0}", sourceTeam.Name));
            //        var sourceTCfU = sourceTSCS.GetTeamConfigurations((new[] { sourceTeam.Identity.TeamFoundationId })).SingleOrDefault();
            //        TeamSettings newTeamSettings = CreateTargetTeamSettings(sourceTCfU);
            //        TeamFoundationTeam newTeam = targetTS.CreateTeam(targetProject.Uri.ToString(), sourceTeam.Name, sourceTeam.Description, null);
            //        targetTSCS.SetTeamSettings(newTeam.Identity.TeamFoundationId, newTeamSettings);
            //    }
            //    else
            //    {
            //        Trace.WriteLine(string.Format("Team found.. skipping"));
            //    }

            //    witstopwatch.Stop();
            //    elapsedms = elapsedms + witstopwatch.ElapsedMilliseconds;
            //    current--;
            //    count++;
            //    TimeSpan average = new TimeSpan(0, 0, 0, 0, (int)(elapsedms / count));
            //    TimeSpan remaining = new TimeSpan(0, 0, 0, 0, (int)(average.TotalMilliseconds * current));
            //    Trace.WriteLine("");
            //    //Trace.WriteLine(string.Format("Average time of {0} per work item and {1} estimated to completion", string.Format(@"{0:s\:fff} seconds", average), string.Format(@"{0:%h} hours {0:%m} minutes {0:s\:fff} seconds", remaining)));

            //}
            //////////////////////////////////////////////////
            stopwatch.Stop();
            Console.WriteLine(@"DONE in {0:%h} hours {0:%m} minutes {0:s\:fff} seconds", stopwatch.Elapsed);
        }
Ejemplo n.º 16
0
        public TfsConnection()
        {
            _projectTeamDictionary = new Dictionary <ProjectInfo, List <TeamFoundationTeam> >();

            try
            {
                TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(Settings.TfsConnectionUri), new Credentials());
                tpc.EnsureAuthenticated();

                ICommonStructureService4 css = tpc.GetService <ICommonStructureService4>();

                if (Settings.ProjectNames.IsNullOrEmpty())
                {
                    _projectTeamDictionary
                        = css.ListAllProjects()
                          .GroupBy(projectInfo => projectInfo)
                          .ToDictionary(projectInfo => projectInfo.Key, projectInfo => new List <TeamFoundationTeam>());
                }
                else
                {
                    string[] projectNames = Settings.ProjectNames.Split(',');
                    foreach (string projectName in projectNames)
                    {
                        if (!_projectTeamDictionary.ContainsKey(css.GetProjectFromName(projectName)))
                        {
                            _projectTeamDictionary.Add(css.GetProjectFromName(projectName), new List <TeamFoundationTeam>());
                        }
                    }
                }

                foreach (ProjectInfo projectInfo in _projectTeamDictionary.Keys)
                {
                    TfsTeamService            tts      = tpc.GetService <TfsTeamService>();
                    List <TeamFoundationTeam> teamList = new List <TeamFoundationTeam>();

                    teamList = tts.QueryTeams(projectInfo.Uri).ToList();

                    if (Settings.TeamNames.IsNullOrEmpty())
                    {
                        foreach (TeamFoundationTeam team in teamList)
                        {
                            Console.WriteLine(" Team: " + team.Name);

                            List <TeamFoundationIdentity> members = team.GetMembers(tpc, MembershipQuery.Expanded).ToList();
                            if (members.Exists(member => member.TeamFoundationId.Equals(tpc.AuthorizedIdentity.TeamFoundationId)))
                            {
                                _projectTeamDictionary[projectInfo].Add(team);
                            }
                        }
                    }
                    else
                    {
                        string[] teamNames = Settings.TeamNames.Split(',');
                        foreach (string teamName in teamNames)
                        {
                            _projectTeamDictionary[projectInfo].AddRange(teamList.FindAll(x => x.Name.Equals(teamName)));
                        }
                    }
                }
            }
            catch (Microsoft.TeamFoundation.TeamFoundationServiceUnavailableException tfsUnavailableException)
            {
                throw new Microsoft.TeamFoundation.TeamFoundationServiceUnavailableException(tfsUnavailableException.Message);
            }
        }