Code inspections

This commit is contained in:
2019-07-19 14:33:41 +01:00
parent 9cf63c4912
commit 0e98f0e370
5 changed files with 60 additions and 70 deletions
+1 -1
View File
@@ -79,7 +79,7 @@ namespace ASCOM.Meade.net
// //
internal AxisRates(TelescopeAxes axis) internal AxisRates(TelescopeAxes axis)
{ {
this._axis = axis; _axis = axis;
// //
// This collection must hold zero or more Rate objects describing the // This collection must hold zero or more Rate objects describing the
// rates of motion ranges for the Telescope.MoveAxis() method // rates of motion ranges for the Telescope.MoveAxis() method
+10 -10
View File
@@ -38,14 +38,14 @@ namespace ASCOM.Meade.net
/// 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.
/// </summary> /// </summary>
//internal static string driverID = "ASCOM.Meade.net.Focuser"; //internal static string driverID = "ASCOM.Meade.net.Focuser";
internal static string DriverId = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType); private static readonly string DriverId = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType);
// TODO Change the descriptive string for your driver then remove this line // TODO Change the descriptive string for your driver then remove this line
/// <summary> /// <summary>
/// Driver description that displays in the ASCOM Chooser. /// Driver description that displays in the ASCOM Chooser.
/// </summary> /// </summary>
private static string _driverDescription = "Meade Generic"; private static readonly string DriverDescription = "Meade Generic";
internal static string ComPort; // Variables to hold the currrent device configuration private static string _comPort; // Variables to hold the currrent device configuration
/// <summary> /// <summary>
/// Private variable to hold an ASCOM Utilities object /// Private variable to hold an ASCOM Utilities object
@@ -193,12 +193,12 @@ namespace ASCOM.Meade.net
} }
catch (Exception ex) catch (Exception ex)
{ {
LogMessage("Connected Set", "Error connecting to port {0} - {1}", ComPort, ex.Message); LogMessage("Connected Set", "Error connecting to port {0} - {1}", _comPort, ex.Message);
} }
} }
else else
{ {
LogMessage("Connected Set", "Disconnecting from port {0}", ComPort); LogMessage("Connected Set", "Disconnecting from port {0}", _comPort);
_sharedResourcesWrapper.Disconnect("Serial"); _sharedResourcesWrapper.Disconnect("Serial");
IsConnected = false; IsConnected = false;
} }
@@ -241,8 +241,8 @@ namespace ASCOM.Meade.net
// TODO customise this device description // TODO customise this device description
get get
{ {
Tl.LogMessage("Description Get", _driverDescription); Tl.LogMessage("Description Get", DriverDescription);
return _driverDescription; return DriverDescription;
} }
} }
@@ -284,7 +284,7 @@ namespace ASCOM.Meade.net
get get
{ {
//string name = "Short driver name - please customise"; //string name = "Short driver name - please customise";
string name = _driverDescription; string name = DriverDescription;
Tl.LogMessage("Name Get", name); Tl.LogMessage("Name Get", name);
return name; return name;
} }
@@ -496,7 +496,7 @@ namespace ASCOM.Meade.net
p.DeviceType = "Focuser"; p.DeviceType = "Focuser";
if (bRegister) if (bRegister)
{ {
p.Register(DriverId, _driverDescription); p.Register(DriverId, DriverDescription);
} }
else else
{ {
@@ -577,7 +577,7 @@ namespace ASCOM.Meade.net
{ {
var profileProperties = _sharedResourcesWrapper.ReadProfile(); var profileProperties = _sharedResourcesWrapper.ReadProfile();
Tl.Enabled = profileProperties.TraceLogger; Tl.Enabled = profileProperties.TraceLogger;
ComPort = profileProperties.ComPort; _comPort = profileProperties.ComPort;
} }
/// <summary> /// <summary>
+30 -40
View File
@@ -33,8 +33,8 @@ namespace ASCOM.Meade.net
#region Access to ole32.dll functions for class factories #region Access to ole32.dll functions for class factories
// Define two common GUID objects for public usage. // Define two common GUID objects for public usage.
public static Guid IidIUnknown = new Guid("{00000000-0000-0000-C000-000000000046}"); private static Guid _iidIUnknown = new Guid("{00000000-0000-0000-C000-000000000046}");
public static Guid IidIDispatch = new Guid("{00020400-0000-0000-C000-000000000046}"); private static Guid _iidIDispatch = new Guid("{00020400-0000-0000-C000-000000000046}");
[Flags] [Flags]
enum Clsctx : uint enum Clsctx : uint
@@ -109,70 +109,60 @@ namespace ASCOM.Meade.net
#region Constructor and Private ClassFactory Data #region Constructor and Private ClassFactory Data
protected readonly Type MClassType; private readonly Type _mClassType;
protected Guid MClassId; private Guid _mClassId;
protected readonly ArrayList MInterfaceTypes; private readonly ArrayList _mInterfaceTypes;
protected uint MClassContext; private UInt32 _mLocked = 0;
protected uint MFlags; private uint _mCookie;
protected UInt32 MLocked = 0; private readonly string _mProgid;
protected uint MCookie;
protected string MProgid;
public ClassFactory(Type type) public ClassFactory(Type type)
{ {
if (type == null) if (type == null)
throw new ArgumentNullException("type"); throw new ArgumentNullException("type");
MClassType = type; _mClassType = type;
//PWGS Get the ProgID from the MetaData //PWGS Get the ProgID from the MetaData
MProgid = Marshal.GenerateProgIdForType(type); _mProgid = Marshal.GenerateProgIdForType(type);
MClassId = Marshal.GenerateGuidForType(type); // Should be nailed down by [Guid(...)] _mClassId = Marshal.GenerateGuidForType(type); // Should be nailed down by [Guid(...)]
MClassContext = (uint)Clsctx.ClsctxLocalServer; // Default ClassContext = (uint)Clsctx.ClsctxLocalServer; // Default
MFlags = (uint)Regcls.RegclsMultipleuse | // Default Flags = (uint)Regcls.RegclsMultipleuse | // Default
(uint)Regcls.RegclsSuspended; (uint)Regcls.RegclsSuspended;
MInterfaceTypes = new ArrayList(); _mInterfaceTypes = new ArrayList();
foreach (Type T in type.GetInterfaces()) // Save all of the implemented interfaces foreach (Type T in type.GetInterfaces()) // Save all of the implemented interfaces
MInterfaceTypes.Add(T); _mInterfaceTypes.Add(T);
} }
#endregion #endregion
#region Common ClassFactory Methods #region Common ClassFactory Methods
public uint ClassContext public uint ClassContext { get; set; }
{
get => MClassContext;
set => MClassContext = value;
}
public Guid ClassId public Guid ClassId
{ {
get => MClassId; get => _mClassId;
set => MClassId = value; set => _mClassId = value;
} }
public uint Flags public uint Flags { get; set; }
{
get => MFlags;
set => MFlags = value;
}
public bool RegisterClassObject() public bool RegisterClassObject()
{ {
// Register the class factory // Register the class factory
int i = CoRegisterClassObject int i = CoRegisterClassObject
( (
ref MClassId, ref _mClassId,
this, this,
MClassContext, ClassContext,
MFlags, Flags,
out MCookie out _mCookie
); );
return (i == 0); return (i == 0);
} }
public bool RevokeClassObject() public bool RevokeClassObject()
{ {
int i = CoRevokeClassObject(MCookie); int i = CoRevokeClassObject(_mCookie);
return (i == 0); return (i == 0);
} }
@@ -201,25 +191,25 @@ namespace ASCOM.Meade.net
// //
// Handle specific requests for implemented interfaces // Handle specific requests for implemented interfaces
// //
foreach (Type iType in MInterfaceTypes) foreach (Type iType in _mInterfaceTypes)
{ {
if (riid == Marshal.GenerateGuidForType(iType)) if (riid == Marshal.GenerateGuidForType(iType))
{ {
ppvObject = Marshal.GetComInterfaceForObject(Activator.CreateInstance(MClassType), iType); ppvObject = Marshal.GetComInterfaceForObject(Activator.CreateInstance(_mClassType), iType);
return; return;
} }
} }
// //
// Handle requests for IDispatch or IUnknown on the class // Handle requests for IDispatch or IUnknown on the class
// //
if (riid == IidIDispatch) if (riid == _iidIDispatch)
{ {
ppvObject = Marshal.GetIDispatchForObject(Activator.CreateInstance(MClassType)); ppvObject = Marshal.GetIDispatchForObject(Activator.CreateInstance(_mClassType));
return; return;
} }
else if (riid == IidIUnknown) else if (riid == _iidIUnknown)
{ {
ppvObject = Marshal.GetIUnknownForObject(Activator.CreateInstance(MClassType)); ppvObject = Marshal.GetIUnknownForObject(Activator.CreateInstance(_mClassType));
} }
else else
{ {
+14 -14
View File
@@ -8,17 +8,17 @@ namespace ASCOM.Meade.net
/// </summary> /// </summary>
class GarbageCollection class GarbageCollection
{ {
protected bool MBContinueThread; private bool _mbContinueThread;
protected bool MGcWatchStopped; private bool _mGcWatchStopped;
protected int MIInterval; private readonly int _miInterval;
protected ManualResetEvent MEventThreadEnded; private readonly ManualResetEvent _mEventThreadEnded;
public GarbageCollection(int iInterval) public GarbageCollection(int iInterval)
{ {
MBContinueThread = true; _mbContinueThread = true;
MGcWatchStopped = false; _mGcWatchStopped = false;
MIInterval = iInterval; _miInterval = iInterval;
MEventThreadEnded = new ManualResetEvent(false); _mEventThreadEnded = new ManualResetEvent(false);
} }
public void GcWatch() public void GcWatch()
@@ -27,16 +27,16 @@ namespace ASCOM.Meade.net
while (ContinueThread()) while (ContinueThread())
{ {
GC.Collect(); GC.Collect();
Thread.Sleep(MIInterval); Thread.Sleep(_miInterval);
} }
MEventThreadEnded.Set(); _mEventThreadEnded.Set();
} }
protected bool ContinueThread() protected bool ContinueThread()
{ {
lock (this) lock (this)
{ {
return MBContinueThread; return _mbContinueThread;
} }
} }
@@ -44,14 +44,14 @@ namespace ASCOM.Meade.net
{ {
lock (this) lock (this)
{ {
MBContinueThread = false; _mbContinueThread = false;
} }
} }
public void WaitForThreadToStop() public void WaitForThreadToStop()
{ {
MEventThreadEnded.WaitOne(); _mEventThreadEnded.WaitOne();
MEventThreadEnded.Reset(); _mEventThreadEnded.Reset();
} }
} }
} }
+5 -5
View File
@@ -153,11 +153,11 @@ namespace ASCOM.Meade.net
#region Profile #region Profile
internal static string DriverId = "ASCOM.MeadeGeneric.Telescope"; private const string DriverId = "ASCOM.MeadeGeneric.Telescope";
// Constants used for Profile persistence // Constants used for Profile persistence
internal static string ComPortProfileName = "COM Port"; private const string ComPortProfileName = "COM Port";
internal static string TraceStateProfileName = "Trace Level"; private const string TraceStateProfileName = "Trace Level";
public static void WriteProfile(ProfileProperties profileProperties) public static void WriteProfile(ProfileProperties profileProperties)
{ {
@@ -172,8 +172,8 @@ namespace ASCOM.Meade.net
} }
} }
private static readonly string ComPortDefault = "COM1"; private const string ComPortDefault = "COM1";
internal static string TraceStateDefault = "false"; private const string TraceStateDefault = "false";
public static ProfileProperties ReadProfile() public static ProfileProperties ReadProfile()
{ {