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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2062 - (hide annotations) (download)
Thu Aug 29 07:54:49 2013 UTC (10 years, 9 months ago) by torben
File size: 4363 byte(s)
1) Add timing to --debug launch
2) Don't write every message to console - it slows down the process a lot
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     long start = DateTime.Now.Ticks;
64 torben 1986 controller.transportAllMessages();
65 torben 2062 long stop = DateTime.Now.Ticks;
66 torben 2005
67 torben 2062 long elapsed = (stop - start) / 10000; //omreg tidsforskel til millisekunder
68    
69     Console.WriteLine("Run took " + elapsed + " milliseconds ");
70    
71 torben 2005 PumpService s = new PumpService();
72    
73     s.startRemoteControl();
74 torben 1986 }
75     catch (Exception e)
76     {
77     Console.WriteLine("Error: " + e.Message);
78     }
79    
80 torben 2062
81    
82    
83    
84 torben 1986 Console.WriteLine("Press any key to continue");
85     Console.ReadKey(); //wait for user input
86 torben 2049 }
87     else if (args[0] == "/i" || args[0] == "/u")
88 torben 1986 {
89    
90     bool undo;
91     if (args[0] == "/i")
92     {
93     undo = false;
94     }
95     else
96     {
97     undo = true;
98     }
99     MyServiceInstaller.DoInstall(undo, new string[] { });
100     }
101 torben 2049 else
102     {
103     Console.WriteLine("DaoMqPumpv2 by THN");
104     Console.WriteLine("Options:");
105     Console.WriteLine(" --debug start a single run debug session");
106     Console.WriteLine(" /i install as a service");
107     Console.WriteLine(" /u un-install service");
108     }
109 torben 1986
110     }
111     else
112     {
113     PumpService service = new PumpService();
114    
115    
116     // now run all the service that we have created.
117     // This doesn't actually cause the services
118     // to run but it registers the services with the
119     // Service Control Manager so that it can
120     // when you start the service the SCM will call
121     // the OnStart method of the service.
122    
123     ServiceBase.Run(service);
124     }
125    
126     }
127     }
128     }

  ViewVC Help
Powered by ViewVC 1.1.20