using System; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Diagnostics; using System.Threading; using Path = System.IO.Path; using Directory = System.IO.Directory; using Image = System.Drawing.Image; using Assembly = System.Reflection.Assembly; using XmlException = System.Xml.XmlException; using FileNotFoundException = System.IO.FileNotFoundException; namespace ProcessInfo { public class ProcessInfoForm : Form { private String programDirectory; private Settings settings; private Throbber throbber; private System.Windows.Forms.ToolBar toolBar; private System.Windows.Forms.ToolBarButton refreshToolBarButton; private System.Windows.Forms.ToolBarButton showBrowserToolBarButton; private System.Windows.Forms.ComboBox sitesComboBox; private System.ComponentModel.IContainer components; private System.Windows.Forms.Splitter splitter; private System.Windows.Forms.Label sitesLabel; private ProcessListView processListView; private AxSHDocVw.AxWebBrowser browser; private System.Windows.Forms.ImageList toolbarImageList; public ProcessInfoForm() { InitializeComponent(); } [STAThread] static void Main() { try { Application.Run( new ProcessInfoForm() ); } catch ( Exception e ) { MessageBox.Show( e.Message, "Fatal error", MessageBoxButtons.OK, MessageBoxIcon.Stop ); } } protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ProcessInfoForm)); this.toolBar = new System.Windows.Forms.ToolBar(); this.refreshToolBarButton = new System.Windows.Forms.ToolBarButton(); this.showBrowserToolBarButton = new System.Windows.Forms.ToolBarButton(); this.toolbarImageList = new System.Windows.Forms.ImageList(this.components); this.sitesComboBox = new System.Windows.Forms.ComboBox(); this.sitesLabel = new System.Windows.Forms.Label(); this.throbber = new ProcessInfo.Throbber(); this.processListView = new ProcessInfo.ProcessListView(); this.splitter = new System.Windows.Forms.Splitter(); this.browser = new AxSHDocVw.AxWebBrowser(); ((System.ComponentModel.ISupportInitialize)(this.browser)).BeginInit(); this.SuspendLayout(); // // toolBar // this.toolBar.Appearance = System.Windows.Forms.ToolBarAppearance.Flat; this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] { this.refreshToolBarButton, this.showBrowserToolBarButton}); this.toolBar.DropDownArrows = true; this.toolBar.ImageList = this.toolbarImageList; this.toolBar.Location = new System.Drawing.Point(0, 0); this.toolBar.Name = "toolBar"; this.toolBar.ShowToolTips = true; this.toolBar.Size = new System.Drawing.Size(816, 28); this.toolBar.TabIndex = 0; this.toolBar.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right; this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick); // // refreshToolBarButton // this.refreshToolBarButton.ImageIndex = 0; this.refreshToolBarButton.Text = " Refresh Processes"; // // showBrowserToolBarButton // this.showBrowserToolBarButton.ImageIndex = 1; this.showBrowserToolBarButton.Pushed = true; this.showBrowserToolBarButton.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton; this.showBrowserToolBarButton.Text = " Show Info"; // // toolbarImageList // this.toolbarImageList.ImageSize = new System.Drawing.Size(16, 16); this.toolbarImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("toolbarImageList.ImageStream"))); this.toolbarImageList.TransparentColor = System.Drawing.Color.Transparent; // // sitesComboBox // this.sitesComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.sitesComboBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.sitesComboBox.ItemHeight = 13; this.sitesComboBox.Location = new System.Drawing.Point(276, 2); this.sitesComboBox.Name = "sitesComboBox"; this.sitesComboBox.Size = new System.Drawing.Size(220, 21); this.sitesComboBox.Sorted = true; this.sitesComboBox.TabIndex = 0; this.sitesComboBox.SelectedIndexChanged += new System.EventHandler(this.sitesComboBox_SelectedIndexChanged); // // sitesLabel // this.sitesLabel.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.sitesLabel.Location = new System.Drawing.Point(224, 6); this.sitesLabel.Name = "sitesLabel"; this.sitesLabel.Size = new System.Drawing.Size(52, 16); this.sitesLabel.TabIndex = 4; this.sitesLabel.Text = "Info Site:"; // // throbber // this.throbber.Location = new System.Drawing.Point(0, 0); this.throbber.Name = "throbber"; this.throbber.Size = new System.Drawing.Size(16, 16); this.throbber.StoppedImage = ((System.Drawing.Image)(resources.GetObject("throbber.StoppedImage"))); this.throbber.TabIndex = 0; this.throbber.Throbbing = false; this.throbber.ThrobImage = ((System.Drawing.Image)(resources.GetObject("throbber.ThrobImage"))); // // processListView // this.processListView.Dock = System.Windows.Forms.DockStyle.Left; this.processListView.FullRowSelect = true; this.processListView.HideSelection = false; this.processListView.Location = new System.Drawing.Point(0, 28); this.processListView.MultiSelect = false; this.processListView.Name = "processListView"; this.processListView.Size = new System.Drawing.Size(392, 498); this.processListView.TabIndex = 9; this.processListView.View = System.Windows.Forms.View.Details; this.processListView.SelectedIndexChanged += new System.EventHandler(this.processListView_SelectedIndexChanged); // // splitter // this.splitter.Location = new System.Drawing.Point(392, 28); this.splitter.Name = "splitter"; this.splitter.Size = new System.Drawing.Size(3, 498); this.splitter.TabIndex = 10; this.splitter.TabStop = false; // // browser // this.browser.Dock = System.Windows.Forms.DockStyle.Fill; this.browser.Enabled = true; this.browser.Location = new System.Drawing.Point(395, 28); this.browser.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("browser.OcxState"))); this.browser.Size = new System.Drawing.Size(421, 498); this.browser.TabIndex = 6; this.browser.DocumentComplete += new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEventHandler(this.browser_DocumentComplete); this.browser.BeforeNavigate2 += new AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2EventHandler(this.browser_BeforeNavigate2); // // ProcessInfoForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(816, 526); this.Controls.Add(this.throbber); this.Controls.Add(this.browser); this.Controls.Add(this.splitter); this.Controls.Add(this.processListView); this.Controls.Add(this.sitesLabel); this.Controls.Add(this.sitesComboBox); this.Controls.Add(this.toolBar); this.Name = "ProcessInfoForm"; this.Text = "ProcessInfo"; this.WindowState = System.Windows.Forms.FormWindowState.Maximized; this.Resize += new System.EventHandler(this.ProcessInfoForm_Resize); this.Load += new System.EventHandler(this.ProcessInfoForm_Load); ((System.ComponentModel.ISupportInitialize)(this.browser)).EndInit(); this.ResumeLayout(false); } private void ProcessInfoForm_Resize(object sender, System.EventArgs e ) { throbber.Top = 6; throbber.Left = (int)Math.Max( sitesComboBox.Right + 10, this.ClientSize.Width - 6 - throbber.Width ); } private void ProcessInfoForm_Load(object sender, System.EventArgs e) { programDirectory = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ); LoadSettings(); LoadSites(); browser.Navigate( "about:blank" ); RefreshProcesses(); } private void LoadSettings() { try { settings = Settings.Load( Path.Combine( programDirectory, "settings.xml" ) ); } catch ( FileNotFoundException ) { settings = new Settings(); } catch ( XmlException e ) { ShowSettingsFileErrorMessageBox( e.Message ); settings = new Settings(); } catch ( InvalidOperationException e ) { ShowSettingsFileErrorMessageBox( e.Message ); settings = new Settings(); } } private void ShowSettingsFileErrorMessageBox( String message ) { MessageBox.Show( this, message, "Settings file error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation ); } private void LoadSites() { foreach( Site site in settings.Sites ) { sitesComboBox.Items.Add( site ); if ( site.Selected ) { sitesComboBox.SelectedItem = site; } } if ( sitesComboBox.Items.Count == 0 ) { sitesComboBox.Enabled = false; sitesComboBox.Items.Add( "Define a site in settings.xml" ); } if ( sitesComboBox.SelectedItem == null ) { sitesComboBox.SelectedIndex = 0; } } // must be called on UI thread private void RefreshProcesses() { refreshToolBarButton.Enabled = false; throbber.Throbbing = true; MethodInvoker refreshProcesses = new MethodInvoker( processListView.RefreshProcesses ); refreshProcesses.BeginInvoke( new AsyncCallback( RefreshProcessesDone ), null ); } // may be called on non-UI thread private void RefreshProcessesDone( IAsyncResult result ) { if ( this.toolBar.InvokeRequired ) { this.toolBar.Invoke( new MethodInvoker( this.EnableRefreshButtonAndStopThrobber ) ); } } // must be called on UI thread private void EnableRefreshButtonAndStopThrobber() { refreshToolBarButton.Enabled = true; throbber.Throbbing = false; } private void ShowWebPage() { if ( ( processListView.SelectedItems.Count <= 0 ) || ( settings.Sites.Length == 0 ) || ( sitesComboBox.SelectedItem == null ) ) { return; } ProcessListViewItem selectedItem = (ProcessListViewItem)processListView.SelectedItems[ 0 ]; Process process = selectedItem.Process; Site site = (Site)sitesComboBox.SelectedItem; Object dummy = new Object(); browser.Navigate( site.GetUrl( process ), ref dummy, ref dummy, ref dummy, ref dummy ); } private void toolBar_ButtonClick( object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e ) { if ( e.Button.Equals( refreshToolBarButton ) ) { refreshToolBarButton_Click( e ); } else if ( e.Button.Equals( showBrowserToolBarButton ) ) { showBrowserToolBarButton_Click( e ); } } private void refreshToolBarButton_Click( ToolBarButtonClickEventArgs e ) { RefreshProcesses(); } private void showBrowserToolBarButton_Click( ToolBarButtonClickEventArgs e ) { if ( e.Button.Pushed ) { browser.Visible = true; splitter.Visible = true; processListView.Dock = DockStyle.Left; } else { browser.Visible = false; splitter.Visible = false; processListView.Dock = DockStyle.Fill; } } private void processListView_SelectedIndexChanged( Object sender, System.EventArgs e ) { ShowWebPage(); } private void sitesComboBox_SelectedIndexChanged(object sender, System.EventArgs e) { ShowWebPage(); } private void browser_BeforeNavigate2(object sender, AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event e) { throbber.Throbbing = true; } // if the browse doesn't reach readycomplete state the throbber will keep throbbing private void browser_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e) { if ( browser.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE ) { throbber.Throbbing = false; } } } }