Click here to Skip to main content
15,896,726 members
Articles / Programming Languages / C#

Smoothy Event Log Viewer 1.2

Rate me:
Please Sign up or sign in to vote.
4.75/5 (42 votes)
7 Oct 2006Ms-PL4 min read 187K   7.4K   119  
MDI event log viewer with quick filter and search capabilities.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SmoothyInterface.Properties;
using System.Collections.Specialized;
using System.Diagnostics;

namespace SmoothyInterface.Forms
{
	public partial class ConnectToComputer : Form
	{
		#region Globals

		private EventLog[] eventLogsRetrieved = null;
		private string machineName = null;
		private List<string> ignoreComputers = null;

		#endregion

		#region Construction

		public ConnectToComputer(List<string> ignoreComputers_)
		{
			#region Assertions

			Debug.Assert(ignoreComputers_ != null);

			#endregion

			InitializeComponent();

			ignoreComputers = ignoreComputers_;

			LoadComputers();
		}
				
		private void ConnectToComputer_Load(object sender, EventArgs e)
		{

		}

		#endregion

		#region Properties

		public EventLog[] EventLogsRetrieved
		{
			get
			{
				return eventLogsRetrieved;
			}
		}

		public string MachineNameSpecified
		{
			get
			{
				return machineName;
			}
		}

		#endregion

		#region Methods

		private void LoadComputers()
		{
			StringCollection computers = Settings.Default.RemoteComputers;

			if (computers != null)
			{
				for (int i = 0; i < computers.Count; i++)
				{
					dlComputerName.Items.Add(computers[i]);
				}
			}
		}

		#endregion

		#region Events

		private void dlComputerName_TextChanged(object sender, EventArgs e)
		{
			btnConnect.Enabled = (dlComputerName.Text != String.Empty);
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
		}

		private void btnConnect_Click(object sender, EventArgs e)
		{
			try
			{
				this.Cursor = Cursors.WaitCursor;

				if (ignoreComputers.Contains(dlComputerName.Text))
				{
					MessageBox.Show("A connection to this computer is allready open.", "Smoothy", MessageBoxButtons.OK, MessageBoxIcon.Information);
				}
				else
				{

					if (Settings.Default.RemoteComputers == null)
					{
						Settings.Default.RemoteComputers = new StringCollection();
					}

					EventLog[] logs = EventLog.GetEventLogs(dlComputerName.Text);					
					eventLogsRetrieved = logs;
					machineName = dlComputerName.Text;

					// Save the machine name in the user's config file
					if (!Settings.Default.RemoteComputers.Contains(machineName))
					{
						Settings.Default.RemoteComputers.Add(machineName);
						Settings.Default.Save();
					}

					this.DialogResult = DialogResult.OK;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show("Failed to connect to remote computer : " + ex.Message, "Smoothy", MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			finally
			{
				this.Cursor = Cursors.Default;
			}
		}

		#endregion

	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Web Developer
South Africa South Africa
The author is a software consultant in South Africa, specializing in bespoke software solutions.

Comments and Discussions