星尘代理StarAgent监听全局,支持局域网搜索

This commit is contained in:
大石头 2021-11-30 15:33:22 +08:00
parent 203c22275b
commit 0bbbbdd8e2
7 changed files with 39 additions and 36 deletions

View File

@ -88,7 +88,6 @@ namespace StarAgent
}
private ApiServer _server;
private ApiServer _server2;
private TimerX _timer;
private StarClient _Client;
private StarFactory _factory;
@ -175,12 +174,12 @@ namespace StarAgent
};
// 监听端口,用于本地通信
if (!set.LocalServer.IsNullOrEmpty())
if (set.LocalPort > 0)
{
var uri = new NetUri(set.LocalServer);
//var uri = new NetUri(set.LocalServer);
try
{
var svr = new ApiServer(uri)
var svr = new ApiServer(set.LocalPort)
{
Log = XTrace.Log
};
@ -200,29 +199,6 @@ namespace StarAgent
{
XTrace.WriteException(ex);
}
try
{
var uri2 = new NetUri(NetType.Unknown, IPAddress.Any, uri.Port);
var svr2 = new ApiServer(uri2)
{
Log = XTrace.Log
};
//svr2.Register(new StarService2
//{
// Service = this,
// Host = Host,
// Manager = _Manager,
//}, null);
svr2.Manager.Services["*"] = _server.Manager.Services["Info"];
svr2.Start();
_server2 = svr2;
}
catch (Exception ex)
{
XTrace.WriteException(ex);
}
}
StartFactory();
@ -268,8 +244,6 @@ namespace StarAgent
_server.TryDispose();
_server = null;
_server2.TryDispose();
_server2 = null;
}
private async Task CheckUpgrade(Object data)

View File

@ -25,9 +25,13 @@ namespace StarAgent
[Description("密钥")]
public String Secret { get; set; }
/// <summary>本地服务。默认udp://127.0.0.1:5500</summary>
[Description("本地服务。默认udp://127.0.0.1:5500")]
public String LocalServer { get; set; } = "udp://127.0.0.1:5500";
///// <summary>本地服务。默认udp://127.0.0.1:5500</summary>
//[Description("本地服务。默认udp://127.0.0.1:5500")]
//public String LocalServer { get; set; } = "udp://127.0.0.1:5500";
/// <summary>本地端口。默认5500</summary>
[Description("本地端口。默认5500")]
public Int32 LocalPort { get; set; } = 5500;
/// <summary>更新通道。默认Release</summary>
[Description("更新通道。默认Release")]

View File

@ -19,6 +19,10 @@
<LangVersion>latest</LangVersion>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Compile Remove="StarService2.cs" />
</ItemGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" />

View File

@ -1,10 +1,12 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using NewLife;
using NewLife.Agent;
using NewLife.Log;
using NewLife.Net;
using NewLife.Reflection;
using NewLife.Remoting;
using NewLife.Serialization;
@ -15,9 +17,14 @@ using Stardust.Models;
namespace StarAgent
{
[Api(null)]
public class StarService
public class StarService : IApi
{
#region
/// <summary>
/// 网络会话
/// </summary>
public IApiSession Session { get; set; }
/// <summary>服务对象</summary>
public ServiceBase Service { get; set; }
@ -71,6 +78,7 @@ namespace StarAgent
FileName = fileName,
Arguments = args,
Server = set.Server,
Services = Manager?.Services.Select(e => e.Name).ToArray(),
};
}
@ -82,12 +90,15 @@ namespace StarAgent
/// <param name="workingDirectory">工作目录</param>
/// <returns></returns>
[Api(nameof(KillAndStart))]
public String KillAndStart(Int32 processId, Int32 delay, String fileName, String arguments, String workingDirectory)
public Object KillAndStart(Int32 processId, Int32 delay, String fileName, String arguments, String workingDirectory)
{
if (Session is INetSession ns && !ns.Remote.Address.IsLocal()) throw new InvalidOperationException("禁止非本机操作!");
var p = Process.GetProcessById(processId);
if (p == null) throw new InvalidOperationException($"无效进程Id[{processId}]");
var name = p.ProcessName;
var pid = 0;
ThreadPoolX.QueueUserWorkItem(() =>
{
@ -125,12 +136,13 @@ namespace StarAgent
};
var p2 = Process.Start(si);
pid = p2.Id;
WriteLog("应用[{0}]启动成功 PID={1}", p2.ProcessName, p2.Id);
}
});
return name;
return new { name, pid };
}
#endregion

View File

@ -262,5 +262,9 @@ namespace Stardust
});
}
#endregion
#region
#endregion
}
}

View File

@ -22,5 +22,10 @@ namespace Stardust.Models
/// <summary>服务端地址</summary>
public String Server { get; set; }
/// <summary>
/// 应用服务
/// </summary>
public String[] Services { get; set; }
}
}

View File

@ -98,7 +98,7 @@ namespace Stardust
}
catch (Exception ex)
{
if (!(ex is ArgumentException)) XTrace.WriteException(ex);
if (ex is not ArgumentException) XTrace.WriteException(ex);
}
}
if (pi == null) pi = new ProcessInfo { Name = service.Name };