mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-03-12 00:45:14 +00:00
Update WelsonJS.Service component
This commit is contained in:
parent
239b039e2a
commit
7456bf903e
|
@ -10,14 +10,22 @@ namespace WelsonJS.Service
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 해당 애플리케이션의 주 진입점입니다.
|
/// 해당 애플리케이션의 주 진입점입니다.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
static void Main()
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
ServiceBase[] ServicesToRun;
|
if (Environment.UserInteractive)
|
||||||
ServicesToRun = new ServiceBase[]
|
|
||||||
{
|
{
|
||||||
new ServiceMain()
|
ServiceMain svc = new ServiceMain();
|
||||||
};
|
svc.TestStartupAndStop(args);
|
||||||
ServiceBase.Run(ServicesToRun);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ServiceBase[] ServicesToRun;
|
||||||
|
ServicesToRun = new ServiceBase[]
|
||||||
|
{
|
||||||
|
new ServiceMain()
|
||||||
|
};
|
||||||
|
ServiceBase.Run(ServicesToRun);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -24,7 +23,15 @@ namespace WelsonJS.Service
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
// set the log file path
|
// 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)
|
protected override void OnStart(string[] args)
|
||||||
|
@ -48,53 +55,86 @@ 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), appName);
|
workingDirectory = Path.Combine(Path.GetTempPath(), appName);
|
||||||
Log("Working directory not provided. Using default value.");
|
Log("Working directory not provided. Using default value: " + workingDirectory);
|
||||||
|
|
||||||
|
if (!Directory.Exists(workingDirectory))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(workingDirectory);
|
||||||
|
Log("Directory created: " + workingDirectory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
Directory.SetCurrentDirectory(workingDirectory);
|
Directory.SetCurrentDirectory(workingDirectory);
|
||||||
|
|
||||||
// set script file path
|
// set path of the script
|
||||||
scriptFilePath = Path.Combine(workingDirectory, "app.js");
|
scriptFilePath = Path.Combine(workingDirectory, "app.js");
|
||||||
|
|
||||||
// try load the script
|
// check the script file exists
|
||||||
if (File.Exists(scriptFilePath))
|
if (File.Exists(scriptFilePath))
|
||||||
{
|
{
|
||||||
scriptText = File.ReadAllText(scriptFilePath);
|
Log($"Script file found: {scriptFilePath}");
|
||||||
scriptControl = new ScriptControl
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Language = "JScript",
|
// load the script
|
||||||
AllowUI = false
|
scriptText = File.ReadAllText(scriptFilePath);
|
||||||
};
|
scriptControl = new ScriptControl
|
||||||
scriptControl.AddCode(scriptText);
|
{
|
||||||
|
Language = "JScript",
|
||||||
|
AllowUI = false
|
||||||
|
};
|
||||||
|
scriptControl.AddCode(scriptText);
|
||||||
|
|
||||||
|
// initialize
|
||||||
|
InvokeScriptMethod("initializeService", scriptName, "start");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log("Exception. " + ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log($"Script file not found: {scriptFilePath}");
|
Log($"Script file not found: {scriptFilePath}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize
|
|
||||||
InvokeScriptMethod("initializeService", scriptName, "start");
|
|
||||||
*/
|
|
||||||
|
|
||||||
// set interval
|
// set interval
|
||||||
timer = new Timer();
|
timer = new Timer();
|
||||||
timer.Interval = 60000; // 1 minute
|
timer.Interval = 60000; // 1 minute
|
||||||
timer.Elapsed += OnElapsedTime;
|
timer.Elapsed += OnElapsedTime;
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
|
Log(appName + " Service Started");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnStop()
|
protected override void OnStop()
|
||||||
{
|
{
|
||||||
//InvokeScriptMethod("initializeService", scriptName, "stop");
|
|
||||||
timer.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)
|
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)
|
private string InvokeScriptMethod(string methodName, params object[] parameters)
|
||||||
|
|
|
@ -8,9 +8,10 @@
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<RootNamespace>WelsonJS.Service</RootNamespace>
|
<RootNamespace>WelsonJS.Service</RootNamespace>
|
||||||
<AssemblyName>WelsonJS.Service</AssemblyName>
|
<AssemblyName>WelsonJS.Service</AssemblyName>
|
||||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
@ -21,6 +22,7 @@
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
@ -30,8 +32,54 @@
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<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>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Configuration.Install" />
|
<Reference Include="System.Configuration.Install" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
|
@ -64,6 +112,7 @@
|
||||||
<WrapperTool>tlbimp</WrapperTool>
|
<WrapperTool>tlbimp</WrapperTool>
|
||||||
<Isolated>False</Isolated>
|
<Isolated>False</Isolated>
|
||||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||||
|
<Private>True</Private>
|
||||||
</COMReference>
|
</COMReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -71,5 +120,8 @@
|
||||||
<DependentUpon>ProjectInstaller.cs</DependentUpon>
|
<DependentUpon>ProjectInstaller.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="app.config" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
3
WelsonJS.Toolkit/WelsonJS.Service/app.config
Normal file
3
WelsonJS.Toolkit/WelsonJS.Service/app.config
Normal 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>
|
|
@ -21,7 +21,8 @@ Global
|
||||||
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{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.ActiveCfg = Debug|x64
|
||||||
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Debug|x64.Build.0 = 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.ActiveCfg = Release|Any CPU
|
||||||
{D6007282-B4F7-4694-AC67-BB838D91B77A}.Release|Any CPU.Build.0 = 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
|
{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
|
{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.ActiveCfg = Debug|Any CPU
|
||||||
{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Debug|x64
|
||||||
{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x64.Build.0 = Debug|Any CPU
|
{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x64.Build.0 = Debug|x64
|
||||||
{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x86.ActiveCfg = Debug|Any CPU
|
{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Debug|x86.Build.0 = Debug|Any CPU
|
{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.ActiveCfg = Release|Any CPU
|
||||||
{09F295EE-5EDB-4327-ABBE-DDCCDF5EDD9E}.Release|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
|
||||||
|
|
|
@ -59,6 +59,24 @@
|
||||||
<LangVersion>7.3</LangVersion>
|
<LangVersion>7.3</LangVersion>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
</PropertyGroup>
|
</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>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
|
|
Loading…
Reference in New Issue
Block a user