From e5ea1961a5443aea8dc75f1e10c984593fb169f5 Mon Sep 17 00:00:00 2001 From: iamboss Date: Wed, 8 Apr 2026 16:33:17 +0800 Subject: [PATCH] refactor(demos): update machining demos and remove legacy demo message handling Made-with: Cursor --- Common/DemoMessageAndExceptionHandling.cs | 57 ------------------- HelloHiAPI.cs | 3 +- .../DemoBuildGeomOnlyMachiningProject.cs | 3 +- Machining/DemoBuildMachiningProject.cs | 3 +- Machining/DemoUseMachiningProject.cs | 3 +- 5 files changed, 8 insertions(+), 61 deletions(-) delete mode 100644 Common/DemoMessageAndExceptionHandling.cs diff --git a/Common/DemoMessageAndExceptionHandling.cs b/Common/DemoMessageAndExceptionHandling.cs deleted file mode 100644 index b34dcd9..0000000 --- a/Common/DemoMessageAndExceptionHandling.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Threading.Tasks; -using Hi.Common; -using Hi.Common.Messages; - -namespace Sample.Common; - -/// -/// Demonstrates common message and exception handling patterns in HiAPI applications -/// -/// -/// ### Source Code -/// [!code-csharp[SampleCode](~/../Hi.Sample/Common/DemoMessageAndExceptionHandling.cs)] -/// -public static class DemoMessageAndExceptionHandling -{ - /// - /// Demonstrates normal message handling - /// - internal static void DemoNormalMessages() - { - #region Normal_Messages - MessageUtil.ReportMessage("Operation completed successfully."); - MessageUtil.ReportWarning("Please check your input."); - #endregion - } - /// - /// Demonstrates exception handling in synchronous code - /// - internal static void DemoSynchronousExceptionHandling() - { - #region Sync_Exception - try - { - // Your code here - throw new NotImplementedException("Demo exception"); - } - catch (Exception ex) - { - ExceptionUtil.ShowException(ex, null); - } - #endregion - } - /// - /// Demonstrates exception handling in asynchronous code - /// - internal static async Task DemoAsynchronousExceptionHandling() - { - #region Async_Exception - await Task.Run(() => - { - // Your async operation here - throw new NotImplementedException("Demo async exception"); - }).ShowIfCatched(null); - #endregion - } -} \ No newline at end of file diff --git a/HelloHiAPI.cs b/HelloHiAPI.cs index 05f80e4..772a908 100644 --- a/HelloHiAPI.cs +++ b/HelloHiAPI.cs @@ -18,7 +18,8 @@ namespace Sample static int Main(string[] args) { Console.WriteLine("HiAPI starting."); - LocalApp.AppBegin(); + using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole()); + LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample")); Console.WriteLine("Hello World! HiAPI."); diff --git a/Machining/DemoBuildGeomOnlyMachiningProject.cs b/Machining/DemoBuildGeomOnlyMachiningProject.cs index 9d05b29..16774fe 100644 --- a/Machining/DemoBuildGeomOnlyMachiningProject.cs +++ b/Machining/DemoBuildGeomOnlyMachiningProject.cs @@ -42,7 +42,8 @@ public static class DemoBuildGeomOnlyMachiningProject static void Main() { - LocalApp.AppBegin(); + using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole()); + LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample")); LocalProjectService localProjectService = new LocalProjectService(); var projectPath = "C:/HiNC-Projects/NewProject/Main.hincproj"; diff --git a/Machining/DemoBuildMachiningProject.cs b/Machining/DemoBuildMachiningProject.cs index c95e66d..a48f355 100644 --- a/Machining/DemoBuildMachiningProject.cs +++ b/Machining/DemoBuildMachiningProject.cs @@ -142,7 +142,8 @@ public static class DemoBuildMachiningProject [STAThread] static void Main() { - LocalApp.AppBegin(); + using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole()); + LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample")); LocalProjectService localProjectService = new LocalProjectService(); var projectPath = "C:/HiNC-Projects/NewProject/Main.hincproj"; diff --git a/Machining/DemoUseMachiningProject.cs b/Machining/DemoUseMachiningProject.cs index 82bd88a..bc65eb7 100644 --- a/Machining/DemoUseMachiningProject.cs +++ b/Machining/DemoUseMachiningProject.cs @@ -21,7 +21,8 @@ public static class DemoUseMachiningProject { static void Main() { - LocalApp.AppBegin(); + using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole()); + LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample")); LocalProjectService localProjectService = new LocalProjectService(); #region ProjectLoading