From 85c77787ce93f05022188399975f3b81c2a2a30c Mon Sep 17 00:00:00 2001 From: Colin Dawson Date: Tue, 12 Nov 2019 10:35:03 +0000 Subject: [PATCH 1/4] Added unit test for getting site count --- Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 0d86815..47d4ba3 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -215,6 +215,17 @@ namespace Meade.net.Telescope.UnitTests Assert.That(exception.Message, Is.EqualTo($"Site {parameters} not allowed, must be between 1 and 4")); } + [Test] + public void Action_Site_Count_WhenCalling_ThenReturnsFour() + { + ConnectTelescope(); + + string parameters = $"Count"; + var result = _telescope.Action("site", parameters); + + Assert.That(result, Is.EqualTo("4")); + } + [TestCase("1", "#:SMHome#", "Home")] [TestCase("2", "#:SNClub#", "Club")] [TestCase("3", "#:SOGPS Site#", "GPS Site")] From 25d88b0609b34f46eb8c5249b2bb4742a2e90c32 Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 30 Nov 2019 19:15:06 +0000 Subject: [PATCH 2/4] Set global com visible to false and only exposed the classes that need to be. --- Meade.net.Telescope/Properties/AssemblyInfo.cs | 2 +- Meade.net.Telescope/Telescope.cs | 1 + Meade.net.focuser/Focuser.cs | 1 + Meade.net.focuser/Properties/AssemblyInfo.cs | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Meade.net.Telescope/Properties/AssemblyInfo.cs b/Meade.net.Telescope/Properties/AssemblyInfo.cs index ab1142a..4604c64 100644 --- a/Meade.net.Telescope/Properties/AssemblyInfo.cs +++ b/Meade.net.Telescope/Properties/AssemblyInfo.cs @@ -18,7 +18,7 @@ using System.Runtime.InteropServices; // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(true)] +[assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("8b9fccb9-87ae-42f7-90af-079e13de6efb")] diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index c77994f..67ad2b8 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -35,6 +35,7 @@ namespace ASCOM.Meade.net [ProgId("ASCOM.MeadeGeneric.Telescope")] [ServedClassName("Meade Generic")] [ClassInterface(ClassInterfaceType.None)] + [ComVisible(true)] public class Telescope : ReferenceCountedObjectBase, ITelescopeV3 { /// diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index 51787bf..e92e611 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -30,6 +30,7 @@ namespace ASCOM.Meade.net [ProgId("ASCOM.MeadeGeneric.focuser")] [ServedClassName("Meade Generic")] [ClassInterface(ClassInterfaceType.None)] + [ComVisible(true)] public class Focuser : ReferenceCountedObjectBase, IFocuserV3 { /// diff --git a/Meade.net.focuser/Properties/AssemblyInfo.cs b/Meade.net.focuser/Properties/AssemblyInfo.cs index 46c7ed0..d77e77d 100644 --- a/Meade.net.focuser/Properties/AssemblyInfo.cs +++ b/Meade.net.focuser/Properties/AssemblyInfo.cs @@ -18,7 +18,7 @@ using System.Runtime.InteropServices; // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(true)] +[assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("4ad7a6d4-6d54-4a9a-bbf3-895353e318f8")] From 1185770a94dc6698d3d7a7970f97426217f83ed4 Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 1 Dec 2019 00:11:13 +0000 Subject: [PATCH 3/4] Added try catch to the default constructor to show the details of an error if something goes wrong. --- .../TelescopeUnitTests.cs | 2 +- Meade.net.Telescope/Telescope.cs | 48 +++++++++++++++---- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 47d4ba3..df3637c 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -220,7 +220,7 @@ namespace Meade.net.Telescope.UnitTests { ConnectTelescope(); - string parameters = $"Count"; + string parameters = "Count"; var result = _telescope.Action("site", parameters); Assert.That(result, Is.EqualTo("4")); diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index 67ad2b8..96173de 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -5,6 +5,8 @@ using System.Collections; using System.Globalization; using System.Reflection; using System.Runtime.InteropServices; +using System.Text; +using System.Windows.Forms; using ASCOM.Astrometry; using ASCOM.Astrometry.AstroUtils; using ASCOM.Astrometry.NOVAS; @@ -79,15 +81,45 @@ namespace ASCOM.Meade.net /// public Telescope() { - //todo move this out to IOC - var util = new Util(); //Initialise util object - _utilities = util; - _utilitiesExtra = util; //Initialise util object - _astroUtilities = new AstroUtils(); // Initialise astro utilities object - _sharedResourcesWrapper = new SharedResourcesWrapper(); - _astroMaths = new AstroMaths.AstroMaths(); + try + { + //todo move this out to IOC + var util = new Util(); //Initialise util object + _utilities = util; + _utilitiesExtra = util; //Initialise util object + _astroUtilities = new AstroUtils(); // Initialise astro utilities object + _sharedResourcesWrapper = new SharedResourcesWrapper(); + _astroMaths = new AstroMaths.AstroMaths(); - Initialise(); + Initialise(); + } + catch (Exception e) + { + StringBuilder sb = new StringBuilder(); + + var currentException = e; + + while (currentException != null) + { + AppendException(sb, currentException); + + currentException = currentException.InnerException; + + if (currentException != null) + sb.AppendLine("-----"); + } + + MessageBox.Show(sb.ToString()); + throw; + } + } + + private void AppendException(StringBuilder sb, Exception currentException) + { + sb.AppendLine(currentException.Message); + sb.AppendLine(); + sb.AppendLine(currentException.StackTrace); + sb.AppendLine(); } public Telescope( IUtil util, IUtilExtra utilExtra, IAstroUtils astroUtilities, ISharedResourcesWrapper sharedResourcesWrapper, IAstroMaths astroMaths) From 97810b5575ecbc83fafe172c757680115fda4a13 Mon Sep 17 00:00:00 2001 From: Colin Date: Mon, 2 Dec 2019 12:39:03 +0000 Subject: [PATCH 4/4] Attempt ad fixing the double.parse error. --- Meade.net/SharedResources.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 21ae49c..b391c15 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -149,7 +149,7 @@ namespace ASCOM.Meade.net driverProfile.DeviceType = "Telescope"; driverProfile.WriteValue(DriverId, TraceStateProfileName, profileProperties.TraceLogger.ToString()); driverProfile.WriteValue(DriverId, ComPortProfileName, profileProperties.ComPort); - driverProfile.WriteValue(DriverId, GuideRateProfileName, profileProperties.GuideRateArcSecondsPerSecond.ToString(CultureInfo.CurrentCulture)); + driverProfile.WriteValue(DriverId, GuideRateProfileName, profileProperties.GuideRateArcSecondsPerSecond.ToString(CultureInfo.InvariantCulture)); driverProfile.WriteValue(DriverId, PrecisionProfileName, profileProperties.Precision); } } @@ -170,7 +170,7 @@ namespace ASCOM.Meade.net driverProfile.DeviceType = "Telescope"; profileProperties.ComPort = driverProfile.GetValue(DriverId, ComPortProfileName, string.Empty, ComPortDefault); profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(DriverId, TraceStateProfileName, string.Empty, TraceStateDefault)); - profileProperties.GuideRateArcSecondsPerSecond = double.Parse(driverProfile.GetValue(DriverId, GuideRateProfileName, string.Empty, GuideRateProfileNameDefault)); + profileProperties.GuideRateArcSecondsPerSecond = double.Parse(driverProfile.GetValue(DriverId, GuideRateProfileName, string.Empty, GuideRateProfileNameDefault), NumberFormatInfo.InvariantInfo); profileProperties.Precision = driverProfile.GetValue(DriverId, PrecisionProfileName, string.Empty, PrecisionDefault); }