// Write to file. public void Write(object sender, EventArgsEx args) { string message = args.Message; if (!String.IsNullOrEmpty(message)) { writer.Write(message); } }
// Switch watching target. public void Switch(object sender, EventArgsEx args) { watcher.Filter = args.Message; }
// Display balloon message. public void Notify(object sender, EventArgsEx args) { string type = args.Type; string tipTitle; string tipText = args.Message; switch (type) { case "error": tipTitle = "Error"; break; case "output": // Fall through. default: tipTitle = "Information"; break; } if (tipText.Length > 196) { tipText = tipText.Substring(0, 196) + "..."; } notifyIcon.Visible = true; notifyIcon.ShowBalloonTip(20, tipTitle, tipText, ToolTipIcon.None); }
// Restart process. public void Restart(object sender, EventArgsEx args) { if (args.Type == "switch") { startInfo.Arguments = "\"" + args.Message + "\""; } if (status == Status.Running) { // Stop current process and start a new process immediately. status = Status.Stopping; process.Exited += Start; process.Kill(); } else if (status == Status.Idle) { EmitEvent("start"); } }
// Refresh UI. public void Refresh(object sender, EventArgsEx args) { bool running = args.Type == "started"; menuStart.Enabled = !running; menuStop.Enabled = running; menuRestart.Enabled = running; notifyIcon.Icon = running ? runningIcon : stoppedIcon; notifyIcon.Text = running ? "Tianma HTTP Server (Running)" : "Tianma HTTP Server (Stopped)"; }