Commit 823fdecce96c38de2ff464853d649a798a3ea5ea
1 parent
247be1a2
- MSMQ kezelés beépítése
- elevated modra való automatikus átváltás - SYSTEM user-ként való indítási lehetőség beépítése
Showing
9 changed files
with
1073 additions
and
68 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
... | ... | @@ -139,7 +139,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
139 | 139 | string input; |
140 | 140 | while (true) |
141 | 141 | { |
142 | - string prompt = text; | |
142 | + string prompt = ""; | |
143 | 143 | if (SilentMode) |
144 | 144 | { |
145 | 145 | if (readlineList == null || readlineList.Length == 0) { return null; } |
... | ... | @@ -154,13 +154,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
154 | 154 | { |
155 | 155 | if (validitylist != null && validitylist.Any()) { prompt += $" Valid values are {'\''+string.Join("','", validitylist)+'\''}."; } |
156 | 156 | if (defaultvalue != null) { prompt += $" Default value is '{defaultvalue}'."; } |
157 | - if (exitvalue != null) { prompt += $" Enter EX to exit."; } | |
157 | + if (exitvalue != null) { prompt += $" Enter '{exitvalue}' to exit."; } | |
158 | 158 | |
159 | - Write(prompt, f, b, bracket, prefix, suffix); | |
160 | - input = Console.ReadLine(); | |
159 | + WriteLine(text, f, b, bracket, prefix, suffix); | |
160 | + if (prompt != null) { WriteLine(prompt); } | |
161 | + Write("-->"); input = Console.ReadLine(); | |
161 | 162 | if (defaultvalue!=null && (input == null || input == "")) { input = defaultvalue; } |
162 | 163 | if (required && string.IsNullOrWhiteSpace(input)) { WriteLine($"Erroneous value!", ConsoleColor.Red); continue; } |
163 | - if (exitvalue != null && input != null && input.ToLower() == exitvalue) { break; } | |
164 | + if (exitvalue != null && input != null && input.ToLower() == exitvalue.ToLower()) { break; } | |
164 | 165 | if (validitylist == null || !validitylist.Any() || string.IsNullOrWhiteSpace(input) || validitylist.Contains(input)) { break; } |
165 | 166 | WriteLine($"Erroneous value!", ConsoleColor.Red); |
166 | 167 | } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
... | ... | @@ -257,6 +257,23 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS |
257 | 257 | public static class ChangePriority { public const string KEY = "CHP"; } |
258 | 258 | } |
259 | 259 | } |
260 | + public static class MSMQManager | |
261 | + { | |
262 | + public const string KEY = "MSQ"; | |
263 | + public static class Function | |
264 | + { | |
265 | + public const string CMD_TASKS = "-TASKS"; | |
266 | + public static class Create{ public const string KEY = "CRE"; } | |
267 | + public static class Remove { public const string KEY = "UIN"; } | |
268 | + public static class SetPermissions { public const string KEY = "PRM"; } | |
269 | + public static class SetDefaultPermissions { public const string KEY = "DPR"; } | |
270 | + public static class GetInfo { public const string KEY = "INF"; } | |
271 | + public static class Send { public const string KEY = "SND"; } | |
272 | + public static class Peek { public const string KEY = "PEK"; } | |
273 | + public static class Read{ public const string KEY = "RED"; } | |
274 | + public static class Purge { public const string KEY = "PRG"; } | |
275 | + } | |
276 | + } | |
260 | 277 | public static class BackupPackageManager |
261 | 278 | { |
262 | 279 | public const string KEY = "BAK"; |
... | ... | @@ -301,6 +318,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS |
301 | 318 | public const string KEY = "TOL"; |
302 | 319 | public static class Functions |
303 | 320 | { |
321 | + public static class StartAsSystem { public const string KEY = "SAS"; } | |
304 | 322 | public static class RegexTester { public const string KEY = "RGX"; } |
305 | 323 | public static class TCPIPTester { public const string KEY = "TCP"; } |
306 | 324 | public static class Tool { public const string KEY = "TOL"; } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs
... | ... | @@ -263,7 +263,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MenuNS |
263 | 263 | if (li > 0) { ColorConsole.Write(new string(' ', MenuItemIndentWidth)); } |
264 | 264 | var str = (string)MenuItemDisplayer.Invoke(menuitem.Parameters, li); |
265 | 265 | if (string.IsNullOrEmpty(str)) { ColorConsole.SetCursorPosition(0, ColorConsole.CursorTop); } |
266 | - if (str == null) { break; } | |
266 | + if (str == null) { break; }//nincs több kiírandó sor | |
267 | 267 | } |
268 | 268 | } |
269 | 269 | } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs
... | ... | @@ -18,9 +18,57 @@ using System.Xml.Linq; |
18 | 18 | using Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS; |
19 | 19 | using VRH.Common; |
20 | 20 | using Microsoft.Win32; |
21 | +using System.Reflection; | |
21 | 22 | |
22 | 23 | namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS |
23 | 24 | { |
25 | + public static class OtherTools | |
26 | + { | |
27 | + public static bool IsRunAsAdmin() | |
28 | + { | |
29 | + WindowsIdentity id = WindowsIdentity.GetCurrent(); | |
30 | + WindowsPrincipal pr = new WindowsPrincipal(id); | |
31 | + return pr.IsInRole(WindowsBuiltInRole.Administrator); | |
32 | + } | |
33 | + public static void StartAsAdmin() | |
34 | + { | |
35 | + if (!OtherTools.IsRunAsAdmin()) | |
36 | + { | |
37 | + ProcessStartInfo proc = new ProcessStartInfo(); | |
38 | + | |
39 | + proc.UseShellExecute = true; | |
40 | + proc.WorkingDirectory = Environment.CurrentDirectory; | |
41 | + proc.FileName = Assembly.GetEntryAssembly().CodeBase; | |
42 | + proc.Verb = "runas"; | |
43 | + try | |
44 | + { | |
45 | + Process.Start(proc); | |
46 | + System.Environment.Exit(1); | |
47 | + } | |
48 | + catch (Exception ex) | |
49 | + { | |
50 | + Console.WriteLine("This program must be run as an administrator! \n\n" + ex.ToString()); | |
51 | + } | |
52 | + } | |
53 | + } | |
54 | + | |
55 | + public static void StartAsSystem(bool silent) | |
56 | + { | |
57 | + if (!silent) | |
58 | + { | |
59 | + var ans = ColorConsole.ReadLine("NT AUTHORITY/SYSTEM", prefix: "Start as ",f:ConsoleColor.Yellow, suffix: "?", bracket: "[]",validitylist:new List<string> { "yes","no"},exitvalue:"EX",defaultvalue:"NO"); | |
60 | + if (ans.ToLower() != "yes") { return; } | |
61 | + } | |
62 | + Process p = new System.Diagnostics.Process(); | |
63 | + p.StartInfo.FileName = @"C:\Log4ProIS\MAINTENANCECONSOLE\PsTools\psexec.exe"; | |
64 | + p.StartInfo.Arguments = @"-sid C:\Log4ProIS\MAINTENANCECONSOLE\Vrh.Log4Pro.MaintenanceConsole.exe"; | |
65 | + // The UseShellExecute flag must be turned off in order to supply a password: | |
66 | + p.StartInfo.UseShellExecute = false; | |
67 | + | |
68 | + p.Start(); | |
69 | + System.Environment.Exit(1); | |
70 | + } | |
71 | + } | |
24 | 72 | public static class ZipTools |
25 | 73 | { |
26 | 74 | public static void Extract1stFileFromZIP(string targetfilefullpath, string ZIPfilefullpath) | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - MSMQManager.cs
... | ... | @@ -5,79 +5,1003 @@ using System.Messaging; |
5 | 5 | using System.Text; |
6 | 6 | using System.Threading.Tasks; |
7 | 7 | |
8 | -namespace Vrh.Log4Pro.MaintenanceConsole | |
8 | +using Vrh.Log4Pro.MaintenanceConsole.MenuNS; | |
9 | +using Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS; | |
10 | +using Vrh.Log4Pro.MaintenanceConsole.ToolsNS; | |
11 | +using Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS; | |
12 | + | |
13 | +using Vrh.XmlProcessing; | |
14 | +using VRH.Common; | |
15 | +using System.Xml.Linq; | |
16 | +using System.Text.RegularExpressions; | |
17 | + | |
18 | + | |
19 | +namespace Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS | |
9 | 20 | { |
10 | - class Manager___MSMQManager | |
21 | + #region MSMQManager class | |
22 | + public static class MSMQManager | |
11 | 23 | { |
12 | - void CreateQueue() | |
24 | + private const string XMLCONNECTIONSTRING = "config=MAINTENANCECONSOLE_MSMQMANAGER;"; | |
25 | + private const string XMLCONNECTIONSTRING_DEFAULT = "file=Config.Xml;element=MSMQManager;"; | |
26 | + | |
27 | + #region Execute | |
28 | + public static object Execute(object o1 = null, object o2 = null) | |
29 | + { | |
30 | + var args = (o1 as Menu.ExecutorParameter).Args; | |
31 | + var functionkey = CommandLine.GetCommandLineArgument(args, CLP.CMD_FUNCTION); | |
32 | + | |
33 | + var config = new MSMQManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); | |
34 | + var ep = new Menu.ExecutorParameter(config, args); | |
35 | + var menufunctions = new Menu("Manage MS Message Queues", "Select the management function!") | |
36 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Create.KEY, "Create MSMQ", Create, ep)) | |
37 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Remove.KEY, "Remove MSMQ", Remove, ep)) | |
38 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.SetPermissions.KEY, "Set MSMQ permisssions", SetPermissions, ep)) | |
39 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.SetDefaultPermissions.KEY, "Set default MSMQ permisssions", SetDefaultPermissions, ep)) | |
40 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.GetInfo.KEY, "Get MSMQ information", GetInfo, ep)) | |
41 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Peek.KEY, "Peek MSMQ message", Peek, ep)) | |
42 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Read.KEY, "Read MSMQ message", Read, ep)) | |
43 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Send.KEY, "Send MSMQ message", Send, ep)) | |
44 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.Function.Purge.KEY, "Purge MSMQ", Purge, ep)) | |
45 | + .SetSelectionMode(Menu.SelectionMode.Single) | |
46 | + .SetMenuHeaderDisplayer(MSMQListDisplayer); | |
47 | + menufunctions.ExecuteMenu(functionkey); | |
48 | + return o2; | |
49 | + } | |
50 | + #endregion Execute | |
51 | + | |
52 | + #region First level Executors with UI | |
53 | + private static object Create(object parameter, object o) | |
54 | + { | |
55 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
56 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
57 | + | |
58 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
59 | + | |
60 | + var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Create)}'!", silent: true); | |
61 | + | |
62 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
63 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
64 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
65 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
66 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
67 | + else { } | |
68 | + foreach (var p in sr.SelectedParameterList) | |
69 | + { | |
70 | + MSMQ st = p.Parameters as MSMQ; | |
71 | + try | |
72 | + { | |
73 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
74 | + MSMQManagerCore.CreateQueue(fullpath, st.Xml_Label); | |
75 | + ColorConsole.WriteLine($"MSMQ:{st.Xml_Name} created.", ConsoleColor.Green); | |
76 | + foreach (var a in st.Xml_AccessRights) | |
77 | + { | |
78 | + MSMQManagerCore.SetPermissions(fullpath, a.un, a.ar, a.ac); | |
79 | + string ctrlstring = | |
80 | + a.ac == AccessControlEntryType.Allow ? "allowed" | |
81 | + : a.ac == AccessControlEntryType.Deny ? "denied" | |
82 | + : a.ac == AccessControlEntryType.Revoke ? "revoked" | |
83 | + : a.ac == AccessControlEntryType.Set ? "set" | |
84 | + : "???"; | |
85 | + ColorConsole.WriteLine($"Access right {a.ar} {ctrlstring} for user:{a.un}.", ConsoleColor.Green); | |
86 | + } | |
87 | + } | |
88 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
89 | + } | |
90 | + return o; | |
91 | + } | |
92 | + private static object Remove(object parameter, object o) | |
93 | + { | |
94 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
95 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
96 | + | |
97 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
98 | + | |
99 | + var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Remove)}'!", silent: true); | |
100 | + | |
101 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
102 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
103 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
104 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
105 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
106 | + else { } | |
107 | + foreach (var p in sr.SelectedParameterList) | |
108 | + { | |
109 | + MSMQ st = p.Parameters as MSMQ; | |
110 | + try | |
111 | + { | |
112 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
113 | + MSMQManagerCore.DeleteQueue(fullpath); | |
114 | + ColorConsole.WriteLine($"MSMQ:{st.Xml_Name} removed.", ConsoleColor.Green); | |
115 | + } | |
116 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
117 | + } | |
118 | + return o; | |
119 | + } | |
120 | + private static object SetDefaultPermissions(object parameter, object o) | |
121 | + { | |
122 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
123 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
124 | + | |
125 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
126 | + | |
127 | + var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(SetDefaultPermissions)}'!", silent: true) | |
128 | + .SetSelectionMode(Menu.SelectionMode.Multi); | |
129 | + | |
130 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
131 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
132 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
133 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
134 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
135 | + else { } | |
136 | + | |
137 | + foreach (var p in sr.SelectedParameterList) | |
138 | + { | |
139 | + MSMQ st = p.Parameters as MSMQ; | |
140 | + try | |
141 | + { | |
142 | + foreach (var a in st.Xml_AccessRights) | |
143 | + { | |
144 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
145 | + MSMQManagerCore.SetPermissions(fullpath, a.un, a.ar, a.ac); | |
146 | + string ctrlstring = | |
147 | + a.ac == AccessControlEntryType.Allow ? "allowed" | |
148 | + : a.ac == AccessControlEntryType.Deny ? "denied" | |
149 | + : a.ac == AccessControlEntryType.Revoke ? "revoked" | |
150 | + : a.ac == AccessControlEntryType.Set ? "set" | |
151 | + : "???"; | |
152 | + ColorConsole.WriteLine($"Access right {a.ar} {ctrlstring} for user:{a.un}.", ConsoleColor.Green); | |
153 | + } | |
154 | + } | |
155 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
156 | + } | |
157 | + return o; | |
158 | + } | |
159 | + private static object SetPermissions(object parameter, object o) | |
160 | + { | |
161 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
162 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
163 | + | |
164 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
165 | + | |
166 | + var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(SetPermissions)}'!", silent: true) | |
167 | + .SetSelectionMode(Menu.SelectionMode.Multi); | |
168 | + | |
169 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
170 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
171 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
172 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
173 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
174 | + else { } | |
175 | + | |
176 | + string defaultusername = "Everyone"; | |
177 | + string defaultaccessrightsstring = nameof(MessageQueueAccessRights.FullControl); | |
178 | + string defaultcontroltypestring = nameof(AccessControlEntryType.Allow); | |
179 | + | |
180 | + while (true) | |
181 | + { | |
182 | + string username = ColorConsole.ReadLine("Enter username:", ConsoleColor.Yellow,defaultvalue:defaultusername); | |
183 | + if (username.ToUpper() == "EX") { break; } | |
184 | + | |
185 | + string accessrightsstring = ColorConsole.ReadLine("Enter access right:", ConsoleColor.Yellow, validitylist: Enum.GetNames(typeof(MessageQueueAccessRights)).Select(e=>e.ToString()).ToList(), defaultvalue: defaultaccessrightsstring); | |
186 | + if (accessrightsstring.ToUpper() == "EX") { break; } | |
187 | + var accessrights = (MessageQueueAccessRights)Enum.Parse(typeof(MessageQueueAccessRights),accessrightsstring); | |
188 | + | |
189 | + string controltypestring = ColorConsole.ReadLine("Enter access right:", ConsoleColor.Yellow, validitylist: Enum.GetNames(typeof(AccessControlEntryType)).Select(e => e.ToString()).ToList(), defaultvalue: defaultcontroltypestring); | |
190 | + if (controltypestring.ToUpper() == "EX") { break; } | |
191 | + var controltype = (AccessControlEntryType)Enum.Parse(typeof(AccessControlEntryType), controltypestring); | |
192 | + | |
193 | + foreach (var p in sr.SelectedParameterList) | |
194 | + { | |
195 | + MSMQ st = p.Parameters as MSMQ; | |
196 | + try | |
197 | + { | |
198 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
199 | + MSMQManagerCore.SetPermissions(fullpath, username, accessrights, controltype); | |
200 | + ColorConsole.WriteLine($"Permissions set for MSMQ:{st.Xml_Name}. Username:{username}, access right: {accessrights}, control type: {controltype}", ConsoleColor.Green); | |
201 | + } | |
202 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
203 | + } | |
204 | + | |
205 | + defaultusername = username; | |
206 | + defaultaccessrightsstring = accessrightsstring; | |
207 | + defaultcontroltypestring = controltypestring; | |
208 | + } | |
209 | + return o; | |
210 | + } | |
211 | + private static object GetInfo(object parameter, object o) | |
13 | 212 | { |
14 | - string ccs = @"localhost\private$\ljskskin"; | |
15 | - string msmqservername = ""; | |
16 | - bool msmqprivate = true; | |
17 | - string msmqname = ""; | |
18 | - string msmqFullname = msmqservername + "\\" + (msmqprivate ? "private$\\" : msmqname); | |
19 | - if (!MessageQueue.Exists(ccs)) { MessageQueue.Create(msmqFullname); } | |
213 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
214 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
215 | + | |
216 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
217 | + | |
218 | + var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(GetInfo)}'!", silent: true) | |
219 | + .SetSelectionMode(Menu.SelectionMode.Multi); | |
220 | + | |
221 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
222 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
223 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
224 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
225 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
226 | + else { } | |
227 | + foreach (var p in sr.SelectedParameterList) | |
228 | + { | |
229 | + MSMQ st = p.Parameters as MSMQ; | |
230 | + ColorConsole.Write($">>> MSMQ detailed info collected for ", ConsoleColor.Yellow); | |
231 | + ColorConsole.Write($"{st.QueueName}", ConsoleColor.Yellow,suffix:", ",prefix: " QueueName : "); | |
232 | + ColorConsole.Write($"{st.MachineName}", ConsoleColor.Yellow,prefix: "MachineName: "); | |
233 | + ColorConsole.WriteLine(); | |
234 | + var qqn = MSMQManagerCore.CreateQualifiedQueueName(st.Xml_AddressPrefix, st.Xml_Server,st.Xml_Private, st.Xml_Name); | |
235 | + var qexists = MSMQManagerCore.CheckIfQueueExists(st.Xml_Server, qqn); | |
236 | + if (!qexists) | |
237 | + { | |
238 | + ColorConsole.WriteLine($" Queue does not exist!", ConsoleColor.Red); | |
239 | + } | |
240 | + else | |
241 | + { | |
242 | + try | |
243 | + { | |
244 | + st = MSMQManagerCore.CollectMSMQInfo(st); | |
245 | + ColorConsole.WriteLine($"{st.Status}", ConsoleColor.Green,prefix: $" Status: "); | |
246 | + ColorConsole.WriteLine($"{st.StatusDescription}", ConsoleColor.Green,prefix:" StatusDescription: "); | |
247 | + ColorConsole.WriteLine($"{st.Id}", ConsoleColor.Green,prefix: " Id: "); | |
248 | + ColorConsole.WriteLine($"{st.Label}", ConsoleColor.Green,prefix: " Label: "); | |
249 | + ColorConsole.WriteLine($"{st.Path}", ConsoleColor.Green,prefix: " Path: "); | |
250 | + ColorConsole.WriteLine($"{st.FormatName}", ConsoleColor.Green,prefix: " FormatName: "); | |
251 | + ColorConsole.Write($"{st.Transactional}", ConsoleColor.Green, prefix: " Transactional: ",suffix: ", "); | |
252 | + ColorConsole.Write($"{st.UseJournalQueue}", ConsoleColor.Green, suffix: ", ",prefix: "UseJournalQueue: "); | |
253 | + ColorConsole.Write($"{st.AccessMode}", ConsoleColor.Green,suffix:", ",prefix: "AccessMode: "); | |
254 | + ColorConsole.Write($"{st.CanRead}", ConsoleColor.Green, suffix: ", ",prefix: "CanRead: "); | |
255 | + ColorConsole.Write($"{st.CanWrite}", ConsoleColor.Green, suffix: ", ",prefix: "CanWrite: "); | |
256 | + ColorConsole.WriteLine(); | |
257 | + ColorConsole.Write($"{st.Authenticate}", ConsoleColor.Green, suffix: ", ",prefix: " Authenticate: "); | |
258 | + ColorConsole.Write($"{st.BasePriority}", ConsoleColor.Green, suffix: ", ",prefix: "BasePriority: "); | |
259 | + ColorConsole.Write($"{st.EncryptionRequired}", ConsoleColor.Green, suffix: ", ",prefix: "EncryptionRequired: "); | |
260 | + ColorConsole.WriteLine(); | |
261 | + ColorConsole.Write($"{st.Formatter}", ConsoleColor.Green, suffix: ", ",prefix: " Formatter: "); | |
262 | + ColorConsole.Write($"{st.LastModifyTime}", ConsoleColor.Green, suffix: ", ",prefix: "LastModifyTime: "); | |
263 | + ColorConsole.WriteLine(); | |
264 | + ColorConsole.Write($"{st.NumOfMessages}", ConsoleColor.Green, suffix: ", ",prefix: " NumOfMessages: "); | |
265 | + ColorConsole.Write($"{st.MaximumJournalSize}", ConsoleColor.Green, suffix: ", ",prefix: "MaximumJournalSize: "); | |
266 | + ColorConsole.Write($"{st.MaximumQueueSize}", ConsoleColor.Green, suffix: ", ",prefix: "MaximumQueueSize: "); | |
267 | + ColorConsole.WriteLine(); | |
268 | + } | |
269 | + catch (Exception ex) { ColorConsole.WriteLine(" "+ex.Message, ConsoleColor.Red); } | |
270 | + } | |
271 | + } | |
272 | + return o; | |
20 | 273 | } |
21 | - void DeleteQueue() | |
274 | + private static object Peek(object parameter, object o) | |
22 | 275 | { |
23 | - string ccs = @"localhost\private$\ljskskin"; | |
24 | - if (MessageQueue.Exists(ccs)) { MessageQueue.Delete(ccs); } | |
276 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
277 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
278 | + | |
279 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
280 | + | |
281 | + var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Peek)}'!", silent: true) | |
282 | + .SetSelectionMode(Menu.SelectionMode.Single); | |
283 | + | |
284 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
285 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
286 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
287 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
288 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
289 | + else { } | |
290 | + foreach (var p in sr.SelectedParameterList) | |
291 | + { | |
292 | + MSMQ st = p.Parameters as MSMQ; | |
293 | + try | |
294 | + { | |
295 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
296 | + MSMQManagerCore.Peek(fullpath, out string msgbody, out string msglabel); | |
297 | + ColorConsole.WriteLine($"Message peeked from MSMQ:{st.Xml_Name}", ConsoleColor.Green); | |
298 | + ColorConsole.WriteLine($" Body: {msgbody}", ConsoleColor.Yellow); | |
299 | + ColorConsole.WriteLine($" Label: {msglabel}", ConsoleColor.Yellow); | |
300 | + } | |
301 | + catch (Exception ex) | |
302 | + { | |
303 | + ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); | |
304 | + } | |
305 | + } | |
306 | + return o; | |
25 | 307 | } |
26 | - void Purge() | |
308 | + private static object Read(object parameter, object o) | |
27 | 309 | { |
28 | - string ccs = @"localhost\private$\ljskskin"; | |
29 | - var msmq = new MessageQueue(ccs); | |
30 | - msmq.Purge(); | |
310 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
311 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
312 | + | |
313 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
314 | + | |
315 | + var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Read)}'!", silent: true) | |
316 | + .SetSelectionMode(Menu.SelectionMode.Single); | |
317 | + | |
318 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
319 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
320 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
321 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
322 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
323 | + else { } | |
324 | + foreach (var p in sr.SelectedParameterList) | |
325 | + { | |
326 | + MSMQ st = p.Parameters as MSMQ; | |
327 | + try | |
328 | + { | |
329 | + var messageformatter = new ActiveXMessageFormatter(); | |
330 | + var encoding = Encoding.UTF8; | |
331 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
332 | + MSMQManagerCore.Read(fullpath, messageformatter, encoding, out string msgbody, out string msglabel); | |
333 | + ColorConsole.WriteLine($"Message read from MSMQ:{st.Xml_Name}", ConsoleColor.Green); | |
334 | + ColorConsole.WriteLine($" Body: {msgbody}", ConsoleColor.Yellow); | |
335 | + ColorConsole.WriteLine($" Label: {msglabel}", ConsoleColor.Yellow); | |
336 | + } | |
337 | + catch (Exception ex) | |
338 | + { | |
339 | + ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); | |
340 | + } | |
341 | + } | |
342 | + return o; | |
31 | 343 | } |
32 | - void Peek() | |
344 | + private static object Send(object parameter, object o) | |
33 | 345 | { |
34 | - string ccs = @"localhost\private$\ljskskin"; | |
35 | - var msmq = new MessageQueue(ccs); | |
346 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
347 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
348 | + | |
349 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
350 | + | |
351 | + var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Send)}'!", silent: true) | |
352 | + .SetSelectionMode(Menu.SelectionMode.Single); | |
36 | 353 | |
37 | - Message m = msmq.Peek(new TimeSpan(0)); | |
38 | - m.BodyStream.Position = 0; | |
39 | - var sr = new System.IO.StreamReader(m.BodyStream); | |
40 | - var label = m.Label; | |
41 | - var body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); | |
42 | - } | |
43 | - void Read() | |
44 | - { | |
45 | - string ccs = @"localhost\private$\ljskskin"; | |
46 | - var msmq = new MessageQueue(ccs); | |
47 | - var frmA = new System.Messaging.ActiveXMessageFormatter(); | |
48 | - var frmB = new System.Messaging.BinaryMessageFormatter(); | |
49 | - var frmX = new System.Messaging.XmlMessageFormatter(); | |
50 | - msmq.Formatter = frmA; | |
354 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
355 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
356 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
357 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
358 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
359 | + else { } | |
360 | + foreach (var p in sr.SelectedParameterList) | |
361 | + { | |
362 | + MSMQ st = p.Parameters as MSMQ; | |
363 | + while (true) | |
364 | + { | |
365 | + try | |
366 | + { | |
367 | + var now = DateTime.Now.ToString(); | |
368 | + string messagebody = ColorConsole.ReadLine("Enter message body:", ConsoleColor.Yellow, defaultvalue: "TEST MESSAGE " + now); | |
369 | + if (messagebody.ToUpper() == "EX") { break; } | |
370 | + | |
371 | + string messagelabel = ColorConsole.ReadLine("Enter message label:", ConsoleColor.Yellow, defaultvalue: "TESTLABEL" + now); | |
372 | + if (messagelabel.ToUpper() == "EX") { break; } | |
373 | + | |
374 | + string messageformatterstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetFormatterNames(), defaultvalue: st.Xml_Formatter); | |
375 | + if (messageformatterstring.ToUpper() == "EX") { break; } | |
376 | + var messageformatter = MSMQManagerCore.SetFormatter(messageformatterstring); | |
377 | + if (messageformatter == null) { var exmsg = $"Message formatter value is incorrect! Value:{st.Xml_Formatter}."; throw new ApplicationException(exmsg); } | |
378 | + | |
379 | + string encodingstring = ColorConsole.ReadLine("Enter encoding:", ConsoleColor.Yellow, validitylist: MSMQManagerCore.GetEncodingNames(), defaultvalue: st.Xml_Encoding); | |
380 | + if (encodingstring.ToUpper() == "EX") { break; } | |
381 | + var encoding = MSMQManagerCore.SetEncoding(encodingstring); | |
382 | + if (encoding == null) { var exmsg = $"Message encoder value is incorrect! Value:{st.Xml_Encoding}."; throw new ApplicationException(exmsg); } | |
383 | + | |
384 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
385 | + MSMQManagerCore.Send(fullpath, messagebody, messagelabel, messageformatter, encoding); | |
386 | + ColorConsole.WriteLine($"Message sent to MSMQ:{st.Xml_Name}.", ConsoleColor.Green); | |
387 | + } | |
388 | + catch (ApplicationException ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
389 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
390 | + } | |
391 | + } | |
392 | + return o; | |
393 | + } | |
394 | + private static object Purge(object parameter, object o) | |
395 | + { | |
396 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<MSMQManagerXmlProcessor>(); | |
397 | + var args = (parameter as Menu.ExecutorParameter).Args; | |
398 | + | |
399 | + var selectedtaskindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.ScheduledTaskManager.Function.CMD_TASKS); | |
400 | + | |
401 | + var menufolders = DisplayMSMQMenu(config, $"Select the MSMQ(s) to manage with function '{nameof(Purge)}'!", silent: true); | |
402 | + | |
403 | + Menu.Selection sr = menufolders.Select(selectedtaskindexes); | |
404 | + if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
405 | + else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
406 | + else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
407 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
408 | + else { } | |
409 | + foreach (var p in sr.SelectedParameterList) | |
410 | + { | |
411 | + MSMQ st = p.Parameters as MSMQ; | |
412 | + try | |
413 | + { | |
414 | + var fullpath = MSMQManagerCore.CreateFullQueuePath(st.Xml_AddressPrefix, st.Xml_Server, st.Xml_Private, st.Xml_Name); | |
415 | + MSMQManagerCore.Purge(fullpath); | |
416 | + ColorConsole.WriteLine($"MSMQ messages purged. Name:{st.Xml_Name}", ConsoleColor.Green); | |
417 | + } | |
418 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
419 | + } | |
420 | + return o; | |
421 | + } | |
422 | + #endregion First level Executors with UI | |
423 | + | |
424 | + #region private methods | |
425 | + #region private DisplayTasks | |
426 | + private static void MSMQListDisplayer() { DisplayMSMQMenu(); } | |
427 | + private static Menu DisplayMSMQMenu(MSMQManagerXmlProcessor config = null, string prompt = null, bool silent = false) | |
428 | + { | |
429 | + if (config == null) { config = new MSMQManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); } | |
430 | + List<MSMQ> msmqdefList = config.GetDefinitionList(); | |
431 | + var menufct = new Menu("Scheduled tasks", prompt) | |
432 | + .SetMenuItemDisplayer(DisplayMSMQInfo) | |
433 | + .SetSelectionMode(Menu.SelectionMode.Multi); | |
434 | + menufct.ClearMenuItemList(); | |
435 | + foreach (var msmqdef in msmqdefList) | |
436 | + { | |
437 | + var st = MSMQManagerCore.CollectMSMQInfo(msmqdef); | |
438 | + menufct.AddMenuItem(new Menu.Item(msmqdef.Xml_Key, null, null, new Menu.ExecutorParameter(pars: st))); | |
439 | + } | |
440 | + if (!silent) { menufct.DisplayItems(1); } | |
441 | + return menufct; | |
442 | + } | |
443 | + #endregion private DisplayTasks | |
444 | + #region private method: DisplayTaskInfo | |
445 | + private static object DisplayMSMQInfo(object obj, int lineix) | |
446 | + { | |
447 | + MSMQ st = (obj as Menu.ExecutorParameter).Parameters as MSMQ; | |
448 | + if (lineix == 0) | |
449 | + { | |
450 | + ColorConsole.Write($"{st.Xml_Name}", ConsoleColor.Black, ConsoleColor.White,prefix: "Queue '",suffix: $"' queue label: '{st.Xml_Label}'."); | |
451 | + ConsoleColor statuscolor; | |
452 | + if (st.Status == "Uninstalled") { statuscolor = ConsoleColor.Red; } | |
453 | + else if (st.Status == "Error") { statuscolor = ConsoleColor.Red; } | |
454 | + else if (st.Status == "Installed") { statuscolor = ConsoleColor.Yellow; } | |
455 | + else if (st.Status == "Ready") { statuscolor = ConsoleColor.Green; } | |
456 | + else { statuscolor = ConsoleColor.Red; } | |
457 | + ColorConsole.Write(st.Status, statuscolor, bracket: "[]", prefix: " ", suffix: ". "); | |
458 | + ColorConsole.WriteLine(); | |
459 | + return " "; | |
460 | + } | |
461 | + else if (lineix == 1) | |
462 | + { | |
463 | + var privatepublictext = st.Xml_Private ? "private" : "public"; | |
464 | + ColorConsole.Write($"{st.Xml_AddressPrefix}{st.Xml_Server}", ConsoleColor.Black, ConsoleColor.White, prefix: "Server:", suffix: $"Queue is { privatepublictext }."); | |
465 | + ColorConsole.WriteLine(); | |
466 | + return " "; | |
467 | + } | |
468 | + else if (lineix == 2) | |
469 | + { | |
470 | + ColorConsole.Write($"{st.Path}", ConsoleColor.Yellow, prefix: "Path ", suffix: ", "); | |
471 | + ColorConsole.WriteLine(); | |
472 | + return " "; | |
473 | + } | |
474 | + else if (lineix == 3) | |
475 | + { | |
476 | + if (st.StatusDescription != null) | |
477 | + { | |
478 | + ConsoleColor color = ConsoleColor.Yellow; | |
479 | + if (st.Status == "Ready") { color = ConsoleColor.Green; } | |
480 | + else if (st.Status == "Error") { color = ConsoleColor.Red; } | |
481 | + ColorConsole.Write($"{st.StatusDescription}", color, prefix: "Status description "); | |
482 | + ColorConsole.WriteLine(); | |
483 | + return " "; | |
484 | + } | |
485 | + return "";//empty=van még szöveg, de most nem történt kiírás | |
486 | + } | |
487 | + else if (lineix == 4) | |
488 | + { | |
489 | + if (st.Status == "Ready") | |
490 | + { | |
491 | + ColorConsole.Write($"{st.FormatName}", ConsoleColor.Yellow, prefix: "FormatName "); | |
492 | + ColorConsole.WriteLine(); | |
493 | + return " "; | |
494 | + } | |
495 | + return ""; | |
496 | + } | |
497 | + else if (lineix == 5) | |
498 | + { | |
499 | + if (st.Status == "Ready") | |
500 | + { | |
501 | + ColorConsole.Write(st.NumOfMessages.ToString(), ConsoleColor.Yellow, prefix: "Num.of msgs in queue ", suffix: ". "); | |
502 | + ColorConsole.Write($"{st.LastModifyTime}", ConsoleColor.Yellow, prefix: "LastModified ", suffix: ", "); | |
503 | + ColorConsole.WriteLine(); | |
504 | + return " "; | |
505 | + } | |
506 | + return ""; | |
507 | + } | |
508 | + else if (lineix == 6) | |
509 | + { | |
510 | + if (st.Status == "Ready") | |
511 | + { | |
512 | + ColorConsole.Write($"{st.AccessMode}", ConsoleColor.Yellow, prefix: "AccessMode ", suffix: ", "); | |
513 | + ColorConsole.Write($"{st.CanRead}", ConsoleColor.Yellow, prefix: "CanRead ", suffix: ", "); | |
514 | + ColorConsole.Write($"{st.CanWrite}", ConsoleColor.Yellow, prefix: "CanWrite ", suffix: ", "); | |
515 | + ColorConsole.WriteLine(); | |
516 | + return " "; | |
517 | + } | |
518 | + return ""; | |
519 | + } | |
520 | + return null; | |
521 | + } | |
522 | + #endregion private method: DisplayTaskInfo | |
523 | + #endregion private methods | |
524 | + } | |
525 | + #endregion MSMQManager class | |
526 | + | |
527 | + #region MSMQManagerCore class | |
528 | + internal static class MSMQManagerCore | |
529 | + { | |
530 | + public static string CreateFullQueuePath(string addressprefix, string msmqservername, bool msmqprivate, string msmqname) | |
531 | + { | |
532 | + CreateQueueNames(addressprefix, msmqservername, msmqprivate, msmqname, out string qqn, out string qfn); | |
533 | + return qfn; | |
534 | + } | |
535 | + public static string CreateQualifiedQueueName(string addressprefix, string msmqservername, bool msmqprivate, string msmqname) | |
536 | + { | |
537 | + CreateQueueNames(addressprefix, msmqservername, msmqprivate, msmqname, out string qqn, out string qfn); | |
538 | + return qqn; | |
539 | + } | |
540 | + private static void CreateQueueNames(string addressprefix, string msmqservername, bool msmqprivate, string msmqname,out string queuequalifiedname, out string msmqFullname) | |
541 | + { | |
542 | + var msmqprivatenamepart = msmqprivate ? "private$\\" : ""; | |
543 | + if (msmqservername == "." || msmqservername.ToLower() == "localhost") { msmqservername = System.Environment.MachineName; } | |
544 | + var msmqservernamepart = string.IsNullOrWhiteSpace(msmqservername) ? "" : $"{msmqservername}\\"; | |
545 | + addressprefix = string.IsNullOrWhiteSpace(addressprefix) ? "" : addressprefix; | |
546 | + msmqFullname = $"{addressprefix}{msmqservernamepart}{msmqprivatenamepart}{msmqname}"; | |
547 | + queuequalifiedname = $"{msmqprivatenamepart}{msmqname}"; | |
548 | + } | |
549 | + public static bool CheckIfQueueExists(string servername,string queuefullname) | |
550 | + { | |
551 | + if (string.IsNullOrWhiteSpace(servername) || servername == "." || servername.ToLower() == "localhost") { servername = System.Environment.MachineName; } | |
552 | + var queuearray = System.Messaging.MessageQueue.GetPrivateQueuesByMachine(servername); | |
553 | + foreach (var q in queuearray) | |
554 | + { | |
555 | + if (q.Path.ToLower().Contains(queuefullname.ToLower()) && q.FormatName.ToLower().Contains(queuefullname.ToLower()) && queuefullname.ToLower().Contains(q.QueueName.ToLower())) { return true; } | |
556 | + } | |
557 | + return false; | |
558 | + //var queuenamelist = queuearray.Select(q => q.Path == queuefullname || q.FormatName== queuefullname || q.QueueName== queuefullname).ToList(); | |
559 | + //return queuenamelist.Any(); | |
560 | + } | |
561 | + public static MSMQ CollectMSMQInfo(MSMQ msmgqef) | |
562 | + { | |
563 | + string msmqaddressprefix = msmgqef.Xml_AddressPrefix; | |
564 | + string msmqservername = msmgqef.Xml_Server; | |
565 | + bool msmqprivate = msmgqef.Xml_Private; | |
566 | + string msmqname = msmgqef.Xml_Name; | |
567 | + var msmqprivatenamepart = msmqprivate ? "private$\\" : ""; | |
568 | + string msmqFullname = $"{msmqaddressprefix}{msmqservername}\\{msmqprivatenamepart}{msmqname}"; | |
569 | + msmgqef.QueueName = msmqname ; | |
570 | + msmgqef.MachineName = msmqservername; | |
571 | + msmgqef.Path = msmqFullname; | |
572 | + try | |
573 | + { | |
574 | + msmgqef.Status = MessageQueue.Exists(msmqFullname) ? "Installed" : "Uninstalled"; | |
575 | + if (msmgqef.Status == "Installed") | |
576 | + { | |
577 | + using (var msmq = new MessageQueue(msmqFullname)) | |
578 | + { | |
579 | + msmgqef.QueueName = msmq.QueueName; | |
580 | + msmgqef.MachineName = msmq.MachineName; | |
581 | + | |
582 | + msmgqef.Id = msmq.Id; | |
583 | + msmgqef.NumOfMessages = MSMQManagerCore.Count(msmq); | |
584 | + msmgqef.Label = msmq.Label; | |
585 | + msmgqef.Formatter = msmq.Formatter; | |
586 | + msmgqef.FormatName = msmq.FormatName; | |
587 | + msmgqef.Path = msmq.Path; | |
588 | + msmgqef.LastModifyTime = msmq.LastModifyTime; | |
589 | + msmgqef.AccessMode = msmq.AccessMode; | |
590 | + msmgqef.CanRead = msmq.CanRead; | |
591 | + msmgqef.CanWrite = msmq.CanWrite; | |
592 | + msmgqef.MaximumQueueSize = msmq.MaximumQueueSize; | |
593 | + msmgqef.UseJournalQueue = msmq.UseJournalQueue; | |
594 | + msmgqef.MaximumJournalSize = msmq.MaximumJournalSize; | |
595 | + | |
596 | + msmgqef.Transactional = msmq.Transactional; | |
597 | + msmgqef.Authenticate = msmq.Authenticate; | |
598 | + msmgqef.BasePriority = msmq.BasePriority; | |
599 | + msmgqef.EncryptionRequired = msmq.EncryptionRequired; | |
600 | + | |
601 | + msmgqef.Status = "Ready"; | |
602 | + } | |
603 | + } | |
604 | + } | |
605 | + catch (Exception ex) { msmgqef.Status = "Error"; msmgqef.StatusDescription = ex.Message + (ex.InnerException!=null? ("\n" + ex.InnerException.Message):""); } | |
606 | + return msmgqef; | |
607 | + } | |
608 | + public static void CreateQueue(string msmqFullname, string label=null) | |
609 | + { | |
610 | + if (!MessageQueue.Exists(msmqFullname)) { MessageQueue.Create(msmqFullname); } | |
611 | + using (var msmq = new MessageQueue(msmqFullname)) | |
612 | + { | |
613 | + if (!string.IsNullOrWhiteSpace(label)) { msmq.Label = label; } | |
614 | + } | |
615 | + } | |
616 | + public static void SetPermissions(string msmqFullname,string username, MessageQueueAccessRights accessrights, AccessControlEntryType controltype) | |
617 | + { | |
618 | + using (var msmq = new MessageQueue(msmqFullname)) | |
619 | + { | |
620 | + //controltype=AccessControlEntryType.Allow; | |
621 | + //accessrights = MessageQueueAccessRights.FullControl; | |
622 | + //accessrights = MessageQueueAccessRights.SetQueueProperties | |
623 | + // | MessageQueueAccessRights.GenericRead | |
624 | + // | MessageQueueAccessRights.ChangeQueuePermissions | |
625 | + // | MessageQueueAccessRights.GetQueuePermissions | |
626 | + // | MessageQueueAccessRights.TakeQueueOwnership | |
627 | + // | MessageQueueAccessRights.GenericWrite | |
628 | + // | MessageQueueAccessRights.DeleteJournalMessage | |
629 | + // | MessageQueueAccessRights.WriteMessage | |
630 | + // | MessageQueueAccessRights.DeleteMessage | |
631 | + // | MessageQueueAccessRights.GetQueueProperties | |
632 | + // | MessageQueueAccessRights.PeekMessage | |
633 | + // | MessageQueueAccessRights.ReceiveJournalMessage | |
634 | + // | MessageQueueAccessRights.ReceiveMessage | |
635 | + // | MessageQueueAccessRights.SetQueueProperties | |
636 | + // | MessageQueueAccessRights.DeleteQueue; | |
637 | + msmq.SetPermissions("EveryOne", accessrights, controltype); | |
638 | + } | |
639 | + } | |
640 | + | |
641 | + public static void DeleteQueue(string msmqFullname) | |
642 | + { | |
643 | + if (MessageQueue.Exists(msmqFullname)) { MessageQueue.Delete(msmqFullname); } | |
644 | + } | |
645 | + public static void Purge(string msmqFullname) | |
646 | + { | |
647 | + using (var msmq = new MessageQueue(msmqFullname)) | |
648 | + { | |
649 | + msmq.Purge(); | |
650 | + } | |
651 | + } | |
652 | + public static void Peek(string msmqFullname, out string body, out string label) | |
653 | + { | |
654 | + using (var msmq = new MessageQueue(msmqFullname)) | |
655 | + { | |
656 | + Message m = msmq.Peek(new TimeSpan(0)); | |
657 | + m.BodyStream.Position = 0; | |
658 | + var sr = new System.IO.StreamReader(m.BodyStream); | |
659 | + label = m.Label; | |
660 | + body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); | |
661 | + } | |
662 | + } | |
663 | + public static void Read(string msmqFullname, IMessageFormatter messageformatter, Encoding encoding, out string body, out string label) | |
664 | + { | |
665 | + using (var msmq = new MessageQueue(msmqFullname)) | |
666 | + { | |
667 | + //frmA = new System.Messaging.ActiveXMessageFormatter(); | |
668 | + //frmA = new System.Messaging.BinaryMessageFormatter(); | |
669 | + //frmA = new System.Messaging.XmlMessageFormatter(); | |
670 | + msmq.Formatter = messageformatter; | |
671 | + | |
672 | + Message m = msmq.Receive(new TimeSpan(0)); | |
673 | + m.BodyStream.Position = 0; | |
674 | + | |
675 | + // encoding = System.Text.Encoding.UTF8; | |
676 | + // encoding = System.Text.Encoding.UTF7; | |
677 | + // encoding = System.Text.Encoding.UTF32; | |
678 | + // encoding = System.Text.Encoding.Unicode; | |
679 | + // encoding = System.Text.Encoding.BigEndianUnicode; | |
680 | + // encoding = System.Text.Encoding.ASCII; | |
681 | + // encoding = System.Text.Encoding.Default; | |
682 | + var sr = new System.IO.StreamReader(m.BodyStream, encoding); | |
683 | + label = m.Label; | |
684 | + body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); | |
685 | + } | |
686 | + } | |
687 | + public static void Send(string msmqFullname, string messagetosend, string messagelabel, IMessageFormatter messageformatter, Encoding encoding) | |
688 | + { | |
689 | + using (var msmq = new MessageQueue(msmqFullname)) | |
690 | + { | |
691 | + ///frmA = new System.Messaging.ActiveXMessageFormatter(); | |
692 | + //enc = System.Text.Encoding.UTF8; | |
693 | + msmq.Formatter = messageformatter; | |
694 | + byte[] encodedmessage = encoding.GetBytes(messagetosend); | |
695 | + | |
696 | + msmq.Send(encodedmessage, messagelabel); | |
697 | + } | |
698 | + } | |
699 | + public static long Count(MessageQueue messageQueue) | |
700 | + { | |
701 | + var enumerator = messageQueue.GetMessageEnumerator2(); | |
702 | + long counter = 0; | |
703 | + while (enumerator.MoveNext()) | |
704 | + { | |
705 | + counter++; | |
706 | + } | |
707 | + return counter; | |
708 | + } | |
709 | + public static IMessageFormatter SetFormatter(string formattername) | |
710 | + { | |
711 | + switch (formattername) | |
712 | + { | |
713 | + case nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter.Values.ActiveXMessageFormatter): return new ActiveXMessageFormatter(); | |
714 | + case nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter.Values.BinaryMessageFormatter): return new BinaryMessageFormatter(); | |
715 | + case nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter.Values.XmlMessageFormatter): return new XmlMessageFormatter(); | |
716 | + default: return null; | |
717 | + } | |
718 | + } | |
719 | + public static List<string> GetFormatterNames() | |
720 | + { | |
721 | + var r = new List<string>(); | |
722 | + r.Add(nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter.Values.ActiveXMessageFormatter)); | |
723 | + r.Add(nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter.Values.BinaryMessageFormatter)); | |
724 | + r.Add(nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter.Values.XmlMessageFormatter)); | |
725 | + return r; | |
726 | + } | |
727 | + public static Encoding SetEncoding(string formattername) | |
728 | + { | |
729 | + switch (formattername) | |
730 | + { | |
731 | + case nameof(Encoding.UTF8): return Encoding.UTF8; | |
732 | + case nameof(Encoding.UTF7): return Encoding.UTF7; | |
733 | + case nameof(Encoding.BigEndianUnicode): return Encoding.BigEndianUnicode; | |
734 | + case nameof(Encoding.Unicode): return Encoding.Unicode; | |
735 | + case nameof(Encoding.ASCII): return Encoding.ASCII; | |
736 | + case nameof(Encoding.UTF32): return Encoding.UTF32; | |
737 | + case nameof(Encoding.Default): return Encoding.Default; | |
738 | + default: return null; | |
739 | + } | |
740 | + } | |
741 | + public static List<string> GetEncodingNames() | |
742 | + { | |
743 | + var r = new List<string>(); | |
744 | + r.Add(nameof(Encoding.UTF8)); | |
745 | + r.Add(nameof(Encoding.UTF7)); | |
746 | + r.Add(nameof(Encoding.UTF32)); | |
747 | + r.Add(nameof(Encoding.BigEndianUnicode)); | |
748 | + r.Add(nameof(Encoding.Unicode)); | |
749 | + r.Add(nameof(Encoding.ASCII)); | |
750 | + r.Add(nameof(Encoding.Default)); | |
751 | + return r; | |
752 | + } | |
753 | + } | |
754 | + #endregion MSMQManagerCore class | |
755 | + | |
756 | + #region MSMQManagerXmlProcessor class | |
757 | + public class MSMQManagerXmlProcessor : XmlParser | |
758 | + { | |
759 | + private List<MSMQ> _msmqlist; | |
760 | + #region constructor | |
761 | + public MSMQManagerXmlProcessor(string xmlcs, string basefolder, string lcid) : base(xmlcs, basefolder, lcid, null) | |
762 | + { | |
763 | + _msmqlist = new List<MSMQ>(); | |
764 | + var msmqxmllist = GetAllXElements(nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues), nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue)); | |
765 | + if (msmqxmllist != null && msmqxmllist.Any()) | |
766 | + { | |
767 | + foreach (var msmqxml in msmqxmllist) { var st = new MSMQ(msmqxml, new MSMQDefaults(RootElement)); if (st.Valid) { _msmqlist.Add(st); } } | |
768 | + } | |
769 | + } | |
770 | + #endregion constructor | |
771 | + #region GetDefinitionList | |
772 | + public List<MSMQ> GetDefinitionList() { return _msmqlist; } | |
773 | + #endregion GetDefinitionList | |
774 | + } | |
775 | + #endregion MSMQManagerXmlProcessor class | |
776 | + | |
777 | + #region Defaults class | |
778 | + public class AccessRights : XmlLinqBase | |
779 | + { | |
780 | + public static AccessRights Factory(XElement arxml) | |
781 | + { | |
782 | + try | |
783 | + { | |
784 | + var r = new AccessRights(); | |
785 | + r.un = r.GetValue(nameof(MSMQ.XmlStructure.MSMQManager.General.AccessRights.AccessRight.Attributes.Username), arxml, MSMQ.XmlStructure.MSMQManager.General.AccessRights.AccessRight.Attributes.Username.Values.DEFAULT); | |
786 | + r.ar = (MessageQueueAccessRights)Enum.Parse(typeof(MessageQueueAccessRights), r.GetValue(nameof(MSMQ.XmlStructure.MSMQManager.General.AccessRights.AccessRight.Attributes.Right), arxml, MSMQ.XmlStructure.MSMQManager.General.AccessRights.AccessRight.Attributes.Right.Values.DEFAULT)); | |
787 | + r.ac = (AccessControlEntryType)Enum.Parse(typeof(AccessControlEntryType), r.GetValue(nameof(MSMQ.XmlStructure.MSMQManager.General.AccessRights.AccessRight.Attributes.Control), arxml, MSMQ.XmlStructure.MSMQManager.General.AccessRights.AccessRight.Attributes.Control.Values.DEFAULT)); | |
788 | + return r; | |
789 | + } | |
790 | + catch { return null; } | |
791 | + } | |
792 | + public string un; | |
793 | + public MessageQueueAccessRights ar; | |
794 | + public AccessControlEntryType ac; | |
795 | + } | |
796 | + public class MSMQDefaults : XmlLinqBase | |
797 | + { | |
798 | + public string Xml_MessageFilesDirectory; | |
799 | + public string Xml_MessageFilesReadToMask; | |
800 | + public string Xml_MessageFilesSendToMask; | |
801 | + public string Xml_DefaultFormatter; | |
802 | + public string Xml_DefaultEncoding; | |
803 | + public List<AccessRights> Xml_AccessRights = new List<AccessRights>(); | |
804 | + public MSMQDefaults(XElement rootxml) | |
805 | + { | |
806 | + var generalxml = GetXElement(rootxml,nameof(MSMQ.XmlStructure.MSMQManager.General)); | |
807 | + var messagefiles = GetXElement(generalxml, nameof(MSMQ.XmlStructure.MSMQManager.General.MessageFiles)); | |
808 | + | |
809 | + Xml_MessageFilesDirectory = GetValue(nameof(MSMQ.XmlStructure.MSMQManager.General.MessageFiles.Attributes.Directory), messagefiles, MSMQ.XmlStructure.MSMQManager.General.MessageFiles.Attributes.Directory.Values.DEFAULT); | |
810 | + Xml_MessageFilesReadToMask = GetValue(nameof(MSMQ.XmlStructure.MSMQManager.General.MessageFiles.Attributes.ReadToMask), messagefiles, MSMQ.XmlStructure.MSMQManager.General.MessageFiles.Attributes.ReadToMask.Values.DEFAULT); | |
811 | + Xml_MessageFilesSendToMask = GetValue(nameof(MSMQ.XmlStructure.MSMQManager.General.MessageFiles.Attributes.SendToMask), messagefiles, MSMQ.XmlStructure.MSMQManager.General.MessageFiles.Attributes.SendToMask.Values.DEFAULT); | |
812 | + Xml_DefaultFormatter = GetValue(nameof(MSMQ.XmlStructure.MSMQManager.General.DefaultFormatter), generalxml, MSMQ.XmlStructure.MSMQManager.General.DefaultFormatter.Values.DEFAULT); | |
813 | + Xml_DefaultEncoding = GetValue(nameof(MSMQ.XmlStructure.MSMQManager.General.DefaultEncoding), generalxml, MSMQ.XmlStructure.MSMQManager.General.DefaultEncoding.Values.DEFAULT); | |
814 | + | |
815 | + try | |
816 | + { | |
817 | + var arxmllist = GetAllXElements(generalxml, nameof(MSMQ.XmlStructure.MSMQManager.General.AccessRights), nameof(MSMQ.XmlStructure.MSMQManager.General.AccessRights.AccessRight)); | |
818 | + foreach (var arxml in arxmllist) { var newa = AccessRights.Factory(arxml); if (newa != null) { Xml_AccessRights.Add(newa); } } | |
819 | + } | |
820 | + catch { } | |
821 | + } | |
822 | + } | |
823 | + #endregion Defaults class | |
824 | + | |
825 | + #region MSMQ class | |
826 | + public class MSMQ : XmlLinqBase | |
827 | + { | |
828 | + #region fields | |
829 | + public bool Valid = true; | |
830 | + public string Xml_Key; | |
831 | + public string Xml_Name; | |
832 | + public string Xml_AddressPrefix = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix.Values.DEFAULT; | |
833 | + public string Xml_Server = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server.Values.DEFAULT; | |
834 | + public bool Xml_Private = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Private.Values.DEFAULT; | |
835 | + public string Xml_Mode = XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode.Values.DEFAULT; | |
836 | + public string Xml_Label; | |
837 | + public string Xml_Formatter = XmlStructure.MSMQManager.General.DefaultFormatter.Values.DEFAULT; | |
838 | + public string Xml_Encoding = XmlStructure.MSMQManager.General.DefaultEncoding.Values.DEFAULT; | |
839 | + public List<AccessRights> Xml_AccessRights = new List<AccessRights>(); | |
840 | + | |
841 | + public string Status; | |
842 | + public string StatusDescription=null; | |
843 | + public Guid Id; | |
844 | + public string QueueName; | |
845 | + public long NumOfMessages; | |
846 | + public string Label; | |
847 | + public string MachineName; | |
848 | + public IMessageFormatter Formatter; | |
849 | + public string FormatName; | |
850 | + public string Path; | |
851 | + public DateTime LastModifyTime; | |
852 | + public QueueAccessMode AccessMode; | |
853 | + public bool CanRead; | |
854 | + public bool CanWrite; | |
855 | + public long MaximumQueueSize; | |
856 | + public bool UseJournalQueue; | |
857 | + public long MaximumJournalSize; | |
858 | + | |
859 | + public bool Transactional; | |
860 | + public bool Authenticate; | |
861 | + public int BasePriority; | |
862 | + public EncryptionRequired EncryptionRequired; | |
863 | + #endregion fields | |
864 | + | |
865 | + #region basic constructor | |
866 | + public MSMQ() { } | |
867 | + #endregion basic constructor | |
868 | + #region xml constructor | |
869 | + public string PriorityText(int pri) | |
870 | + { | |
871 | + return | |
872 | + (pri == 0 ? "Realtime" | |
873 | + : pri == 1 ? "High" | |
874 | + : pri == 2 ? "High" | |
875 | + : pri == 3 ? "Normal" | |
876 | + : pri == 4 ? "Normal" | |
877 | + : pri == 5 ? "Normal" | |
878 | + : pri == 6 ? "Normal" | |
879 | + : pri == 7 ? "Low" | |
880 | + : pri == 8 ? "Low" | |
881 | + : pri == 9 ? "Idle" | |
882 | + : pri == 10 ? "Idle" | |
883 | + : "Idle") + $"({pri})"; | |
884 | + } | |
885 | + public MSMQ(XElement msmqxml,MSMQDefaults msmqdefaults) | |
886 | + { | |
887 | + Valid = true; | |
888 | + string ATTRIBUTEMANDATORY = nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue) + " attribute is mandatory! Name: {0}"; | |
889 | + Xml_Key = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Key), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Key.Values.DEFAULT); | |
890 | + Xml_Name = msmqxml.Attribute(XName.Get(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Name)))?.Value; | |
891 | + if (string.IsNullOrWhiteSpace(Xml_Name)) { throw new ApplicationException(string.Format(ATTRIBUTEMANDATORY, nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Name))); } | |
892 | + Xml_AddressPrefix = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.AddressPrefix.Values.DEFAULT); | |
893 | + Xml_Server = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Server.Values.DEFAULT); | |
894 | + if (Xml_Server == "." || Xml_Server.ToLower() == "localhost") { Xml_Server = System.Environment.MachineName; } | |
895 | + | |
896 | + Xml_Private = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Private), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Private.Values.DEFAULT); | |
897 | + Xml_Mode = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode), msmqxml, XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Mode.Values.DEFAULT); | |
898 | + Xml_Label = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Label), msmqxml, Xml_Name); | |
899 | + Xml_Formatter = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Formatter), msmqxml, msmqdefaults.Xml_DefaultFormatter); | |
900 | + Xml_Encoding = GetValue(nameof(XmlStructure.MSMQManager.MessageQueues.MessageQueue.Attributes.Encoding), msmqxml, msmqdefaults.Xml_DefaultEncoding); | |
901 | + | |
902 | + foreach (var ar in msmqdefaults.Xml_AccessRights) { Xml_AccessRights.Add(ar); } | |
903 | + try | |
904 | + { | |
905 | + var arxmllist = GetAllXElements(msmqxml, nameof(MSMQ.XmlStructure.MSMQManager.MessageQueues.MessageQueue.AccessRight)); | |
906 | + foreach (var arxml in arxmllist) { var newa = AccessRights.Factory(arxml); if (newa != null) { Xml_AccessRights.Add(newa); } } | |
907 | + } | |
908 | + catch{ } | |
51 | 909 | |
52 | - Message m = msmq.Receive(new TimeSpan(0)); | |
53 | - m.BodyStream.Position = 0; | |
54 | - | |
55 | - Encoding enc = System.Text.Encoding.UTF8; | |
56 | - enc = System.Text.Encoding.UTF7; | |
57 | - enc = System.Text.Encoding.UTF32; | |
58 | - enc = System.Text.Encoding.Unicode; | |
59 | - enc = System.Text.Encoding.BigEndianUnicode; | |
60 | - enc = System.Text.Encoding.ASCII; | |
61 | - enc = System.Text.Encoding.Default; | |
62 | - var sr = new System.IO.StreamReader(m.BodyStream, enc); | |
63 | - var label = m.Label; | |
64 | - var body = sr.ReadToEnd().Replace(((char)0).ToString(), ""); | |
65 | - } | |
66 | - void Send() | |
67 | - { | |
68 | - string ccs = @"localhost\private$\ljskskin"; | |
69 | - | |
70 | - var frmA = new System.Messaging.ActiveXMessageFormatter(); | |
71 | - var msmq = new MessageQueue(ccs); | |
72 | - msmq.Formatter = frmA; | |
73 | 910 | |
74 | - string messagetosend = ""; | |
75 | - string messagelabel = ""; | |
76 | - | |
77 | - Encoding enc = System.Text.Encoding.UTF8; | |
78 | - byte[] encodedmessage = enc.GetBytes(messagetosend); | |
911 | + } | |
912 | + #endregion xml constructor | |
913 | + #region cloner constructor | |
914 | + public MSMQ(MSMQ msmq) | |
915 | + { | |
916 | + Valid = msmq.Valid; | |
917 | + Xml_Key = msmq.Xml_Key; | |
918 | + Xml_Name = msmq.Xml_Name; | |
919 | + Xml_Server = msmq.Xml_Server; | |
920 | + Xml_Private = msmq.Xml_Private; | |
921 | + Xml_Mode = msmq.Xml_Mode; | |
922 | + Xml_Label = msmq.Xml_Label; | |
923 | + Xml_Formatter= msmq.Xml_Formatter; | |
924 | + Xml_Encoding = msmq.Xml_Encoding; | |
925 | + } | |
926 | + #endregion cloner constructor | |
927 | + #region XmlStructure | |
928 | + public static class XmlStructure | |
929 | + { | |
930 | + public static class MSMQManager | |
931 | + { | |
932 | + public static class General | |
933 | + { | |
934 | + public static class AccessRights | |
935 | + { | |
936 | + public static class AccessRight | |
937 | + { | |
938 | + public static class Attributes | |
939 | + { | |
940 | + public static class Username { public static class Values { public const string DEFAULT = "Everyone"; } } | |
941 | + public static class Right {public static class Values { public const string DEFAULT = nameof(MessageQueueAccessRights.FullControl); } } | |
942 | + public static class Control { public static class Values { public const string DEFAULT = nameof(AccessControlEntryType.Allow); } } | |
943 | + } | |
944 | + } | |
945 | + } | |
946 | + public static class MessageFiles | |
947 | + { | |
948 | + public static class Attributes | |
949 | + { | |
950 | + public static class Directory { public static class Values { public const string DEFAULT = ""; } } | |
951 | + public static class SendToMask { public static class Values { public const string DEFAULT = "*.*"; } } | |
952 | + public static class ReadToMask { public static class Values { public const string DEFAULT = "*.*"; } } | |
953 | + } | |
954 | + } | |
955 | + public static class DefaultFormatter { public static class Values { public const string DEFAULT = nameof(ActiveXMessageFormatter); } } | |
956 | + public static class DefaultEncoding { public static class Values { public const string DEFAULT = nameof(System.Text.Encoding.UTF8); } } | |
957 | + } | |
79 | 958 | |
80 | - msmq.Send(encodedmessage, messagelabel); | |
959 | + public static class MessageQueues | |
960 | + { | |
961 | + public static class MessageQueue | |
962 | + { | |
963 | + public static class Attributes | |
964 | + { | |
965 | + public static class Key { public static class Values { public const string DEFAULT = ""; } } | |
966 | + public static class AddressPrefix{ public static class Values { public const string DEFAULT = ""; } } | |
967 | + public static class Server { public static class Values { public const string DEFAULT = "."; } } | |
968 | + public static class Name { } | |
969 | + public static class Label { } | |
970 | + public static class Private { public static class Values { public const bool DEFAULT = true; } } | |
971 | + public static class Mode | |
972 | + { | |
973 | + public static class Values | |
974 | + { | |
975 | + public const string DEFAULT = "In"; | |
976 | + public static class In { } | |
977 | + public static class Out { } | |
978 | + } | |
979 | + } | |
980 | + public static class Formatter | |
981 | + { | |
982 | + public static class Values | |
983 | + { | |
984 | + public static class ActiveXMessageFormatter { } | |
985 | + public static class BinaryMessageFormatter { } | |
986 | + public static class XmlMessageFormatter { } | |
987 | + } | |
988 | + } | |
989 | + public static class Encoding { } | |
990 | + } | |
991 | + public static class AccessRight | |
992 | + { | |
993 | + public static class Attributes | |
994 | + { | |
995 | + public static class Username { public static class Values { public const string DEFAULT = "Everyone"; } } | |
996 | + public static class Right { public static class Values { public const string DEFAULT = nameof(MessageQueueAccessRights.FullControl); } } | |
997 | + public static class Control { public static class Values { public const string DEFAULT = nameof(AccessControlEntryType.Allow); } } | |
998 | + } | |
999 | + } | |
1000 | + } | |
1001 | + } | |
1002 | + } | |
81 | 1003 | } |
1004 | + #endregion XmlStructure | |
82 | 1005 | } |
1006 | + #endregion MSMQ class | |
83 | 1007 | } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - MaintenanceToolManager.cs
... | ... | @@ -39,6 +39,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS |
39 | 39 | var config = new MaintenanceToolsXmlProcessor(xmlcs, "", "hu-HU"); |
40 | 40 | |
41 | 41 | var menufunctions = new Menu("Maintenance Tools", "Select function!") |
42 | + .AddMenuItem(new Menu.Item(CLP.Module.MaintenanceToolManager.Functions.StartAsSystem.KEY, "Start As NT AUTHORITY/SYSTEM", StartAsSystem, new Menu.ExecutorParameter(cfg: config))) | |
42 | 43 | .AddMenuItem(new Menu.Item(CLP.Module.MaintenanceToolManager.Functions.RegexTester.KEY, "Regex tester", RegexTester,new Menu.ExecutorParameter(cfg:config))) |
43 | 44 | .AddMenuItem(new Menu.Item(CLP.Module.MaintenanceToolManager.Functions.TCPIPTester.KEY, "TcpIp Tester", TcpIpTester, new Menu.ExecutorParameter(cfg: config, null))) |
44 | 45 | .AddMenuItem(new Menu.Item(CLP.Module.MaintenanceToolManager.Functions.Tool.KEY, "Tool sample", Tool2, new Menu.ExecutorParameter(cfg: config, null))) |
... | ... | @@ -68,6 +69,11 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS |
68 | 69 | return o; |
69 | 70 | } |
70 | 71 | #region RegexTester |
72 | + public static object StartAsSystem(object parameter, object o) | |
73 | + { | |
74 | + OtherTools.StartAsSystem(false); | |
75 | + return o; | |
76 | + } | |
71 | 77 | private static object RegexTester(object parameter, object o) |
72 | 78 | { |
73 | 79 | var config = (parameter as Menu.ExecutorParameter).GetConfig<MaintenanceToolsXmlProcessor>(); | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Program.cs
... | ... | @@ -18,6 +18,7 @@ using Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS; |
18 | 18 | using Vrh.Log4Pro.MaintenanceConsole.BackupPackageManagerNS; |
19 | 19 | using Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS; |
20 | 20 | using Vrh.Log4Pro.MaintenanceConsole.ScheduledTaskManagerNS; |
21 | +using Vrh.Log4Pro.MaintenanceConsole.MSMQManagerNS; | |
21 | 22 | using Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS; |
22 | 23 | using Vrh.Log4Pro.MaintenanceConsole.MaintenanceToolManagerNS; |
23 | 24 | using Vrh.Log4Pro.MaintenanceConsole.UserManagerNS; |
... | ... | @@ -28,6 +29,7 @@ using Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS; |
28 | 29 | using Vrh.XmlProcessing; |
29 | 30 | using VRH.Common; |
30 | 31 | using System.Xml.Linq; |
32 | +using System.Reflection; | |
31 | 33 | |
32 | 34 | namespace Vrh.Log4Pro.MaintenanceConsole |
33 | 35 | { |
... | ... | @@ -35,6 +37,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole |
35 | 37 | { |
36 | 38 | static void Main(string[] args) |
37 | 39 | { |
40 | + OtherTools.StartAsAdmin(); | |
41 | + OtherTools.StartAsSystem(silent:false); | |
38 | 42 | //while (true) |
39 | 43 | //{ |
40 | 44 | // Console.Clear(); |
... | ... | @@ -95,6 +99,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole |
95 | 99 | .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.KEY, "Windows Service Manager", WindowsServiceManager.Execute, new Menu.ExecutorParameter(args: args))) |
96 | 100 | .AddMenuItem(new Menu.Item(CLP.Module.FileCleanerManager.KEY, "File Cleaner Manager", FileCleanerManager.Execute, new Menu.ExecutorParameter(args: args))) |
97 | 101 | .AddMenuItem(new Menu.Item(CLP.Module.ScheduledTaskManager.KEY, "Scheduled Task Manager", ScheduledTaskManager.Execute, new Menu.ExecutorParameter(args: args))) |
102 | + .AddMenuItem(new Menu.Item(CLP.Module.MSMQManager.KEY, "MS MessageQueue (MSMQ) Manager", MSMQManager.Execute, new Menu.ExecutorParameter(args: args))) | |
98 | 103 | .AddMenuItem(new Menu.Item(CLP.Module.BackupPackageManager.KEY, "Backup Package Manager", BackupPackageManager.Execute, new Menu.ExecutorParameter(args: args))) |
99 | 104 | .AddMenuItem(new Menu.Item(CLP.Module.SQLDataBaseManager.KEY, "SQL Database Manager", SQLDataBaseManager.Execute, new Menu.ExecutorParameter(args: args))) |
100 | 105 | .AddMenuItem(new Menu.Item(CLP.Module.Log4ProUserManager.KEY, "Log4Pro User Manager", UserManager.Execute, new Menu.ExecutorParameter(args: args))) | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
... | ... | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; |
32 | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
33 | 33 | // by using the '*' as shown below: |
34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.8.5.0")] | |
36 | -[assembly: AssemblyFileVersion("1.8.5.0")] | |
35 | +[assembly: AssemblyVersion("1.9.0.0")] | |
36 | +[assembly: AssemblyFileVersion("1.9.0.0")] | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj
... | ... | @@ -172,6 +172,7 @@ |
172 | 172 | <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> |
173 | 173 | <HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> |
174 | 174 | </Reference> |
175 | + <Reference Include="PresentationFramework" /> | |
175 | 176 | <Reference Include="System" /> |
176 | 177 | <Reference Include="System.AppContext, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
177 | 178 | <HintPath>..\packages\System.AppContext.4.1.0\lib\net463\System.AppContext.dll</HintPath> |
... | ... | @@ -331,6 +332,7 @@ |
331 | 332 | <Reference Include="System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> |
332 | 333 | <HintPath>..\packages\Microsoft.AspNet.Providers.Core.2.0.0\lib\net40\System.Web.Providers.dll</HintPath> |
333 | 334 | </Reference> |
335 | + <Reference Include="System.Windows" /> | |
334 | 336 | <Reference Include="System.Windows.Forms" /> |
335 | 337 | <Reference Include="System.Xml.Linq" /> |
336 | 338 | <Reference Include="System.Data.DataSetExtensions" /> |
... | ... | @@ -346,6 +348,7 @@ |
346 | 348 | <Reference Include="Vrh.XmlProcessing, Version=1.27.1.0, Culture=neutral, processorArchitecture=MSIL"> |
347 | 349 | <HintPath>..\packages\Vrh.XmlProcessing.1.27.1\lib\net45\Vrh.XmlProcessing.dll</HintPath> |
348 | 350 | </Reference> |
351 | + <Reference Include="WindowsBase" /> | |
349 | 352 | </ItemGroup> |
350 | 353 | <ItemGroup> |
351 | 354 | <Compile Include="ConsoleFunction - Tools - TcpIp.cs" /> | ... | ... |