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