diff --git a/AstroMath.UnitTests/AstroMathsUnitTests.cs b/AstroMath.UnitTests/AstroMathsUnitTests.cs index a72f498..c6c0082 100644 --- a/AstroMath.UnitTests/AstroMathsUnitTests.cs +++ b/AstroMath.UnitTests/AstroMathsUnitTests.cs @@ -52,7 +52,7 @@ namespace AstroMath.UnitTests public void UTtoGST_book() { DateTime dateTime = new DateTime(1980, 04, 22, 14, 36, 51, 670, DateTimeKind.Utc); - double gst = _astroMath.UTtoGST(dateTime); + double gst = _astroMath.UTtoGst(dateTime); Assert.That(gst, Is.EqualTo(4.667932706211154)); } @@ -61,7 +61,7 @@ namespace AstroMath.UnitTests public void UTtoGst() { DateTime dateTime = new DateTime(2019, 05, 18, 22, 26, 15, DateTimeKind.Utc); - double gst = _astroMath.UTtoGST(dateTime); + double gst = _astroMath.UTtoGst(dateTime); Assert.That(gst, Is.EqualTo(14.191879687876451)); } @@ -71,7 +71,7 @@ namespace AstroMath.UnitTests { double gst = 4.668119; var longitude = -64; - var lst = _astroMath.GSTtoLST(gst, longitude); + var lst = _astroMath.GsTtoLst(gst, longitude); Assert.That(lst, Is.EqualTo(0.4014523333333333)); } @@ -80,7 +80,7 @@ namespace AstroMath.UnitTests { double gst = 14.257589512545053; var longitude = -1.7833333333333332; - var lst = _astroMath.GSTtoLST(gst, longitude); + var lst = _astroMath.GsTtoLst(gst, longitude); Assert.That(lst, Is.EqualTo(14.138700623656163)); } diff --git a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs index 4cfd9f0..1f29a92 100644 --- a/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs +++ b/Meade.net.Telescope.UnitTests/TelescopeUnitTests.cs @@ -37,9 +37,9 @@ namespace Meade.net.Telescope.UnitTests _sharedResourcesWrapperMock = new Mock(); _sharedResourcesWrapperMock.Setup(x => x.SendString(":GZ#")).Returns("DDD*MM’SS"); - _sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497).Returns(() => "AUTOSTAR"); - _sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497_31EE).Returns(() => "31Ee"); - _sharedResourcesWrapperMock.Setup(x => x.AUTOSTAR497_43EG) .Returns(() => "43Eg"); + _sharedResourcesWrapperMock.Setup(x => x.Autostar497).Returns(() => "AUTOSTAR"); + _sharedResourcesWrapperMock.Setup(x => x.Autostar49731Ee).Returns(() => "31Ee"); + _sharedResourcesWrapperMock.Setup(x => x.Autostar49743Eg) .Returns(() => "43Eg"); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny())).Callback(action => { action(); }); _sharedResourcesWrapperMock.Setup(x => x.Lock(It.IsAny>())).Returns>( (func) => func()); @@ -56,8 +56,8 @@ namespace Meade.net.Telescope.UnitTests private void ConnectTelescope() { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.Autostar49731Ee); _telescope.Connected = true; } @@ -238,8 +238,8 @@ namespace Meade.net.Telescope.UnitTests [TestCase(false)] public void Connected_Get_ReturnsExpectedValue(bool expectedConnected) { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.Autostar49731Ee); _telescope.Connected = expectedConnected; Assert.That(_telescope.Connected, Is.EqualTo(expectedConnected)); @@ -275,8 +275,8 @@ namespace Meade.net.Telescope.UnitTests [Test] public void Connected_Set_WhenFailsToConnect_ThenDisconnects() { - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); - _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497_31EE); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.Autostar497); + _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => _sharedResourcesWrapperMock.Object.Autostar49731Ee); _sharedResourcesWrapperMock.Setup(x => x.SendString(It.IsAny())).Throws(new Exception("TestFailed")); @@ -999,7 +999,7 @@ namespace Meade.net.Telescope.UnitTests public void PulseGuide_WhenConnectedAndNewerPulseGuidingNotAvailable_ThenSendsOldCommandsAndWaits(GuideDirections direction) { var duration = 0; - _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.AUTOSTAR497); + _sharedResourcesWrapperMock.Setup(x => x.ProductName).Returns(() => _sharedResourcesWrapperMock.Object.Autostar497); _sharedResourcesWrapperMock.Setup(x => x.FirmwareVersion).Returns(() => "31Ed"); _telescope.Connected = true; diff --git a/Meade.net.Telescope/AstroMaths/AstroMaths.cs b/Meade.net.Telescope/AstroMaths/AstroMaths.cs index 45fea5f..17e168b 100644 --- a/Meade.net.Telescope/AstroMaths/AstroMaths.cs +++ b/Meade.net.Telescope/AstroMaths/AstroMaths.cs @@ -10,8 +10,8 @@ namespace ASCOM.Meade.net.AstroMaths public double RightAscensionToHourAngle(DateTime utcDateTime, double longitude, double rightAscension) { var ut = DateTimeToDecimalHours( utcDateTime); - var gst = UTtoGST( utcDateTime); - var lst = GSTtoLST( gst, longitude); + var gst = UTtoGst( utcDateTime); + var lst = GsTtoLst( gst, longitude); var raHours = rightAscension; var h1 = lst - raHours; var h = h1; @@ -24,8 +24,8 @@ namespace ASCOM.Meade.net.AstroMaths public double HourAngleToRightAscension(DateTime utcDateTime, double longitude, double hourAngle ) { - var gst = UTtoGST(utcDateTime); - var lst = GSTtoLST( gst, longitude); + var gst = UTtoGst(utcDateTime); + var lst = GsTtoLst( gst, longitude); var raHours = hourAngle; var h1 = lst - raHours; var h = h1; @@ -129,7 +129,7 @@ namespace ASCOM.Meade.net.AstroMaths } //todo convert to extension method - public double UTtoGST(DateTime utcDateTime) + public double UTtoGst(DateTime utcDateTime) { Util util = new Util(); @@ -171,7 +171,7 @@ namespace ASCOM.Meade.net.AstroMaths return t1; } - public double GSTtoLST(double gst, double longitude) + public double GsTtoLst(double gst, double longitude) { var l = longitude/ 15; diff --git a/Meade.net.Telescope/AstroMaths/IAstroMaths.cs b/Meade.net.Telescope/AstroMaths/IAstroMaths.cs index ff4ef4e..dfcab3a 100644 --- a/Meade.net.Telescope/AstroMaths/IAstroMaths.cs +++ b/Meade.net.Telescope/AstroMaths/IAstroMaths.cs @@ -11,7 +11,7 @@ namespace ASCOM.Meade.net.AstroMaths double DegreesToRadians(double degrees); double RadiansToDegrees(double radians); double DateTimeToDecimalHours( DateTime utcDateTime); - double UTtoGST(DateTime utcDateTime); - double GSTtoLST(double gst, double longitude); + double UTtoGst(DateTime utcDateTime); + double GsTtoLst(double gst, double longitude); } } \ No newline at end of file diff --git a/Meade.net.Telescope/Rates.cs b/Meade.net.Telescope/Rates.cs index bf75539..8d9e970 100644 --- a/Meade.net.Telescope/Rates.cs +++ b/Meade.net.Telescope/Rates.cs @@ -70,8 +70,8 @@ namespace ASCOM.Meade.net [ComVisible(true)] public class AxisRates : IAxisRates, IEnumerable { - private TelescopeAxes axis; - private readonly Rate[] rates; + private TelescopeAxes _axis; + private readonly Rate[] _rates; // // Constructor - Internal prevents public creation @@ -79,7 +79,7 @@ namespace ASCOM.Meade.net // internal AxisRates(TelescopeAxes axis) { - this.axis = axis; + this._axis = axis; // // This collection must hold zero or more Rate objects describing the // rates of motion ranges for the Telescope.MoveAxis() method @@ -96,23 +96,23 @@ namespace ASCOM.Meade.net // TODO Initialize this array with any Primary axis rates that your driver may provide // Example: m_Rates = new Rate[] { new Rate(10.5, 30.2), new Rate(54.0, 43.6) } //this.rates = new Rate[0]; - rates = new Rate[] { new Rate(1, 1), new Rate(2, 2), new Rate(3, 3), new Rate(4, 4) }; + _rates = new Rate[] { new Rate(1, 1), new Rate(2, 2), new Rate(3, 3), new Rate(4, 4) }; break; case TelescopeAxes.axisSecondary: // TODO Initialize this array with any Secondary axis rates that your driver may provide //this.rates = new Rate[0]; - rates = new Rate[] { new Rate(1, 1), new Rate(2, 2), new Rate(3, 3), new Rate(4, 4) }; + _rates = new Rate[] { new Rate(1, 1), new Rate(2, 2), new Rate(3, 3), new Rate(4, 4) }; break; case TelescopeAxes.axisTertiary: // TODO Initialize this array with any Tertiary axis rates that your driver may provide - rates = new Rate[0]; + _rates = new Rate[0]; break; } } #region IAxisRates Members - public int Count => rates.Length; + public int Count => _rates.Length; public void Dispose() { @@ -121,10 +121,10 @@ namespace ASCOM.Meade.net public IEnumerator GetEnumerator() { - return rates.GetEnumerator(); + return _rates.GetEnumerator(); } - public IRate this[int index] => rates[index - 1]; + public IRate this[int index] => _rates[index - 1]; #endregion } @@ -149,11 +149,11 @@ namespace ASCOM.Meade.net [ComVisible(true)] public class TrackingRates : ITrackingRates, IEnumerable, IEnumerator { - private readonly DriveRates[] trackingRates; + private readonly DriveRates[] _trackingRates; // this is used to make the index thread safe - private readonly ThreadLocal pos = new ThreadLocal(() => { return -1; }); - private static readonly object lockObj = new object(); + private readonly ThreadLocal _pos = new ThreadLocal(() => { return -1; }); + private static readonly object LockObj = new object(); // // Default constructor - Internal prevents public creation @@ -166,17 +166,17 @@ namespace ASCOM.Meade.net // the tracking rates supported by your telescope. The one value // (tracking rate) that MUST be supported is driveSidereal! // - trackingRates = new[] { DriveRates.driveSidereal, DriveRates.driveLunar }; + _trackingRates = new[] { DriveRates.driveSidereal, DriveRates.driveLunar }; // TODO Initialize this array with any additional tracking rates that your driver may provide } #region ITrackingRates Members - public int Count => trackingRates.Length; + public int Count => _trackingRates.Length; public IEnumerator GetEnumerator() { - pos.Value = -1; + _pos.Value = -1; return this as IEnumerator; } @@ -185,7 +185,7 @@ namespace ASCOM.Meade.net // TODO Add any required object cleanup here } - public DriveRates this[int index] => trackingRates[index - 1]; + public DriveRates this[int index] => _trackingRates[index - 1]; #endregion @@ -195,22 +195,22 @@ namespace ASCOM.Meade.net { get { - lock (lockObj) + lock (LockObj) { - if (pos.Value < 0 || pos.Value >= trackingRates.Length) + if (_pos.Value < 0 || _pos.Value >= _trackingRates.Length) { throw new System.InvalidOperationException(); } - return trackingRates[pos.Value]; + return _trackingRates[_pos.Value]; } } } public bool MoveNext() { - lock (lockObj) + lock (LockObj) { - if (++pos.Value >= trackingRates.Length) + if (++_pos.Value >= _trackingRates.Length) { return false; } @@ -220,7 +220,7 @@ namespace ASCOM.Meade.net public void Reset() { - pos.Value = -1; + _pos.Value = -1; } #endregion } diff --git a/Meade.net.Telescope/Telescope.cs b/Meade.net.Telescope/Telescope.cs index c082f33..264dacb 100644 --- a/Meade.net.Telescope/Telescope.cs +++ b/Meade.net.Telescope/Telescope.cs @@ -39,15 +39,15 @@ namespace ASCOM.Meade.net /// The DeviceID is used by ASCOM applications to load the driver at runtime. /// //internal static string driverID = "ASCOM.Meade.net.Telescope"; - private static readonly 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 /// /// Driver description that displays in the ASCOM Chooser. /// - private static readonly string driverDescription = "Meade Generic"; + private static readonly string DriverDescription = "Meade Generic"; - private static string comPort; // Variables to hold the currrent device configuration + private static string _comPort; // Variables to hold the currrent device configuration /// /// Private variable to hold an ASCOM Utilities object @@ -65,7 +65,7 @@ namespace ASCOM.Meade.net /// /// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify) /// - private TraceLogger tl; + private TraceLogger _tl; private readonly ISharedResourcesWrapper _sharedResourcesWrapper; @@ -100,7 +100,7 @@ namespace ASCOM.Meade.net private void Initialise() { //todo move the TraceLogger out to a factory class. - tl = new TraceLogger("", "Meade.net.Telescope"); + _tl = new TraceLogger("", "Meade.net.Telescope"); LogMessage("Telescope", "Starting initialisation"); ReadProfile(); // Read device configuration from the ASCOM Profile store @@ -279,9 +279,9 @@ namespace ASCOM.Meade.net Connected = false; // Clean up the tracelogger and util objects - tl.Enabled = false; - tl.Dispose(); - tl = null; + _tl.Enabled = false; + _tl.Dispose(); + _tl = null; } public bool Connected @@ -299,18 +299,18 @@ namespace ASCOM.Meade.net if (value) { - LogMessage("Connected Set", "Connecting to port {0}", comPort); + LogMessage("Connected Set", "Connecting to port {0}", _comPort); try { _sharedResourcesWrapper.Connect("Serial"); try { - LogMessage("Connected Set", $"Connected to port {comPort}. Product: {_sharedResourcesWrapper.ProductName} Version:{_sharedResourcesWrapper.FirmwareVersion}"); + LogMessage("Connected Set", $"Connected to port {_comPort}. Product: {_sharedResourcesWrapper.ProductName} Version:{_sharedResourcesWrapper.FirmwareVersion}"); SetLongFormat(true); _userNewerPulseGuiding = IsNewPulseGuidingSupported(); - _targetDeclination = INVALID_PARAMETER; - _targetRightAscension = INVALID_PARAMETER; + _targetDeclination = InvalidParameter; + _targetRightAscension = InvalidParameter; _tracking = true; LogMessage("Connected Set", $"New Pulse Guiding Supported: {_userNewerPulseGuiding}"); @@ -324,12 +324,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; } @@ -338,9 +338,9 @@ namespace ASCOM.Meade.net public bool IsNewPulseGuidingSupported() { - if (_sharedResourcesWrapper.ProductName == _sharedResourcesWrapper.AUTOSTAR497) + if (_sharedResourcesWrapper.ProductName == _sharedResourcesWrapper.Autostar497) { - return FirmwareIsGreaterThan(_sharedResourcesWrapper.AUTOSTAR497_31EE); + return FirmwareIsGreaterThan(_sharedResourcesWrapper.Autostar49731Ee); } return false; @@ -395,8 +395,8 @@ namespace ASCOM.Meade.net // TODO customise this device description get { - LogMessage("Description Get", driverDescription); - return driverDescription; + LogMessage("Description Get", DriverDescription); + return DriverDescription; } } @@ -447,7 +447,7 @@ namespace ASCOM.Meade.net ////Returns: dd.d# //string name = $"{telescopeProduceName} - {firmwareVersion}"; - string name = driverDescription; + string name = DriverDescription; LogMessage("Name Get", name); return name; } @@ -525,7 +525,7 @@ namespace ASCOM.Meade.net CheckConnected("AlignmentMode Set"); //todo tidy this up into a better solution that means can :GW#, :AL#, :AA#, & :AP# and checked for Autostar properly - if (!FirmwareIsGreaterThan(_sharedResourcesWrapper.AUTOSTAR497_43EG)) + if (!FirmwareIsGreaterThan(_sharedResourcesWrapper.Autostar49743Eg)) throw new PropertyNotImplementedException("AlignmentMode",true ); //todo make this only try with Autostar 43Eg and above. @@ -636,10 +636,10 @@ namespace ASCOM.Meade.net private set => _atPark = value; } - public IAxisRates AxisRates(TelescopeAxes Axis) + public IAxisRates AxisRates(TelescopeAxes axis) { - LogMessage("AxisRates", "Get - " + Axis.ToString()); - return new AxisRates(Axis); + LogMessage("AxisRates", "Get - " + axis.ToString()); + return new AxisRates(axis); } public double Azimuth @@ -673,15 +673,15 @@ namespace ASCOM.Meade.net } } - public bool CanMoveAxis(TelescopeAxes Axis) + public bool CanMoveAxis(TelescopeAxes axis) { - LogMessage("CanMoveAxis", "Get - " + Axis.ToString()); - switch (Axis) + LogMessage("CanMoveAxis", "Get - " + axis.ToString()); + switch (axis) { case TelescopeAxes.axisPrimary: return true; //RA or AZ case TelescopeAxes.axisSecondary: return true; //Dev or Alt case TelescopeAxes.axisTertiary: return false; //rotator / derotator - default: throw new InvalidValueException("CanMoveAxis", Axis.ToString(), "0 to 2"); + default: throw new InvalidValueException("CanMoveAxis", axis.ToString(), "0 to 2"); } } @@ -1538,19 +1538,19 @@ namespace ASCOM.Meade.net } } - private const double INVALID_PARAMETER = -1000; + private const double InvalidParameter = -1000; public void SlewToTargetAsync() { CheckConnected("SlewToTargetAsync"); - if (TargetDeclination == INVALID_PARAMETER || TargetRightAscension == INVALID_PARAMETER) + if (TargetDeclination == InvalidParameter || TargetRightAscension == InvalidParameter) throw new InvalidOperationException("No target selected to slew to."); DoSlewAsync(true); } - private bool movingAxis() + private bool MovingAxis() { return _movingPrimary || _movingSecondary; } @@ -1562,7 +1562,7 @@ namespace ASCOM.Meade.net if (!Connected) return false; - if (movingAxis()) + if (MovingAxis()) return true; CheckConnected("Slewing Get"); @@ -1620,12 +1620,12 @@ namespace ASCOM.Meade.net throw new InvalidOperationException("Unable to perform sync"); } - private double _targetDeclination = INVALID_PARAMETER; + private double _targetDeclination = InvalidParameter; public double TargetDeclination { get { - if (_targetDeclination == INVALID_PARAMETER) + if (_targetDeclination == InvalidParameter) throw new InvalidOperationException("Target not set"); //var result = SerialPort.CommandTerminated(":Gd#", "#"); @@ -1675,12 +1675,12 @@ namespace ASCOM.Meade.net } } - private double _targetRightAscension = INVALID_PARAMETER; + private double _targetRightAscension = InvalidParameter; public double TargetRightAscension { get { - if (_targetRightAscension == INVALID_PARAMETER) + if (_targetRightAscension == InvalidParameter) throw new InvalidOperationException("Target not set"); //var result = SerialPort.CommandTerminated(":Gr#", "#"); @@ -1820,9 +1820,9 @@ namespace ASCOM.Meade.net public class TelescopeDateDetails { - public string telescopeDate { get; set; } - public string telescopeTime { get; set; } - public TimeSpan utcCorrection { get; set; } + public string TelescopeDate { get; set; } + public string TelescopeTime { get; set; } + public TimeSpan UtcCorrection { get; set; } } public DateTime UTCDate @@ -1836,34 +1836,34 @@ namespace ASCOM.Meade.net TelescopeDateDetails telescopeDateDetails = _sharedResourcesWrapper.Lock(() => { TelescopeDateDetails tdd = new TelescopeDateDetails(); - tdd.telescopeDate = _sharedResourcesWrapper.SendString(":GC#"); + 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#"); + 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(); + tdd.UtcCorrection = GetUtcCorrection(); return tdd; }); - int month = telescopeDateDetails.telescopeDate.Substring(0, 2).ToInteger(); - int day = telescopeDateDetails.telescopeDate.Substring(3, 2).ToInteger(); - int year = telescopeDateDetails.telescopeDate.Substring(6, 2).ToInteger(); + int month = telescopeDateDetails.TelescopeDate.Substring(0, 2).ToInteger(); + int day = telescopeDateDetails.TelescopeDate.Substring(3, 2).ToInteger(); + int year = telescopeDateDetails.TelescopeDate.Substring(6, 2).ToInteger(); if (year < 2000) //todo fix this hack that will create a Y2K100 bug { year = year + 2000; } - int hour = telescopeDateDetails.telescopeTime.Substring(0, 2).ToInteger(); - int minute = telescopeDateDetails.telescopeTime.Substring(3, 2).ToInteger(); - int second = telescopeDateDetails.telescopeTime.Substring(6, 2).ToInteger(); + int hour = telescopeDateDetails.TelescopeTime.Substring(0, 2).ToInteger(); + int minute = telescopeDateDetails.TelescopeTime.Substring(3, 2).ToInteger(); + int second = telescopeDateDetails.TelescopeTime.Substring(6, 2).ToInteger(); var utcDate = new DateTime(year, month, day, hour, minute, second, DateTimeKind.Utc) + - telescopeDateDetails.utcCorrection; + telescopeDateDetails.UtcCorrection; LogMessage("UTCDate", "Get - " + utcDate.ToString("MM/dd/yy HH:mm:ss")); @@ -1934,18 +1934,18 @@ namespace ASCOM.Meade.net /// This is harmless if the driver is already registered/unregistered. /// /// If true, registers the driver, otherwise unregisters it. - private static void RegUnregASCOM(bool bRegister) + private static void RegUnregAscom(bool bRegister) { - using (var P = new Profile()) + using (var p = new Profile()) { - P.DeviceType = "Telescope"; + p.DeviceType = "Telescope"; if (bRegister) { - P.Register(driverID, driverDescription); + p.Register(DriverId, DriverDescription); } else { - P.Unregister(driverID); + p.Unregister(DriverId); } } } @@ -1968,9 +1968,9 @@ namespace ASCOM.Meade.net /// This technique should mean that it is never necessary to manually register a driver with ASCOM. /// [ComRegisterFunction] - public static void RegisterASCOM(Type t) + public static void RegisterAscom(Type t) { - RegUnregASCOM(true); + RegUnregAscom(true); } /// @@ -1991,9 +1991,9 @@ namespace ASCOM.Meade.net /// This technique should mean that it is never necessary to manually unregister a driver from ASCOM. /// [ComUnregisterFunction] - public static void UnregisterASCOM(Type t) + public static void UnregisterAscom(Type t) { - RegUnregASCOM(false); + RegUnregAscom(false); } #endregion @@ -2021,8 +2021,8 @@ namespace ASCOM.Meade.net internal void ReadProfile() { var profileProperties = _sharedResourcesWrapper.ReadProfile(); - tl.Enabled = profileProperties.TraceLogger; - comPort = profileProperties.ComPort; + _tl.Enabled = profileProperties.TraceLogger; + _comPort = profileProperties.ComPort; } /// @@ -2034,7 +2034,7 @@ namespace ASCOM.Meade.net internal void LogMessage(string identifier, string message, params object[] args) { var msg = string.Format(message, args); - tl.LogMessage(identifier, msg); + _tl.LogMessage(identifier, msg); } #endregion } diff --git a/Meade.net.focuser/Focuser.cs b/Meade.net.focuser/Focuser.cs index de1c03b..f2dc2ab 100644 --- a/Meade.net.focuser/Focuser.cs +++ b/Meade.net.focuser/Focuser.cs @@ -38,14 +38,14 @@ namespace ASCOM.Meade.net /// The DeviceID is used by ASCOM applications to load the driver at runtime. /// //internal static string driverID = "ASCOM.Meade.net.Focuser"; - internal static string driverID = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType); + internal static string DriverId = Marshal.GenerateProgIdForType(MethodBase.GetCurrentMethod().DeclaringType); // TODO Change the descriptive string for your driver then remove this line /// /// Driver description that displays in the ASCOM Chooser. /// - private static string driverDescription = "Meade Generic"; + private static string _driverDescription = "Meade Generic"; - internal static string comPort; // Variables to hold the currrent device configuration + internal static string ComPort; // Variables to hold the currrent device configuration /// /// Private variable to hold an ASCOM Utilities object @@ -55,7 +55,7 @@ namespace ASCOM.Meade.net /// /// Variable to hold the trace logger object (creates a diagnostic log file with information that you specify) /// - internal static TraceLogger tl; + internal static TraceLogger Tl; private readonly ISharedResourcesWrapper _sharedResourcesWrapper; @@ -74,14 +74,14 @@ namespace ASCOM.Meade.net private void Initialise() { - tl = new TraceLogger("", "Meade.net.focusser"); + Tl = new TraceLogger("", "Meade.net.focusser"); - tl.LogMessage("Focuser", "Starting initialisation"); + Tl.LogMessage("Focuser", "Starting initialisation"); ReadProfile(); // Read device configuration from the ASCOM Profile store IsConnected = false; // Initialise connected to false - tl.LogMessage("Focuser", "Completed initialisation"); + Tl.LogMessage("Focuser", "Completed initialisation"); } @@ -99,17 +99,17 @@ namespace ASCOM.Meade.net /// 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(); } } @@ -155,9 +155,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 @@ -169,7 +169,7 @@ namespace ASCOM.Meade.net } set { - tl.LogMessage("Connected", "Set {0}", value); + Tl.LogMessage("Connected", "Set {0}", value); if (value == IsConnected) return; @@ -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; } } @@ -253,7 +253,7 @@ namespace ASCOM.Meade.net Version version = Assembly.GetExecutingAssembly().GetName().Version; // TODO customise this driver description string driverInfo = "Information about the driver itself. Version: " + String.Format(CultureInfo.InvariantCulture, "{0}.{1}", version.Major, version.Minor); - tl.LogMessage("DriverInfo Get", driverInfo); + Tl.LogMessage("DriverInfo Get", driverInfo); return driverInfo; } } @@ -264,7 +264,7 @@ namespace ASCOM.Meade.net { Version version = Assembly.GetExecutingAssembly().GetName().Version; string driverVersion = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", version.Major, version.Minor); - tl.LogMessage("DriverVersion Get", driverVersion); + Tl.LogMessage("DriverVersion Get", driverVersion); return driverVersion; } } @@ -284,8 +284,8 @@ namespace ASCOM.Meade.net get { //string name = "Short driver name - please customise"; - string name = driverDescription; - tl.LogMessage("Name Get", name); + string name = _driverDescription; + Tl.LogMessage("Name Get", name); return name; } } @@ -298,14 +298,14 @@ namespace ASCOM.Meade.net { 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"); @@ -325,7 +325,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 } } @@ -334,12 +334,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 } } @@ -349,7 +349,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 } } @@ -359,37 +359,37 @@ namespace ASCOM.Meade.net { get { - tl.LogMessage("MaxStep Get", _maxStep.ToString()); + Tl.LogMessage("MaxStep Get", _maxStep.ToString()); return _maxStep; } } - public void Move(int Position) + public void Move(int position) { - tl.LogMessage("Move", Position.ToString()); + Tl.LogMessage("Move", position.ToString()); CheckConnected("Move"); //todo implement backlash compensation //todo implement direction reverse //todo implement dynamic braking - if (Position < -MaxIncrement || Position > MaxIncrement) + if (position < -MaxIncrement || position > MaxIncrement) { - throw new InvalidValueException($"position out of range {-MaxIncrement} < {Position} < {MaxIncrement}"); + throw new InvalidValueException($"position out of range {-MaxIncrement} < {position} < {MaxIncrement}"); } - if (Position == 0) + if (position == 0) return; - if (Position > 0) + if (position > 0) { //desired move direction is out - MoveFocuser(true, Math.Abs(Position)); + MoveFocuser(true, Math.Abs(position)); } else { //desired move direction is in - MoveFocuser(false, Math.Abs(Position)); + MoveFocuser(false, Math.Abs(position)); } } @@ -436,7 +436,7 @@ namespace ASCOM.Meade.net { get { - tl.LogMessage("StepSize Get", "Not implemented"); + Tl.LogMessage("StepSize Get", "Not implemented"); throw new PropertyNotImplementedException("StepSize", false); } } @@ -445,12 +445,12 @@ namespace ASCOM.Meade.net { get { - tl.LogMessage("TempComp Get", false.ToString()); + Tl.LogMessage("TempComp Get", false.ToString()); return false; } set { - tl.LogMessage("TempComp Set", "Not implemented"); + Tl.LogMessage("TempComp Set", "Not implemented"); throw new PropertyNotImplementedException("TempComp", false); } } @@ -459,7 +459,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 } } @@ -468,7 +468,7 @@ namespace ASCOM.Meade.net { get { - tl.LogMessage("Temperature Get", "Not implemented"); + Tl.LogMessage("Temperature Get", "Not implemented"); throw new PropertyNotImplementedException("Temperature", false); } } @@ -489,18 +489,18 @@ namespace ASCOM.Meade.net /// This is harmless if the driver is already registered/unregistered. /// /// If true, registers the driver, otherwise unregisters it. - private static void RegUnregASCOM(bool bRegister) + private static void RegUnregAscom(bool bRegister) { - using (var P = new Profile()) + using (var p = new Profile()) { - P.DeviceType = "Focuser"; + p.DeviceType = "Focuser"; if (bRegister) { - P.Register(driverID, driverDescription); + p.Register(DriverId, _driverDescription); } else { - P.Unregister(driverID); + p.Unregister(DriverId); } } } @@ -523,9 +523,9 @@ namespace ASCOM.Meade.net /// This technique should mean that it is never necessary to manually register a driver with ASCOM. /// [ComRegisterFunction] - public static void RegisterASCOM(Type t) + public static void RegisterAscom(Type t) { - RegUnregASCOM(true); + RegUnregAscom(true); } /// @@ -546,9 +546,9 @@ namespace ASCOM.Meade.net /// This technique should mean that it is never necessary to manually unregister a driver from ASCOM. /// [ComUnregisterFunction] - public static void UnregisterASCOM(Type t) + public static void UnregisterAscom(Type t) { - RegUnregASCOM(false); + RegUnregAscom(false); } #endregion @@ -576,8 +576,8 @@ namespace ASCOM.Meade.net internal void ReadProfile() { var profileProperties = _sharedResourcesWrapper.ReadProfile(); - tl.Enabled = profileProperties.TraceLogger; - comPort = profileProperties.ComPort; + Tl.Enabled = profileProperties.TraceLogger; + ComPort = profileProperties.ComPort; } /// @@ -589,7 +589,7 @@ namespace ASCOM.Meade.net internal 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 } diff --git a/Meade.net/ClassFactory.cs b/Meade.net/ClassFactory.cs index 7b61d4f..1f5c265 100644 --- a/Meade.net/ClassFactory.cs +++ b/Meade.net/ClassFactory.cs @@ -33,43 +33,43 @@ namespace ASCOM.Meade.net #region Access to ole32.dll functions for class factories // Define two common GUID objects for public usage. - public static Guid IID_IUnknown = new Guid("{00000000-0000-0000-C000-000000000046}"); - public static Guid IID_IDispatch = new Guid("{00020400-0000-0000-C000-000000000046}"); + public static Guid IidIUnknown = new Guid("{00000000-0000-0000-C000-000000000046}"); + public static Guid IidIDispatch = new Guid("{00020400-0000-0000-C000-000000000046}"); [Flags] - enum CLSCTX : uint + enum Clsctx : uint { - CLSCTX_INPROC_SERVER = 0x1, - CLSCTX_INPROC_HANDLER = 0x2, - CLSCTX_LOCAL_SERVER = 0x4, - CLSCTX_INPROC_SERVER16 = 0x8, - CLSCTX_REMOTE_SERVER = 0x10, - CLSCTX_INPROC_HANDLER16 = 0x20, - CLSCTX_RESERVED1 = 0x40, - CLSCTX_RESERVED2 = 0x80, - CLSCTX_RESERVED3 = 0x100, - CLSCTX_RESERVED4 = 0x200, - CLSCTX_NO_CODE_DOWNLOAD = 0x400, - CLSCTX_RESERVED5 = 0x800, - CLSCTX_NO_CUSTOM_MARSHAL = 0x1000, - CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000, - CLSCTX_NO_FAILURE_LOG = 0x4000, - CLSCTX_DISABLE_AAA = 0x8000, - CLSCTX_ENABLE_AAA = 0x10000, - CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000, - CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, - CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, - CLSCTX_ALL = CLSCTX_SERVER | CLSCTX_INPROC_HANDLER + ClsctxInprocServer = 0x1, + ClsctxInprocHandler = 0x2, + ClsctxLocalServer = 0x4, + ClsctxInprocServer16 = 0x8, + ClsctxRemoteServer = 0x10, + ClsctxInprocHandler16 = 0x20, + ClsctxReserved1 = 0x40, + ClsctxReserved2 = 0x80, + ClsctxReserved3 = 0x100, + ClsctxReserved4 = 0x200, + ClsctxNoCodeDownload = 0x400, + ClsctxReserved5 = 0x800, + ClsctxNoCustomMarshal = 0x1000, + ClsctxEnableCodeDownload = 0x2000, + ClsctxNoFailureLog = 0x4000, + ClsctxDisableAaa = 0x8000, + ClsctxEnableAaa = 0x10000, + ClsctxFromDefaultContext = 0x20000, + ClsctxInproc = ClsctxInprocServer | ClsctxInprocHandler, + ClsctxServer = ClsctxInprocServer | ClsctxLocalServer | ClsctxRemoteServer, + ClsctxAll = ClsctxServer | ClsctxInprocHandler } [Flags] - enum REGCLS : uint + enum Regcls : uint { - REGCLS_SINGLEUSE = 0, - REGCLS_MULTIPLEUSE = 1, - REGCLS_MULTI_SEPARATE = 2, - REGCLS_SUSPENDED = 4, - REGCLS_SURROGATE = 8 + RegclsSingleuse = 0, + RegclsMultipleuse = 1, + RegclsMultiSeparate = 2, + RegclsSuspended = 4, + RegclsSurrogate = 8 } // // CoRegisterClassObject() is used to register a Class Factory @@ -109,30 +109,30 @@ namespace ASCOM.Meade.net #region Constructor and Private ClassFactory Data - protected readonly Type m_ClassType; - protected Guid m_ClassId; - protected readonly ArrayList m_InterfaceTypes; - protected uint m_ClassContext; - protected uint m_Flags; - protected UInt32 m_locked = 0; - protected uint m_Cookie; - protected string m_progid; + 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; public ClassFactory(Type type) { if (type == null) throw new ArgumentNullException("type"); - m_ClassType = type; + MClassType = type; //PWGS Get the ProgID from the MetaData - m_progid = Marshal.GenerateProgIdForType(type); - m_ClassId = Marshal.GenerateGuidForType(type); // Should be nailed down by [Guid(...)] - m_ClassContext = (uint)CLSCTX.CLSCTX_LOCAL_SERVER; // Default - m_Flags = (uint)REGCLS.REGCLS_MULTIPLEUSE | // Default - (uint)REGCLS.REGCLS_SUSPENDED; - m_InterfaceTypes = new ArrayList(); + MProgid = Marshal.GenerateProgIdForType(type); + MClassId = Marshal.GenerateGuidForType(type); // Should be nailed down by [Guid(...)] + MClassContext = (uint)Clsctx.ClsctxLocalServer; // Default + MFlags = (uint)Regcls.RegclsMultipleuse | // Default + (uint)Regcls.RegclsSuspended; + MInterfaceTypes = new ArrayList(); foreach (Type T in type.GetInterfaces()) // Save all of the implemented interfaces - m_InterfaceTypes.Add(T); + MInterfaceTypes.Add(T); } #endregion @@ -140,20 +140,20 @@ namespace ASCOM.Meade.net #region Common ClassFactory Methods public uint ClassContext { - get => m_ClassContext; - set => m_ClassContext = value; + get => MClassContext; + set => MClassContext = value; } public Guid ClassId { - get => m_ClassId; - set => m_ClassId = value; + get => MClassId; + set => MClassId = value; } public uint Flags { - get => m_Flags; - set => m_Flags = value; + get => MFlags; + set => MFlags = value; } public bool RegisterClassObject() @@ -161,18 +161,18 @@ namespace ASCOM.Meade.net // Register the class factory int i = CoRegisterClassObject ( - ref m_ClassId, + ref MClassId, this, - m_ClassContext, - m_Flags, - out m_Cookie + MClassContext, + MFlags, + out MCookie ); return (i == 0); } public bool RevokeClassObject() { - int i = CoRevokeClassObject(m_Cookie); + int i = CoRevokeClassObject(MCookie); return (i == 0); } @@ -201,25 +201,25 @@ namespace ASCOM.Meade.net // // Handle specific requests for implemented interfaces // - foreach (Type iType in m_InterfaceTypes) + foreach (Type iType in MInterfaceTypes) { if (riid == Marshal.GenerateGuidForType(iType)) { - ppvObject = Marshal.GetComInterfaceForObject(Activator.CreateInstance(m_ClassType), iType); + ppvObject = Marshal.GetComInterfaceForObject(Activator.CreateInstance(MClassType), iType); return; } } // // Handle requests for IDispatch or IUnknown on the class // - if (riid == IID_IDispatch) + if (riid == IidIDispatch) { - ppvObject = Marshal.GetIDispatchForObject(Activator.CreateInstance(m_ClassType)); + ppvObject = Marshal.GetIDispatchForObject(Activator.CreateInstance(MClassType)); return; } - else if (riid == IID_IUnknown) + else if (riid == IidIUnknown) { - ppvObject = Marshal.GetIUnknownForObject(Activator.CreateInstance(m_ClassType)); + ppvObject = Marshal.GetIUnknownForObject(Activator.CreateInstance(MClassType)); } else { diff --git a/Meade.net/GarbageCollection.cs b/Meade.net/GarbageCollection.cs index 99aba52..714af79 100644 --- a/Meade.net/GarbageCollection.cs +++ b/Meade.net/GarbageCollection.cs @@ -8,35 +8,35 @@ namespace ASCOM.Meade.net /// class GarbageCollection { - protected bool m_bContinueThread; - protected bool m_GCWatchStopped; - protected int m_iInterval; - protected ManualResetEvent m_EventThreadEnded; + protected bool MBContinueThread; + protected bool MGcWatchStopped; + protected int MIInterval; + protected ManualResetEvent MEventThreadEnded; public GarbageCollection(int iInterval) { - m_bContinueThread = true; - m_GCWatchStopped = false; - m_iInterval = iInterval; - m_EventThreadEnded = new ManualResetEvent(false); + MBContinueThread = true; + MGcWatchStopped = false; + MIInterval = iInterval; + MEventThreadEnded = new ManualResetEvent(false); } - public void GCWatch() + public void GcWatch() { // Pause for a moment to provide a delay to make threads more apparent. while (ContinueThread()) { GC.Collect(); - Thread.Sleep(m_iInterval); + Thread.Sleep(MIInterval); } - m_EventThreadEnded.Set(); + MEventThreadEnded.Set(); } protected bool ContinueThread() { lock (this) { - return m_bContinueThread; + return MBContinueThread; } } @@ -44,14 +44,14 @@ namespace ASCOM.Meade.net { lock (this) { - m_bContinueThread = false; + MBContinueThread = false; } } public void WaitForThreadToStop() { - m_EventThreadEnded.WaitOne(); - m_EventThreadEnded.Reset(); + MEventThreadEnded.WaitOne(); + MEventThreadEnded.Reset(); } } } diff --git a/Meade.net/LocalServer.cs b/Meade.net/LocalServer.cs index 8bbee9e..ddafa39 100644 --- a/Meade.net/LocalServer.cs +++ b/Meade.net/LocalServer.cs @@ -31,52 +31,52 @@ namespace ASCOM.Meade.net #region Access to kernel32.dll, user32.dll, and ole32.dll functions [Flags] - enum CLSCTX : uint + enum Clsctx : uint { - CLSCTX_INPROC_SERVER = 0x1, - CLSCTX_INPROC_HANDLER = 0x2, - CLSCTX_LOCAL_SERVER = 0x4, - CLSCTX_INPROC_SERVER16 = 0x8, - CLSCTX_REMOTE_SERVER = 0x10, - CLSCTX_INPROC_HANDLER16 = 0x20, - CLSCTX_RESERVED1 = 0x40, - CLSCTX_RESERVED2 = 0x80, - CLSCTX_RESERVED3 = 0x100, - CLSCTX_RESERVED4 = 0x200, - CLSCTX_NO_CODE_DOWNLOAD = 0x400, - CLSCTX_RESERVED5 = 0x800, - CLSCTX_NO_CUSTOM_MARSHAL = 0x1000, - CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000, - CLSCTX_NO_FAILURE_LOG = 0x4000, - CLSCTX_DISABLE_AAA = 0x8000, - CLSCTX_ENABLE_AAA = 0x10000, - CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000, - CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, - CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER, - CLSCTX_ALL = CLSCTX_SERVER | CLSCTX_INPROC_HANDLER + ClsctxInprocServer = 0x1, + ClsctxInprocHandler = 0x2, + ClsctxLocalServer = 0x4, + ClsctxInprocServer16 = 0x8, + ClsctxRemoteServer = 0x10, + ClsctxInprocHandler16 = 0x20, + ClsctxReserved1 = 0x40, + ClsctxReserved2 = 0x80, + ClsctxReserved3 = 0x100, + ClsctxReserved4 = 0x200, + ClsctxNoCodeDownload = 0x400, + ClsctxReserved5 = 0x800, + ClsctxNoCustomMarshal = 0x1000, + ClsctxEnableCodeDownload = 0x2000, + ClsctxNoFailureLog = 0x4000, + ClsctxDisableAaa = 0x8000, + ClsctxEnableAaa = 0x10000, + ClsctxFromDefaultContext = 0x20000, + ClsctxInproc = ClsctxInprocServer | ClsctxInprocHandler, + ClsctxServer = ClsctxInprocServer | ClsctxLocalServer | ClsctxRemoteServer, + ClsctxAll = ClsctxServer | ClsctxInprocHandler } [Flags] - enum COINIT : uint + enum Coinit : uint { /// Initializes the thread for multi-threaded object concurrency. - COINIT_MULTITHREADED = 0x0, + CoinitMultithreaded = 0x0, /// Initializes the thread for apartment-threaded object concurrency. - COINIT_APARTMENTTHREADED = 0x2, + CoinitApartmentthreaded = 0x2, /// Disables DDE for Ole1 support. - COINIT_DISABLE_OLE1DDE = 0x4, + CoinitDisableOle1Dde = 0x4, /// Trades memory for speed. - COINIT_SPEED_OVER_MEMORY = 0x8 + CoinitSpeedOverMemory = 0x8 } [Flags] - enum REGCLS : uint + enum Regcls : uint { - REGCLS_SINGLEUSE = 0, - REGCLS_MULTIPLEUSE = 1, - REGCLS_MULTI_SEPARATE = 2, - REGCLS_SUSPENDED = 4, - REGCLS_SURROGATE = 8 + RegclsSingleuse = 0, + RegclsMultipleuse = 1, + RegclsMultiSeparate = 2, + RegclsSuspended = 4, + RegclsSurrogate = 8 } @@ -94,7 +94,7 @@ namespace ASCOM.Meade.net // We will need this API to post a WM_QUIT message to the main // thread in order to terminate this application. [DllImport("user32.dll")] - static extern bool PostThreadMessage(uint idThread, uint Msg, UIntPtr wParam, + static extern bool PostThreadMessage(uint idThread, uint msg, UIntPtr wParam, IntPtr lParam); // GetCurrentThreadId() allows us to obtain the thread id of the @@ -105,21 +105,21 @@ namespace ASCOM.Meade.net #endregion #region Private Data - private static int objsInUse; // Keeps a count on the total number of objects alive. - private static int serverLocks; // Keeps a lock count on this application. - private static frmMain s_MainForm = null; // Reference to our main form - private static ArrayList s_ComObjectAssys; // Dynamically loaded assemblies containing served COM objects - private static ArrayList s_ComObjectTypes; // Served COM object types - private static ArrayList s_ClassFactories; // Served COM object class factories - private static string s_appId = "{4e68ec46-5ffc-49e7-b298-38a548df0bfd}"; // Our AppId - private static readonly Object lockObject = new object(); + private static int _objsInUse; // Keeps a count on the total number of objects alive. + private static int _serverLocks; // Keeps a lock count on this application. + private static FrmMain _sMainForm = null; // Reference to our main form + private static ArrayList _sComObjectAssys; // Dynamically loaded assemblies containing served COM objects + private static ArrayList _sComObjectTypes; // Served COM object types + private static ArrayList _sClassFactories; // Served COM object class factories + private static string _sAppId = "{4e68ec46-5ffc-49e7-b298-38a548df0bfd}"; // Our AppId + private static readonly Object LockObject = new object(); #endregion // This property returns the main thread's id. public static uint MainThreadId { get; private set; } // Stores the main thread's thread id. // Used to tell if started by COM or manually - public static bool StartedByCOM { get; private set; } // True if server started by COM (-embedding) + public static bool StartedByCom { get; private set; } // True if server started by COM (-embedding) #region Server Lock, Object Counting, and AutoQuit on COM startup @@ -128,9 +128,9 @@ namespace ASCOM.Meade.net { get { - lock (lockObject) + lock (LockObject) { - return objsInUse; + return _objsInUse; } } } @@ -139,14 +139,14 @@ namespace ASCOM.Meade.net public static int CountObject() { // Increment the global count of objects. - return Interlocked.Increment(ref objsInUse); + return Interlocked.Increment(ref _objsInUse); } // This method performs a thread-safe decrementation the objects count. public static int UncountObject() { // Decrement the global count of objects. - return Interlocked.Decrement(ref objsInUse); + return Interlocked.Decrement(ref _objsInUse); } // Returns the current server lock count. @@ -154,9 +154,9 @@ namespace ASCOM.Meade.net { get { - lock (lockObject) + lock (LockObject) { - return serverLocks; + return _serverLocks; } } } @@ -166,7 +166,7 @@ namespace ASCOM.Meade.net public static int CountLock() { // Increment the global lock count of this server. - return Interlocked.Increment(ref serverLocks); + return Interlocked.Increment(ref _serverLocks); } // This method performs a thread-safe decrementation the @@ -174,7 +174,7 @@ namespace ASCOM.Meade.net public static int UncountLock() { // Decrement the global lock count of this server. - return Interlocked.Decrement(ref serverLocks); + return Interlocked.Decrement(ref _serverLocks); } // AttemptToTerminateServer() will check to see if the objects count and the server @@ -186,11 +186,11 @@ namespace ASCOM.Meade.net // public static void ExitIf() { - lock (lockObject) + lock (LockObject) { if ((ObjectsCount <= 0) && (ServerLockCount <= 0)) { - if (StartedByCOM) + if (StartedByCom) { UIntPtr wParam = new UIntPtr(0); IntPtr lParam = new IntPtr(0); @@ -213,8 +213,8 @@ namespace ASCOM.Meade.net // private static bool LoadComObjectAssemblies() { - s_ComObjectAssys = new ArrayList(); - s_ComObjectTypes = new ArrayList(); + _sComObjectAssys = new ArrayList(); + _sComObjectTypes = new ArrayList(); // put everything into one folder, the same as the server. string assyPath = Assembly.GetEntryAssembly().Location; @@ -243,8 +243,8 @@ namespace ASCOM.Meade.net if (attrbutes.Length > 0) { //MessageBox.Show("Adding Type: " + type.Name + " " + type.FullName); - s_ComObjectTypes.Add(type); //PWGS - much simpler - s_ComObjectAssys.Add(so); + _sComObjectTypes.Add(type); //PWGS - much simpler + _sComObjectAssys.Add(so); } } } @@ -339,10 +339,10 @@ namespace ASCOM.Meade.net // // HKCR\APPID\appid // - using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("APPID\\" + s_appId)) + using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("APPID\\" + _sAppId)) { key.SetValue(null, assyDescription); - key.SetValue("AppID", s_appId); + key.SetValue("AppID", _sAppId); key.SetValue("AuthenticationLevel", 1, RegistryValueKind.DWord); } // @@ -351,7 +351,7 @@ namespace ASCOM.Meade.net using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("APPID\\{0}", Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)))) { - key.SetValue("AppID", s_appId); + key.SetValue("AppID", _sAppId); } } catch (Exception ex) @@ -367,7 +367,7 @@ namespace ASCOM.Meade.net // // For each of the driver assemblies // - foreach (Type type in s_ComObjectTypes) + foreach (Type type in _sComObjectTypes) { bool bFail = false; try @@ -383,7 +383,7 @@ namespace ASCOM.Meade.net using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(string.Format("CLSID\\{0}", clsid))) { key.SetValue(null, progid); // Could be assyTitle/Desc??, but .NET components show ProgId here - key.SetValue("AppId", s_appId); + key.SetValue("AppId", _sAppId); using (RegistryKey key2 = key.CreateSubKey("Implemented Categories")) { key2.CreateSubKey("{62C8FE65-4EBB-45e7-B440-6E39B2CDBF29}"); @@ -417,10 +417,10 @@ namespace ASCOM.Meade.net // Pull the display name from the ServedClassName attribute. attr = Attribute.GetCustomAttribute(type, typeof(ServedClassNameAttribute)); //PWGS Changed to search type for attribute rather than assembly string chooserName = ((ServedClassNameAttribute)attr).DisplayName ?? "MultiServer"; - using (var P = new Profile()) + using (var p = new Profile()) { - P.DeviceType = deviceType; - P.Register(progid, chooserName); + p.DeviceType = deviceType; + p.Register(progid, chooserName); } } catch (Exception ex) @@ -453,14 +453,14 @@ namespace ASCOM.Meade.net // // Local server's DCOM/AppID information // - Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", s_appId), false); + Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", _sAppId), false); Registry.ClassesRoot.DeleteSubKey(string.Format("APPID\\{0}", Application.ExecutablePath.Substring(Application.ExecutablePath.LastIndexOf('\\') + 1)), false); // // For each of the driver assemblies // - foreach (Type type in s_ComObjectTypes) + foreach (Type type in _sComObjectTypes) { string clsid = Marshal.GenerateGuidForType(type).ToString("B"); string progid = Marshal.GenerateProgIdForType(type); @@ -487,10 +487,10 @@ namespace ASCOM.Meade.net // // ASCOM // - using (var P = new Profile()) + using (var p = new Profile()) { - P.DeviceType = deviceType; - P.Unregister(progid); + p.DeviceType = deviceType; + p.Unregister(progid); } } catch (Exception) { } @@ -506,11 +506,11 @@ namespace ASCOM.Meade.net // private static bool RegisterClassFactories() { - s_ClassFactories = new ArrayList(); - foreach (Type type in s_ComObjectTypes) + _sClassFactories = new ArrayList(); + foreach (Type type in _sComObjectTypes) { ClassFactory factory = new ClassFactory(type); // Use default context & flags - s_ClassFactories.Add(factory); + _sClassFactories.Add(factory); if (!factory.RegisterClassObject()) { MessageBox.Show("Failed to register class factory for " + type.Name, @@ -525,7 +525,7 @@ namespace ASCOM.Meade.net private static void RevokeClassFactories() { ClassFactory.SuspendClassObjects(); // Prevent race conditions - foreach (ClassFactory factory in s_ClassFactories) + foreach (ClassFactory factory in _sClassFactories) factory.RevokeClassObject(); } #endregion @@ -549,7 +549,7 @@ namespace ASCOM.Meade.net switch (args[0].ToLower()) { case "-embedding": - StartedByCOM = true; // Indicate COM started us + StartedByCom = true; // Indicate COM started us break; case "-register": @@ -575,7 +575,7 @@ namespace ASCOM.Meade.net } } else - StartedByCOM = false; + StartedByCom = false; return bRet; } @@ -595,24 +595,24 @@ namespace ASCOM.Meade.net if (!ProcessArguments(args)) return; // Register/Unregister // Initialize critical member variables. - objsInUse = 0; - serverLocks = 0; + _objsInUse = 0; + _serverLocks = 0; MainThreadId = GetCurrentThreadId(); Thread.CurrentThread.Name = "Main Thread"; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - s_MainForm = new frmMain(); - if (StartedByCOM) s_MainForm.WindowState = FormWindowState.Minimized; + _sMainForm = new FrmMain(); + if (StartedByCom) _sMainForm.WindowState = FormWindowState.Minimized; // Register the class factories of the served objects 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"; - GCThread.Start(); + GarbageCollection garbageCollector = new GarbageCollection(1000); + Thread gcThread = new Thread(new ThreadStart(garbageCollector.GcWatch)); + gcThread.Name = "Garbage Collection Thread"; + gcThread.Start(); // // Start the message loop. This serializes incoming calls to our @@ -620,7 +620,7 @@ namespace ASCOM.Meade.net // try { - Application.Run(s_MainForm); + Application.Run(_sMainForm); } finally { @@ -630,8 +630,8 @@ namespace ASCOM.Meade.net RevokeClassFactories(); // Now stop the Garbage Collector thread. - GarbageCollector.StopThread(); - GarbageCollector.WaitForThreadToStop(); + garbageCollector.StopThread(); + garbageCollector.WaitForThreadToStop(); } } #endregion diff --git a/Meade.net/SharedResources.cs b/Meade.net/SharedResources.cs index 1d5a709..d42147e 100644 --- a/Meade.net/SharedResources.cs +++ b/Meade.net/SharedResources.cs @@ -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 /// /// Shared serial port /// - public static Serial SharedSerial => s_sharedSerial ?? (s_sharedSerial = new Serial()); + public static Serial SharedSerial => _sSharedSerial ?? (_sSharedSerial = new Serial()); /// /// 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 /// 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 /// - private static Dictionary connectedDevices = new Dictionary(); + private static Dictionary _connectedDevices = new Dictionary(); /// /// This is called in the driver Connect(true) property, @@ -253,15 +253,15 @@ namespace ASCOM.Meade.net /// 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(Func 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; } } diff --git a/Meade.net/Wrapper/SharedResourcesWrapper.cs b/Meade.net/Wrapper/SharedResourcesWrapper.cs index cbfa0d3..c49454c 100644 --- a/Meade.net/Wrapper/SharedResourcesWrapper.cs +++ b/Meade.net/Wrapper/SharedResourcesWrapper.cs @@ -4,10 +4,10 @@ namespace ASCOM.Meade.net.Wrapper { public interface ISharedResourcesWrapper { - string AUTOSTAR497 { get; } - string AUTOSTAR497_31EE { get; } + string Autostar497 { get; } + string Autostar49731Ee { get; } - string AUTOSTAR497_43EG { get;} + string Autostar49743Eg { get;} void Connect(string deviceId); void Disconnect(string deviceId); @@ -34,10 +34,10 @@ namespace ASCOM.Meade.net.Wrapper { #region AutostarProducts - public string AUTOSTAR497 => "Autostar"; + public string Autostar497 => "Autostar"; - public string AUTOSTAR497_31EE => "31Ee"; - public string AUTOSTAR497_43EG => "43Eg"; + public string Autostar49731Ee => "31Ee"; + public string Autostar49743Eg => "43Eg"; #endregion diff --git a/Meade.net/frmMain.Designer.cs b/Meade.net/frmMain.Designer.cs index 83c8dd1..e8bef51 100644 --- a/Meade.net/frmMain.Designer.cs +++ b/Meade.net/frmMain.Designer.cs @@ -2,7 +2,7 @@ using System; namespace ASCOM.Meade.net { - partial class frmMain + partial class FrmMain { /// /// Required designer variable. @@ -48,7 +48,7 @@ namespace ASCOM.Meade.net this.ClientSize = new System.Drawing.Size(233, 52); this.Controls.Add(this.label1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; - this.Name = "frmMain"; + this.Name = "FrmMain"; this.Text = "Meade.net Driver Server"; this.ResumeLayout(false); diff --git a/Meade.net/frmMain.cs b/Meade.net/frmMain.cs index 7ac44b7..2ae5c27 100644 --- a/Meade.net/frmMain.cs +++ b/Meade.net/frmMain.cs @@ -2,11 +2,11 @@ using System.Windows.Forms; namespace ASCOM.Meade.net { - public partial class frmMain : Form + public partial class FrmMain : Form { delegate void SetTextCallback(string text); - public frmMain() + public FrmMain() { InitializeComponent(); }