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