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