void m_visClient_ConnectionStateChanged(object sender, VisualizationEventArgs e) { if (m_visClient.IsConnected) { ToolTipService.SetToolTip(CaptureMenu.FindName("btnServer") as DependencyObject, String.Format("Change Infrastructure (Currently connected to '{0}')", m_visClient.ServerEndpoint)); connectionStatus.Visibility = System.Windows.Visibility.Collapsed; sbHideSelector.Begin(); } else { ToolTipService.SetToolTip(CaptureMenu.FindName("btnServer") as DependencyObject, "Change Infrastructure (Not Connected)"); if (connectionStatus.Visibility == System.Windows.Visibility.Collapsed) // Retry connecton { m_visClient.Connect(); } else { connectionStatus.Content = String.Format("Couldn't establish a connection please ensure the service is running and is available. '{0}'", e.ErrorText); connectionStatus.AllowApprove = true; } } }
/// <summary> /// Current diagram has changed /// </summary> private void lstSelection_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count > 0 && e.AddedItems[0] is Diagram) { m_currentDiagram = (e.AddedItems[0] as Diagram).CreateControl() as UserControl; m_currentDiagram.VerticalContentAlignment = m_currentDiagram.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; m_currentDiagram.HorizontalContentAlignment = m_currentDiagram.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; visualizerContent.Children.Clear(); visualizerContent.Children.Add(m_currentDiagram); sbHideSelector.Begin(); } else if (e.AddedItems.Count > 0 && e.AddedItems[0] is Server) { connectionStatus.Visibility = System.Windows.Visibility.Visible; // btnHideConnection.Visibility = System.Windows.Visibility.Collapsed; connectionStatus.Content = String.Format("Connecting to {0} at {1}:{2}", (e.AddedItems[0] as Server).Name, (e.AddedItems[0] as Server).Address, (e.AddedItems[0] as Server).Port); // Disconnect from the current service if (m_visClient != null) { m_visClient.Close(); m_visClient.ConnectionStateChanged -= new EventHandler <VisualizationEventArgs>(m_visClient_ConnectionStateChanged); m_visClient.EventReceived -= new EventHandler <Visualization.Core.VisualizationEventArgs>(m_visClient_EventReceived); } // Connect to new service m_visClient = (e.AddedItems[0] as Server).CreateClient(this.Dispatcher); m_visClient.ConnectionStateChanged += new EventHandler <VisualizationEventArgs>(m_visClient_ConnectionStateChanged); m_visClient.EventReceived += new EventHandler <Visualization.Core.VisualizationEventArgs>(m_visClient_EventReceived); m_visClient.Connect(); } }