프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / ConvertService / ServiceController / Markus.Service.StationController / AppInit.cs @ 5c387707

이력 | 보기 | 이력해설 | 다운로드 (2.92 KB)

1
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
using static Markus.Service.Extensions.Encrypt;
11
using Markus.Service.WcfClient.StationServiceTask;
12

    
13
namespace Markus.Service.StationController
14
{
15
    public partial class App : Application
16
    {
17
        public static  List<StationServiceClient> StationClientList;
18
        public static string MarkusDataBaseConnecitonString;
19
        public static string ConvertProcessName;
20

    
21
        public App()
22
        {
23
            var path = GetAppPath("ConvertService");
24
            System.Diagnostics.Debug.WriteLine(path);
25
            ServiceConnection();
26
        }
27

    
28
        private void ServiceConnection()
29
        {
30
            try
31
            {
32
                var configFileName = $"StationController.ini";
33

    
34
                var config = ConfigHelper.AppConfig(configFileName);
35

    
36
                var serviceUri = config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.SERVICE_ADDRESS, "http://Localhost:9101/StationService");
37
                StationClientList = new List<StationServiceClient>();
38

    
39
               foreach (var item in serviceUri.Split(','))
40
                {
41

    
42
                    BasicHttpBinding httpbinding = new BasicHttpBinding();
43
                    httpbinding.CloseTimeout = new TimeSpan(0, 10, 0);
44
                    httpbinding.ReceiveTimeout = new TimeSpan(0, 10, 0);
45
                    httpbinding.SendTimeout = new TimeSpan(0, 10, 0);
46
                    httpbinding.OpenTimeout = new TimeSpan(0, 10, 0);
47

    
48

    
49
                    EndpointAddress myEndpoint = new EndpointAddress(UriHelper.UriCreate(item));
50
                    var StationClient = new StationServiceClient(httpbinding, myEndpoint);
51

    
52
                    StationClientList.Add(StationClient);
53
                }
54

    
55
                MarkusDataBaseConnecitonString = AESEncrypter.Decrypt(config.GetValue(CONFIG_DEFINE.SERVICE, CONFIG_DEFINE.MARKUS_CONNECTION_STRING));
56

    
57
                ConvertProcessName = config.GetValue(CONFIG_DEFINE.CONVERTPROCESS, CONFIG_DEFINE.PROCESS_NAME);
58
            }
59
            catch (Exception ex)
60
            {
61
                MessageBox.Show(ex.Message);
62
            }
63
        }
64

    
65
        private string GetAppPath(string productName)
66
        {
67
            const string foldersPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders";
68
            var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
69

    
70
            var subKey = baseKey.OpenSubKey(foldersPath);
71
            if (subKey == null)
72
            {
73
                baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
74
                subKey = baseKey.OpenSubKey(foldersPath);
75
            }
76
            return subKey != null ? subKey.GetValueNames().FirstOrDefault(kv => kv.Contains(productName)) : "ERROR";
77
        }
78

    
79
    }
80
}
클립보드 이미지 추가 (최대 크기: 500 MB)