Update WelsonJS.Service component

This commit is contained in:
Namhyeon Go 2024-07-22 20:15:31 +09:00
parent 239b039e2a
commit 7456bf903e
6 changed files with 155 additions and 33 deletions

View File

@ -10,14 +10,22 @@ namespace WelsonJS.Service
/// <summary>
/// 해당 애플리케이션의 주 진입점입니다.
/// </summary>
static void Main()
static void Main(string[] args)
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
if (Environment.UserInteractive)
{
new ServiceMain()
};
ServiceBase.Run(ServicesToRun);
ServiceMain svc = new ServiceMain();
svc.TestStartupAndStop(args);
}
else
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new ServiceMain()
};
ServiceBase.Run(ServicesToRun);
}
}
}
}

View File

@ -4,7 +4,6 @@ using System.Timers;
using MSScriptControl;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
namespace WelsonJS.Service
{
@ -24,7 +23,15 @@ namespace WelsonJS.Service
InitializeComponent();
// set the log file path
logFilePath = Path.Combine(Path.GetTempPath(), "WelsonJS.ServiceLog.txt");
logFilePath = Path.Combine(Path.GetTempPath(), "WelsonJS.Service.Log.txt");
Log(appName + " Service Loaded");
}
internal void TestStartupAndStop(string[] args)
{
this.OnStart(args);
Console.ReadLine();
this.OnStop();
}
protected override void OnStart(string[] args)
@ -48,53 +55,86 @@ namespace WelsonJS.Service
// set working directory
if (string.IsNullOrEmpty(workingDirectory))
{
workingDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), appName);
Log("Working directory not provided. Using default value.");
workingDirectory = Path.Combine(Path.GetTempPath(), appName);
Log("Working directory not provided. Using default value: " + workingDirectory);
if (!Directory.Exists(workingDirectory))
{
Directory.CreateDirectory(workingDirectory);
Log("Directory created: " + workingDirectory);
}
}
/*
Directory.SetCurrentDirectory(workingDirectory);
// set script file path
// set path of the script
scriptFilePath = Path.Combine(workingDirectory, "app.js");
// try load the script
// check the script file exists
if (File.Exists(scriptFilePath))
{
scriptText = File.ReadAllText(scriptFilePath);
scriptControl = new ScriptControl
Log($"Script file found: {scriptFilePath}");
try
{
Language = "JScript",
AllowUI = false
};
scriptControl.AddCode(scriptText);
// load the script
scriptText = File.ReadAllText(scriptFilePath);
scriptControl = new ScriptControl
{
Language = "JScript",
AllowUI = false
};
scriptControl.AddCode(scriptText);
// initialize
InvokeScriptMethod("initializeService", scriptName, "start");
}
catch (Exception ex)
{
Log("Exception. " + ex.Message);
}
}
else
{
Log($"Script file not found: {scriptFilePath}");
}
// initialize
InvokeScriptMethod("initializeService", scriptName, "start");
*/
// set interval
timer = new Timer();
timer.Interval = 60000; // 1 minute
timer.Elapsed += OnElapsedTime;
timer.Start();
Log(appName + " Service Started");
}
protected override void OnStop()
{
//InvokeScriptMethod("initializeService", scriptName, "stop");
timer.Stop();
//scriptControl.Reset();
//scriptControl = null;
try
{
InvokeScriptMethod("initializeService", scriptName, "stop");
scriptControl.Reset();
}
catch (Exception ex)
{
Log("Exception. " + ex.Message);
}
scriptControl = null;
Log(appName + " Service Stopped");
}
private void OnElapsedTime(object source, ElapsedEventArgs e)
{
//InvokeScriptMethod("initializeService", scriptName, "elapsedTime");
try
{
InvokeScriptMethod("initializeService", scriptName, "elapsedTime");
}
catch (Exception ex)
{
Log("Exception. " + ex.Message);
}
}
private string InvokeScriptMethod(string methodName, params object[] parameters)

View File

@ -8,9 +8,10 @@
<OutputType>WinExe</OutputType>
<RootNamespace>WelsonJS.Service</RootNamespace>
<AssemblyName>WelsonJS.Service</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -21,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -30,8 +32,54 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
@ -64,6 +112,7 @@
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
<Private>True</Private>
</COMReference>
</ItemGroup>
<ItemGroup>
@ -71,5 +120,8 @@
<DependentUpon>ProjectInstaller.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

View File

@ -21,7 +21,8 @@ Global
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Debug|x64.ActiveCfg = Debug|x64
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Debug|x64.Build.0 = Debug|x64
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Debug|x86.ActiveCfg = Debug|Any CPU
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Debug|x86.ActiveCfg = Debug|x86
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Debug|x86.Build.0 = Debug|x86
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Release|Any CPU.Build.0 = Release|Any CPU
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Release|x64.ActiveCfg = Release|x64
@ -29,10 +30,10 @@ Global
{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}.Debug|x64.ActiveCfg = Debug|x64
{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x64.Build.0 = Debug|x64
{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x86.ActiveCfg = Debug|x86
{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x86.Build.0 = Debug|x86
{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

View File

@ -59,6 +59,24 @@
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />