Update WelsonJS.Service component

This commit is contained in:
Namhyeon Go 2024-07-22 18:47:08 +09:00
parent 7c6c633362
commit 239b039e2a
9 changed files with 260 additions and 19 deletions

View File

@ -15,7 +15,7 @@ namespace WelsonJS.Service
ServiceBase[] ServicesToRun; ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] ServicesToRun = new ServiceBase[]
{ {
new Service1() new ServiceMain()
}; };
ServiceBase.Run(ServicesToRun); ServiceBase.Run(ServicesToRun);
} }

View File

@ -0,0 +1,61 @@
namespace WelsonJS.Service
{
partial class ProjectInstaller
{
/// <summary>
/// 필수 디자이너 변수입니다.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 사용 중인 모든 리소스를 정리합니다.
/// </summary>
/// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 디자이너 지원에 필요한 메서드입니다.
/// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
/// </summary>
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;
}
}

View File

@ -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();
}
}
}

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="serviceProcessInstaller1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="serviceInstaller1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>195, 17</value>
</metadata>
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
</root>

View File

@ -1,6 +1,6 @@
namespace WelsonJS.Service namespace WelsonJS.Service
{ {
partial class Service1 partial class ServiceMain
{ {
/// <summary> /// <summary>
/// 필수 디자이너 변수입니다. /// 필수 디자이너 변수입니다.

View File

@ -4,22 +4,27 @@ using System.Timers;
using MSScriptControl; using MSScriptControl;
using System.IO; using System.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
namespace WelsonJS.Service namespace WelsonJS.Service
{ {
public partial class Service1 : ServiceBase public partial class ServiceMain : ServiceBase
{ {
private Timer timer; private Timer timer;
private string workingDirectory; private string workingDirectory;
private string scriptFilePath; private string scriptFilePath;
private string scriptText; private string scriptText;
private string scriptName;
private ScriptControl scriptControl; private ScriptControl scriptControl;
private string appName; private string logFilePath;
private readonly string logFileName = "ServiceLog.txt"; private readonly string appName = "WelsonJS";
public Service1() public ServiceMain()
{ {
InitializeComponent(); InitializeComponent();
// set the log file path
logFilePath = Path.Combine(Path.GetTempPath(), "WelsonJS.ServiceLog.txt");
} }
protected override void OnStart(string[] args) protected override void OnStart(string[] args)
@ -34,8 +39,8 @@ namespace WelsonJS.Service
workingDirectory = entry.Value; workingDirectory = entry.Value;
break; break;
case "app-name": case "script-name":
appName = entry.Value; scriptName = entry.Value;
break; break;
} }
} }
@ -43,9 +48,10 @@ namespace WelsonJS.Service
// set working directory // set working directory
if (string.IsNullOrEmpty(workingDirectory)) 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."); Log("Working directory not provided. Using default value.");
} }
/*
Directory.SetCurrentDirectory(workingDirectory); Directory.SetCurrentDirectory(workingDirectory);
// set script file path // set script file path
@ -68,7 +74,8 @@ namespace WelsonJS.Service
} }
// initialize // initialize
InvokeScriptMethod("initializeService", appName, "start"); InvokeScriptMethod("initializeService", scriptName, "start");
*/
// set interval // set interval
timer = new Timer(); timer = new Timer();
@ -79,15 +86,15 @@ namespace WelsonJS.Service
protected override void OnStop() protected override void OnStop()
{ {
InvokeScriptMethod("initializeService", appName, "stop"); //InvokeScriptMethod("initializeService", scriptName, "stop");
timer.Stop(); timer.Stop();
scriptControl.Reset(); //scriptControl.Reset();
scriptControl = null; //scriptControl = null;
} }
private void OnElapsedTime(object source, ElapsedEventArgs e) private void OnElapsedTime(object source, ElapsedEventArgs e)
{ {
InvokeScriptMethod("initializeService", appName, "elapsedTime"); //InvokeScriptMethod("initializeService", scriptName, "elapsedTime");
} }
private string InvokeScriptMethod(string methodName, params object[] parameters) private string InvokeScriptMethod(string methodName, params object[] parameters)
@ -97,7 +104,6 @@ namespace WelsonJS.Service
private void Log(string message) private void Log(string message)
{ {
string logFilePath = Path.Combine(workingDirectory, logFileName);
using (StreamWriter writer = new StreamWriter(logFilePath, true)) using (StreamWriter writer = new StreamWriter(logFilePath, true))
{ {
writer.WriteLine($"{DateTime.Now}: {message}"); writer.WriteLine($"{DateTime.Now}: {message}");

View File

@ -33,18 +33,26 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Management" />
<Reference Include="System.ServiceProcess" /> <Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Service1.cs"> <Compile Include="ServiceMain.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="Service1.Designer.cs"> <Compile Include="ServiceMain.Designer.cs">
<DependentUpon>Service1.cs</DependentUpon> <DependentUpon>ServiceMain.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="ProjectInstaller.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ProjectInstaller.Designer.cs">
<DependentUpon>ProjectInstaller.cs</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -58,5 +66,10 @@
<EmbedInteropTypes>True</EmbedInteropTypes> <EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference> </COMReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="ProjectInstaller.resx">
<DependentUpon>ProjectInstaller.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 17.8.34322.80
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WelsonJS.Toolkit", "WelsonJS.Toolkit\WelsonJS.Toolkit.csproj", "{D6007282-B4F7-4694-AC67-BB838D91B77A}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WelsonJS.Toolkit", "WelsonJS.Toolkit\WelsonJS.Toolkit.csproj", "{D6007282-B4F7-4694-AC67-BB838D91B77A}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WelsonJS.Service", "WelsonJS.Service\WelsonJS.Service.csproj", "{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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.ActiveCfg = Release|x64
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Release|x64.Build.0 = Release|x64 {D6007282-B4F7-4694-AC67-BB838D91B77A}.Release|x64.Build.0 = Release|x64
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Release|x86.ActiveCfg = Release|Any CPU {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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

3
app.js
View File

@ -589,7 +589,8 @@ function initializeService(name, eventType) {
(function(action) { (function(action) {
if (eventType in action) { if (eventType in action) {
try { try {
action[eventType](); var f = action[eventType];
if (typeof f === "function") f();
} catch (e) { } catch (e) {
console.error("Exception:", e.message); console.error("Exception:", e.message);
} }