public MessageWindow(StatusMessage message, double duration) { InitializeComponent(); //Message to be displayed in the window Message.Content = message.Message; //Begin closing the window after the specified duration has elapsed. Timer closeTimer = new Timer(duration); closeTimer.Elapsed += closeTimer_Elapsed; closeTimer.Start(); //This cannot be in the constructor directly, because the ActualWidth of items //does not get set until AFTER the constructor. Since I couldn't get the Initialize //event to fire, this method seems to work good. Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new VoidDelegate(delegate { Width = Message.ActualWidth + 50; //Set the default placement to the bottom right corner, above the Taskbar. Left = SystemParameters.WorkArea.Right - Width - 20; Top = SystemParameters.WorkArea.Bottom - Height - 20; })); }
private void LoadConfiguration(bool reconfigure) { if (reconfigure) { buildUpdates.Clear(); buildContent.Clear(); lastStatusMessage = new StatusMessage { Message = "" }; buildIdsAlertedInProgress.Clear(); buildIdUris.Clear(); buildIdsAlertedQueued.Clear(); buildIdsAlertedDone.Clear(); currentIconColour = IconColour.Grey; statusMessages.Clear(); buildContentView.Clear(); foreach (var server in servers) { server.Dispose(); } } //StatusMessage initializing = new StatusMessage { Message = "Initializing..." }; //MessageWindow.Show(initializing, 3000); if (File.Exists(TeamServer.ServerConfigurationPath)) { try { servers = GetServersFromConfigurationFile(); if (servers == null || servers.Count == 0) { RunConfigurationWindow(); servers = GetServersFromConfigurationFile(); } } catch (Exception) { servers = new List<TeamServer>(); } } else { RunConfigurationWindow(); servers = GetServersFromConfigurationFile(); } //Add version as menu item if (!reconfigure) { MenuItem versionMenuItem = new MenuItem { Header = "Version : " + Assembly.GetExecutingAssembly().GetName().Version }; NotifyIconMainIcon.ContextMenu.Items.Insert(0, versionMenuItem); NotifyIconMainIcon.ContextMenu.Items.Insert(1, new Separator()); //Add Reconfigure option into menu MenuItem reconfigureMenuItem = new MenuItem { Header = "Change Servers" }; reconfigureMenuItem.Click += reconfigureMenuItem_Click; NotifyIconMainIcon.ContextMenu.Items.Insert(2, reconfigureMenuItem); } //Attach to server events foreach (TeamServer server in servers) { server.OnProjectsUpdated += Server_OnProjectsUpdated; } //Open xml file of builds to hide LoadHiddenBuilds(); InitializeServers(); }
private IconColour? CheckCancelledBuilds(BuildQueueQueryResult result) { IconColour? returnColour = null; var buildIdHistories = from build in result.Builds select build.Id; List<int> cancelledBuilds = new List<int>(); foreach (int buildId in buildIdsAlertedInProgress) { if (!buildIdHistories.Contains(buildId)) { //Build was cancelled cancelledBuilds.Add(buildId); } } foreach (int buildId in cancelledBuilds) { buildIdsAlertedInProgress.Remove(buildId); string uri = buildIdUris[buildId]; buildIdUris.Remove(buildId); StatusMessage message = new StatusMessage { EventDate = DateTime.Now, BuildStatus = IconColour.Green, Message = String.Format(CultureInfo.CurrentUICulture, ResourcesMain.NotifierWindow_Stopped, GetFriendlyName(uri)) }; statusMessages.Enqueue(message); returnColour = IconColour.Red; NotifyIconMainIcon.Text = ResourcesMain.MainWindow_Title; UpdateMainWindowItem(uri, BuildStatus.Failed, String.Empty); } return returnColour; }
private void AlertChanges(BuildQueryEventArgs buildQueryEventArgs) { bool iconChanged = false; IconColour mainIconColour = IconColour.Green; //Cleanup history CleanupIds(); //Find in progress builds foreach (BuildQueueQueryResult queueResult in buildQueryEventArgs.BuildQueueQueryResults) { //Check for cancelled builds IconColour? iconColour = CheckCancelledBuilds(queueResult); if (iconColour.HasValue) { mainIconColour = iconColour.Value; iconChanged = true; } //Loop through builds with active histories foreach (QueuedBuild build in queueResult.Builds.OrderBy(item => item.Id)) { //Check if build is hidden if (HiddenBuilds.Contains(build.BuildDefinitionUri)) { continue; } //Get the friendly names string buildName = GetFriendlyName(build.BuildDefinitionUri); //Adding builds while the tray is running can cause it to fail, only builds which have atleast 1 successfull build will be displayed. if (!String.IsNullOrEmpty(buildName)) { //Check if this is an "In Progress" status and has not been displayed before if ((!buildIdsAlertedInProgress.Contains(build.Id)) && (build.Status == QueueStatus.InProgress)) { StatusMessage message = new StatusMessage { EventDate = DateTime.Now, BuildStatus = IconColour.Amber, Message = String.Format(CultureInfo.CurrentUICulture, ResourcesMain.NotifierWindow_InProgress, build.RequestedBy, buildName) }; statusMessages.Enqueue(message); mainIconColour = IconColour.Amber; iconChanged = true; buildIdsAlertedInProgress.Add(build.Id); buildIdUris.Add(build.Id, build.BuildDefinitionUri); NotifyIconMainIcon.Text = ResourcesMain.MainWindow_Title + " - Building"; UpdateMainWindowItem(build.BuildDefinitionUri, BuildStatus.InProgress, build.RequestedBy); } //Check if this is an "Queued" status and has not been displayed before else if ((!buildIdsAlertedQueued.Contains(build.Id)) && (build.Status == QueueStatus.Queued)) { StatusMessage message = new StatusMessage { EventDate = DateTime.Now, BuildStatus = IconColour.Amber, Message = String.Format(CultureInfo.CurrentUICulture, ResourcesMain.NotifierWindow_Queued, build.RequestedBy, buildName) }; statusMessages.Enqueue(message); buildIdsAlertedQueued.Add(build.Id); }//Check if this is an "Completed" status and has not been displayed before else if ((!buildIdsAlertedDone.Contains(build.Id)) && (build.Status == QueueStatus.Completed)) { StatusMessage message = new StatusMessage { EventDate = DateTime.Now }; buildIdsAlertedInProgress.Remove(build.Id); buildIdUris.Remove(build.Id); //Get the status from the build log foreach (BuildDetail item in buildContent) { if (item.BuildDefinitionUri == build.BuildDefinitionUri) { switch (item.Status) { case BuildStatus.Succeeded: message.BuildStatus = IconColour.Green; message.Message = String.Format(CultureInfo.CurrentUICulture, ResourcesMain.NotifierWindow_BuildPassed, buildName); break; case BuildStatus.PartiallySucceeded: message.BuildStatus = IconColour.Red; message.Message = String.Format(CultureInfo.CurrentUICulture, ResourcesMain.NotifierWindow_BuildPartial, buildName); break; default: message.BuildStatus = IconColour.Red; message.Message = String.Format(CultureInfo.CurrentUICulture, ResourcesMain.NotifierWindow_FailedBuild, build.RequestedFor, buildName); break; } message.HyperlinkUri = new Uri(item.LogLocation); mainIconColour = message.BuildStatus; iconChanged = true; break; } } NotifyIconMainIcon.Text = ResourcesMain.MainWindow_Title; statusMessages.Enqueue(message); buildIdsAlertedDone.Add(build.Id); } } } } //Only pop up if new messages if (statusMessages.Count > 0) { lastStatusMessage = statusMessages.Dequeue(); MessageWindow.Show(lastStatusMessage, 3000); } //Only update the main icon if its a valid status change if (iconChanged) { SetIcon(mainIconColour); } }
/// <summary> /// Shows a message window, focusing on the parent after creation. /// </summary> /// <param name="message">Message to display</param> /// <param name="duration">Amount of time, in milliseconds, to show the window</param> /// <param name="parent">Window to send focus to</param> public static void Show(StatusMessage message, double duration, Window parent) { MessageWindow w = new MessageWindow(message, duration); w.Show(); parent.Focus(); }
/// <summary> /// Creates and shows a MessageWindow. /// </summary> /// <param name="message">Message to display</param> /// <param name="duration">Amount of time, in milliseconds, to show the window</param> public static void Show(StatusMessage message, double duration) { MessageWindow w = new MessageWindow(message, duration); w.Show(); }