Example #1
0
        public BuildTreeBuildsDelta(IEnumerable <IBuildNode> currentBuildNodes, IReadOnlyDictionary <CacheKey, BuildStatus>?previousStatesOfBuildIds, PartialSucceededTreatmentMode partialSucceededTreatmentMode)
        {
            // without information of the previous state, a delta is not possible to calculate
            if (previousStatesOfBuildIds == null)
            {
                return;
            }

            foreach (var newBuild in currentBuildNodes)
            {
                if (previousStatesOfBuildIds.TryGetValue(newBuild.Build.CacheKey(), out var previousStatus))
                {
                    if (previousStatus != newBuild.Status)
                    {
                        AddToDelta(newBuild);
                    }
                }
                else
                {
                    AddToDelta(newBuild);
                }
            }

            void AddToDelta(IBuildNode buildNode)
            {
                switch (buildNode.Status)
                {
                case BuildStatus.Cancelled:
                    CancelledBuilds.Add(buildNode);
                    break;

                case BuildStatus.Failed:
                    FailedBuilds.Add(buildNode);
                    break;

                case BuildStatus.Succeeded:
                    SucceededBuilds.Add(buildNode);
                    break;

                case BuildStatus.PartiallySucceeded:
                    switch (partialSucceededTreatmentMode)
                    {
                    case PartialSucceededTreatmentMode.TreatAsSucceeded:
                        SucceededBuilds.Add(buildNode);
                        break;

                    case PartialSucceededTreatmentMode.TreatAsFailed:
                        FailedBuilds.Add(buildNode);
                        break;
                    }

                    break;
                }
            }
        }
Example #2
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));
                }
            }
        }
Example #3
0
 public void Clear()
 {
     FailedBuilds.Clear();
     SucceededBuilds.Clear();
     CancelledBuilds.Clear();
 }
Example #4
0
 public void RemoveNode(IBuildNode node)
 {
     FailedBuilds.Remove(node);
     CancelledBuilds.Remove(node);
     SucceededBuilds.Remove(node);
 }