From 239b039e2a1e650ae158398012428b1206e49bd2 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Mon, 22 Jul 2024 18:47:08 +0900 Subject: [PATCH] Update WelsonJS.Service component --- WelsonJS.Toolkit/WelsonJS.Service/Program.cs | 2 +- .../ProjectInstaller.Designer.cs | 61 +++++++++ .../WelsonJS.Service/ProjectInstaller.cs | 17 +++ .../WelsonJS.Service/ProjectInstaller.resx | 129 ++++++++++++++++++ ...e1.Designer.cs => ServiceMain.Designer.cs} | 2 +- .../{Service1.cs => ServiceMain.cs} | 32 +++-- .../WelsonJS.Service/WelsonJS.Service.csproj | 19 ++- WelsonJS.Toolkit/WelsonJS.Toolkit.sln | 14 ++ app.js | 3 +- 9 files changed, 260 insertions(+), 19 deletions(-) create mode 100644 WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.Designer.cs create mode 100644 WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.cs create mode 100644 WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.resx rename WelsonJS.Toolkit/WelsonJS.Service/{Service1.Designer.cs => ServiceMain.Designer.cs} (97%) rename WelsonJS.Toolkit/WelsonJS.Service/{Service1.cs => ServiceMain.cs} (79%) diff --git a/WelsonJS.Toolkit/WelsonJS.Service/Program.cs b/WelsonJS.Toolkit/WelsonJS.Service/Program.cs index c1edf6f..79cd516 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/Program.cs +++ b/WelsonJS.Toolkit/WelsonJS.Service/Program.cs @@ -15,7 +15,7 @@ namespace WelsonJS.Service ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { - new Service1() + new ServiceMain() }; ServiceBase.Run(ServicesToRun); } diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.Designer.cs b/WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.Designer.cs new file mode 100644 index 0000000..ad02ae1 --- /dev/null +++ b/WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.Designer.cs @@ -0,0 +1,61 @@ +namespace WelsonJS.Service +{ + partial class ProjectInstaller + { + /// + /// 필수 디자이너 변수입니다. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 사용 중인 모든 리소스를 정리합니다. + /// + /// 관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region 구성 요소 디자이너에서 생성한 코드 + + /// + /// 디자이너 지원에 필요한 메서드입니다. + /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요. + /// + private void InitializeComponent() + { + this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller(); + this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller(); + // + // serviceProcessInstaller1 + // + this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem; + this.serviceProcessInstaller1.Password = null; + this.serviceProcessInstaller1.Username = null; + // + // serviceInstaller1 + // + this.serviceInstaller1.Description = "WelsonJS is the framework to build a Windows app on the Windows built-in JavaScri" + + "pt engine."; + this.serviceInstaller1.DisplayName = "WelsonJS.Service"; + this.serviceInstaller1.ServiceName = "WelsonJS.Service"; + this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic; + // + // ProjectInstaller + // + this.Installers.AddRange(new System.Configuration.Install.Installer[] { + this.serviceProcessInstaller1, + this.serviceInstaller1}); + + } + + #endregion + + private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1; + private System.ServiceProcess.ServiceInstaller serviceInstaller1; + } +} \ No newline at end of file diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.cs b/WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.cs new file mode 100644 index 0000000..4ff7df4 --- /dev/null +++ b/WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Configuration.Install; + +namespace WelsonJS.Service +{ + [RunInstaller(true)] + public partial class ProjectInstaller : System.Configuration.Install.Installer + { + public ProjectInstaller() + { + InitializeComponent(); + } + } +} diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.resx b/WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.resx new file mode 100644 index 0000000..594e034 --- /dev/null +++ b/WelsonJS.Toolkit/WelsonJS.Service/ProjectInstaller.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 195, 17 + + + False + + \ No newline at end of file diff --git a/WelsonJS.Toolkit/WelsonJS.Service/Service1.Designer.cs b/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.Designer.cs similarity index 97% rename from WelsonJS.Toolkit/WelsonJS.Service/Service1.Designer.cs rename to WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.Designer.cs index 7a6c229..dfd5fe9 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/Service1.Designer.cs +++ b/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.Designer.cs @@ -1,6 +1,6 @@ namespace WelsonJS.Service { - partial class Service1 + partial class ServiceMain { /// /// 필수 디자이너 변수입니다. diff --git a/WelsonJS.Toolkit/WelsonJS.Service/Service1.cs b/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs similarity index 79% rename from WelsonJS.Toolkit/WelsonJS.Service/Service1.cs rename to WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs index f27d67e..481ac26 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/Service1.cs +++ b/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs @@ -4,22 +4,27 @@ using System.Timers; using MSScriptControl; using System.IO; using System.Collections.Generic; +using System.Diagnostics; namespace WelsonJS.Service { - public partial class Service1 : ServiceBase + public partial class ServiceMain : ServiceBase { private Timer timer; private string workingDirectory; private string scriptFilePath; private string scriptText; + private string scriptName; private ScriptControl scriptControl; - private string appName; - private readonly string logFileName = "ServiceLog.txt"; + private string logFilePath; + private readonly string appName = "WelsonJS"; - public Service1() + public ServiceMain() { InitializeComponent(); + + // set the log file path + logFilePath = Path.Combine(Path.GetTempPath(), "WelsonJS.ServiceLog.txt"); } protected override void OnStart(string[] args) @@ -34,8 +39,8 @@ namespace WelsonJS.Service workingDirectory = entry.Value; break; - case "app-name": - appName = entry.Value; + case "script-name": + scriptName = entry.Value; break; } } @@ -43,9 +48,10 @@ namespace WelsonJS.Service // set working directory if (string.IsNullOrEmpty(workingDirectory)) { - workingDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WelsonJS"); + workingDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), appName); Log("Working directory not provided. Using default value."); } + /* Directory.SetCurrentDirectory(workingDirectory); // set script file path @@ -68,7 +74,8 @@ namespace WelsonJS.Service } // initialize - InvokeScriptMethod("initializeService", appName, "start"); + InvokeScriptMethod("initializeService", scriptName, "start"); + */ // set interval timer = new Timer(); @@ -79,15 +86,15 @@ namespace WelsonJS.Service protected override void OnStop() { - InvokeScriptMethod("initializeService", appName, "stop"); + //InvokeScriptMethod("initializeService", scriptName, "stop"); timer.Stop(); - scriptControl.Reset(); - scriptControl = null; + //scriptControl.Reset(); + //scriptControl = null; } private void OnElapsedTime(object source, ElapsedEventArgs e) { - InvokeScriptMethod("initializeService", appName, "elapsedTime"); + //InvokeScriptMethod("initializeService", scriptName, "elapsedTime"); } private string InvokeScriptMethod(string methodName, params object[] parameters) @@ -97,7 +104,6 @@ namespace WelsonJS.Service private void Log(string message) { - string logFilePath = Path.Combine(workingDirectory, logFileName); using (StreamWriter writer = new StreamWriter(logFilePath, true)) { writer.WriteLine($"{DateTime.Now}: {message}"); diff --git a/WelsonJS.Toolkit/WelsonJS.Service/WelsonJS.Service.csproj b/WelsonJS.Toolkit/WelsonJS.Service/WelsonJS.Service.csproj index 629ddf2..ae59fb0 100644 --- a/WelsonJS.Toolkit/WelsonJS.Service/WelsonJS.Service.csproj +++ b/WelsonJS.Toolkit/WelsonJS.Service/WelsonJS.Service.csproj @@ -33,18 +33,26 @@ + + - + Component - - Service1.cs + + ServiceMain.cs + + Component + + + ProjectInstaller.cs + @@ -58,5 +66,10 @@ True + + + ProjectInstaller.cs + + \ No newline at end of file diff --git a/WelsonJS.Toolkit/WelsonJS.Toolkit.sln b/WelsonJS.Toolkit/WelsonJS.Toolkit.sln index 1a3ba0e..389242d 100644 --- a/WelsonJS.Toolkit/WelsonJS.Toolkit.sln +++ b/WelsonJS.Toolkit/WelsonJS.Toolkit.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.8.34322.80 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WelsonJS.Toolkit", "WelsonJS.Toolkit\WelsonJS.Toolkit.csproj", "{D6007282-B4F7-4694-AC67-BB838D91B77A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WelsonJS.Service", "WelsonJS.Service\WelsonJS.Service.csproj", "{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -25,6 +27,18 @@ Global {D6007282-B4F7-4694-AC67-BB838D91B77A}.Release|x64.ActiveCfg = Release|x64 {D6007282-B4F7-4694-AC67-BB838D91B77A}.Release|x64.Build.0 = Release|x64 {D6007282-B4F7-4694-AC67-BB838D91B77A}.Release|x86.ActiveCfg = Release|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x64.ActiveCfg = Debug|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x64.Build.0 = Debug|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x86.ActiveCfg = Debug|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x86.Build.0 = Debug|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Release|Any CPU.Build.0 = Release|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Release|x64.ActiveCfg = Release|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Release|x64.Build.0 = Release|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Release|x86.ActiveCfg = Release|Any CPU + {09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/app.js b/app.js index eb1ab17..3699fc6 100644 --- a/app.js +++ b/app.js @@ -589,7 +589,8 @@ function initializeService(name, eventType) { (function(action) { if (eventType in action) { try { - action[eventType](); + var f = action[eventType]; + if (typeof f === "function") f(); } catch (e) { console.error("Exception:", e.message); }