프로젝트

일반

사용자정보

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

markus / FinalService / FinalServiceBase / KCOM_FinalService / Program.cs @ 42d49521

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

1 42d49521 taeseongkim
#if DEBUG
2
using KCOMDataModel.DataModel;
3
#endif
4
using System;
5
using System.IO;
6
using System.Reflection;
7
using System.ServiceProcess;
8
using log4net;
9
using KCOM_FinalService.Common;
10
11
namespace KCOM_FinalService
12
{
13
    public static class Program
14
    {
15
        /// <summary>
16
        /// Application Data Folder
17
        /// </summary>
18
        public static string AppDataFolder
19
        {
20
            get
21
            {
22
                return AppDomain.CurrentDomain.BaseDirectory;
23
                //.return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MARKUS");
24
            }
25
        }
26
27
        public static ServiceBase[] ServicesToRun = null;
28
29
        public static MethodInfo UploadFinalPDFMethod { get; set; }
30
        public static object UploadFinalPDFInst { get; set; }
31
        public static string UploadFinalAssmPath { get; set; }
32
33
        public static MarkusFinalService service;
34
35
        /// <summary>
36
        /// The main entry point for the application.
37
        /// </summary>
38
        public static void Main(string[] args)
39
        {
40
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
41
42
            log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "FinalService.log");
43
44
            /// get legacy interface for upload final pdf file
45
            string UploadFinalDllPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UploadFinal.dll");
46
            if (File.Exists(UploadFinalDllPath))
47
            {
48
                Assembly asm = Assembly.LoadFrom(UploadFinalDllPath);
49
50
                UploadFinalAssmPath = UploadFinalDllPath;
51
52
                Type _UploadFinalClassType = asm.GetType("UploadFinal.UploadFinal");
53
54
                //Legacy IF
55
                Program.UploadFinalPDFMethod = _UploadFinalClassType.GetMethod("UploadFinalPDF", new Type[] { typeof(string), typeof(string), typeof(KCOMDataModel.DataModel.FINAL_PDF), typeof(string) });
56
                if (null != Program.UploadFinalPDFMethod)
57
                {
58
                    Program.UploadFinalPDFInst = Activator.CreateInstance(_UploadFinalClassType, null);
59
                }
60
            }
61
62
            try
63
            {
64
                
65
                if (Environment.UserInteractive)
66
                {
67
                    service = new MarkusFinalService();
68
                    service.TestStartupAndStop(args);
69
                }
70
                else
71
                {
72
                    /// up to here
73
                    ServicesToRun = new ServiceBase[]
74
                    {
75
                        new MarkusFinalService()
76
                    };
77
                    ServiceBase.Run(ServicesToRun);
78
                }
79
            }
80
            catch (Exception ex)
81
            {
82
                Console.WriteLine(ex);
83
            }
84
        }
85
86
        /// <summary>
87
        /// log unhandled exception
88
        /// </summary>
89
        /// <author>humkyung</author>
90
        /// <date>2019.06.04</date>
91
        /// <param name="sender"></param>
92
        /// <param name="e"></param>
93
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
94
        {
95
            try
96
            {
97
                service.logger.Write(e.ExceptionObject as Exception);
98
            }
99
            catch (Exception ex)
100
            {
101
                Console.WriteLine(ex.InnerException.ToString());
102
            }
103
            finally
104
            {
105
            }
106
        }
107
    }
108
}
클립보드 이미지 추가 (최대 크기: 500 MB)