Пример #1
0
        /// <summary>
        /// Add existing areas
        /// </summary>
        /// <param name="TeamProjectName"></param>
        /// <param name="TeamName"></param>
        static void AddTeamIterations(string TeamProjectName, string TeamName)
        {
            TeamContext teamContext = new TeamContext(TeamProjectName, TeamName);

            Console.WriteLine("Add iterations to the team " + TeamName);

            string[] iterations = { @"R2\R2.1\Ver1", @"R2\R2.1\Ver2" };

            foreach (string it in iterations)
            {
                WorkItemClassificationNode projectIt = WitClient.GetClassificationNodeAsync(TeamProjectName, TreeStructureGroup.Iterations, it).Result; // get iteration from project
                TeamSettingsIteration      teamIt    = WorkClient.PostTeamIterationAsync(new TeamSettingsIteration {
                    Id = projectIt.Identifier
                }, teamContext).Result;                                                                                                                        //add iteration to a team by guid
                Console.WriteLine("Added iteration " + teamIt.Name);
            }
        }
Пример #2
0
        public async Task <bool> RegisterIterations()
        {
            bool result = true;

            VssConnection connection = new VssConnection(new Uri(Options.Url),
                                                         new VssBasicCredential(string.Empty, Options.PAT));

            //  get VSTS's project collection
            ProjectHttpClient projectClient             = connection.GetClient <ProjectHttpClient>();
            IEnumerable <TeamProjectReference> projects = projectClient.GetProjects().Result;
            var targetProject =
                projects.FirstOrDefault(p => string.CompareOrdinal(p.Name, Options.Project) == 0);

            if (targetProject == null)
            {
                Console.WriteLine($"Project {Options.Project} not found in Server {Options.Url}");
                return(false);
            }

            // get team of project setting
            TeamHttpClient teamClient = connection.GetClient <TeamHttpClient>();
            var            teams      = await teamClient.GetTeamsAsync(targetProject.Id.ToString());

            // found specific team
            var team = teams.FirstOrDefault(p => string.CompareOrdinal(p.Name, Options.Team) == 0);

            if (team == null)
            {
                Console.WriteLine($"Team {Options.Team} not found in Project {Options.Project}");
                return(false);
            }
            WorkHttpClient workHttpClient = connection.GetClient <WorkHttpClient>();

            // get team's iteration
            var teamContext = new TeamContext(targetProject.Id, team.Id);
            var teamSetting = await workHttpClient.GetTeamIterationsAsync(teamContext);

            if (teamSetting == null)
            {
                Console.WriteLine("Can\'t get team Iteration");
                return(false);
            }
            try
            {
                int SprintCounter = Options.SprintStartIndex;
                do
                {
                    var teamIteration = new TeamSettingsIteration
                    {
                        // these date values looks like ignore.
                        Attributes = new TeamIterationAttributes
                        {
                            StartDate  = DateTime.Today,
                            FinishDate = DateTime.Today
                        },
                        Name = string.Format($"Sprint {SprintCounter}"),
                        Path = string.Format($"{Options.Project}\\{Options.SprintPrefix} {SprintCounter}"),
                    };

                    // add team iteration from Project iteration.
                    var execResult = await workHttpClient.PostTeamIterationAsync(teamIteration, teamContext);

                    if (execResult != null)
                    {
                        SprintCounter++;
                        Console.WriteLine($"Sprint {execResult.Path} add team iteration");
                    }
                } while (true);
            }
            catch (Exception ex)
            {
                // Exception is ignore, because PostTeamIteration Async method can't return error value.
            }
            return(result);
        }
