Code inspection cleanup

This commit is contained in:
2019-09-28 22:20:21 +01:00
parent b962420b94
commit e782ac36fb
15 changed files with 184 additions and 187 deletions
+11 -7
View File
@@ -113,11 +113,13 @@ namespace AstroMath.UnitTests
{
var latitude = 52.0;
EquatorialCoordinates equatorialCoordinates = new EquatorialCoordinates();
equatorialCoordinates.RightAscension = 5.862222222222222;//5 51' 44"
equatorialCoordinates.Declination = 23.21944444444444;//23 13' 10"
var equatorialCoordinates = new EquatorialCoordinates
{
RightAscension = 5.862222222222222, //5 51' 44"
Declination = 23.21944444444444 //23 13' 10"
};
var hourAngle = 5.682222;
const double hourAngle = 5.682222;
var altAz = _astroMath.ConvertEqToHoz(hourAngle, latitude, equatorialCoordinates);
@@ -131,9 +133,11 @@ namespace AstroMath.UnitTests
DateTime dateTime = new DateTime(2019, 05, 18, 22, 26, 15, DateTimeKind.Utc);
var longitude = -1.7833333333333332;
var latitude = 52.0;
EquatorialCoordinates equatorialCoordinates = new EquatorialCoordinates();
equatorialCoordinates.RightAscension = 4.15361111111111;
equatorialCoordinates.Declination = 30.0019444444444;
EquatorialCoordinates equatorialCoordinates = new EquatorialCoordinates
{
RightAscension = 4.15361111111111,
Declination = 30.0019444444444
};
var hourAngle = _astroMath.RightAscensionToHourAngle(dateTime, longitude, equatorialCoordinates.RightAscension);
var altaz = _astroMath.ConvertEqToHoz(hourAngle, latitude, equatorialCoordinates);
@@ -23,11 +23,13 @@ namespace Meade.net.Focuser.UnitTests
[SetUp]
public void Setup()
{
_profileProperties = new ProfileProperties();
_profileProperties.TraceLogger = false;
_profileProperties.ComPort = "TestCom1";
_profileProperties.GuideRateArcSecondsPerSecond = 1.23;
_profileProperties.Precision = "Unchanged";
_profileProperties = new ProfileProperties
{
TraceLogger = false,
ComPort = "TestCom1",
GuideRateArcSecondsPerSecond = 1.23,
Precision = "Unchanged"
};
_utilMock = new Mock<IUtil>();
@@ -84,7 +86,7 @@ namespace Meade.net.Focuser.UnitTests
{
var actionName = "Action";
var exception = Assert.Throws<ActionNotImplementedException>(() => { var actualResult = _focuser.Action(actionName, string.Empty); });
Assert.Throws<ActionNotImplementedException>(() => { var actualResult = _focuser.Action(actionName, string.Empty); });
}
[Test]
@@ -246,8 +248,6 @@ namespace Meade.net.Focuser.UnitTests
[Test]
public void DriverInfo_Get()
{
Version version = System.Reflection.Assembly.GetAssembly(typeof(ASCOM.Meade.net.Focuser)).GetName().Version;
string exptectedDriverInfo = $"{_focuser.Description} .net driver. Version: {_focuser.DriverVersion}";
var driverInfo = _focuser.DriverInfo;
@@ -28,11 +28,13 @@ namespace Meade.net.Telescope.UnitTests
[SetUp]
public void Setup()
{
_profileProperties = new ProfileProperties();
_profileProperties.TraceLogger = false;
_profileProperties.ComPort = "TestCom1";
_profileProperties.GuideRateArcSecondsPerSecond = 1.23;
_profileProperties.Precision = "Unchanged";
_profileProperties = new ProfileProperties
{
TraceLogger = false,
ComPort = "TestCom1",
GuideRateArcSecondsPerSecond = 1.23,
Precision = "Unchanged"
};
_utilMock = new Mock<IUtil>();
_utilExtraMock = new Mock<IUtilExtra>();
@@ -521,8 +523,6 @@ namespace Meade.net.Telescope.UnitTests
[Test]
public void DriverInfo_Get()
{
Version version = System.Reflection.Assembly.GetAssembly(typeof(ASCOM.Meade.net.Telescope)).GetName().Version;
string exptectedDriverInfo = $"{_telescope.Description} .net driver. Version: {_telescope.DriverVersion}";
var driverInfo = _telescope.DriverInfo;
+5 -4
View File
@@ -9,7 +9,7 @@ namespace ASCOM.Meade.net.AstroMaths
//returns the decimal hour angle for given right ascension on a given datetime for a given logitude.
public double RightAscensionToHourAngle(DateTime utcDateTime, double longitude, double rightAscension)
{
var ut = DateTimeToDecimalHours( utcDateTime);
//var ut = DateTimeToDecimalHours( utcDateTime);
var gst = UTtoGst( utcDateTime);
var lst = GsTtoLst( gst, longitude);
var raHours = rightAscension;
@@ -82,10 +82,11 @@ namespace ASCOM.Meade.net.AstroMaths
var upperA = Math.Atan2(y, x);
var upperB = RadiansToDegrees(upperA);
var horizonCoordinates = new HorizonCoordinates();
horizonCoordinates.Altitude = RadiansToDegrees(Math.Asin(sinA));
var horizonCoordinates = new HorizonCoordinates
{
Altitude = RadiansToDegrees(Math.Asin(sinA)), Azimuth = upperB
};
horizonCoordinates.Azimuth = upperB;
if (upperB < 0)
{
+14 -18
View File
@@ -19,17 +19,14 @@ namespace ASCOM.Meade.net
[ComVisible(true)]
public class Rate : IRate
{
private double _maximum = 0;
private double _minimum = 0;
//
// Default constructor - Internal prevents public creation
// of instances. These are values for AxisRates.
//
internal Rate(double minimum, double maximum)
{
_maximum = maximum;
_minimum = minimum;
Maximum = maximum;
Minimum = minimum;
}
#region Implementation of IRate
@@ -39,17 +36,9 @@ namespace ASCOM.Meade.net
// TODO Add any required object cleanup here
}
public double Maximum
{
get => _maximum;
set => _maximum = value;
}
public double Maximum { get; set; }
public double Minimum
{
get => _minimum;
set => _minimum = value;
}
public double Minimum { get; set; }
#endregion
}
@@ -152,7 +141,7 @@ namespace ASCOM.Meade.net
private readonly DriveRates[] _trackingRates;
// this is used to make the index thread safe
private readonly ThreadLocal<int> _pos = new ThreadLocal<int>(() => { return -1; });
private readonly ThreadLocal<int> _pos = new ThreadLocal<int>(() => -1);
private static readonly object LockObj = new object();
//
@@ -176,7 +165,11 @@ namespace ASCOM.Meade.net
public IEnumerator GetEnumerator()
{
_pos.Value = -1;
lock (LockObj)
{
_pos.Value = -1;
}
return this as IEnumerator;
}
@@ -220,7 +213,10 @@ namespace ASCOM.Meade.net
public void Reset()
{
_pos.Value = -1;
lock (LockObj)
{
_pos.Value = -1;
}
}
#endregion
}
+25 -29
View File
@@ -99,8 +99,6 @@ namespace ASCOM.Meade.net
private double _guideRate;
private const double SIDRATE = 0.9972695677; //synodic/solar seconds per sidereal second
private void Initialise()
{
//todo move the TraceLogger out to a factory class.
@@ -152,9 +150,7 @@ namespace ASCOM.Meade.net
get
{
LogMessage("SupportedActions Get", "Returning empty arraylist");
var supportedActions = new ArrayList();
supportedActions.Add("handbox");
supportedActions.Add("site");
var supportedActions = new ArrayList {"handbox", "site"};
return supportedActions;
}
}
@@ -540,9 +536,9 @@ namespace ASCOM.Meade.net
CheckConnected("SelectSite");
if (site < 1)
throw new ArgumentOutOfRangeException("site",site,"Site cannot be lower than 1");
throw new ArgumentOutOfRangeException(nameof(site),site,"Site cannot be lower than 1");
else if (site > 4)
throw new ArgumentOutOfRangeException("site", site, "Site cannot be higher than 4");
throw new ArgumentOutOfRangeException(nameof(site), site, "Site cannot be higher than 4");
_sharedResourcesWrapper.SendBlind($":W{site}#");
//:W<n>#
@@ -555,9 +551,9 @@ namespace ASCOM.Meade.net
CheckConnected("SetSiteName");
if (site < 1)
throw new ArgumentOutOfRangeException("site", site, "Site cannot be lower than 1");
throw new ArgumentOutOfRangeException(nameof(site), site, "Site cannot be lower than 1");
else if (site > 4)
throw new ArgumentOutOfRangeException("site", site, "Site cannot be higher than 4");
throw new ArgumentOutOfRangeException(nameof(site), site, "Site cannot be higher than 4");
string command = String.Empty;
switch (site)
@@ -609,9 +605,9 @@ namespace ASCOM.Meade.net
CheckConnected("GetSiteName");
if (site < 1)
throw new ArgumentOutOfRangeException("site", site, "Site cannot be lower than 1");
throw new ArgumentOutOfRangeException(nameof(site), site, "Site cannot be lower than 1");
else if (site > 4)
throw new ArgumentOutOfRangeException("site", site, "Site cannot be higher than 4");
throw new ArgumentOutOfRangeException(nameof(site), site, "Site cannot be higher than 4");
switch (site)
{
@@ -637,7 +633,7 @@ namespace ASCOM.Meade.net
//A # terminated string with the name of the requested site.
}
throw new ArgumentOutOfRangeException("site", site, "Site out of range");
throw new ArgumentOutOfRangeException(nameof(site), site, "Site out of range");
}
public string Description
@@ -874,7 +870,7 @@ namespace ASCOM.Meade.net
}
}
private bool _atPark = false;
private bool _atPark;
public bool AtPark
{
@@ -1162,10 +1158,10 @@ namespace ASCOM.Meade.net
if (!value.InRange(0, 15.0417))
{
throw new InvalidValueException(propertyName, value.ToString(), "0 to 15.0417”/sec");
throw new InvalidValueException(propertyName, value.ToString(CultureInfo.CurrentCulture), $"{0.ToString(CultureInfo.CurrentCulture)} to {15.0417.ToString(CultureInfo.CurrentCulture)}”/sec");
}
LogMessage($"{propertyName} Set", $"Setting new guiderate {value.ToString()} arc seconds/second ({value.ToString()} degrees/second)");
LogMessage($"{propertyName} Set", $"Setting new guiderate {value.ToString(CultureInfo.CurrentCulture)} arc seconds/second ({value.ToString(CultureInfo.CurrentCulture)} degrees/second)");
_sharedResourcesWrapper.SendBlind($":Rg{value:00.0}#");
//:RgSS.S#
//Set guide rate to +/ -SS.S to arc seconds per second.This rate is added to or subtracted from the current tracking
@@ -1709,9 +1705,7 @@ namespace ASCOM.Meade.net
LogMessage("SlewToAltAzAsync", $"Az={azimuth} Alt={altitude}");
HorizonCoordinates altAz = new HorizonCoordinates();
altAz.Azimuth = azimuth;
altAz.Altitude = altitude;
HorizonCoordinates altAz = new HorizonCoordinates {Azimuth = azimuth, Altitude = altitude};
var utcDateTime = UTCDate;
var latitude = SiteLatitude;
@@ -2128,18 +2122,20 @@ namespace ASCOM.Meade.net
LogMessage("UTCDate", "Get started");
TelescopeDateDetails telescopeDateDetails = _sharedResourcesWrapper.Lock(() =>
var telescopeDateDetails = _sharedResourcesWrapper.Lock(() =>
{
TelescopeDateDetails tdd = new TelescopeDateDetails();
tdd.TelescopeDate = _sharedResourcesWrapper.SendString(":GC#");
//:GC# Get current date.
//Returns: MM/DD/YY#
//The current local calendar date for the telescope.
tdd.TelescopeTime = _sharedResourcesWrapper.SendString(":GL#");
//:GL# Get Local Time in 24 hour format
//Returns: HH:MM:SS#
//The Local Time in 24 - hour Format
tdd.UtcCorrection = GetUtcCorrection();
var tdd = new TelescopeDateDetails
{
TelescopeDate = _sharedResourcesWrapper.SendString(":GC#"),
//:GC# Get current date.
//Returns: MM/DD/YY#
//The current local calendar date for the telescope.
TelescopeTime = _sharedResourcesWrapper.SendString(":GL#"),
//:GL# Get Local Time in 24 hour format
//Returns: HH:MM:SS#
//The Local Time in 24 - hour Format
UtcCorrection = GetUtcCorrection()
};
return tdd;
});
+27 -27
View File
@@ -54,7 +54,7 @@ namespace ASCOM.Meade.net
/// <summary>
/// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify)
/// </summary>
private static TraceLogger Tl;
private static TraceLogger _tl;
private readonly ISharedResourcesWrapper _sharedResourcesWrapper;
@@ -83,7 +83,7 @@ namespace ASCOM.Meade.net
private void Initialise()
{
//todo move the TraceLogger out to a factory class.
Tl = new TraceLogger("", "Meade.Generic.focusser");
_tl = new TraceLogger("", "Meade.Generic.focusser");
ReadProfile(); // Read device configuration from the ASCOM Profile store
@@ -108,17 +108,17 @@ namespace ASCOM.Meade.net
/// </summary>
public void SetupDialog()
{
Tl.LogMessage("SetupDialog", "Opening setup dialog");
_tl.LogMessage("SetupDialog", "Opening setup dialog");
_sharedResourcesWrapper.SetupDialog();
ReadProfile();
Tl.LogMessage("SetupDialog", "complete");
_tl.LogMessage("SetupDialog", "complete");
}
public ArrayList SupportedActions
{
get
{
Tl.LogMessage("SupportedActions Get", "Returning empty arraylist");
_tl.LogMessage("SupportedActions Get", "Returning empty arraylist");
return new ArrayList();
}
}
@@ -163,9 +163,9 @@ namespace ASCOM.Meade.net
public void Dispose()
{
// Clean up the tracelogger and util objects
Tl.Enabled = false;
Tl.Dispose();
Tl = null;
_tl.Enabled = false;
_tl.Dispose();
_tl = null;
}
public bool Connected
@@ -177,7 +177,7 @@ namespace ASCOM.Meade.net
}
set
{
Tl.LogMessage("Connected", "Set {0}", value);
_tl.LogMessage("Connected", "Set {0}", value);
if (value == IsConnected)
return;
@@ -216,7 +216,7 @@ namespace ASCOM.Meade.net
// TODO customise this device description
get
{
Tl.LogMessage("Description Get", DriverDescription);
_tl.LogMessage("Description Get", DriverDescription);
return DriverDescription;
}
}
@@ -259,7 +259,7 @@ namespace ASCOM.Meade.net
{
//string name = "Short driver name - please customise";
string name = DriverDescription;
Tl.LogMessage("Name Get", name);
_tl.LogMessage("Name Get", name);
return name;
}
}
@@ -274,14 +274,14 @@ namespace ASCOM.Meade.net
{
CheckConnected("Absolute Get");
Tl.LogMessage("Absolute Get", false.ToString());
_tl.LogMessage("Absolute Get", false.ToString());
return false; // This is a relative focuser
}
}
public void Halt()
{
Tl.LogMessage("Halt", "Halting");
_tl.LogMessage("Halt", "Halting");
CheckConnected("Halt");
@@ -302,7 +302,7 @@ namespace ASCOM.Meade.net
{
get
{
Tl.LogMessage("IsMoving Get", false.ToString());
_tl.LogMessage("IsMoving Get", false.ToString());
return false; // This focuser always moves instantaneously so no need for IsMoving ever to be True
}
}
@@ -311,12 +311,12 @@ namespace ASCOM.Meade.net
{
get
{
Tl.LogMessage("Link Get", Connected.ToString());
_tl.LogMessage("Link Get", Connected.ToString());
return Connected; // Direct function to the connected method, the Link method is just here for backwards compatibility
}
set
{
Tl.LogMessage("Link Set", value.ToString());
_tl.LogMessage("Link Set", value.ToString());
Connected = value; // Direct function to the connected method, the Link method is just here for backwards compatibility
}
}
@@ -326,7 +326,7 @@ namespace ASCOM.Meade.net
{
get
{
Tl.LogMessage("MaxIncrement Get", _maxIncrement.ToString());
_tl.LogMessage("MaxIncrement Get", _maxIncrement.ToString());
return _maxIncrement; // Maximum change in one move
}
}
@@ -336,14 +336,14 @@ namespace ASCOM.Meade.net
{
get
{
Tl.LogMessage("MaxStep Get", _maxStep.ToString());
_tl.LogMessage("MaxStep Get", _maxStep.ToString());
return _maxStep;
}
}
public void Move(int position)
{
Tl.LogMessage("Move", position.ToString());
_tl.LogMessage("Move", position.ToString());
CheckConnected("Move");
//todo implement backlash compensation
@@ -405,7 +405,7 @@ namespace ASCOM.Meade.net
{
get
{
Tl.LogMessage("StepSize Get", "Not implemented");
_tl.LogMessage("StepSize Get", "Not implemented");
throw new PropertyNotImplementedException("StepSize", false);
}
}
@@ -414,13 +414,13 @@ namespace ASCOM.Meade.net
{
get
{
Tl.LogMessage("TempComp Get", false.ToString());
_tl.LogMessage("TempComp Get", false.ToString());
return false;
}
// ReSharper disable once ValueParameterNotUsed
set
{
Tl.LogMessage("TempComp Set", "Not implemented");
_tl.LogMessage("TempComp Set", "Not implemented");
throw new PropertyNotImplementedException("TempComp", false);
}
}
@@ -429,7 +429,7 @@ namespace ASCOM.Meade.net
{
get
{
Tl.LogMessage("TempCompAvailable Get", false.ToString());
_tl.LogMessage("TempCompAvailable Get", false.ToString());
return false; // Temperature compensation is not available in this driver
}
}
@@ -438,7 +438,7 @@ namespace ASCOM.Meade.net
{
get
{
Tl.LogMessage("Temperature Get", "Not implemented");
_tl.LogMessage("Temperature Get", "Not implemented");
throw new PropertyNotImplementedException("Temperature", false);
}
}
@@ -546,10 +546,10 @@ namespace ASCOM.Meade.net
private void ReadProfile()
{
var profileProperties = _sharedResourcesWrapper.ReadProfile();
Tl.Enabled = profileProperties.TraceLogger;
_tl.Enabled = profileProperties.TraceLogger;
_comPort = profileProperties.ComPort;
LogMessage("ReadProfile", $"Trace logger enabled: {Tl.Enabled}");
LogMessage("ReadProfile", $"Trace logger enabled: {_tl.Enabled}");
LogMessage("ReadProfile", $"Com Port: {_comPort}");
}
@@ -562,7 +562,7 @@ namespace ASCOM.Meade.net
private static void LogMessage(string identifier, string message, params object[] args)
{
var msg = string.Format(message, args);
Tl.LogMessage(identifier, msg);
_tl.LogMessage(identifier, msg);
}
#endregion
}
+1 -1
View File
@@ -12,7 +12,7 @@ namespace ASCOM.Meade.net
Product = "", Copyright = "", Trademark = "",
AssemblyVersion = "", FileVersion = "", Guid = "",
NeutralLanguage = "";
public bool IsComVisible = false;
public bool IsComVisible;
// Return a particular assembly attribute value.
public static T GetAssemblyAttribute<T>(Assembly assembly)
+5 -5
View File
@@ -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.
private static readonly Guid _iidIUnknown = new Guid("{00000000-0000-0000-C000-000000000046}");
private static readonly Guid _iidIDispatch = new Guid("{00020400-0000-0000-C000-000000000046}");
private static readonly Guid IidIUnknown = new Guid("{00000000-0000-0000-C000-000000000046}");
private static readonly Guid IidIDispatch = new Guid("{00020400-0000-0000-C000-000000000046}");
[Flags]
enum Clsctx : uint
@@ -118,7 +118,7 @@ namespace ASCOM.Meade.net
public ClassFactory(Type type)
{
if (type == null)
throw new ArgumentNullException("type");
throw new ArgumentNullException(nameof(type));
_mClassType = type;
//PWGS Get the ProgID from the MetaData
@@ -201,12 +201,12 @@ namespace ASCOM.Meade.net
//
// Handle requests for IDispatch or IUnknown on the class
//
if (riid == _iidIDispatch)
if (riid == IidIDispatch)
{
ppvObject = Marshal.GetIDispatchForObject(Activator.CreateInstance(_mClassType));
return;
}
else if (riid == _iidIUnknown)
else if (riid == IidIUnknown)
{
ppvObject = Marshal.GetIUnknownForObject(Activator.CreateInstance(_mClassType));
}
+37 -30
View File
@@ -29,7 +29,7 @@ namespace ASCOM.Meade.net
public static class Server
{
private const string DRIVER_NAME = "Meade Generic";
private const string DriverName = "Meade Generic";
#region Access to kernel32.dll, user32.dll, and ole32.dll functions
[Flags]
@@ -259,7 +259,7 @@ namespace ASCOM.Meade.net
catch (Exception e)
{
MessageBox.Show($"Failed to load served COM class assembly {fi.Name} - {e.Message}",
DRIVER_NAME, MessageBoxButtons.OK, MessageBoxIcon.Stop);
DriverName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
return false;
}
@@ -287,19 +287,21 @@ namespace ASCOM.Meade.net
//
private static void ElevateSelf(string arg)
{
ProcessStartInfo si = new ProcessStartInfo();
si.Arguments = arg;
si.WorkingDirectory = Environment.CurrentDirectory;
si.FileName = Application.ExecutablePath;
si.Verb = "runas";
var si = new ProcessStartInfo
{
Arguments = arg,
WorkingDirectory = Environment.CurrentDirectory,
FileName = Application.ExecutablePath,
Verb = "runas"
};
try { Process.Start(si); }
catch (System.ComponentModel.Win32Exception)
{
MessageBox.Show($"The {DRIVER_NAME} was not {(arg == "/register" ? "registered" : "unregistered")} because you did not allow it.", DRIVER_NAME, MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show($"The {DriverName} was not {(arg == "/register" ? "registered" : "unregistered")} because you did not allow it.", DriverName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), DRIVER_NAME, MessageBoxButtons.OK, MessageBoxIcon.Stop);
MessageBox.Show(ex.ToString(), DriverName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
return;
}
@@ -349,8 +351,8 @@ namespace ASCOM.Meade.net
//
// HKCR\APPID\exename.ext
//
using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("APPID\\{0}",
Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1))))
using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(
$"APPID\\{Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)}"))
{
key.SetValue("AppID", _sAppId);
}
@@ -358,7 +360,7 @@ namespace ASCOM.Meade.net
catch (Exception ex)
{
MessageBox.Show($"Error while registering the server:\n{ex}",
DRIVER_NAME, MessageBoxButtons.OK, MessageBoxIcon.Stop);
DriverName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;
}
finally
@@ -381,7 +383,7 @@ namespace ASCOM.Meade.net
//PWGS Generate device type from the Class name
string deviceType = type.Name;
using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("CLSID\\{0}", clsid)))
using (RegistryKey key = Registry.ClassesRoot.CreateSubKey($"CLSID\\{clsid}"))
{
key.SetValue(null, progid); // Could be assyTitle/Desc??, but .NET components show ProgId here
key.SetValue("AppId", _sAppId);
@@ -427,7 +429,7 @@ namespace ASCOM.Meade.net
catch (Exception ex)
{
MessageBox.Show("Error while registering the server:\n" + ex.ToString(),
DRIVER_NAME, MessageBoxButtons.OK, MessageBoxIcon.Stop);
DriverName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
bFail = true;
}
finally
@@ -454,9 +456,9 @@ namespace ASCOM.Meade.net
//
// Local server's DCOM/AppID information
//
Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", _sAppId), false);
Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}",
Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)), false);
Registry.ClassesRoot.DeleteSubKey($"APPID\\{_sAppId}", false);
Registry.ClassesRoot.DeleteSubKey(
$"APPID\\{Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)}", false);
//
// For each of the driver assemblies
@@ -472,17 +474,17 @@ namespace ASCOM.Meade.net
//
// HKCR\progid
//
Registry.ClassesRoot.DeleteSubKey(String.Format("{0}\\CLSID", progid), false);
Registry.ClassesRoot.DeleteSubKey($"{progid}\\CLSID", false);
Registry.ClassesRoot.DeleteSubKey(progid, false);
//
// HKCR\CLSID\clsid
//
Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Implemented Categories\\{{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}}", clsid), false);
Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Implemented Categories", clsid), false);
Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\ProgId", clsid), false);
Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\LocalServer32", clsid), false);
Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}\\Programmable", clsid), false);
Registry.ClassesRoot.DeleteSubKey(String.Format("CLSID\\{0}", clsid), false);
Registry.ClassesRoot.DeleteSubKey($"CLSID\\{clsid}\\Implemented Categories\\{{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}}", false);
Registry.ClassesRoot.DeleteSubKey($"CLSID\\{clsid}\\Implemented Categories", false);
Registry.ClassesRoot.DeleteSubKey($"CLSID\\{clsid}\\ProgId", false);
Registry.ClassesRoot.DeleteSubKey($"CLSID\\{clsid}\\LocalServer32", false);
Registry.ClassesRoot.DeleteSubKey($"CLSID\\{clsid}\\Programmable", false);
Registry.ClassesRoot.DeleteSubKey($"CLSID\\{clsid}", false);
try
{
//
@@ -494,7 +496,10 @@ namespace ASCOM.Meade.net
p.Unregister(progid);
}
}
catch (Exception) { }
catch (Exception)
{
// ignored
}
}
}
#endregion
@@ -515,7 +520,7 @@ namespace ASCOM.Meade.net
if (!factory.RegisterClassObject())
{
MessageBox.Show("Failed to register class factory for " + type.Name,
DRIVER_NAME, MessageBoxButtons.OK, MessageBoxIcon.Stop);
DriverName, MessageBoxButtons.OK, MessageBoxIcon.Stop);
return false;
}
}
@@ -571,7 +576,7 @@ namespace ASCOM.Meade.net
default:
MessageBox.Show("Unknown argument: " + args[0] + "\nValid are : -register, -unregister and -embedding",
DRIVER_NAME, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
DriverName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
break;
}
}
@@ -610,9 +615,11 @@ namespace ASCOM.Meade.net
RegisterClassFactories();
// Start up the garbage collection thread.
GarbageCollection garbageCollector = new GarbageCollection(1000);
Thread gcThread = new Thread(new ThreadStart(garbageCollector.GcWatch));
gcThread.Name = "Garbage Collection Thread";
var garbageCollector = new GarbageCollection(1000);
var gcThread = new Thread(garbageCollector.GcWatch)
{
Name = "Garbage Collection Thread"
};
gcThread.Start();
//
+5 -5
View File
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Windows.Forms;
@@ -52,7 +53,7 @@ namespace ASCOM.Meade.net
comboBoxComPort.SelectedItem = profileProperties.ComPort;
}
txtGuideRate.Text = profileProperties.GuideRateArcSecondsPerSecond.ToString();
txtGuideRate.Text = profileProperties.GuideRateArcSecondsPerSecond.ToString(CultureInfo.CurrentCulture);
try
{
cboPrecision.SelectedItem = profileProperties.Precision;
@@ -86,7 +87,6 @@ namespace ASCOM.Meade.net
private void TextBox1_TextChanged(object sender, EventArgs e)
{
//const double SIDRATE = 0.9972695677; //synodic/solar seconds per sidereal second
try
{
double newGuideRate = double.Parse(txtGuideRate.Text.Trim());
@@ -103,17 +103,17 @@ namespace ASCOM.Meade.net
_guideRateValid = false;
}
UpdateOKButton();
UpdateOkButton();
}
private void UpdateOKButton()
private void UpdateOkButton()
{
cmdOK.Enabled = _guideRateValid && (comboBoxComPort.SelectedItem != null);
}
private void ComboBoxComPort_SelectedValueChanged(object sender, EventArgs e)
{
UpdateOKButton();
UpdateOkButton();
}
public void SetReadOnlyMode()
+24 -29
View File
@@ -15,6 +15,7 @@
//
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using ASCOM.Utilities;
@@ -64,7 +65,7 @@ namespace ASCOM.Meade.net
/// <summary>
/// number of connections to the shared serial port
/// </summary>
public static int Connections { get; set; } = 0;
public static int Connections { get; set; }
public static void SendBlind(string message)
{
@@ -179,7 +180,7 @@ namespace ASCOM.Meade.net
driverProfile.DeviceType = "Telescope";
driverProfile.WriteValue(DriverId, TraceStateProfileName, profileProperties.TraceLogger.ToString());
driverProfile.WriteValue(DriverId, ComPortProfileName, profileProperties.ComPort);
driverProfile.WriteValue(DriverId, GuideRateProfileName, profileProperties.GuideRateArcSecondsPerSecond.ToString());
driverProfile.WriteValue(DriverId, GuideRateProfileName, profileProperties.GuideRateArcSecondsPerSecond.ToString(CultureInfo.CurrentCulture));
driverProfile.WriteValue(DriverId, PrecisionProfileName, profileProperties.Precision);
}
}
@@ -264,9 +265,9 @@ 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 readonly Dictionary<string, DeviceHardware> _connectedDevices = new Dictionary<string, DeviceHardware>();
private static readonly Dictionary<string, DeviceHardware> ConnectedDevices = new Dictionary<string, DeviceHardware>();
private static readonly Dictionary<string, DeviceHardware> _connectedDeviceIds = new Dictionary<string, DeviceHardware>();
private static readonly Dictionary<string, DeviceHardware> ConnectedDeviceIds = new Dictionary<string, DeviceHardware>();
/// <summary>
@@ -278,17 +279,17 @@ namespace ASCOM.Meade.net
{
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 (!_connectedDeviceIds.ContainsKey(driverId))
_connectedDeviceIds.Add(driverId, new DeviceHardware());
_connectedDeviceIds[driverId].Count++; // increment the value
if (!ConnectedDeviceIds.ContainsKey(driverId))
ConnectedDeviceIds.Add(driverId, new DeviceHardware());
ConnectedDeviceIds[driverId].Count++; // increment the value
if (deviceId == "Serial")
{
if (_connectedDevices[deviceId].Count == 1)
if (ConnectedDevices[deviceId].Count == 1)
{
var profileProperties = ReadProfile();
SharedSerial.PortName = profileProperties.ComPort;
@@ -308,8 +309,8 @@ namespace ASCOM.Meade.net
return new ConnectionInfo
{
Connections = _connectedDevices[deviceId].Count,
SameDevice = _connectedDeviceIds[driverId].Count
Connections = ConnectedDevices[deviceId].Count,
SameDevice = ConnectedDeviceIds[driverId].Count
};
}
}
@@ -318,12 +319,12 @@ namespace ASCOM.Meade.net
{
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;
@@ -331,16 +332,16 @@ namespace ASCOM.Meade.net
}
}
if (_connectedDeviceIds.ContainsKey(driverId))
if (ConnectedDeviceIds.ContainsKey(driverId))
{
_connectedDeviceIds[driverId].Count--;
ConnectedDeviceIds[driverId].Count--;
}
}
}
public static bool IsConnected()
{
foreach (var device in _connectedDevices)
foreach (var device in ConnectedDevices)
{
if (device.Value.Count > 0)
return true;
@@ -351,8 +352,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;
}
@@ -381,13 +382,7 @@ namespace ASCOM.Meade.net
/// </summary>
public class DeviceHardware
{
private int _count;
internal int Count
{
set => _count = value;
get => _count;
}
internal int Count { set; get; }
internal DeviceHardware()
{
+6 -6
View File
@@ -10,20 +10,20 @@ namespace ASCOM.Meade.net
{
#region Autostar 497/Audiostar
public readonly static string Autostar497 = "Autostar";
public static readonly string Autostar497 = "Autostar";
//Autostar/Audiostar firmware revisions
public readonly static string Autostar497_30Ee = "30Ee";
public readonly static string Autostar497_31Ee = "31Ee";
public readonly static string Autostar497_43Eg = "43Eg";
public static readonly string Autostar497_30Ee = "30Ee";
public static readonly string Autostar497_31Ee = "31Ee";
public static readonly string Autostar497_43Eg = "43Eg";
#endregion
#region LX200GPS
public readonly static string LX200GPS = "LX2001";
public static readonly string LX200GPS = "LX2001";
public readonly static string LX200GPS_42G = "4.2G";
public static readonly string LX200GPS_42G = "4.2G";
#endregion
}
+7 -7
View File
@@ -77,11 +77,11 @@ namespace ASCOM.Meade.net
// Published in The Delphi Magazine 55, page 16
// Converted to C# by Kevin Gale
IntPtr foregroundWindow = GetForegroundWindow();
IntPtr Dummy = IntPtr.Zero;
IntPtr dummy = IntPtr.Zero;
uint foregroundThreadId = GetWindowThreadProcessId(foregroundWindow, Dummy);
uint foregroundThreadId = GetWindowThreadProcessId(foregroundWindow, dummy);
uint thisThreadId = GetWindowThreadProcessId(hWnd, Dummy);
uint thisThreadId = GetWindowThreadProcessId(hWnd, dummy);
if (AttachThreadInput(thisThreadId, foregroundThreadId, true))
{
@@ -94,12 +94,12 @@ namespace ASCOM.Meade.net
{
// Code by Daniel P. Stasinski
// Converted to C# by Kevin Gale
IntPtr Timeout = IntPtr.Zero;
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, Timeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Dummy, SPIF_SENDCHANGE);
IntPtr timeout = IntPtr.Zero;
SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, timeout, 0);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, dummy, SPIF_SENDCHANGE);
BringWindowToTop(hWnd); // IE 5.5 related hack
SetForegroundWindow(hWnd);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, Timeout, SPIF_SENDCHANGE);
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, timeout, SPIF_SENDCHANGE);
}
}
}
-2
View File
@@ -4,8 +4,6 @@ namespace ASCOM.Meade.net
{
public partial class FrmMain : Form
{
delegate void SetTextCallback(string text);
public FrmMain()
{
InitializeComponent();