Esempio n. 1
1
        private async Task<TimeSpan> GetLastSuccesfulBuildTimeRest(TfsTeamProjectCollection teamProjectCollection, DefinitionReference definitionReference, BuildHttpClient httpClient)
        {
            var buildTime = new TimeSpan();

            try
            {
                var lastSuccessFullList = await httpClient.GetBuildsAsync(definitions: new List<int> { definitionReference.Id }, project: definitionReference.Project.Id, resultFilter: BuildResult.Succeeded,  statusFilter: Microsoft.TeamFoundation.Build.WebApi.BuildStatus.Completed, top: 1).ConfigureAwait(false);
                var build = lastSuccessFullList.FirstOrDefault();

                if (build == null)
                {
                    var lastPartiallySucceededList =   await httpClient.GetBuildsAsync(definitions: new List<int> { definitionReference.Id }, project: definitionReference.Project.Id, resultFilter: BuildResult.PartiallySucceeded, statusFilter: Microsoft.TeamFoundation.Build.WebApi.BuildStatus.Completed, top: 1).ConfigureAwait(false);
                    build = lastPartiallySucceededList.FirstOrDefault();
                }

                if (build != null)
                {
                    buildTime = build.FinishTime.GetValueOrDefault() - build.StartTime.GetValueOrDefault();
                }
                

            }
            catch (Exception)
            {
                
                throw;
            }
            return buildTime;
        }
Esempio n. 2
0
 public TfsBuildDefinition(DefinitionReference definition)
 {
     Name     = definition.Name;
     NativeId = definition.Id;
     Id       = NativeId.ToString(CultureInfo.InvariantCulture);
     Links    = new ReferenceLinks();
 }
        public TfsBuildDefinition(DefinitionReference definition)
        {
            Name     = definition.Name;
            NativeId = definition.Id;
            Id       = NativeId.ToString();

            _url = definition.Url;
        }
Esempio n. 4
0
 public BuildPipeline(DefinitionReference definitionRef)
 {
     Name    = definitionRef.Name;
     Path    = definitionRef.Path;
     Url     = definitionRef.Url;
     Id      = definitionRef.Id;
     Project = new TeamProject
     {
         TeamProjectName = definitionRef.Project.Name,
         Url             = definitionRef.Url
     };
 }
Esempio n. 5
0
        public Build QueueBuild(BuildDefinitionReference definition)
        {
            DefinitionReference definitionReference = new DefinitionReference();

            definitionReference.Id      = definition.Id;
            definitionReference.Project = definition.Project;
            Build build = new Build();

            build.Definition = definitionReference;
            build.Project    = definition.Project;
            var result = _buildClient.QueueBuildAsync(build).GetAwaiter().GetResult();

            return(result);
        }
Esempio n. 6
0
        public async Task <Build> GetBuildDefinitionLastBuild(string project, DefinitionReference def)
        {
            var buildClient = Connection.GetClient <BuildHttpClient>();

            return(def == null ? null : (await buildClient.GetBuildsAsync(project, new[] { def.Id }, top: 1)).FirstOrDefault());
        }
Esempio n. 7
0
        private void UpdateWatchedBuild(DefinitionReference buildDefinition, List <Build> builds)
        {
            bool wasFailedBuild  = false;
            bool wasWatchedBuild = false;

            var watchedBuildViewModel = WatchedBuilds.FirstOrDefault(b => b.Id == buildDefinition.Id);

            if (watchedBuildViewModel != null)
            {
                wasWatchedBuild = true;
            }
            else
            {
                watchedBuildViewModel = FailedBuilds.FirstOrDefault(b => b.Id == buildDefinition.Id);
                if (watchedBuildViewModel != null)
                {
                    wasFailedBuild = true;
                }
                else
                {
                    watchedBuildViewModel = new WatchedBuildViewModel(buildDefinition.Id, buildDefinition.Name);
                }
            }

            watchedBuildViewModel.Result = builds.First().Result;
            watchedBuildViewModel.LastBuilds.Clear();
            foreach (var buildResult in builds.Take(5).Reverse().Select(b => b.Result).ToList())
            {
                watchedBuildViewModel.LastBuilds.Add(buildResult);
            }

            if (watchedBuildViewModel.Result == BuildResult.Failed)
            {
                if (!wasFailedBuild)
                {
                    Application.Current.Dispatcher.Invoke(() => FailedBuilds.Add(watchedBuildViewModel));

                    var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);

                    var textElements = toastXml.GetElementsByTagName("text");
                    textElements[0].AppendChild(toastXml.CreateTextNode("Build failed"));       // title
                    textElements[1].AppendChild(toastXml.CreateTextNode(buildDefinition.Name)); // line 1
                    textElements[2].AppendChild(toastXml.CreateTextNode("Build failed"));       // line 2

                    var imageElements = toastXml.GetElementsByTagName("image");
                    imageElements[0].Attributes.GetNamedItem("src").NodeValue =
                        $"file:///{Path.GetFullPath("redcross.png")}";

                    var toast = new ToastNotification(toastXml);

                    ToastNotificationManager.CreateToastNotifier().Show(toast);
                }
                if (wasWatchedBuild)
                {
                    Application.Current.Dispatcher.Invoke(() => WatchedBuilds.Add(watchedBuildViewModel));
                }
            }
            else if (!wasWatchedBuild)
            {
                Application.Current.Dispatcher.Invoke(() => WatchedBuilds.Add(watchedBuildViewModel));
                if (wasFailedBuild)
                {
                    Application.Current.Dispatcher.Invoke(() => FailedBuilds.Remove(watchedBuildViewModel));
                }
            }
        }
        private static BuildDefinition GetBuildDefinition(BuildDefinitionReference latestDefinitionReference, DefinitionReference baseDefinition)
        {
            var xamlDefinition = baseDefinition as XamlBuildDefinition;

            if (xamlDefinition != null)
            {
                return(new BuildDefinition(latestDefinitionReference, xamlDefinition));
            }

            var definition = baseDefinition as Microsoft.TeamFoundation.Build.WebApi.BuildDefinition;

            if (definition != null)
            {
                return(new BuildDefinition(latestDefinitionReference, definition));
            }

            throw new Exception($"{nameof(baseDefinition)} has unexpected type {baseDefinition.GetType()}");
        }
Esempio n. 9
0
        private Dictionary<string, int> GetTestResultsRest(TfsTeamProjectCollection teamProjectCollection, DefinitionReference definitionReference, Build build)
        {
            var testResults = new Dictionary<string, int>();
            try
            {
                var testManagementService = teamProjectCollection.GetService<ITestManagementService>();

                var testManagementTeamProject = testManagementService.GetTeamProject(definitionReference.Project.Name);
                var testRuns = testManagementTeamProject.TestRuns.ByBuild(build.Uri).ToList();

                if (testRuns.Any())
                {
                    

                    var totalTests = testRuns.Sum(x => x.TotalTests);
                    var totalPassedTests = testRuns.Sum(x => x.PassedTests);

                    testResults.Add("PassedTests", totalPassedTests);
                    testResults.Add("TotalTests", totalTests);
                }
                
            }
            catch (Exception e)
            {
                LogService.WriteError(e);
                throw;
            }
            return testResults;


        }