diff --git a/WelsonJS.Toolkit/WelsonJS.Service/MessageReceiver.cs b/WelsonJS.Toolkit/WelsonJS.Service/MessageReceiver.cs
new file mode 100644
index 0000000..4465f2c
--- /dev/null
+++ b/WelsonJS.Toolkit/WelsonJS.Service/MessageReceiver.cs
@@ -0,0 +1,78 @@
+// MessageReceiver.cs
+// https://github.com/gnh1201/welsonjs
+using DeviceId;
+using Grpc.Core;
+using Grpc.Net.Client;
+using System.ServiceProcess;
+using System.Threading.Tasks;
+using WelsonJS.GrpcService;
+
+namespace WelsonJS.Service
+{
+ public class MessageReceiver
+ {
+ private GrpcChannel channel;
+ private ServiceMain parent;
+ private string deviceId;
+
+ public MessageReceiver(ServiceBase parent, string workingDirectory)
+ {
+ this.parent = (ServiceMain)parent;
+
+ // Read the device ID on this computer
+ deviceId = new DeviceIdBuilder()
+ .OnWindows(windows => windows.AddWindowsDeviceId())
+ .ToString();
+
+ // Read configuration from settings.ini
+ try
+ {
+ // Get the GRPC server URL from settings
+ string grpcServerAddress = this.parent.GetSettingsFileHandler().Read("GRPC_SERVER_ADDRESS");
+
+ // Set the GRPC channel
+ channel = GrpcChannel.ForAddress(grpcServerAddress);
+ }
+ catch
+ {
+ channel = null;
+ }
+ }
+
+ public void Start()
+ {
+ if (channel != null)
+ {
+ Task.Run(() => GetTask());
+ }
+ else
+ {
+ parent.Log("Not Initializd GRPC channel");
+ }
+
+ }
+
+ private async Task GetTask()
+ {
+ try
+ {
+ var client = new MessageController.MessageControllerClient(channel);
+
+ var request = new MessageRequest {
+ ClientId = deviceId
+ };
+ var call = client.SendMessageStream(request);
+
+ while (await call.ResponseStream.MoveNext())
+ {
+ var response = call.ResponseStream.Current;
+ parent.Log($"Received: {response.Message}");
+ }
+ }
+ finally
+ {
+ channel?.Dispose();
+ }
+ }
+ }
+}
diff --git a/WelsonJS.Toolkit/WelsonJS.Service/Protos/WelsonJS.GrpcService.proto b/WelsonJS.Toolkit/WelsonJS.Service/Protos/WelsonJS.GrpcService.proto
new file mode 100644
index 0000000..b3b542f
--- /dev/null
+++ b/WelsonJS.Toolkit/WelsonJS.Service/Protos/WelsonJS.GrpcService.proto
@@ -0,0 +1,15 @@
+syntax = "proto3";
+
+option csharp_namespace = "WelsonJS.GrpcService";
+
+service MessageController {
+ rpc SendMessageStream (MessageRequest) returns (stream MessageReply);
+}
+
+message MessageRequest {
+ string clientId = 1;
+}
+
+message MessageReply {
+ string message = 1;
+}
\ No newline at end of file
diff --git a/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs b/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs
index f590ccd..f9ac891 100644
--- a/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs
+++ b/WelsonJS.Toolkit/WelsonJS.Service/ServiceMain.cs
@@ -50,7 +50,7 @@ namespace WelsonJS.Service
private bool disabledFileMonitor = false;
private ScreenMatching screenMatcher;
private FileEventMonitor fileEventMonitor;
- private IniFile settingsController;
+ private IniFile settingsFileHandler;
[DllImport("user32.dll")]
private static extern int GetSystemMetrics(int nIndex);
@@ -111,11 +111,11 @@ namespace WelsonJS.Service
{
try
{
- settingsController = new IniFile(settingsFilePath);
+ settingsFileHandler = new IniFile(settingsFilePath);
}
catch (Exception)
{
- settingsController = null;
+ settingsFileHandler = null;
}
}
@@ -137,19 +137,6 @@ namespace WelsonJS.Service
defaultTimer.Elapsed += OnElapsedTime;
timers.Add(defaultTimer);
- // Trace an event of file creation
- if (!disabledFileMonitor)
- {
- fileEventMonitor = new FileEventMonitor(this, workingDirectory);
- fileEventMonitor.Start();
-
- Log("File Event Monitor started.");
- }
- else
- {
- Log("Disabled the File Event Monitor (Sysinternals Sysmon based file event monitor)");
- }
-
// check this session is the user interactive mode
if (Environment.UserInteractive) {
this.OnUserInteractiveEnvironment();
@@ -164,6 +151,11 @@ namespace WelsonJS.Service
Log(appName + " Service Loaded");
}
+ public IniFile GetSettingsFileHandler()
+ {
+ return settingsFileHandler;
+ }
+
internal void TestStartupAndStop()
{
this.OnStart(this.args);
@@ -175,7 +167,7 @@ namespace WelsonJS.Service
{
base.OnStart(args);
- // check the script file exists
+ // Check exists the entry script file
if (File.Exists(scriptFilePath))
{
Log($"Script file found: {scriptFilePath}");
@@ -205,7 +197,25 @@ namespace WelsonJS.Service
Log($"Script file not found: {scriptFilePath}");
}
- timers.ForEach(timer => timer?.Start()); // start
+ // Trace a Sysmon file events (If Sysinternals Sysmon installed)
+ if (!disabledFileMonitor)
+ {
+ fileEventMonitor = new FileEventMonitor(this, workingDirectory);
+ fileEventMonitor.Start();
+
+ Log("Trace a Sysmon file events (If Sysinternals Sysmon installed) started.");
+ }
+ else
+ {
+ Log("Trace a Sysmon file events (If Sysinternals Sysmon installed) is disabled");
+ }
+
+ // Start GRPC based message receiver
+ MessageReceiver receiver = new MessageReceiver(this, workingDirectory);
+ receiver.Start();
+
+ // Start all the registered timers
+ timers.ForEach(timer => timer?.Start());
Log(appName + " Service Started");
}
diff --git a/WelsonJS.Toolkit/WelsonJS.Service/WelsonJS.Service.csproj b/WelsonJS.Toolkit/WelsonJS.Service/WelsonJS.Service.csproj
index 5322866..21dcc8f 100644
--- a/WelsonJS.Toolkit/WelsonJS.Service/WelsonJS.Service.csproj
+++ b/WelsonJS.Toolkit/WelsonJS.Service/WelsonJS.Service.csproj
@@ -1,5 +1,6 @@
+
@@ -82,10 +83,37 @@
+
+ ..\packages\DeviceId.6.7.0\lib\net40\DeviceId.dll
+
+
+ ..\packages\DeviceId.Windows.6.6.0\lib\net40\DeviceId.Windows.dll
+
+
+ ..\packages\Google.Protobuf.3.27.3\lib\net45\Google.Protobuf.dll
+
+
+ ..\packages\Grpc.Core.2.46.6\lib\net45\Grpc.Core.dll
+
+
+ ..\packages\Grpc.Core.Api.2.65.0\lib\net462\Grpc.Core.Api.dll
+
+
+ ..\packages\Grpc.Net.Client.2.65.0\lib\net462\Grpc.Net.Client.dll
+
+
+ ..\packages\Grpc.Net.Common.2.65.0\lib\netstandard2.0\Grpc.Net.Common.dll
+
..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll
+
+ ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.1\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll
+
+
+ ..\packages\Microsoft.Extensions.Logging.Abstractions.8.0.1\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll
+
..\packages\RestSharp.111.4.1\lib\net48\RestSharp.dll
@@ -95,12 +123,18 @@
+
+ ..\packages\System.Diagnostics.DiagnosticSource.8.0.1\lib\net462\System.Diagnostics.DiagnosticSource.dll
+
..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll
+
+ ..\packages\System.Net.Http.WinHttpHandler.8.0.2\lib\net462\System.Net.Http.WinHttpHandler.dll
+
..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll
@@ -127,6 +161,7 @@
+
Component
@@ -172,11 +207,21 @@
WelsonJS.Toolkit
+
+
+ Always
+
+
이 프로젝트는 이 컴퓨터에 없는 NuGet 패키지를 참조합니다. 해당 패키지를 다운로드하려면 NuGet 패키지 복원을 사용하십시오. 자세한 내용은 http://go.microsoft.com/fwlink/?LinkID=322105를 참조하십시오. 누락된 파일은 {0}입니다.
+
+
+
+
+
\ No newline at end of file
diff --git a/WelsonJS.Toolkit/WelsonJS.Service/app.config b/WelsonJS.Toolkit/WelsonJS.Service/app.config
index f9833da..c942ff2 100644
--- a/WelsonJS.Toolkit/WelsonJS.Service/app.config
+++ b/WelsonJS.Toolkit/WelsonJS.Service/app.config
@@ -7,6 +7,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WelsonJS.Toolkit/WelsonJS.Service/packages.config b/WelsonJS.Toolkit/WelsonJS.Service/packages.config
index 9f75793..22fe122 100644
--- a/WelsonJS.Toolkit/WelsonJS.Service/packages.config
+++ b/WelsonJS.Toolkit/WelsonJS.Service/packages.config
@@ -1,10 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/WelsonJS.Toolkit/WelsonJS.Toolkit/TinyINIController/IniFile.cs b/WelsonJS.Toolkit/WelsonJS.Toolkit/TinyINIController/IniFile.cs
index d9c6b70..4e47530 100644
--- a/WelsonJS.Toolkit/WelsonJS.Toolkit/TinyINIController/IniFile.cs
+++ b/WelsonJS.Toolkit/WelsonJS.Toolkit/TinyINIController/IniFile.cs
@@ -4,7 +4,9 @@ using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
-// https://github.com/niklyadov/tiny-ini-file-class
+// TinyINIController
+// Original source code: https://github.com/niklyadov/tiny-ini-file-class
+
namespace WelsonJS.TinyINIController
{
public class IniFile
@@ -17,14 +19,15 @@ namespace WelsonJS.TinyINIController
private readonly FileInfo FileInfo;
- private readonly string exe = Assembly.GetExecutingAssembly().GetName().Name;
+ //private readonly string exe = Assembly.GetExecutingAssembly().GetName().Name;
+ private readonly string defaultSection = "Default";
private readonly FileAccess fileAccess;
public IniFile(string path = null, FileAccess access = FileAccess.ReadWrite)
{
fileAccess = access;
- FileInfo = new FileInfo(path ?? exe);
+ FileInfo = new FileInfo(path ?? defaultSection);
}
public string Read(string key, string section = null)
@@ -33,7 +36,7 @@ namespace WelsonJS.TinyINIController
if (fileAccess != FileAccess.Write)
{
- GetPrivateProfileString(section ?? exe, key, "", RetVal, 65025, FileInfo.FullName);
+ GetPrivateProfileString(section ?? defaultSection, key, "", RetVal, 65025, FileInfo.FullName);
}
else
{
@@ -46,7 +49,7 @@ namespace WelsonJS.TinyINIController
{
if (fileAccess != FileAccess.Read)
{
- WritePrivateProfileString(section ?? exe, key, value, FileInfo.FullName);
+ WritePrivateProfileString(section ?? defaultSection, key, value, FileInfo.FullName);
}
else
{
@@ -56,12 +59,12 @@ namespace WelsonJS.TinyINIController
public void DeleteKey(string key, string section = null)
{
- Write(key, null, section ?? exe);
+ Write(key, null, section ?? defaultSection);
}
public void DeleteSection(string section = null)
{
- Write(null, null, section ?? exe);
+ Write(null, null, section ?? defaultSection);
}
public bool KeyExists(string key, string section = null)