Code inspections
This commit is contained in:
+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