diff --git a/.gitignore b/.gitignore
index 8bd2635..d691a1c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -355,4 +355,7 @@ MigrationBackup/
# ExceptionLessConfig
-exceptionless.txt
\ No newline at end of file
+exceptionless.txt
+
+# Local agent workflow state
+.superpowers/
diff --git a/Installer/SolidWorksLookup.aip b/Installer/SolidWorksLookup.aip
index 2db9f6d..592e620 100644
--- a/Installer/SolidWorksLookup.aip
+++ b/Installer/SolidWorksLookup.aip
@@ -7,8 +7,8 @@
-
-
+
+
@@ -93,7 +93,7 @@
-
+
@@ -107,13 +107,7 @@
-
-
-
-
-
-
@@ -123,7 +117,6 @@
-
@@ -132,10 +125,7 @@
-
-
-
@@ -143,26 +133,14 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -394,6 +372,6 @@
-
+
diff --git a/SldWorksLookup.sln b/SldWorksLookup.sln
index 8c90cd7..7daa64a 100644
--- a/SldWorksLookup.sln
+++ b/SldWorksLookup.sln
@@ -5,6 +5,8 @@ VisualStudioVersion = 16.0.29613.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SldWorksLookup", "SldWorksLookup\SldWorksLookup.csproj", "{94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SldWorksLookup.RegressionTests", "tests\SldWorksLookup.RegressionTests\SldWorksLookup.RegressionTests.csproj", "{4F5C2952-0D72-4F69-9294-9C8E5764086D}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -17,10 +19,18 @@ Global
{94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Debug|x64.ActiveCfg = Debug|x64
{94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Debug|x64.Build.0 = Debug|x64
- {94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Release|Any CPU.ActiveCfg = Debug|Any CPU
- {94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Release|Any CPU.Build.0 = Debug|Any CPU
- {94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Release|x64.ActiveCfg = Debug|x64
- {94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Release|x64.Build.0 = Debug|x64
+ {94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Release|Any CPU.Build.0 = Release|Any CPU
+ {94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Release|x64.ActiveCfg = Release|x64
+ {94D6A6F6-D6AF-4B2F-8D72-AFC8746C97BB}.Release|x64.Build.0 = Release|x64
+ {4F5C2952-0D72-4F69-9294-9C8E5764086D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4F5C2952-0D72-4F69-9294-9C8E5764086D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4F5C2952-0D72-4F69-9294-9C8E5764086D}.Debug|x64.ActiveCfg = Debug|x64
+ {4F5C2952-0D72-4F69-9294-9C8E5764086D}.Debug|x64.Build.0 = Debug|x64
+ {4F5C2952-0D72-4F69-9294-9C8E5764086D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4F5C2952-0D72-4F69-9294-9C8E5764086D}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4F5C2952-0D72-4F69-9294-9C8E5764086D}.Release|x64.ActiveCfg = Release|x64
+ {4F5C2952-0D72-4F69-9294-9C8E5764086D}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/SldWorksLookup/AddIn.cs b/SldWorksLookup/AddIn.cs
index fd103ad..7e0b5a4 100644
--- a/SldWorksLookup/AddIn.cs
+++ b/SldWorksLookup/AddIn.cs
@@ -15,6 +15,7 @@
using System;
using System.Linq;
using Xarial.XCad.SolidWorks.Enums;
+using SldWorksLookup.Helper;
namespace SldWorksLookup
{
@@ -24,6 +25,7 @@ namespace SldWorksLookup
[Icon(typeof(Resource),nameof(Resource.BrowseData_16x))]
public class AddIn:SwAddInEx
{
+ private readonly List _captureWindows = new List();
public override void OnConnect()
{
@@ -135,9 +137,13 @@ private void CmdGroup_CommandClick(Command_e spec)
}
catch (Exception ex)
{
- //ex.ToExceptionless(LogExtension.Client)
- // .AddTags($"CmdError:{spec}")
- // .Submit();
+ Application.ShowMessageBox(ExceptionUtil.GetUserMessage(ex), MessageBoxIcon_e.Error);
+ if (LogExtension.Client != null)
+ {
+ ex.ToExceptionless(LogExtension.Client)
+ .AddTags($"CmdError:{spec}")
+ .Submit();
+ }
}
}
@@ -173,35 +179,48 @@ private void SnoopAdvancedHole()
try
{
var featData = feat.GetDefinition() as IAdvancedHoleFeatureData;
-
- featData.AccessSelections(doc, null);
-
- var elems =(featData.GetNearSideElements() as object[]).Cast().ToList();
-
- var types = new List() {
- typeof(ICounterboreElementData),
- typeof(ICountersinkElementData),
- typeof(IStraightElementData),
- typeof(IStraightTapElementData ),
- typeof(ITaperedTapElementData)};
-
- foreach (var ele in elems)
- {
- var matchtype = types.FirstOrDefault(p => p.IsInstanceOfType(ele));
-
- ins.Add(InstanceProperty.Create(ele,matchtype ?? typeof(IAdvancedHoleElementData)));
- }
- ins.Add(InstanceProperty.Create("Base Type", typeof(string)));
- foreach (var ele in elems)
+ if (featData == null)
{
- ins.Add(InstanceProperty.Create(ele,typeof(IAdvancedHoleElementData)));
+ Application.ShowMessageBox("Cannot read advancedhole definition");
+ return;
}
- featData.ReleaseSelectionAccess();
+ SelectionAccessScope.Run(
+ () => featData.AccessSelections(doc, null),
+ () => featData.ReleaseSelectionAccess(),
+ () =>
+ {
+ var nearSideElements = featData.GetNearSideElements() as object[];
+ if (nearSideElements == null)
+ throw new InvalidOperationException("Advancedhole near-side elements are unavailable.");
+
+ var elems = nearSideElements
+ .OfType()
+ .ToList();
+
+ var types = new List() {
+ typeof(ICounterboreElementData),
+ typeof(ICountersinkElementData),
+ typeof(IStraightElementData),
+ typeof(IStraightTapElementData ),
+ typeof(ITaperedTapElementData)};
+
+ foreach (var ele in elems)
+ {
+ var matchtype = types.FirstOrDefault(p => p.IsInstanceOfType(ele));
+
+ ins.Add(InstanceProperty.Create(ele, matchtype ?? typeof(IAdvancedHoleElementData)));
+ }
+ ins.Add(InstanceProperty.Create("Base Type", typeof(string)));
+ foreach (var ele in elems)
+ {
+ ins.Add(InstanceProperty.Create(ele, typeof(IAdvancedHoleElementData)));
+ }
+ });
}
catch (System.Exception ex)
{
- Application.Sw.SendMsgToUser($"{ex.Message},{type} Cannot match a SolidWorks Interface");
+ Application.Sw.SendMsgToUser($"{ExceptionUtil.GetUserMessage(ex)},{type} Cannot match a SolidWorks Interface");
}
var selPpopWindow = CreatePopupWindow();
@@ -218,6 +237,8 @@ private void ShowColorWindow()
private void ShowCaptureWindow()
{
var window = new CaptureCmd(Application);
+ _captureWindows.Add(window);
+ window.Closed += (sender, args) => _captureWindows.Remove(window);
window?.Show();
}
@@ -227,6 +248,7 @@ private void GetObject()
if (doc == null)
{
Application.ShowMessageBox($"No active doc");
+ return;
}
var getObjectVM = new GetObjectByPIDWindowViewModel(doc, this.Application);
var window = CreatePopupWindow();
@@ -324,6 +346,11 @@ private void SnoopPID()
public override void OnDisconnect()
{
+ foreach (var window in _captureWindows.ToList())
+ {
+ window.Close();
+ }
+ _captureWindows.Clear();
LogExtension.LogEnded();
}
}
diff --git a/SldWorksLookup/Helper/ConstructionCleanup.cs b/SldWorksLookup/Helper/ConstructionCleanup.cs
new file mode 100644
index 0000000..188444c
--- /dev/null
+++ b/SldWorksLookup/Helper/ConstructionCleanup.cs
@@ -0,0 +1,20 @@
+using System;
+
+namespace SldWorksLookup.Helper
+{
+ internal static class ConstructionCleanup
+ {
+ public static void Run(Action initialize, Action cleanup)
+ {
+ try
+ {
+ initialize();
+ }
+ catch
+ {
+ cleanup();
+ throw;
+ }
+ }
+ }
+}
diff --git a/SldWorksLookup/Helper/EditScope.cs b/SldWorksLookup/Helper/EditScope.cs
new file mode 100644
index 0000000..9812163
--- /dev/null
+++ b/SldWorksLookup/Helper/EditScope.cs
@@ -0,0 +1,20 @@
+using System;
+
+namespace SldWorksLookup.Helper
+{
+ internal static class EditScope
+ {
+ public static void Run(Action enter, Action exit, Action body)
+ {
+ enter();
+ try
+ {
+ body();
+ }
+ finally
+ {
+ exit();
+ }
+ }
+ }
+}
diff --git a/SldWorksLookup/Helper/ExceptionUtil.cs b/SldWorksLookup/Helper/ExceptionUtil.cs
new file mode 100644
index 0000000..34b4cb4
--- /dev/null
+++ b/SldWorksLookup/Helper/ExceptionUtil.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Reflection;
+
+namespace SldWorksLookup.Helper
+{
+ internal static class ExceptionUtil
+ {
+ public static string GetUserMessage(Exception exception)
+ {
+ while (exception is TargetInvocationException && exception.InnerException != null)
+ {
+ exception = exception.InnerException;
+ }
+
+ if (!string.IsNullOrWhiteSpace(exception?.Message))
+ return exception.Message;
+
+ return "Command failed.";
+ }
+ }
+}
diff --git a/SldWorksLookup/Helper/ObjectMatcherUtil.cs b/SldWorksLookup/Helper/ObjectMatcherUtil.cs
index ebada21..f8e0b6e 100644
--- a/SldWorksLookup/Helper/ObjectMatcherUtil.cs
+++ b/SldWorksLookup/Helper/ObjectMatcherUtil.cs
@@ -15,15 +15,18 @@ public static bool IsArray(this object obj)
public static bool IsValueArray(this object obj)
{
- bool flag = false;
if (obj is Array array)
{
- if (array.Length > 0 && array.GetValue(0).GetType().IsValueType)
+ foreach (var item in array)
{
- flag = true;
+ if (item != null)
+ {
+ return item.GetType().IsValueType || item is string;
+ }
}
}
- return flag;
+
+ return false;
}
public static IEnumerable