프로젝트

일반

사용자정보

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

markus / ConvertService / ServiceBase / Markus.Service.StationController / AppInit.cs @ e19522be

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

1 0498c12e taeseongkim
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 0157b158 taeseongkim
        public static  List<StationService.StationServiceClient> StationClientList;
17 0498c12e taeseongkim
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 0157b158 taeseongkim
                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 0498c12e taeseongkim
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
}
클립보드 이미지 추가 (최대 크기: 500 MB)