diff --git a/XCoder/Program.cs b/XCoder/Program.cs
index c564427..2b6828a 100644
--- a/XCoder/Program.cs
+++ b/XCoder/Program.cs
@@ -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;
@@ -35,7 +33,6 @@ static class Program
Application.Run(new FrmMDI());
}
- static TimerX _timer;
static StarFactory _factory;
static StarClient _Client;
private static void StartClient()
@@ -72,42 +69,11 @@ static class Program
}
};
- // 使用跟踪
- //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();
- }
}
\ No newline at end of file
diff --git a/XCoderLinux/Program.cs b/XCoderLinux/Program.cs
index 3d4a5ac..916ef67 100644
--- a/XCoderLinux/Program.cs
+++ b/XCoderLinux/Program.cs
@@ -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;
}
}
diff --git a/XCoderLinux/XCoderLinux.csproj b/XCoderLinux/XCoderLinux.csproj
index 8c3072e..908c030 100644
--- a/XCoderLinux/XCoderLinux.csproj
+++ b/XCoderLinux/XCoderLinux.csproj
@@ -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>
@@ -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" />
@@ -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>
\ No newline at end of file