Skip to content

Commit

Permalink
XCoderLinux接入星尘
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Aug 23, 2024
1 parent ef51b88 commit 6865968
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 75 deletions.
44 changes: 5 additions & 39 deletions XCoder/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System.Net.NetworkInformation;
using System.Text;
using System.Text;
using NewLife;
using NewLife.Log;
using NewLife.Threading;
using NewLife.Model;
using Stardust;
using Stardust.Models;

namespace XCoder;

Expand Down Expand Up @@ -35,7 +33,6 @@ static void Main()
Application.Run(new FrmMDI());
}

static TimerX _timer;
static StarFactory _factory;
static StarClient _Client;
private static void StartClient()
Expand Down Expand Up @@ -72,42 +69,11 @@ private static void StartClient()
}
};

// 使用跟踪
//client.UseTrace();
client.Open();

Application.ApplicationExit += (s, e) => client.Logout("ApplicationExit");

// 可能需要多次尝试
_timer = new TimerX(TryConnectServer, client, 0, 5_000) { Async = true };
//Application.ApplicationExit += (s, e) => client.Logout("ApplicationExit");
Host.RegisterExit(() => client.Logout("ApplicationExit"));

_Client = client;
}

private static async Task TryConnectServer(Object state)
{
if (!NetworkInterface.GetIsNetworkAvailable() || AgentInfo.GetIps().IsNullOrEmpty())
{
return;
}

var client = state as StarClient;

try
{
await client.Login();
//await CheckUpgrade(client);
}
catch (Exception ex)
{
// 登录报错后,加大定时间隔,输出简单日志
//_timer.Period = 30_000;
if (_timer.Period < 30_000) _timer.Period += 5_000;

XTrace.Log?.Error(ex.Message);

return;
}

_timer.TryDispose();
}
}
95 changes: 70 additions & 25 deletions XCoderLinux/Program.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,82 @@
using System;
using Gtk;
using Gtk;
using NewLife;
using NewLife.Log;
using NewLife.Model;
using Stardust;

namespace XCoder
namespace XCoder;

static class Program
{
static class Program
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
XTrace.UseConsole();
MachineInfo.RegisterAsync();
XTrace.UseConsole();
MachineInfo.RegisterAsync();

StartClient();

GLib.ExceptionManager.UnhandledException += ExceptionManager_UnhandledException;

// 检查环境
GtkHelper.CheckRuntime();

Application.Init();
var window = new SharpApp();
window.ShowAll();
// Window.InteractiveDebugging = true;
//XTrace2.UseWinForm(window);
Application.Run();
}

private static void ExceptionManager_UnhandledException(GLib.UnhandledExceptionArgs args)
{
if (args.ExceptionObject is Exception ex) XTrace.WriteException(ex);
}

GLib.ExceptionManager.UnhandledException += ExceptionManager_UnhandledException;
static StarFactory _factory;
static StarClient _Client;
private static void StartClient()
{
var set = XConfig.Current;
var server = set.Server;
if (server.IsNullOrEmpty()) return;

// 检查环境
GtkHelper.CheckRuntime();
XTrace.WriteLine("初始化服务端地址:{0}", server);

Application.Init();
var window = new SharpApp();
window.ShowAll();
// Window.InteractiveDebugging = true;
//XTrace2.UseWinForm(window);
Application.Run();
}
_factory = new StarFactory(server, "XCoderLinux", null)
{
Log = XTrace.Log,
};

private static void ExceptionManager_UnhandledException(GLib.UnhandledExceptionArgs args)
var client = new StarClient(server)
{
if (args.ExceptionObject is Exception ex) XTrace.WriteException(ex);
}
Code = set.Code,
Secret = set.Secret,
ProductCode = "XCoderLinux",

Tracer = _factory.Tracer,
Log = XTrace.Log,
};

// 登录后保存证书
client.OnLogined += (s, e) =>
{
if (client.Logined && !client.Code.IsNullOrEmpty())
{
set.Code = client.Code;
set.Secret = client.Secret;
set.Save();
}
};

client.Open();

Host.RegisterExit(() => client.Logout("ApplicationExit"));

_Client = client;
}
}
13 changes: 2 additions & 11 deletions XCoderLinux/XCoderLinux.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AssemblyTitle>新生命码神工具</AssemblyTitle>
<Description>众多开发者工具</Description>
<Company>新生命开发团队</Company>
<Copyright>©2002-2023 NewLife</Copyright>
<Copyright>©2002-2024 NewLife</Copyright>
<VersionPrefix>8.0</VersionPrefix>
<VersionSuffix>$([System.DateTime]::Now.ToString(`yyyy.MMdd`))</VersionSuffix>
<Version>$(VersionPrefix).$(VersionSuffix)</Version>
Expand Down Expand Up @@ -50,7 +50,7 @@
<ItemGroup>
<PackageReference Include="GtkSharp" Version="3.24.24.95" />
<PackageReference Include="NewLife.Core" Version="10.10.2024.803" />
<PackageReference Include="NewLife.Remoting" Version="3.0.2024.805" />
<PackageReference Include="NewLife.Stardust" Version="3.0.2024.806" />
<PackageReference Include="NewLife.XCode" Version="11.15.2024.806" />
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
<PackageReference Include="System.Management" Version="8.0.0" />
Expand All @@ -76,13 +76,4 @@
</Compile>
</ItemGroup>

<!--<ItemGroup>
<Reference Include="NewLife.Core">
<HintPath>..\..\Bin\netstandard2.1\NewLife.Core.dll</HintPath>
</Reference>
<Reference Include="XCode">
<HintPath>..\..\Bin\netstandard2.1\XCode.dll</HintPath>
</Reference>
</ItemGroup>-->

</Project>

0 comments on commit 6865968

Please sign in to comment.