using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.IO; using System.Drawing; using System.Xml; using System.Net; using System.Runtime.InteropServices; using System; using System.Windows.Forms; namespace tileserver { class Program { [DllImport("kernel32.dll")] static extern IntPtr GetConsoleWindow(); [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); const int SW_HIDE = 0; const int SW_SHOW = 5; public static string folder = ""; public static string fileExtension = ".meta"; public static int cache = 0; public static int port = 0; public static int TILE_SIZE = 256; public static ControllerJSON controllerJSON = null; public static ControllerHTTP controllerHTTP = null; static bool existsParameter(string[] args, string parameter) { for (int i = 0; i < args.Length; i++) { if (args[i].Equals(parameter)) { return true; } } return false; } static string getParameter(string[] args, string parameter) { for (int i = 0; i < args.Length; i++) { if (args[i].Equals(parameter)) { return args[i + 1]; } } return null; } class MyApplicationContext : ApplicationContext { //Component declarations private NotifyIcon TrayIcon; private ContextMenuStrip TrayIconContextMenu; private ToolStripMenuItem CloseMenuItem; public MyApplicationContext() { Application.ApplicationExit += new EventHandler(this.OnApplicationExit); InitializeComponent(); TrayIcon.Visible = true; } private void InitializeComponent() { TrayIcon = new NotifyIcon(); TrayIcon.BalloonTipIcon = ToolTipIcon.Info; TrayIcon.BalloonTipTitle = "Tile server"; TrayIcon.BalloonTipText = "Provide gis tile service"; TrayIcon.Text = "Tile server"; //The icon is added to the project resources. //Here I assume that the name of the file is 'TrayIcon.ico' // TrayIcon.Icon = new Icon("tileserver.ico"); //Optional - handle doubleclicks on the icon: TrayIcon.DoubleClick += TrayIcon_DoubleClick; //Optional - Add a context menu to the TrayIcon: TrayIconContextMenu = new ContextMenuStrip(); CloseMenuItem = new ToolStripMenuItem(); TrayIconContextMenu.SuspendLayout(); // // TrayIconContextMenu // this.TrayIconContextMenu.Items.AddRange(new ToolStripItem[] {this.CloseMenuItem}); this.TrayIconContextMenu.Name = "TrayIconContextMenu"; this.TrayIconContextMenu.Size = new Size(153, 70); // // CloseMenuItem // this.CloseMenuItem.Name = "CloseMenuItem"; this.CloseMenuItem.Size = new Size(152, 22); this.CloseMenuItem.Text = "Close"; this.CloseMenuItem.Click += new EventHandler(this.CloseMenuItem_Click); TrayIconContextMenu.ResumeLayout(false); TrayIcon.ContextMenuStrip = TrayIconContextMenu; } private void OnApplicationExit(object sender, EventArgs e) { //Cleanup so that the icon will be removed when the application is closed TrayIcon.Visible = false; } private void TrayIcon_DoubleClick(object sender, EventArgs e) { //Here you can do stuff if the tray icon is doubleclicked TrayIcon.ShowBalloonTip(10000); } private void CloseMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("Do you really want to close?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { Application.Exit(); } } } static void Main(string[] args) { if (existsParameter(args, "-name") == true) { Console.Title = getParameter(args, "-name"); } fileExtension = getParameter(args, "-extension"); folder = getParameter(args, "-folder"); port = Int32.Parse(getParameter(args, "-port")); if (existsParameter(args, "-tilesize") == true) { TILE_SIZE = Int32.Parse(getParameter(args, "-tilesize")); } if (existsParameter(args, "-cache") == true) { cache = Int32.Parse(getParameter(args, "-cache")); } if (existsParameter(args, "-wms") == false) { controllerJSON = new ControllerJSON(); } else { controllerHTTP = new ControllerHTTP(8012); } if (existsParameter(args, "-hide") == true) { Console.WriteLine("Hide"); var handle = GetConsoleWindow(); ShowWindow(handle, SW_HIDE); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MyApplicationContext()); Application.Run(); } } }