Code inspections
This commit is contained in:
@@ -30,10 +30,10 @@ namespace ASCOM.Meade.net
|
||||
public static class SharedResources
|
||||
{
|
||||
// object used for locking to prevent multiple drivers accessing common code at the same time
|
||||
private static readonly object lockObject = new object();
|
||||
private static readonly object LockObject = new object();
|
||||
|
||||
// Shared serial port. This will allow multiple drivers to use one single serial port.
|
||||
private static Serial s_sharedSerial; // Shared serial port
|
||||
private static Serial _sSharedSerial; // Shared serial port
|
||||
|
||||
//
|
||||
// Public access to shared resources
|
||||
@@ -58,7 +58,7 @@ namespace ASCOM.Meade.net
|
||||
/// <summary>
|
||||
/// Shared serial port
|
||||
/// </summary>
|
||||
public static Serial SharedSerial => s_sharedSerial ?? (s_sharedSerial = new Serial());
|
||||
public static Serial SharedSerial => _sSharedSerial ?? (_sSharedSerial = new Serial());
|
||||
|
||||
/// <summary>
|
||||
/// number of connections to the shared serial port
|
||||
@@ -67,7 +67,7 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public static void SendBlind(string message)
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
SharedSerial.ClearBuffers();
|
||||
SharedSerial.Transmit(message);
|
||||
@@ -90,7 +90,7 @@ namespace ASCOM.Meade.net
|
||||
/// <returns></returns>
|
||||
public static string SendString(string message)
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
SharedSerial.ClearBuffers();
|
||||
SharedSerial.Transmit(message);
|
||||
@@ -100,7 +100,7 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public static string SendChar(string message)
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
SharedSerial.ClearBuffers();
|
||||
SharedSerial.Transmit(message);
|
||||
@@ -110,7 +110,7 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public static string ReadTerminated()
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
return SharedSerial.ReceiveTerminated("#");
|
||||
}
|
||||
@@ -128,7 +128,7 @@ namespace ASCOM.Meade.net
|
||||
{
|
||||
set
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
@@ -153,40 +153,40 @@ namespace ASCOM.Meade.net
|
||||
|
||||
#region Profile
|
||||
|
||||
internal static string driverID = "ASCOM.MeadeGeneric.Telescope";
|
||||
internal static string DriverId = "ASCOM.MeadeGeneric.Telescope";
|
||||
|
||||
// Constants used for Profile persistence
|
||||
internal static string comPortProfileName = "COM Port";
|
||||
internal static string traceStateProfileName = "Trace Level";
|
||||
internal static string ComPortProfileName = "COM Port";
|
||||
internal static string TraceStateProfileName = "Trace Level";
|
||||
|
||||
public static void WriteProfile(ProfileProperties profileProperties)
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
using (Profile driverProfile = new Profile())
|
||||
{
|
||||
driverProfile.DeviceType = "Telescope";
|
||||
driverProfile.WriteValue(driverID, traceStateProfileName, profileProperties.TraceLogger.ToString());
|
||||
driverProfile.WriteValue(driverID, comPortProfileName, profileProperties.ComPort);
|
||||
driverProfile.WriteValue(DriverId, TraceStateProfileName, profileProperties.TraceLogger.ToString());
|
||||
driverProfile.WriteValue(DriverId, ComPortProfileName, profileProperties.ComPort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly string comPortDefault = "COM1";
|
||||
internal static string traceStateDefault = "false";
|
||||
private static readonly string ComPortDefault = "COM1";
|
||||
internal static string TraceStateDefault = "false";
|
||||
|
||||
public static ProfileProperties ReadProfile()
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
ProfileProperties profileProperties = new ProfileProperties();
|
||||
using (Profile driverProfile = new Profile())
|
||||
{
|
||||
driverProfile.DeviceType = "Telescope";
|
||||
profileProperties.ComPort =
|
||||
driverProfile.GetValue(driverID, comPortProfileName, string.Empty, comPortDefault);
|
||||
profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(driverID,
|
||||
traceStateProfileName, string.Empty, traceStateDefault));
|
||||
driverProfile.GetValue(DriverId, ComPortProfileName, string.Empty, ComPortDefault);
|
||||
profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(DriverId,
|
||||
TraceStateProfileName, string.Empty, TraceStateDefault));
|
||||
}
|
||||
|
||||
return profileProperties;
|
||||
@@ -209,14 +209,14 @@ namespace ASCOM.Meade.net
|
||||
|
||||
var profileProperties = ReadProfile();
|
||||
|
||||
using (SetupDialogForm F = new SetupDialogForm())
|
||||
using (SetupDialogForm f = new SetupDialogForm())
|
||||
{
|
||||
F.SetProfile(profileProperties);
|
||||
f.SetProfile(profileProperties);
|
||||
|
||||
var result = F.ShowDialog();
|
||||
var result = f.ShowDialog();
|
||||
if (result == System.Windows.Forms.DialogResult.OK)
|
||||
{
|
||||
profileProperties = F.GetProfile();
|
||||
profileProperties = f.GetProfile();
|
||||
|
||||
WriteProfile(profileProperties); // Persist device configuration values to the ASCOM Profile store
|
||||
}
|
||||
@@ -244,7 +244,7 @@ namespace ASCOM.Meade.net
|
||||
/// The Key is the connection number that identifies the device, it could be the COM port name,
|
||||
/// USB ID or IP Address, the Value is the DeviceHardware class
|
||||
/// </summary>
|
||||
private static Dictionary<string, DeviceHardware> connectedDevices = new Dictionary<string, DeviceHardware>();
|
||||
private static Dictionary<string, DeviceHardware> _connectedDevices = new Dictionary<string, DeviceHardware>();
|
||||
|
||||
/// <summary>
|
||||
/// This is called in the driver Connect(true) property,
|
||||
@@ -253,15 +253,15 @@ namespace ASCOM.Meade.net
|
||||
/// <param name="deviceId"></param>
|
||||
public static void Connect(string deviceId)
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
if (!connectedDevices.ContainsKey(deviceId))
|
||||
connectedDevices.Add(deviceId, new DeviceHardware());
|
||||
connectedDevices[deviceId].count++; // increment the value
|
||||
if (!_connectedDevices.ContainsKey(deviceId))
|
||||
_connectedDevices.Add(deviceId, new DeviceHardware());
|
||||
_connectedDevices[deviceId].Count++; // increment the value
|
||||
|
||||
if (deviceId == "Serial")
|
||||
{
|
||||
if (connectedDevices[deviceId].count == 1)
|
||||
if (_connectedDevices[deviceId].Count == 1)
|
||||
{
|
||||
var profileProperties = ReadProfile();
|
||||
SharedSerial.PortName = profileProperties.ComPort;
|
||||
@@ -283,14 +283,14 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public static void Disconnect(string deviceId)
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
if (connectedDevices.ContainsKey(deviceId))
|
||||
if (_connectedDevices.ContainsKey(deviceId))
|
||||
{
|
||||
connectedDevices[deviceId].count--;
|
||||
if (connectedDevices[deviceId].count <= 0)
|
||||
_connectedDevices[deviceId].Count--;
|
||||
if (_connectedDevices[deviceId].Count <= 0)
|
||||
{
|
||||
connectedDevices.Remove(deviceId);
|
||||
_connectedDevices.Remove(deviceId);
|
||||
if (deviceId == "Serial")
|
||||
{
|
||||
SharedSerial.Connected = false;
|
||||
@@ -302,8 +302,8 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public static bool IsConnected(string deviceId)
|
||||
{
|
||||
if (connectedDevices.ContainsKey(deviceId))
|
||||
return (connectedDevices[deviceId].count > 0);
|
||||
if (_connectedDevices.ContainsKey(deviceId))
|
||||
return (_connectedDevices[deviceId].Count > 0);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
@@ -312,7 +312,7 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public static void Lock(Action action)
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
action();
|
||||
}
|
||||
@@ -320,7 +320,7 @@ namespace ASCOM.Meade.net
|
||||
|
||||
public static T Lock<T>(Func<T> func)
|
||||
{
|
||||
lock (lockObject)
|
||||
lock (LockObject)
|
||||
{
|
||||
return func();
|
||||
}
|
||||
@@ -334,7 +334,7 @@ namespace ASCOM.Meade.net
|
||||
{
|
||||
private int _count;
|
||||
|
||||
internal int count
|
||||
internal int Count
|
||||
{
|
||||
set => _count = value;
|
||||
get => _count;
|
||||
@@ -342,7 +342,7 @@ namespace ASCOM.Meade.net
|
||||
|
||||
internal DeviceHardware()
|
||||
{
|
||||
count = 0;
|
||||
Count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user