Alejandro Acuña
2024-08-12 831c7bd85763b5eb5ef46664c65f0181824f9e13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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();
 
        }
 
 
 
 
 
 
 
 
 
    }
 
 
 
}