本地星尘客户端。连接本机星尘代理StarAgent

This commit is contained in:
大石头 2020-11-29 23:40:38 +08:00
parent 12cee8148f
commit 29beca49c4
2 changed files with 61 additions and 1 deletions

View File

@ -0,0 +1,61 @@
using System;
using System.Diagnostics;
using NewLife;
using NewLife.Log;
using NewLife.Remoting;
namespace Stardust
{
/// <summary>本地星尘客户端。连接本机星尘代理StarAgent</summary>
public class LocalStarClient
{
#region
private ApiClient _client;
#endregion
#region
#endregion
#region
private void Init()
{
if (_client != null) return;
_client = new ApiClient("udp://127.0.0.1:5500")
{
Log = XTrace.Log,
};
var set = Setting.Current;
if (set.Debug) _client.EncoderLog = XTrace.Log;
}
#endregion
#region
/// <summary>自杀并重启</summary>
/// <returns></returns>
public Boolean KillAndRestartMySelf()
{
Init();
var p = Process.GetCurrentProcess();
var fileName = p.MainModule.FileName;
// 发起命令
var rs = _client.Invoke<String>("KillAndStart", new
{
processId = p.Id,
delay = 3,
fileName = fileName,
arguments = Environment.CommandLine,
workingDirectory = Environment.CurrentDirectory,
});
// 本进程退出
//p.Kill();
return !rs.IsNullOrEmpty();
}
#endregion
}
}

View File

@ -7,7 +7,6 @@ using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using NewLife;
using NewLife.Http;