첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

TestSolution.zip
다운로드

[TestAction 프로젝트]

▶ CustomAction.cs

using Microsoft.Deployment.WindowsInstaller;
using System;
using System.IO;

using TestLibrary;

namespace TestAction
{
    /// <summary>
    /// 커스텀 액션
    /// </summary>
    public class CustomAction
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 최초 설치 시작 액션 실행하기 - ExecuteFirstInstallStartAction(session)

        /// <summary>
        /// 최초 설치 시작 액션 실행하기
        /// </summary>
        /// <param name="session">세션</param>
        /// <returns>액션 결과</returns>
        [CustomAction]
        public static ActionResult ExecuteFirstInstallStartAction(Session session)
        {
            ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");

            logHelper.WriteLog($"ExecuteFirstInstallStartAction : {ApplicationEnvironment.Version}");

            return ActionResult.Success;
        }

        #endregion
        #region 최초 설치 종료 액션 실행하기 - ExecuteFirstInstallEndAction(session)

        /// <summary>
        /// 최초 설치 종료 액션 실행하기
        /// </summary>
        /// <param name="session">세션</param>
        /// <returns>액션 결과</returns>
        [CustomAction]
        public static ActionResult ExecuteFirstInstallEndAction(Session session)
        {
            ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");

            logHelper.WriteLog($"ExecuteFirstInstallEndAction : {ApplicationEnvironment.Version}");

            #region 윈도우즈 서비스를 생성하고 시작한다.

            try
            {
                string directoryPath = session["APPDIR"];
                string filePath      = Path.Combine(directoryPath, ApplicationEnvironment.ServiceFileName);

                logHelper.WriteLog($"SERVICE FILE PATH : {filePath}");

                WindowsServiceHelper.CreateWindowsService(ApplicationEnvironment.ServiceName, filePath);

                logHelper.WriteLog($"SERVICE CREATED : {ApplicationEnvironment.ServiceName}");

                WindowsServiceHelper.StartWindowsService(ApplicationEnvironment.ServiceName);

                logHelper.WriteLog($"SERVICE STARTED : {ApplicationEnvironment.ServiceName}");
            }
            catch(Exception exception)
            {
                logHelper.WriteErrorLog(exception, "ExecuteFirstInstallEndAction Error");
            }

            #endregion

            return ActionResult.Success;
        }

        #endregion

        #region 업그레이드 설치 시작 액션 실행하기 - ExecuteUpgradeInstallStartAction(session)

        /// <summary>
        /// 업그레이드 설치 시작 액션 실행하기
        /// </summary>
        /// <param name="session">세션</param>
        /// <returns>액션 결과</returns>
        [CustomAction]
        public static ActionResult ExecuteUpgradeInstallStartAction(Session session)
        {
            ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");

            logHelper.WriteLog($"ExecuteUpgradeInstallStartAction : {ApplicationEnvironment.Version}");

            #region 윈도우즈 서비스를 중단하고 삭제한다.

            try
            {
                string directoryPath = session["APPDIR"];
                string filePath      = Path.Combine(directoryPath, ApplicationEnvironment.ServiceFileName);

                logHelper.WriteLog($"SERVICE FILE PATH : {filePath}");

                WindowsServiceHelper.StopWindowsService(ApplicationEnvironment.ServiceName);

                logHelper.WriteLog($"SERVICE STOPPED : {ApplicationEnvironment.ServiceName}");

                WindowsServiceHelper.DeleteWindowsService(ApplicationEnvironment.ServiceName);

                logHelper.WriteLog($"SERVICE DELETED : {ApplicationEnvironment.ServiceName}");
            }
            catch(Exception exception)
            {
                logHelper.WriteErrorLog(exception, "ExecuteUpgradeInstallStartAction Error");
            }

            #endregion

            return ActionResult.Success;
        }

        #endregion
        #region 업그레이드 설치 종료 액션 실행하기 - ExecuteUpgradeInstallEndAction(session)

        /// <summary>
        /// 업그레이드 설치 종료 액션 실행하기
        /// </summary>
        /// <param name="session">세션</param>
        /// <returns>액션 결과</returns>
        [CustomAction]
        public static ActionResult ExecuteUpgradeInstallEndAction(Session session)
        {
            ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");

            logHelper.WriteLog($"ExecuteUpgradeInstallEndAction : {ApplicationEnvironment.Version}");

            #region 윈도우즈 서비스를 생성하고 시작한다.

            try
            {
                string directoryPath = session["APPDIR"];
                string filePath      = Path.Combine(directoryPath, ApplicationEnvironment.ServiceFileName);

                logHelper.WriteLog($"SERVICE FILE PATH : {filePath}");

                WindowsServiceHelper.CreateWindowsService(ApplicationEnvironment.ServiceName, filePath);

                logHelper.WriteLog($"SERVICE CREATED : {ApplicationEnvironment.ServiceName}");

                WindowsServiceHelper.StartWindowsService(ApplicationEnvironment.ServiceName);

                logHelper.WriteLog($"SERVICE STARTED : {ApplicationEnvironment.ServiceName}");
            }
            catch(Exception exception)
            {
                logHelper.WriteErrorLog(exception, "ExecuteFirstInstallEndAction Error");
            }

            #endregion

            return ActionResult.Success;
        }

        #endregion

        #region 설치 제거 시작 액션 실행하기 - ExecuteUninstallStartAction(session)

        /// <summary>
        /// 설치 제거 시작 액션 실행하기
        /// </summary>
        /// <param name="session">세션</param>
        /// <returns>액션 결과</returns>
        [CustomAction]
        public static ActionResult ExecuteUninstallStartAction(Session session)
        {
            ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");

            logHelper.WriteLog($"ExecuteUninstallStartAction : {ApplicationEnvironment.Version}");

            #region 윈도우즈 서비스를 중단하고 삭제한다.

            try
            {
                string directoryPath = session["APPDIR"];
                string filePath      = Path.Combine(directoryPath, ApplicationEnvironment.ServiceFileName);

                logHelper.WriteLog($"SERVICE FILE PATH : {filePath}");

                WindowsServiceHelper.StopWindowsService(ApplicationEnvironment.ServiceName);

                logHelper.WriteLog($"SERVICE STOPPED : {ApplicationEnvironment.ServiceName}");

                WindowsServiceHelper.DeleteWindowsService(ApplicationEnvironment.ServiceName);

                logHelper.WriteLog($"SERVICE DELETED : {ApplicationEnvironment.ServiceName}");
            }
            catch(Exception exception)
            {
                logHelper.WriteErrorLog(exception, "ExecuteUpgradeInstallStartAction Error");
            }

            #endregion

            return ActionResult.Success;
        }

        #endregion
        #region 설치 제거 종료 액션 실행하기 - ExecuteUninstallEndAction(session)

        /// <summary>
        /// 설치 제거 종료 액션 실행하기
        /// </summary>
        /// <param name="session">세션</param>
        /// <returns>액션 결과</returns>
        [CustomAction]
        public static ActionResult ExecuteUninstallEndAction(Session session)
        {
            ILogHelper logHelper = new FileLogHelper("d:\\", "TestNode.log");

            logHelper.WriteLog($"ExecuteUninstallEndAction : {ApplicationEnvironment.Version}");

            return ActionResult.Success;
        }

        #endregion
    }
}
728x90
그리드형(광고전용)
Posted by icodebroker
,