refactor(demos): update machining demos and remove legacy demo message handling

Made-with: Cursor
This commit is contained in:
iamboss 2026-04-08 16:33:17 +08:00
parent 96eb6ad050
commit e5ea1961a5
5 changed files with 8 additions and 61 deletions

View File

@ -1,57 +0,0 @@
using System;
using System.Threading.Tasks;
using Hi.Common;
using Hi.Common.Messages;
namespace Sample.Common;
/// <summary>
/// Demonstrates common message and exception handling patterns in HiAPI applications
/// </summary>
/// <remarks>
/// ### Source Code
/// [!code-csharp[SampleCode](~/../Hi.Sample/Common/DemoMessageAndExceptionHandling.cs)]
/// </remarks>
public static class DemoMessageAndExceptionHandling
{
/// <summary>
/// Demonstrates normal message handling
/// </summary>
internal static void DemoNormalMessages()
{
#region Normal_Messages
MessageUtil.ReportMessage("Operation completed successfully.");
MessageUtil.ReportWarning("Please check your input.");
#endregion
}
/// <summary>
/// Demonstrates exception handling in synchronous code
/// </summary>
internal static void DemoSynchronousExceptionHandling()
{
#region Sync_Exception
try
{
// Your code here
throw new NotImplementedException("Demo exception");
}
catch (Exception ex)
{
ExceptionUtil.ShowException(ex, null);
}
#endregion
}
/// <summary>
/// Demonstrates exception handling in asynchronous code
/// </summary>
internal static async Task DemoAsynchronousExceptionHandling()
{
#region Async_Exception
await Task.Run(() =>
{
// Your async operation here
throw new NotImplementedException("Demo async exception");
}).ShowIfCatched(null);
#endregion
}
}

View File

@ -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.");

View File

@ -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";

View File

@ -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";

View File

@ -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