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

Annotation of /dao/DaoMqPump2/DaoMqPump2/MainProgram.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2070 - (hide annotations) (download)
Wed Nov 13 10:09:10 2013 UTC (10 years, 6 months ago) by torben
File size: 4182 byte(s)
Add ElapsedTimer to ease debug timing
1 torben 1986 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 torben 2062 {
57 torben 1986 try
58     {
59 torben 2062
60    
61 torben 1986 TransportController controller = TransportController.getInstance();
62 torben 2062
63 torben 2070 ElapsedTimer timer = new ElapsedTimer();
64 torben 1986 controller.transportAllMessages();
65 torben 2005
66 torben 2070 timer.stopAndPrint("debug run");
67 torben 2062
68 torben 2005 PumpService s = new PumpService();
69    
70     s.startRemoteControl();
71 torben 1986 }
72     catch (Exception e)
73     {
74     Console.WriteLine("Error: " + e.Message);
75     }
76    
77 torben 2062
78    
79    
80    
81 torben 1986 Console.WriteLine("Press any key to continue");
82     Console.ReadKey(); //wait for user input
83 torben 2049 }
84     else if (args[0] == "/i" || args[0] == "/u")
85 torben 1986 {
86    
87     bool undo;
88     if (args[0] == "/i")
89     {
90     undo = false;
91     }
92     else
93     {
94     undo = true;
95     }
96     MyServiceInstaller.DoInstall(undo, new string[] { });
97     }
98 torben 2049 else
99     {
100     Console.WriteLine("DaoMqPumpv2 by THN");
101     Console.WriteLine("Options:");
102     Console.WriteLine(" --debug start a single run debug session");
103     Console.WriteLine(" /i install as a service");
104     Console.WriteLine(" /u un-install service");
105     }
106 torben 1986
107     }
108     else
109     {
110     PumpService service = new PumpService();
111    
112    
113     // now run all the service that we have created.
114     // This doesn't actually cause the services
115     // to run but it registers the services with the
116     // Service Control Manager so that it can
117     // when you start the service the SCM will call
118     // the OnStart method of the service.
119    
120     ServiceBase.Run(service);
121     }
122    
123     }
124     }
125     }

  ViewVC Help
Powered by ViewVC 1.1.20