using System.Windows.Forms;
using System;
using System.Configuration;
namespace Trigger
{
///
/// A for logging purposes
///
public partial class Log : Form
{
/// The type of the logged message
public enum Type
{
/// This is a network event
NetworkEvent,
/// This is a system event
SystemEvent,
/// This is a power event
PowerEvent,
/// This is a screen event
ScreenEvent,
/// This is a process event
ProcessesEvent,
/// This is a device event
DeviceEvent,
/// This is a command line event
CommandLineEvent,
/// This is an action
Action,
/// This is an message without type
Other,
/// This is an error message
Error,
}
/// Our
private Main Main;
///
///
public Log(Main Main)
{
InitializeComponent();
this.Main = Main;
}
#region Methods
///
/// Appends the specified to the log box
///
///
///
public void LogText(string text, Type type)
{
if (this.txt.InvokeRequired)
{
this.txt.Invoke(new MethodInvoker(() => this.LogText(text, type)));
return;
}
this.txt.AppendText(text);
}
///
/// Appends the specified to the log box prepending the current time
///
///
///
public void LogTextDate(string text, Type type)
{
this.LogText(DateTime.Now.ToLongTimeString() + " " + text, type);
}
///
/// Appends the specified to the log box () and opens a new line
///
///
///
public void LogLine(string text, Type type)
{
if (this.txt.InvokeRequired)
{
this.txt.Invoke(new MethodInvoker(() => this.LogLine(text, type)));
return;
}
this.txt.AppendText(text + "\n");
this.txt.ScrollToCaret();
}
///
/// Appends the specified to the log box () prepending the current time and opens a new line
///
///
///
public void LogLineDate(string text, Type type)
{
this.LogLine(DateTime.Now.ToLongTimeString() + " " + text, type);
}
///
/// Creates a new line in the log box
///
public void Line(Type type)
{
if (this.txt.InvokeRequired)
{
this.txt.Invoke(new MethodInvoker(() => this.Line(type)));
return;
}
this.txt.AppendText("\n");
this.txt.ScrollToCaret();
}
///
/// Shows this in the foreground
///
new public void Show()
{
this.BringToFront();
this.WindowState = FormWindowState.Normal;
Actions.System.SetForegroundWindow(this);
this.Main.tsmNotifyIcon_Log.Visible = false;
base.Show();
}
///
/// Hides this
///
new public void Hide()
{
this.Main.tsmNotifyIcon_Log.Visible = true;
base.Hide();
}
#endregion
#region Event handlers
///
/// Prevent this form from closing, simply hide it
/// This is neccessary because we may want to have a look at the log later again
///
///
///
private void Log_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
this.Hide();
e.Cancel = true;
}
}
///
/// Clears the log
///
///
///
private void tsb_Clear_Click(object sender, EventArgs e)
{
this.txt.Clear();
}
///
/// Saves the settings which logs shall be displayed
///
///
///
private void tsb_Options_DropDownItem_CheckedChanged(object sender, EventArgs e)
{
ToolStripMenuItem tsmi = (ToolStripMenuItem)sender;
Properties.Settings.Default[tsmi.Name] = tsmi.Checked;
Properties.Settings.Default.Save();
}
///
/// Opens the
/// See .RefreshStatus
///
///
///
private void tsb_Stats_Click(object sender, EventArgs e)
{
this.Main.RefreshStatus();
}
///
/// Close the application
///
///
///
private void tsb_Exit_Click(object sender, EventArgs e)
{
this.Main.Close();
}
///
/// Enable some keys
///
///
///
private void txt_KeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
{
case Keys.S:
this.Main.RefreshStatus();
e.Handled = true;
break;
case Keys.Escape:
this.Hide();
e.Handled = true;
break;
}
}
///
/// Opens the
///
///
///
private void manageTasksToolStripMenuItem_Click(object sender, EventArgs e)
{
new TaskOptions(this.Main).Show();
}
#endregion
}
}