Пример #3
0
        static void Main(string[] args)
        {
            VssCredentials creds = new VssClientCredentials();

            creds.Storage = new VssClientCredentialStorage();
            VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);

            v = connection;

            // Dont need this code at the moment.
            GitHttpClient gitClient = connection.GetClient <GitHttpClient>();
            var           repo      = gitClient.GetRepositoryAsync(c_projectname, c_reponame).Result;

            //// Get process templates
            //ProcessHttpClient processClient = connection.GetClient<ProcessHttpClient>();
            //var processes = processClient.GetProcessesAsync().Result;



            // Retrieve a list of projects from the account. (and ask if they should be deleted).  This is to tidy up my test data.
            Console.WriteLine("Preparing a list of projects you may wish to delete!");
            var projectHttpClient = connection.GetClient <ProjectHttpClient>();

            //then - same as above..iterate over the project references(with a hard-coded pagination of the first 10 entries only)
            foreach (var projectReference in projectHttpClient.GetProjects(top: 20, skip: 0).Result)
            {
                var teamProject = projectHttpClient.GetProject(projectReference.Id.ToString()).Result;
                //var urlForTeamProject = ((ReferenceLink)teamProject.Links.Links["web"]).Href;

                //Console.WriteLine("Team Project '{0}' (Id: {1}) at Web Url: '{2}' & API Url: '{3}'",
                //teamProject.Name,
                //teamProject.Id,
                //urlForTeamProject,
                //teamProject.Url);
                if (teamProject.Description == "This is a dummy project")
                {
                    Console.WriteLine("Delete this project {0}? (Y/N) default=No", teamProject.Name);
                    string s = Console.ReadLine();
                    if (s == "Y")
                    {
                        projectHttpClient.QueueDeleteProject(teamProject.Id);
                    }
                }
            }
            // return;

            bool   createVSTSProject = false;
            string p = null;

            if (createVSTSProject)
            {
                // Create a new project
                Console.WriteLine("***************Project Creation ******************");
                Console.WriteLine("Enter your project name");
                p = null;
                do
                {
                    p = Console.ReadLine();
                } while (String.IsNullOrEmpty(p));


                projectHttpClient = connection.GetClient <ProjectHttpClient>();
                string projectName    = CreateProject(connection, projectHttpClient, p);
                var    createdProject = projectHttpClient.GetProject(projectName).Result;

                Console.WriteLine("retrieve and delete default iterations from project");
                WorkHttpClient workClient = connection.GetClient <WorkHttpClient>();
                TeamContext    tc         = new TeamContext(createdProject.Name);
                var            iterations = workClient.GetTeamIterationsAsync(tc).Result;
                foreach (var item in iterations)
                {
                    workClient.DeleteTeamIterationAsync(tc, item.Id).SyncResult();
                    Console.WriteLine("Deleting {0}", item.Name);
                }

                DateTime projectStartDate              = new DateTime(2017, 07, 01);
                int      discoveryIterationDays        = 30;
                int      breathingSpaceDays            = 3;
                int      standardIterationDays         = 14;
                int      alphaStandardIterations       = 4;
                int      privateBetaStandardIterations = 4;
                int      publicBetaStandardIterations  = 6;

                DateTime startDate = projectStartDate;
                DateTime endDate   = startDate.AddDays(discoveryIterationDays);

                // Create a discovery iteration to get hold of a node to use as the re-assignment node when deleting stock iterations.
                Console.WriteLine("Creating a Discovery Phase from {0} to {1}", startDate, endDate);
                var node                  = AddIteration(createdProject.Id, "Discovery", startDate, endDate);
                int discoveryNodeId       = node.Id;
                TeamSettingsIteration tsi = new TeamSettingsIteration();
                tsi.Id = node.Identifier;
                var x = workClient.PostTeamIterationAsync(tsi, tc).Result;

                // Delete the standard iterations that come with a new project
                WorkItemTrackingHttpClient workItemTrackingClient = v.GetClient <WorkItemTrackingHttpClient>();
                workItemTrackingClient.DeleteClassificationNodeAsync(createdProject.Id, TreeStructureGroup.Iterations, "Iteration 1", discoveryNodeId).SyncResult();
                workItemTrackingClient.DeleteClassificationNodeAsync(createdProject.Id, TreeStructureGroup.Iterations, "Iteration 2", discoveryNodeId).SyncResult();
                workItemTrackingClient.DeleteClassificationNodeAsync(createdProject.Id, TreeStructureGroup.Iterations, "Iteration 3", discoveryNodeId).SyncResult();

                // Dont really need this at the moment
                // var processConfiguration = workClient.GetProcessConfigurationAsync(projectName).Result;

                // Add Alpha Phase
                startDate = endDate.AddDays(breathingSpaceDays);
                endDate   = startDate.AddDays((alphaStandardIterations + 2 * standardIterationDays));
                Console.WriteLine("Creating an Alpha Phase from {0} to {1}", startDate, endDate);
                node   = AddIteration(createdProject.Id, "Alpha", startDate, endDate);
                tsi    = new TeamSettingsIteration();
                tsi.Id = node.Identifier;
                x      = workClient.PostTeamIterationAsync(tsi, tc).Result;

                endDate = startDate.AddDays(standardIterationDays);
                Console.WriteLine("Creating an inception iteration from {0} to {1}", startDate, endDate);
                AddIteration(createdProject.Id, "Inception", startDate, endDate, "Alpha");
                tsi    = new TeamSettingsIteration();
                tsi.Id = node.Identifier;
                x      = workClient.PostTeamIterationAsync(tsi, tc).Result;

                for (int i = 0; i < alphaStandardIterations; i++)
                {
                    startDate = endDate.AddDays(1);
                    endDate   = startDate.AddDays(standardIterationDays);
                    Console.WriteLine("Creating a Standard Iteration {0} from {1} to {2}", i + 1, startDate, endDate);
                    AddIteration(createdProject.Id, String.Format("Iteration {0}", i + 1), startDate, endDate, "Alpha");
                    tsi    = new TeamSettingsIteration();
                    tsi.Id = node.Identifier;
                    x      = workClient.PostTeamIterationAsync(tsi, tc).Result;
                }

                startDate = endDate.AddDays(1);
                endDate   = startDate.AddDays(standardIterationDays);
                Console.WriteLine("Creating an conclusion iteration from {0} to {1}", startDate, endDate);
                AddIteration(createdProject.Id, "Conclusion", startDate, endDate, "Alpha");
                tsi    = new TeamSettingsIteration();
                tsi.Id = node.Identifier;
                x      = workClient.PostTeamIterationAsync(tsi, tc).Result;

                startDate = endDate.AddDays(breathingSpaceDays);
                endDate   = startDate.AddDays((privateBetaStandardIterations + publicBetaStandardIterations) * standardIterationDays);
                Console.WriteLine("Creating a Beta Phase from {0} to {1}", startDate, endDate);
                AddIteration(createdProject.Id, "Beta", startDate, endDate);
                tsi    = new TeamSettingsIteration();
                tsi.Id = node.Identifier;
                x      = workClient.PostTeamIterationAsync(tsi, tc).Result;

                // test putting the sample project into GiT.
                // This would actually retrieve the files from the core template project.


                gitClient = connection.GetClient <GitHttpClient>();
                repo      = gitClient.GetRepositoryAsync(createdProject.Name, createdProject.Name).Result;
                GitHelper gh     = new GitHelper(connection);
                var       pushes = gh.ListPushesIntoMaster(c_projectname, c_reponame);
                var       push   = gh.CreatePush(createdProject.Name, repo.Name);
                pushes = gh.ListPushesIntoMaster(createdProject.Name, repo.Name);
            }
            // Create a new project
            Console.WriteLine("***************Create a DevTest Lab ******************");
            Console.WriteLine("Enter a deployment name (need to work out how to capture template paramters here");
            Console.WriteLine("or q to quit");
            p = null;
            do
            {
                p = Console.ReadLine();
            } while (String.IsNullOrEmpty(p));
            if (p == "q")
            {
                return;
            }
            DeployerParameters parameters = new DeployerParameters();

            parameters.ResourceGroupName     = "Xekina-RG";
            parameters.DeploymentName        = "Xekina-Lab-Deployment";
            parameters.ResourceGroupLocation = "North Europe"; // must be specified for creating a new resource group
            parameters.PathToTemplateFile    = "./Files/azuredeploy.json";
            parameters.PathToParameterFile   = "./Files/azuredeploy.parameters.json";
            // TODO: Get this from app.settings
            parameters.TenantId       = CloudConfigurationManager.GetSetting("TenantId");
            parameters.ClientId       = CloudConfigurationManager.GetSetting("ClientId");
            parameters.ClientSecret   = CloudConfigurationManager.GetSetting("ClientSecret");
            parameters.SubscriptionId = CloudConfigurationManager.GetSetting("SubscriptionId");

            string     templateParameters = File.ReadAllText(parameters.PathToParameterFile);
            RootObject ltp = JsonConvert.DeserializeObject <RootObject>(templateParameters);

            ltp.parameters.newLabName.value = "XekinaLab";
            parameters.ParameterFileContent = JsonConvert.SerializeObject(ltp);
            Deployer deployer = new Deployer(parameters);

            deployer.Deploy().SyncResult();
            Console.ReadLine();
            return;
        }