Compare commits
No commits in common. "dd4c3ef28fc91611faf4baaa851f8025a431d6c5" and "96eb6ad0509a61b82f8478b30e6ad712548cabff" have entirely different histories.
dd4c3ef28f
...
96eb6ad050
57
Common/DemoMessageAndExceptionHandling.cs
Normal file
57
Common/DemoMessageAndExceptionHandling.cs
Normal file
@ -0,0 +1,57 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -18,8 +18,7 @@ namespace Sample
|
||||
static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("HiAPI starting.");
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
|
||||
LocalApp.AppBegin();
|
||||
|
||||
Console.WriteLine("Hello World! HiAPI.");
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using Hi.Common.XmlUtils;
|
||||
using Hi.Common.XmlUtils;
|
||||
using Hi.Geom;
|
||||
using Hi.Mech;
|
||||
using Hi.Mech.Topo;
|
||||
@ -25,7 +25,7 @@ namespace Sample.MachineTool
|
||||
{
|
||||
static DemoBuildMachineTool()
|
||||
{
|
||||
XFactory.Regs.Add(XName, (xml, baseDirectory, relFile, progress, res) => new DemoBuildMachineTool());
|
||||
XFactory.Regs.Add(XName, (xml, baseDirectory, relFile, res) => new DemoBuildMachineTool());
|
||||
}
|
||||
/// <summary>
|
||||
/// Generates an XYZ-ABC machine tool instance from embedded resources.
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using Hi.Common.XmlUtils;
|
||||
using Hi.Common.XmlUtils;
|
||||
using Hi.Geom;
|
||||
using Hi.MachiningProcs;
|
||||
using Hi.Mech.Topo;
|
||||
@ -42,8 +42,7 @@ public static class DemoBuildGeomOnlyMachiningProject
|
||||
|
||||
static void Main()
|
||||
{
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
|
||||
LocalApp.AppBegin();
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
var projectPath = "C:/HiNC-Projects/NewProject/Main.hincproj";
|
||||
@ -83,10 +82,9 @@ public static class DemoBuildGeomOnlyMachiningProject
|
||||
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
|
||||
};
|
||||
|
||||
IProgress<object> progress = null;
|
||||
localProjectService.MachiningChain
|
||||
= XFactory.GenByFile<CodeXyzabcMachineTool>(
|
||||
"Resource", "MachineTool/PMC-B1/PMC-B1.mt", progress);
|
||||
"Resource", "MachineTool/PMC-B1/PMC-B1.mt", GenMode.Default);
|
||||
localProjectService.MachiningChainFile = "PMC-B1/PMC-B1.mt";
|
||||
|
||||
localProjectService.SaveProject();
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using Hi.Milling.Apts;
|
||||
using Hi.Common.XmlUtils;
|
||||
using Hi.Geom;
|
||||
@ -142,8 +142,7 @@ public static class DemoBuildMachiningProject
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
|
||||
LocalApp.AppBegin();
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
var projectPath = "C:/HiNC-Projects/NewProject/Main.hincproj";
|
||||
@ -152,8 +151,6 @@ public static class DemoBuildMachiningProject
|
||||
localProjectService.LoadProject(projectPath);
|
||||
MachiningProject machiningProject = localProjectService.MachiningProject;
|
||||
|
||||
IProgress<object> progress = null;
|
||||
|
||||
#region ConfigureMachiningToolHouse
|
||||
localProjectService.MachiningToolHouse = new MachiningToolHouse()
|
||||
{
|
||||
@ -197,16 +194,16 @@ public static class DemoBuildMachiningProject
|
||||
IdealGeom = null,
|
||||
WorkpieceGeomToFixtureBuckleTransformer = new StaticTranslation(new Vec3d(0, 0, 0)),
|
||||
CuttingPara = XFactory.GenByFile<ICuttingPara>(
|
||||
"Resource/CuttingParameter", "Al6061T6.mp", progress),
|
||||
"Resource/CuttingParameter", "Al6061T6.mp", GenMode.Default),
|
||||
WorkpieceMaterial = XFactory.GenByFile<WorkpieceMaterial>(
|
||||
"Resource/WorkpieceMaterial", "Al6061T6.WorkpieceMaterial", progress),
|
||||
"Resource/WorkpieceMaterial", "Al6061T6.WorkpieceMaterial", GenMode.Default),
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region ConfigureMachineChain
|
||||
localProjectService.MachiningChain
|
||||
= XFactory.GenByFile<CodeXyzabcMachineTool>(
|
||||
"Resource", "MachineTool/PMC-B1/PMC-B1.mt", progress);
|
||||
"Resource", "MachineTool/PMC-B1/PMC-B1.mt", GenMode.Default);
|
||||
#endregion
|
||||
|
||||
machiningProject.MakeXmlSourceToFile(projectPath);
|
||||
|
||||
@ -21,8 +21,7 @@ public static class DemoUseMachiningProject
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
using var loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(b => b.AddConsole());
|
||||
LocalApp.AppBegin(loggerFactory.CreateLogger("Hi.Sample"));
|
||||
LocalApp.AppBegin();
|
||||
LocalProjectService localProjectService = new LocalProjectService();
|
||||
|
||||
#region ProjectLoading
|
||||
|
||||
@ -4,8 +4,8 @@ using Hi.Disp;
|
||||
using Hi.Geom;
|
||||
using Hi.Mech.Topo;
|
||||
|
||||
namespace Sample.Mech;
|
||||
|
||||
namespace Sample.Mech
|
||||
{
|
||||
/// <summary>
|
||||
/// Demonstrates the creation and visualization of mechanical assemblies with kinematic linkages.
|
||||
/// Shows how to build coordinate systems, establish kinematic relationships, and capture visual output.
|
||||
@ -79,3 +79,4 @@ public static class DemoTopo1
|
||||
SnapshotToFile(GetDemoAsmb());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user