Trying to reduce code duplication

This commit is contained in:
2020-09-03 23:34:04 +01:00
parent 47d0a047a5
commit d728dbe272
4 changed files with 35 additions and 23 deletions
+5 -7
View File
@@ -40,6 +40,11 @@ namespace ASCOM.Meade.net
[ComVisible(true)] [ComVisible(true)]
public class Telescope : MeadeTelescopeBase, ITelescopeV3 public class Telescope : MeadeTelescopeBase, ITelescopeV3
{ {
static Telescope()
{
ClassName = nameof(Telescope);
}
/// <summary> /// <summary>
/// ASCOM DeviceID (COM ProgID) for this driver. /// ASCOM DeviceID (COM ProgID) for this driver.
/// The DeviceID is used by ASCOM applications to load the driver at runtime. /// The DeviceID is used by ASCOM applications to load the driver at runtime.
@@ -2225,13 +2230,6 @@ namespace ASCOM.Meade.net
#region ASCOM Registration #region ASCOM Registration
private static IProfileFactory _profileFactory;
public static IProfileFactory ProfileFactory
{
get => _profileFactory ?? (_profileFactory = new ProfileFactory());
set => _profileFactory = value;
}
// Register or unregister driver for ASCOM. This is harmless if already // Register or unregister driver for ASCOM. This is harmless if already
// registered or unregistered. // registered or unregistered.
// //
+7 -9
View File
@@ -32,6 +32,11 @@ namespace ASCOM.Meade.net
[ComVisible(true)] [ComVisible(true)]
public class Focuser : MeadeTelescopeBase, IFocuserV3 public class Focuser : MeadeTelescopeBase, IFocuserV3
{ {
static Focuser()
{
ClassName = nameof(Focuser);
}
/// <summary> /// <summary>
/// ASCOM DeviceID (COM ProgID) for this driver. /// ASCOM DeviceID (COM ProgID) for this driver.
/// The DeviceID is used by ASCOM applications to load the driver at runtime. /// The DeviceID is used by ASCOM applications to load the driver at runtime.
@@ -264,6 +269,7 @@ namespace ASCOM.Meade.net
} }
private readonly int _maxStep = 7000; private readonly int _maxStep = 7000;
public int MaxStep public int MaxStep
{ {
get get
@@ -409,14 +415,6 @@ namespace ASCOM.Meade.net
#region ASCOM Registration #region ASCOM Registration
private static IProfileFactory _profileFactory;
public static IProfileFactory ProfileFactory
{
get => _profileFactory ?? (_profileFactory = new ProfileFactory());
set => _profileFactory = value;
}
// Register or unregister driver for ASCOM. This is harmless if already // Register or unregister driver for ASCOM. This is harmless if already
// registered or unregistered. // registered or unregistered.
// //
@@ -429,7 +427,7 @@ namespace ASCOM.Meade.net
{ {
using (IProfileWrapper p = ProfileFactory.Create()) using (IProfileWrapper p = ProfileFactory.Create())
{ {
p.DeviceType = "Focuser"; p.DeviceType = ClassName;
if (bRegister) if (bRegister)
{ {
p.Register(DriverId, DriverDescription); p.Register(DriverId, DriverDescription);
+22 -5
View File
@@ -9,6 +9,13 @@ namespace ASCOM.Meade.net
[ComVisible(false)] [ComVisible(false)]
public class MeadeTelescopeBase : ReferenceCountedObjectBase public class MeadeTelescopeBase : ReferenceCountedObjectBase
{ {
static MeadeTelescopeBase()
{
ClassName = nameof(MeadeTelescopeBase);
}
public static string ClassName { get; protected set; }
/// <summary> /// <summary>
/// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify) /// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify)
/// </summary> /// </summary>
@@ -41,16 +48,14 @@ namespace ASCOM.Meade.net
protected void Initialise() protected void Initialise()
{ {
var typeName = GetType().Name; Tl = new TraceLogger("", $"Meade.Generic.{ClassName}");
Tl = new TraceLogger("", $"Meade.Generic.{typeName}");
ReadProfile(); // Read device configuration from the ASCOM Profile store ReadProfile(); // Read device configuration from the ASCOM Profile store
IsConnected = false; // Initialise connected to false IsConnected = false; // Initialise connected to false
LogMessage(typeName, "Completed initialisation"); LogMessage(ClassName, "Completed initialisation");
LogMessage(typeName, $"Driver version: {DriverVersion}"); LogMessage(ClassName, $"Driver version: {DriverVersion}");
} }
/// <summary> /// <summary>
@@ -123,5 +128,17 @@ namespace ASCOM.Meade.net
return driverVersion; return driverVersion;
} }
} }
#region ASCOM Registration
private static IProfileFactory _profileFactory;
public static IProfileFactory ProfileFactory
{
get => _profileFactory ?? (_profileFactory = new ProfileFactory());
set => _profileFactory = value;
}
#endregion
} }
} }
+1 -2
View File
@@ -309,8 +309,7 @@ namespace ASCOM.Meade.net
//Returns: sHH# or sHH.H# //Returns: sHH# or sHH.H#
//The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the
//sHH# form is returned, otherwise the longer form is returned. //sHH# form is returned, otherwise the longer form is returned.
double utcOffsetHours; if (!double.TryParse(utcOffSet, out var utcOffsetHours))
if (!double.TryParse(utcOffSet, out utcOffsetHours))
{ {
var message = "Unable to decode response from the telescope, This is likely a hardware serial communications error."; var message = "Unable to decode response from the telescope, This is likely a hardware serial communications error.";
traceLogger.LogIssue("Connect", message); traceLogger.LogIssue("Connect", message);