-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathServerProcessManager.cs
More file actions
50 lines (41 loc) · 1.64 KB
/
Copy pathServerProcessManager.cs
File metadata and controls
50 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Serilog;
using StackExchange.Redis;
namespace core
{
public class ServerProcessManager
{
/// <summary>
/// Global instance
/// </summary>
public static ServerProcessManager sInstance = new ServerProcessManager();
public ConnectionMultiplexer cache = null;
public void Init( string server_addr, string cache_server_addr)
{
cache = ConnectionMultiplexer.Connect(cache_server_addr);
var db = cache.GetDatabase();
var serverProcessInfo = new ServerProcess();
serverProcessInfo.ProcessId = Process.GetCurrentProcess().Id;
serverProcessInfo.ProcessName = Process.GetCurrentProcess().ProcessName;
serverProcessInfo.WorkingDirectory = System.IO.Directory.GetCurrentDirectory();
serverProcessInfo.ServerAddress = server_addr;
serverProcessInfo.SubmitTime = DateTime.UtcNow;
db.HashSet("server_info", $"{server_addr}", JsonConvert.SerializeObject(serverProcessInfo));
}
public async Task<List<ServerProcess>> GetServerProesss()
{
List<ServerProcess> serverProcesses = new List<ServerProcess>();
var entry = await cache.GetDatabase().HashGetAllAsync("server_info");
for (int i = 0; i < entry.Length; ++i)
{
serverProcesses.Add(JsonConvert.DeserializeObject<ServerProcess>(entry[i].Value));
}
return serverProcesses;
}
}
}