markus / ConvertService / ServiceBase / Markus.Service.StationController / AppInit.cs @ e19522be
이력 | 보기 | 이력해설 | 다운로드 (2.18 KB)
1 |
using Markus.Service.Helper; |
---|---|
2 |
using Markus.Service.StationController.StationService; |
3 |
using Microsoft.Win32; |
4 |
using System; |
5 |
using System.Collections.Generic; |
6 |
using System.Linq; |
7 |
using System.ServiceModel; |
8 |
using System.Text; |
9 |
using System.Threading.Tasks; |
10 |
using System.Windows; |
11 |
|
12 |
namespace Markus.Service.StationController |
13 |
{ |
14 |
public partial class App : Application |
15 |
{ |
16 |
public static List<StationService.StationServiceClient> StationClientList; |
17 |
|
18 |
public App() |
19 |
{ |
20 |
var path = GetAppPath("ConvertService"); |
21 |
System.Diagnostics.Debug.WriteLine(path); |
22 |
ServiceConnection(); |
23 |
} |
24 |
|
25 |
private void ServiceConnection() |
26 |
{ |
27 |
try |
28 |
{ |
29 |
var configFileName = $"StationController.ini"; |
30 |
|
31 |
var config = ConfigHelper.AppConfig(configFileName); |
32 |
|
33 |
var serviceUri = config.GetValue("SERVICE", "ADDRESS", "http://Localhost:9101/StationService"); |
34 |
StationClientList = new List<StationServiceClient>(); |
35 |
|
36 |
foreach (var item in serviceUri.Split(',')) |
37 |
{ |
38 |
|
39 |
BasicHttpBinding myBinding = new BasicHttpBinding(); |
40 |
EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate(item)); |
41 |
var StationClient = new StationService.StationServiceClient(myBinding, myEndpoint); |
42 |
|
43 |
StationClientList.Add(StationClient); |
44 |
} |
45 |
|
46 |
} |
47 |
catch (Exception ex) |
48 |
{ |
49 |
} |
50 |
} |
51 |
|
52 |
private string GetAppPath(string productName) |
53 |
{ |
54 |
const string foldersPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders"; |
55 |
var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); |
56 |
|
57 |
var subKey = baseKey.OpenSubKey(foldersPath); |
58 |
if (subKey == null) |
59 |
{ |
60 |
baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); |
61 |
subKey = baseKey.OpenSubKey(foldersPath); |
62 |
} |
63 |
return subKey != null ? subKey.GetValueNames().FirstOrDefault(kv => kv.Contains(productName)) : "ERROR"; |
64 |
} |
65 |
|
66 |
} |
67 |
} |