markus / ConvertService / ServiceBase / MonitorTest / MainWindow.xaml.cs @ c6bf88fd
이력 | 보기 | 이력해설 | 다운로드 (5.8 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Diagnostics; |
4 |
using System.Linq; |
5 |
using System.ServiceModel; |
6 |
using System.ServiceProcess; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Timers; |
10 |
using System.Windows; |
11 |
using System.Windows.Controls; |
12 |
using System.Windows.Data; |
13 |
using System.Windows.Documents; |
14 |
using System.Windows.Input; |
15 |
using System.Windows.Media; |
16 |
using System.Windows.Media.Imaging; |
17 |
using System.Windows.Navigation; |
18 |
using System.Windows.Shapes; |
19 |
using System.Windows.Threading; |
20 |
using Markus.Service; |
21 |
using Markus.Service.Extensions; |
22 |
using Markus.Service.Helper; |
23 |
|
24 |
namespace MonitorTest |
25 |
{ |
26 |
/// <summary> |
27 |
/// MainWindow.xaml에 대한 상호 작용 논리 |
28 |
/// </summary> |
29 |
public partial class MainWindow : Window |
30 |
{ |
31 |
public MainWindow() |
32 |
{ |
33 |
InitializeComponent(); |
34 |
|
35 |
} |
36 |
|
37 |
//Markus.Service.WorkMonitor.ServiceMonitor monitor = new Markus.Service.WorkMonitor.ServiceMonitor(); |
38 |
|
39 |
private void Button_Click(object sender, RoutedEventArgs e) |
40 |
{ |
41 |
// monitor.AddCallback(test.processTest, $"test{monitor.timers.Count}", new TimeSpan(0, 0, 1), new TimeSpan(0, 0, 10)); |
42 |
} |
43 |
|
44 |
private void btProcessAguemnt_Click(object sender, RoutedEventArgs e) |
45 |
{ |
46 |
var process = Process.GetProcessesByName(txtProcessName.Text); |
47 |
|
48 |
if (process.Count() > 0) |
49 |
{ |
50 |
foreach (var item in process) |
51 |
{ |
52 |
System.Diagnostics.Debug.WriteLine(string.Join("",item.Arguments().CommandLine)); |
53 |
} |
54 |
|
55 |
} |
56 |
} |
57 |
|
58 |
private void btProcessWorking_Click(object sender, RoutedEventArgs e) |
59 |
{ |
60 |
var process = Process.GetProcessesByName("PerfWatson2"); |
61 |
|
62 |
if (process.Count() > 0) |
63 |
{ |
64 |
System.Diagnostics.Debug.WriteLine(process.First().StartInfo.WorkingDirectory); |
65 |
} |
66 |
} |
67 |
|
68 |
private void btTimerTest_Click(object sender, RoutedEventArgs e) |
69 |
{ |
70 |
timer = new System.Timers.Timer(new TimeSpan(0, 0, 0, 1).TotalMilliseconds); |
71 |
timer.Elapsed += OnTimedEvent; |
72 |
timer.AutoReset = true; |
73 |
timer.Start(); |
74 |
} |
75 |
|
76 |
private enum SimpleServiceCustomCommands { StopWorker = 128, RestartWorker, CheckWorker }; |
77 |
private const string StationProcessName = "Markus.Service.Station"; |
78 |
private const string StationServiceName = "ServiceStation"; |
79 |
|
80 |
ServiceController serviceController; |
81 |
StationService.StationServiceClient stationServiceClient; |
82 |
System.Timers.Timer timer; |
83 |
private void ServiceInitialize() |
84 |
{ |
85 |
if (serviceController == null) |
86 |
{ |
87 |
serviceController = new ServiceController(StationServiceName); |
88 |
} |
89 |
|
90 |
#region 컨버터 서비스 연결 |
91 |
|
92 |
} |
93 |
|
94 |
private void WcfClientInitialize() |
95 |
{ |
96 |
var process = Process.GetProcessesByName(StationProcessName); |
97 |
|
98 |
if (process.Count() > 0) |
99 |
{ |
100 |
if (stationServiceClient == null) |
101 |
{ |
102 |
string serviceWorkDir = process.First().Arguments().WorkingDirectory; |
103 |
|
104 |
var config = ConfigHelper.AppConfig(System.IO.Path.Combine(serviceWorkDir, $"{StationServiceName}.ini" )); |
105 |
|
106 |
var endpointName = config.GetValue(CONFIG_DEFINE.WCF_ENDPOINT, CONFIG_DEFINE.STATION_SERVICE_NAME); |
107 |
var port = config.GetValue(CONFIG_DEFINE.WCF_ENDPOINT, CONFIG_DEFINE.STATION_PORT); |
108 |
|
109 |
if (!string.IsNullOrWhiteSpace(endpointName) && port.IsNumber()) |
110 |
{ |
111 |
var serviceUri = UriHelper.UriCreate($"http://localhost:{port}/{endpointName}"); |
112 |
BasicHttpBinding myBinding = new BasicHttpBinding(); |
113 |
EndpointAddress myEndpoint = new EndpointAddress(serviceUri); |
114 |
|
115 |
stationServiceClient = new StationService.StationServiceClient(myBinding, myEndpoint); |
116 |
} |
117 |
} |
118 |
} |
119 |
|
120 |
#endregion |
121 |
} |
122 |
|
123 |
|
124 |
private void OnTimedEvent(object sender, ElapsedEventArgs e) |
125 |
{ |
126 |
timer.Enabled = false; |
127 |
try |
128 |
{ |
129 |
|
130 |
if (serviceController == null) |
131 |
{ |
132 |
serviceController = null; |
133 |
ServiceInitialize(); |
134 |
} |
135 |
else |
136 |
{ |
137 |
serviceController.Refresh(); |
138 |
System.Diagnostics.Debug.WriteLine(" serviceController.Status : " + serviceController.Status); |
139 |
|
140 |
if (serviceController.Status != ServiceControllerStatus.Running && serviceController.Status != ServiceControllerStatus.StartPending) |
141 |
{ |
142 |
serviceController.Start(); |
143 |
} |
144 |
else |
145 |
{ |
146 |
if (stationServiceClient == null) |
147 |
{ |
148 |
WcfClientInitialize(); |
149 |
} |
150 |
else |
151 |
{ |
152 |
System.Diagnostics.Debug.WriteLine(" stationServiceClient.State : " + stationServiceClient.State); |
153 |
|
154 |
var result = stationServiceClient.AliveConvertList(); |
155 |
} |
156 |
} |
157 |
} |
158 |
} |
159 |
catch (Exception ex) |
160 |
{ |
161 |
// serviceController.ExecuteCommand((int)SimpleServiceCustomCommands.RestartWorker); |
162 |
} |
163 |
finally |
164 |
{ |
165 |
timer.Enabled = true; |
166 |
} |
167 |
} |
168 |
} |
169 |
|
170 |
public class test |
171 |
{ |
172 |
public static void processTest(object state ) |
173 |
{ |
174 |
System.Diagnostics.Debug.WriteLine($"{state}"); |
175 |
} |
176 |
} |
177 |
} |