Program.cs 1.91 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Web.Administration;
using System.Management;
using System.Diagnostics;

using Vrh.XmlProcessing;
using VRH.Common;
using System.Xml.Linq;

namespace Vrh.Log4Pro.MaintenanceConsole
{
	class Program
	{
		static void Main(string[] args)
		{
			ColorConsole.ReadLine("Press a key to start...");
			var appconfigpath = CommandLine.GetCommandLineArgument(args, "-APPCONFIG");
			CommandLine.SetAppConfigFile(appconfigpath);

			try { ColorConsole.SetWindowSize(120, 64); } 
			catch (Exception ex)
			{
				ColorConsole.WriteLine("Change the size of the console fonts smaller!");
				ColorConsole.ReadKey();
				return;
			}
			if (!Tools.IsElevated)
			{
				ColorConsole.WriteLine("Run as administartor!");
				ColorConsole.ReadKey();
				return;
			}

			var mm = new Menu("Log4ProIS Maintenance Console")
				.AddMenuItem(new Menu.Item("WAM", "Web Application Manager", WebApplicationManager.Execute))
				.AddMenuItem(new Menu.Item("WSM", "Windows Service Manager", WindowsServiceManager.Execute))
				.AddMenuItem(new Menu.Item("FCL", "File Cleaner Manager", FileCleanerManager.Execute))
				.AddMenuItem(new Menu.Item("SCH", "Scheduled Task Manager", ScheduledTaskmanagerManager.Execute))
				.AddMenuItem(new Menu.ItemSeparator('-'))
				.AddMenuItem(new Menu.Item("TOL", "Maintenance tools", MaintenanceToolManager.Execute))
				.SetSelectionMode(Menu.SelectionMode.Single);

			var commandmode = !string.IsNullOrEmpty(CommandLine.GetCommandLineArgument(args, "-MODULE"));
			if (commandmode)
			{
				var silentmode = !string.IsNullOrEmpty(CommandLine.GetCommandLineArgument(args, "-SILENT", switchtype: true));
				ColorConsole.SetSilentMode(silentmode);
				Menu.SetCommandModeAllMenus();
				mm.ExecuteCmd(args);
			}
			else
			{
				mm.ExecuteMenu();
				ColorConsole.PressAnykeyToContinue();
			}
		}
	}
}