/[projects]/dao/DaoMqPump2/DaoMqPump2/MainProgram.cs
ViewVC logotype

Contents of /dao/DaoMqPump2/DaoMqPump2/MainProgram.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2049 - (show annotations) (download)
Fri Aug 23 16:26:20 2013 UTC (10 years, 9 months ago) by torben
File size: 3978 byte(s)
add CLI info to main program
1 using System;
2 using System.Collections;
3 using System.Text;
4
5 using System.ServiceProcess;
6 using System.Diagnostics;
7
8 using System.Configuration.Install;
9 using System.Collections.Specialized;
10 using System.Runtime.InteropServices;
11
12 //Create a Console App - remember to add the System.ServiceProcess assembly to references
13
14 namespace DaoMqPump2
15 {
16
17
18 class MainProgram
19 {
20 public enum LoadLibraryFlags : uint
21 {
22 DONT_RESOLVE_DLL_REFERENCES = 0x00000001,
23 LOAD_IGNORE_CODE_AUTHZ_LEVEL = 0x00000010,
24 LOAD_LIBRARY_AS_DATAFILE = 0x00000002,
25 LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040,
26 LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x00000020,
27 LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008
28 }
29
30 [DllImport("Kernel32.dll", CallingConvention = CallingConvention.StdCall)]
31 public static extern bool AddDllDirectory(String lpPathName);
32
33 [DllImport("kernel32.dll")]
34 static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags);
35
36
37 static void Main(string[] args)
38 {
39 //AddDllDirectory("c:\\Program Files\\IBM\\Websphere MQ\\bin");
40
41 /*string libPath = "c:\\Program Files\\IBM\\Websphere MQ\\bin\\mqic32.dll";
42
43 IntPtr res = LoadLibraryEx(libPath, IntPtr.Zero, LoadLibraryFlags.LOAD_WITH_ALTERED_SEARCH_PATH);
44
45 if (res == IntPtr.Zero)
46 {
47 EventLog.WriteEntry("DaoMqPump2", "error loading " + libPath, EventLogEntryType.Warning);
48 Console.WriteLine("Error loading library");
49 Console.ReadKey(); //wait for user input
50 return;
51 }*/
52
53 if (args.Length == 1)
54 {
55 if (args[0] == "--debug")
56 {
57 try
58 {
59 TransportController controller = TransportController.getInstance();
60 controller.transportAllMessages();
61
62 PumpService s = new PumpService();
63
64 s.startRemoteControl();
65 }
66 catch (Exception e)
67 {
68 Console.WriteLine("Error: " + e.Message);
69 }
70
71 Console.WriteLine("Press any key to continue");
72 Console.ReadKey(); //wait for user input
73 }
74 else if (args[0] == "/i" || args[0] == "/u")
75 {
76
77 bool undo;
78 if (args[0] == "/i")
79 {
80 undo = false;
81 }
82 else
83 {
84 undo = true;
85 }
86 MyServiceInstaller.DoInstall(undo, new string[] { });
87 }
88 else
89 {
90 Console.WriteLine("DaoMqPumpv2 by THN");
91 Console.WriteLine("Options:");
92 Console.WriteLine(" --debug start a single run debug session");
93 Console.WriteLine(" /i install as a service");
94 Console.WriteLine(" /u un-install service");
95 }
96
97 }
98 else
99 {
100 PumpService service = new PumpService();
101
102
103 // now run all the service that we have created.
104 // This doesn't actually cause the services
105 // to run but it registers the services with the
106 // Service Control Manager so that it can
107 // when you start the service the SCM will call
108 // the OnStart method of the service.
109
110 ServiceBase.Run(service);
111 }
112
113 }
114 }
115 }

  ViewVC Help
Powered by ViewVC 1.1.20