using System; using System.Collections; using System.Text; using System.ServiceProcess; using System.Diagnostics; using System.Configuration.Install; using System.Collections.Specialized; using System.Runtime.InteropServices; using DaoCommon; //Create a Console App - remember to add the System.ServiceProcess assembly to references namespace DaoMqPump2 { class MainProgram { public enum LoadLibraryFlags : uint { DONT_RESOLVE_DLL_REFERENCES = 0x00000001, LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010, LOAD_LIBRARY_AS_DATAFILE = 0x00000002, LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040, LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020, LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008 } [DllImport("Kernel32.dll", CallingConvention = CallingConvention.StdCall)] public static extern bool AddDllDirectory(String lpPathName); [DllImport("kernel32.dll")] static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags); static void Main(string[] args) { //AddDllDirectory("c:\\Program Files\\IBM\\Websphere MQ\\bin"); /*string libPath = "c:\\Program Files\\IBM\\Websphere MQ\\bin\\mqic32.dll"; IntPtr res = LoadLibraryEx(libPath, IntPtr.Zero, LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH); if (res == IntPtr.Zero) { EventLog.WriteEntry("DaoMqPump2", "error loading " + libPath, EventLogEntryType.Warning); Console.WriteLine("Error loading library"); Console.ReadKey(); //wait for user input return; }*/ if (args.Length == 1) { if (args[0] == "--debug") { try { TransportController controller = TransportController.getInstance(); ElapsedTimer timer = new ElapsedTimer(); controller.transportAllMessages(); timer.stopAndPrint("debug run"); PumpService s = new PumpService(); s.startRemoteControl(); } catch (Exception e) { Console.WriteLine("Error: " + e.Message); } Console.WriteLine("Press any key to continue"); Console.ReadKey(); //wait for user input } else if (args[0] == "/i" || args[0] == "/u") { bool undo; if (args[0] == "/i") { undo = false; } else { undo = true; } MyServiceInstaller.DoInstall(undo, new string[] { }); } else { Console.WriteLine("DaoMqPumpv2 by THN"); Console.WriteLine("Options:"); Console.WriteLine(" --debug start a single run debug session"); Console.WriteLine(" /i install as a service"); Console.WriteLine(" /u un-install service"); } } else { PumpService service = new PumpService(); // now run all the service that we have created. // This doesn't actually cause the services // to run but it registers the services with the // Service Control Manager so that it can // when you start the service the SCM will call // the OnStart method of the service. ServiceBase.Run(service); } } } }