Commit 6cd93dfa32d0ad0773a161b29bc1da360cee018d

Authored by Schwirg László
1 parent 735c2a08

- teszt eljárások hozzáadása

Showing 1 changed file with 116 additions and 6 deletions   Show diff stats
Vrh.Log4Pro.MaintenanceConsole/Program.cs
@@ -30,6 +30,8 @@ using Vrh.XmlProcessing; @@ -30,6 +30,8 @@ using Vrh.XmlProcessing;
30 using VRH.Common; 30 using VRH.Common;
31 using System.Xml.Linq; 31 using System.Xml.Linq;
32 using System.Reflection; 32 using System.Reflection;
  33 +using System.Messaging;
  34 +using System.IO;
33 35
34 namespace Vrh.Log4Pro.MaintenanceConsole 36 namespace Vrh.Log4Pro.MaintenanceConsole
35 { 37 {
@@ -37,7 +39,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole @@ -37,7 +39,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole
37 { 39 {
38 static void Main(string[] args) 40 static void Main(string[] args)
39 { 41 {
40 - //TESTS.GetWorkingProcesses(); 42 + //TESTS.MSMQTest();
41 //return; 43 //return;
42 var forcedmodulekey = CommandLine.GetCommandLineArgument(args, CLP.CMD_MODULE); 44 var forcedmodulekey = CommandLine.GetCommandLineArgument(args, CLP.CMD_MODULE);
43 var commandmode = !string.IsNullOrEmpty(forcedmodulekey); 45 var commandmode = !string.IsNullOrEmpty(forcedmodulekey);
@@ -90,28 +92,136 @@ namespace Vrh.Log4Pro.MaintenanceConsole @@ -90,28 +92,136 @@ namespace Vrh.Log4Pro.MaintenanceConsole
90 ColorConsole.PressAnykeyToContinue(); 92 ColorConsole.PressAnykeyToContinue();
91 } 93 }
92 } 94 }
93 - public static class TESTS 95 + public static class TESTS
94 { 96 {
95 public static void GetWorkingProcesses() 97 public static void GetWorkingProcesses()
96 - { 98 + {
97 using (ServerManager manager = new ServerManager()) 99 using (ServerManager manager = new ServerManager())
98 { 100 {
99 var workerprocesses = manager.ApplicationPools.SelectMany(pool => pool.WorkerProcesses); 101 var workerprocesses = manager.ApplicationPools.SelectMany(pool => pool.WorkerProcesses);
100 var workerprocessesCount = workerprocesses.Count(); 102 var workerprocessesCount = workerprocesses.Count();
101 Console.WriteLine($"Number of worker processes: {workerprocessesCount}"); 103 Console.WriteLine($"Number of worker processes: {workerprocessesCount}");
102 foreach (var wp in workerprocesses) 104 foreach (var wp in workerprocesses)
103 - { 105 + {
104 Console.WriteLine($"process AppPoolName: {wp.AppPoolName}, process ProcessId: {wp.ProcessId}, process State: {wp.State}, process IsLocallyStored: {wp.IsLocallyStored}"); 106 Console.WriteLine($"process AppPoolName: {wp.AppPoolName}, process ProcessId: {wp.ProcessId}, process State: {wp.State}, process IsLocallyStored: {wp.IsLocallyStored}");
105 Console.WriteLine($" ApplicationDomains: {wp.ApplicationDomains.Count()}"); 107 Console.WriteLine($" ApplicationDomains: {wp.ApplicationDomains.Count()}");
106 foreach (var ad in wp.ApplicationDomains) 108 foreach (var ad in wp.ApplicationDomains)
107 - { 109 + {
108 Console.WriteLine($" VirtualPath: {ad.VirtualPath}, PhysicalPath: {ad.PhysicalPath}"); 110 Console.WriteLine($" VirtualPath: {ad.VirtualPath}, PhysicalPath: {ad.PhysicalPath}");
109 } 111 }
110 - } 112 + }
111 } 113 }
112 Console.ReadKey(); 114 Console.ReadKey();
113 } 115 }
114 } 116 }
  117 + public static class MSMQTESTS
  118 + {
  119 + public static void MSMQTest()
  120 + {
  121 + using (var myNewQueue = new MessageQueue(@"SLNOTEBOOKDELL\private$\LJSTOWEBALM"))
  122 + {
  123 + while (true)
  124 + {
  125 + Console.WriteLine("Set formatter (ActiveXMessageFormatter(A),BinaryMessageFormatter(B),XmlMessageFormatter(X)):");
  126 + var msgformatter = Console.ReadLine();
  127 + if (string.IsNullOrEmpty(msgformatter)|| msgformatter.ToLower()=="a") msgformatter = "ActiveXMessageFormatter";
  128 + if (msgformatter.ToLower() == "x") msgformatter = "XmlMessageFormatter";
  129 + if (msgformatter.ToLower() == "b") msgformatter = "BinaryMessageFormatter";
  130 + Console.WriteLine("Set encoding (Default(d),UTF8(8),UTF7(7),UTF32(32),Unicode(U),BigEndianUnicode(B),ASCII(A),none:");
  131 + var msgencoding = Console.ReadLine();
  132 + if (string.IsNullOrEmpty(msgencoding) || msgencoding.ToLower() == "8") msgencoding = "UTF8";
  133 + if (msgencoding.ToLower() == "7") msgencoding = "UTF7";
  134 + if (msgencoding.ToLower() == "32") msgencoding = "UTF32";
  135 + if (msgencoding.ToLower() == "a") msgencoding = "ASCII";
  136 + if (msgencoding.ToLower() == "d") msgencoding = "Default";
  137 + if (msgencoding.ToLower() == "b") msgencoding = "BigEndianUnicode";
  138 + if (msgencoding.ToLower() == "u") msgencoding = "Unicode";
  139 +
  140 + Console.WriteLine("Set message to send:");
  141 + var text = Console.ReadLine();
  142 + if (string.IsNullOrEmpty(text)) text= "ABCDabcd12345#$@{}[]";
  143 + MSMQSend(myNewQueue, msgformatter, msgencoding, text);
  144 + Console.WriteLine("Press a key to read back and remove...");
  145 + Console.ReadKey();
  146 + var message = MSMQRead(myNewQueue, msgformatter, msgencoding);
  147 + Console.WriteLine($"MessageBody ({msgformatter},{msgencoding}):{message}");
  148 + Console.WriteLine("------------------------------------------------------------");
  149 +
  150 + if (Console.ReadLine().ToLower() == "ex") break;
  151 + }
  152 + return;
  153 + }
  154 + }
  155 + private static void MSMQSend(MessageQueue msmq, string msgformatter, string msgencoding, string text)
  156 + {
  157 + Message msg = new System.Messaging.Message();
  158 + msg.Formatter = SetFormatter(msgformatter);
  159 + if (msg.Formatter is XmlMessageFormatter) { msg.Body = text; }
  160 + else
  161 + {
  162 + var enc = SetEncoding(msgencoding);
  163 + if (enc == null) { msg.Body = text; }
  164 + else { msg.BodyStream = new MemoryStream(enc.GetBytes(text)); }
  165 + }
  166 + msg.Label = msgformatter + "_" + msgencoding;
  167 + msmq.Send(msg);
  168 + Console.WriteLine($"Message: {text}, Label:{msg.Label}");
  169 + }
  170 + private static string MSMQRead(MessageQueue msmq, string msgformatter, string msgencoding)
  171 + {
  172 + string msgBody = null;
  173 + using (var e = msmq.GetMessageEnumerator2())
  174 + {
  175 + if (!e.MoveNext(new TimeSpan(0, 0, 10))) return "no more message";
  176 + System.Messaging.Message msg = e.Current;
  177 +
  178 + StreamReader reader;
  179 + msg.Formatter = SetFormatter(msgformatter);
  180 + if (msg.Formatter is XmlMessageFormatter)
  181 + {
  182 + ((XmlMessageFormatter)msg.Formatter).TargetTypes = new Type[] { typeof(string), };
  183 + msgBody = (string)msg.Body;
  184 + }
  185 + else
  186 + {
  187 + var enc = SetEncoding(msgencoding);
  188 + if (enc == null) { msgBody = (string)msg.Body; }
  189 + else { reader = new StreamReader(msg.BodyStream, enc); msgBody = reader.ReadToEnd(); }
  190 + }
  191 + e.RemoveCurrent();
  192 + }
  193 + return msgBody;
  194 + }
  195 + public static IMessageFormatter SetFormatter(string formattername)
  196 + {
  197 + IMessageFormatter mf;
  198 + switch (formattername)
  199 + {
  200 + case "XmlMessageFormatter": mf = new XmlMessageFormatter(); break;
  201 + case "BinaryMessageFormatter": mf = new BinaryMessageFormatter(); break;
  202 + default:
  203 + case "ActiveXMessageFormatter": mf = new ActiveXMessageFormatter(); break;
  204 + }
  205 + return mf;
  206 + }
  207 + public static Encoding SetEncoding(string encodingname)
  208 + {
  209 + Encoding enc;
  210 + switch (encodingname)
  211 + {
  212 + case "none": enc = null; break;
  213 + case "UTF7": enc = Encoding.UTF7; break;
  214 + case "UTF8": enc = Encoding.UTF8; break;
  215 + case "UTF32": enc = Encoding.UTF32; break;
  216 + case "Unicode": enc = Encoding.Unicode; break;
  217 + case "BigEndianUnicode": enc = Encoding.BigEndianUnicode; break;
  218 + case "ASCII": enc = Encoding.ASCII; break;
  219 + default:
  220 + case "Default": enc = Encoding.Default; break;
  221 + }
  222 + return enc;
  223 + }
  224 + }
115 225
116 #region MaintenanceConsoleXmlProcessor class 226 #region MaintenanceConsoleXmlProcessor class
117 public class MaintenanceConsoleXmlProcessor : XmlParser 227 public class MaintenanceConsoleXmlProcessor : XmlParser