// // // // // // ***************************************** // **** Button_Click() **** // ***************************************** /// <summary> /// This manages all button clicks on this control. /// </summary> private void Button_Click(object sender, EventArgs e) { if (m_FrontEndServer != null) { m_FrontEndServer.Log.NewEntry(LogLevel.Major, "Violet.Button_Click: {0} {1}", ((Control)sender).Name, e); } // Determine which service is selected. ServiceListEntry selectedServiceEntry = null; if (listBoxServices.SelectedItem != null) { selectedServiceEntry = (ServiceListEntry)listBoxServices.SelectedItem; } // Determine which button was clicked. if (sender == buttonLaunchDisplay) { // If service is an engine hub, request its display. if (selectedServiceEntry != null && selectedServiceEntry.Service is IEngineHub) { m_FrontEndServer.TryRequestDisplay(selectedServiceEntry.ServiceName); } } else if (sender == buttonLaunchLogViewer) { // If service is a local hub, open its log viewer. if (selectedServiceEntry != null && selectedServiceEntry.Service is Hub) { ((Hub)selectedServiceEntry.Service).Log.IsViewActive = true; } } }//
}//UpdateThisControl(); // // // // ***************************************************** // **** Create ServiceListEntry() **** // ***************************************************** /// <summary> /// Called each time new service is added to application. Here, it is examined /// and added to our list. /// </summary> /// <param name="serviceName"></param> /// <param name="entry"></param> /// <returns></returns> private bool TryCreateServiceListEntry(string serviceName, out ServiceListEntry entry) { IService iService; if (m_AppServices.TryGetService(serviceName, out iService)) { // Discover a frontend server to which we can send requests. if (m_FrontEndServer == null && iService is FrontEndServer) { m_FrontEndServer = (FrontEndServer)iService; } // Create a entry element for this service. entry = new ServiceListEntry(); entry.ServiceName = serviceName; entry.ServiceClassName = iService.GetType().Name; entry.Service = iService; if (iService is ForeignService) { ForeignService foreignService = (ForeignService)iService; entry.IsForeign = true; string[] s = foreignService.ClassName.Split('.'); entry.ServiceClassName = s[s.Length - 1]; } return(true); } else { entry = null; return(false); } }// TryCreateServiceListEntry()
}//ServiceViewer() // // // // // // #endregion//Constructors #region no Properties // ***************************************************************** // **** Properties **** // ***************************************************************** // // #endregion//Properties #region no Public Methods // ***************************************************************** // **** Public Methods **** // ***************************************************************** // // // // // // #endregion//Public Methods #region Private Methods // ***************************************************************** // **** Private Methods **** // ***************************************************************** // private void UpdateThisControl(object sender, EventArgs eventArgs) { if (this.InvokeRequired) { BeginInvoke(new EventHandler(UpdateThisControl), sender, eventArgs); } else { // Check for new services lock (m_ServicesNew) { if (m_ServicesNew.Count > 0) { this.listBoxServices.SuspendLayout(); while (m_ServicesNew.Count > 0) { ServiceListEntry entry = m_ServicesNew[0]; entry.Index = this.listBoxServices.Items.Add(entry); m_ServicesNew.RemoveAt(0); } if (this.listBoxServices.SelectedIndex < 0) { this.listBoxServices.SelectedIndex = 0; } this.listBoxServices.ResumeLayout(false); } } IsThisControlNeedsUpdating = false; } }//UpdateThisControl();
// ***************************************************************** // **** Event Handlers **** // ***************************************************************** private void listBoxServices_DrawItem(object sender, DrawItemEventArgs e) { Color myColor = Color.Red; Font myFont = new Font(e.Font, FontStyle.Italic); ServiceListEntry service = (ServiceListEntry)listBoxServices.Items[e.Index]; if (service.IsForeign) { //using(Brush brush = new SolidBrush(myColor)) //{ // e.Graphics.DrawString( service.ServiceName , myFont, brush, e.Bounds); //} e.Graphics.DrawString(service.ServiceName, myFont, new SolidBrush(e.ForeColor), e.Bounds); } else { e.Graphics.DrawString(service.ServiceName, e.Font, new SolidBrush(e.ForeColor), e.Bounds); } }//listBoxServices_DrawItem()
}// TryCreateServiceListEntry() // // // // ********************************************* // **** UpdateServiceSelection() **** // ********************************************* private void UpdateServiceSelection() { int index = listBoxServices.SelectedIndex; if (index >= 0 && index < listBoxServices.Items.Count) { ServiceListEntry entry = (ServiceListEntry)listBoxServices.Items[index]; textServiceName.Text = entry.ServiceName; textServiceType.Text = entry.ServiceClassName; if (entry.IsForeign) { ForeignService foreignService = (ForeignService)entry.Service; textServiceLocation.Text = "Foreign";//foreignService.Parent. } else { textServiceLocation.Text = "Local"; } // Update state of buttons if (entry.Service is IEngineHub) { buttonLaunchDisplay.Enabled = true; } else { buttonLaunchDisplay.Enabled = false; } if (entry.Service is Hub) { buttonLaunchLogViewer.Enabled = true; } else { buttonLaunchLogViewer.Enabled = false; } } }
void service_DidResolveService(NetService service) { ServiceListEntry item = new ServiceListEntry(service); item.Resolved = true; servicesList.Items.Add(item); }