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 |
catch (Exception e)
|
63 |
{
|
64 |
Console.WriteLine("Error: " + e.Message);
|
65 |
}
|
66 |
|
67 |
Console.WriteLine("Press any key to continue");
|
68 |
Console.ReadKey(); //wait for user input
|
69 |
}
|
70 |
|
71 |
if (args[0] == "/i" || args[0] == "/u")
|
72 |
{
|
73 |
|
74 |
bool undo;
|
75 |
if (args[0] == "/i")
|
76 |
{
|
77 |
undo = false;
|
78 |
}
|
79 |
else
|
80 |
{
|
81 |
undo = true;
|
82 |
}
|
83 |
MyServiceInstaller.DoInstall(undo, new string[] { });
|
84 |
}
|
85 |
|
86 |
}
|
87 |
else
|
88 |
{
|
89 |
PumpService service = new PumpService();
|
90 |
|
91 |
|
92 |
// now run all the service that we have created.
|
93 |
// This doesn't actually cause the services
|
94 |
// to run but it registers the services with the
|
95 |
// Service Control Manager so that it can
|
96 |
// when you start the service the SCM will call
|
97 |
// the OnStart method of the service.
|
98 |
|
99 |
ServiceBase.Run(service);
|
100 |
}
|
101 |
|
102 |
}
|
103 |
}
|
104 |
}
|