Altered the profile read exception handling a little.
This commit is contained in:
@@ -148,6 +148,7 @@
|
|||||||
<Compile Include="TelescopeList.cs" />
|
<Compile Include="TelescopeList.cs" />
|
||||||
<Compile Include="ThreadSafeValue.cs" />
|
<Compile Include="ThreadSafeValue.cs" />
|
||||||
<Compile Include="Win32Utilities.cs" />
|
<Compile Include="Win32Utilities.cs" />
|
||||||
|
<Compile Include="Wrapper\GetValueException.cs" />
|
||||||
<Compile Include="Wrapper\IProfileWrapper.cs" />
|
<Compile Include="Wrapper\IProfileWrapper.cs" />
|
||||||
<Compile Include="Wrapper\SharedResourcesWrapper.cs" />
|
<Compile Include="Wrapper\SharedResourcesWrapper.cs" />
|
||||||
<EmbeddedResource Include="frmMain.resx">
|
<EmbeddedResource Include="frmMain.resx">
|
||||||
|
|||||||
@@ -283,30 +283,30 @@ namespace ASCOM.Meade.net
|
|||||||
{
|
{
|
||||||
driverProfile.DeviceType = "Telescope";
|
driverProfile.DeviceType = "Telescope";
|
||||||
profileProperties.ComPort = driverProfile.GetValue(DriverId, ComPortProfileName, string.Empty, ComPortDefault);
|
profileProperties.ComPort = driverProfile.GetValue(DriverId, ComPortProfileName, string.Empty, ComPortDefault);
|
||||||
profileProperties.TimeoutMs = Convert.ToInt32(driverProfile.GetValue(DriverId, TimeoutMsName, string.Empty, TimeoutMsDefault));
|
profileProperties.TimeoutMs = driverProfile.GetValueInt(DriverId, TimeoutMsName, string.Empty, TimeoutMsDefault);
|
||||||
profileProperties.RtsDtrEnabled = Convert.ToBoolean(driverProfile.GetValue(DriverId, RtsDtrProfileName, string.Empty, RtsDtrDefault));
|
profileProperties.RtsDtrEnabled = driverProfile.GetValueBool(DriverId, RtsDtrProfileName, string.Empty, RtsDtrDefault);
|
||||||
profileProperties.TraceLogger = Convert.ToBoolean(driverProfile.GetValue(DriverId, TraceStateProfileName, string.Empty, TraceStateDefault));
|
profileProperties.TraceLogger = driverProfile.GetValueBool(DriverId, TraceStateProfileName, string.Empty, TraceStateDefault);
|
||||||
profileProperties.GuideRateArcSecondsPerSecond = double.Parse(driverProfile.GetValue(DriverId, GuideRateProfileName, string.Empty, GuideRateProfileNameDefault), NumberFormatInfo.InvariantInfo);
|
profileProperties.GuideRateArcSecondsPerSecond = driverProfile.GetValueDouble(DriverId, GuideRateProfileName, string.Empty, GuideRateProfileNameDefault);
|
||||||
profileProperties.Precision = driverProfile.GetValue(DriverId, PrecisionProfileName, string.Empty, PrecisionDefault);
|
profileProperties.Precision = driverProfile.GetValue(DriverId, PrecisionProfileName, string.Empty, PrecisionDefault);
|
||||||
profileProperties.GuidingStyle = driverProfile.GetValue(DriverId, GuidingStyleProfileName, string.Empty, GuidingStyleDefault);
|
profileProperties.GuidingStyle = driverProfile.GetValue(DriverId, GuidingStyleProfileName, string.Empty, GuidingStyleDefault);
|
||||||
profileProperties.BacklashCompensation = Convert.ToInt32(driverProfile.GetValue(DriverId, BacklashCompensationName, string.Empty, BacklashCompensationDefault));
|
profileProperties.BacklashCompensation = driverProfile.GetValueInt(DriverId, BacklashCompensationName, string.Empty, BacklashCompensationDefault);
|
||||||
profileProperties.ReverseFocusDirection = Convert.ToBoolean(driverProfile.GetValue(DriverId, ReverseFocusDirectionName, string.Empty, ReverseFocuserDiectionDefault));
|
profileProperties.ReverseFocusDirection = driverProfile.GetValueBool(DriverId, ReverseFocusDirectionName, string.Empty, ReverseFocuserDiectionDefault);
|
||||||
profileProperties.DynamicBreaking = Convert.ToBoolean(driverProfile.GetValue(DriverId, DynamicBreakingName, string.Empty, DynamicBreakingDefault));
|
profileProperties.DynamicBreaking = driverProfile.GetValueBool(DriverId, DynamicBreakingName, string.Empty, DynamicBreakingDefault);
|
||||||
profileProperties.SiteElevation = Convert.ToInt32(driverProfile.GetValue(DriverId, SiteElevationName, string.Empty, SiteElevationDefault));
|
profileProperties.SiteElevation = driverProfile.GetValueInt(DriverId, SiteElevationName, string.Empty, SiteElevationDefault);
|
||||||
profileProperties.SettleTime = Convert.ToInt16(driverProfile.GetValue(DriverId, SettleTimeName, string.Empty, SettleTimeDefault));
|
profileProperties.SettleTime = driverProfile.GetValueShort(DriverId, SettleTimeName, string.Empty, SettleTimeDefault);
|
||||||
profileProperties.StopBits = driverProfile.GetValue(DriverId, StopBitsName, string.Empty, StopBitsDefault);
|
profileProperties.StopBits = driverProfile.GetValue(DriverId, StopBitsName, string.Empty, StopBitsDefault);
|
||||||
profileProperties.DataBits = Convert.ToInt32(driverProfile.GetValue(DriverId, DataBitsName, string.Empty, DataBitsDefault));
|
profileProperties.DataBits = driverProfile.GetValueInt(DriverId, DataBitsName, string.Empty, DataBitsDefault);
|
||||||
profileProperties.Handshake = driverProfile.GetValue(DriverId, HandShakeName, string.Empty, HandShakeDefault);
|
profileProperties.Handshake = driverProfile.GetValue(DriverId, HandShakeName, string.Empty, HandShakeDefault);
|
||||||
profileProperties.Speed = Convert.ToInt32(driverProfile.GetValue(DriverId, SpeedName, string.Empty, SpeedDefault));
|
profileProperties.Speed = driverProfile.GetValueInt(DriverId, SpeedName, string.Empty, SpeedDefault);
|
||||||
profileProperties.Parity = driverProfile.GetValue(DriverId, ParityName, string.Empty, ParityDefault);
|
profileProperties.Parity = driverProfile.GetValue(DriverId, ParityName, string.Empty, ParityDefault);
|
||||||
profileProperties.SendDateTime = Convert.ToBoolean(driverProfile.GetValue(DriverId, SendDateTimeName, string.Empty, SendDateTimeDefault));
|
profileProperties.SendDateTime = driverProfile.GetValueBool(DriverId, SendDateTimeName, string.Empty, SendDateTimeDefault);
|
||||||
|
|
||||||
profileProperties.ParkedBehaviour = EnumExtensionMethods.GetValueFromDescription<ParkedBehaviour>(driverProfile.GetValue(DriverId, ParkedBehaviourName, string.Empty, ParkedBehaviourDefault));
|
profileProperties.ParkedBehaviour = EnumExtensionMethods.GetValueFromDescription<ParkedBehaviour>(driverProfile.GetValue(DriverId, ParkedBehaviourName, string.Empty, ParkedBehaviourDefault));
|
||||||
profileProperties.ParkedAlt = double.Parse(driverProfile.GetValue(DriverId, ParkedAltName, string.Empty, ParkedAltDefault), NumberFormatInfo.InvariantInfo);
|
profileProperties.ParkedAlt = driverProfile.GetValueDouble(DriverId, ParkedAltName, string.Empty, ParkedAltDefault);
|
||||||
profileProperties.ParkedAz = double.Parse(driverProfile.GetValue(DriverId, ParkedAzimuthName, string.Empty, ParkedAzimuthDefault), NumberFormatInfo.InvariantInfo);
|
profileProperties.ParkedAz = driverProfile.GetValueDouble(DriverId, ParkedAzimuthName, string.Empty, ParkedAzimuthDefault);
|
||||||
profileProperties.FocalLength = double.Parse(driverProfile.GetValue(DriverId, FocalLengthName, string.Empty, FocalLengthDefault), NumberFormatInfo.InvariantInfo);
|
profileProperties.FocalLength = driverProfile.GetValueDouble(DriverId, FocalLengthName, string.Empty, FocalLengthDefault);
|
||||||
profileProperties.ApertureArea = double.Parse(driverProfile.GetValue(DriverId, ApertureAreaName, string.Empty, ApertureAreaDefault), NumberFormatInfo.InvariantInfo);
|
profileProperties.ApertureArea = driverProfile.GetValueDouble(DriverId, ApertureAreaName, string.Empty, ApertureAreaDefault);
|
||||||
profileProperties.ApertureDiameter = double.Parse(driverProfile.GetValue(DriverId, ApertureDiameterName, string.Empty, ApertureDiameterDefault), NumberFormatInfo.InvariantInfo);
|
profileProperties.ApertureDiameter = driverProfile.GetValueDouble(DriverId, ApertureDiameterName, string.Empty, ApertureDiameterDefault);
|
||||||
}
|
}
|
||||||
|
|
||||||
return profileProperties;
|
return profileProperties;
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ASCOM.Meade.net.Wrapper
|
||||||
|
{
|
||||||
|
public class GetValueException : Exception
|
||||||
|
{
|
||||||
|
public GetValueException(
|
||||||
|
string driverId,
|
||||||
|
string name,
|
||||||
|
string subKey,
|
||||||
|
string defaultValue,
|
||||||
|
Exception innerException
|
||||||
|
) : base ( $"Error getting value {name} from driver {driverId} in {subKey} and default value {defaultValue} cannot be used.", innerException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetValueException(
|
||||||
|
string driverId,
|
||||||
|
string name,
|
||||||
|
string subKey,
|
||||||
|
string defaultValue,
|
||||||
|
string value,
|
||||||
|
Exception innerException):
|
||||||
|
base($"Error converting value {name} from {value}", innerException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
using System.Globalization;
|
||||||
using ASCOM.Utilities;
|
using ASCOM.Utilities;
|
||||||
using ASCOM.Utilities.Interfaces;
|
using ASCOM.Utilities.Interfaces;
|
||||||
|
|
||||||
@@ -7,7 +8,11 @@ namespace ASCOM.Meade.net.Wrapper
|
|||||||
{
|
{
|
||||||
public interface IProfileWrapper : IProfile, IProfileExtra, IDisposable
|
public interface IProfileWrapper : IProfile, IProfileExtra, IDisposable
|
||||||
{
|
{
|
||||||
|
int GetValueInt(string driverId, string name, string subKey, string defaultValue);
|
||||||
|
short GetValueShort(string driverId, string name, string subKey, string defaultValue);
|
||||||
|
|
||||||
|
bool GetValueBool(string driverId, string name, string subKey, string defaultValue);
|
||||||
|
double GetValueDouble(string driverId, string name, string subKey, string defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ProfileWrapper : IProfileWrapper
|
public class ProfileWrapper : IProfileWrapper
|
||||||
@@ -36,7 +41,68 @@ namespace ASCOM.Meade.net.Wrapper
|
|||||||
|
|
||||||
public string GetValue(string driverId, string name, string subKey, string defaultValue)
|
public string GetValue(string driverId, string name, string subKey, string defaultValue)
|
||||||
{
|
{
|
||||||
return _profile.GetValue(driverId, name, subKey, defaultValue);
|
try
|
||||||
|
{
|
||||||
|
return _profile.GetValue(driverId, name, subKey, defaultValue);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new GetValueException(driverId, name, subKey, defaultValue, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetValueInt(string driverId, string name, string subKey, string defaultValue)
|
||||||
|
{
|
||||||
|
var value = _profile.GetValue(driverId, name, subKey, defaultValue);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return int.Parse(value, CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new GetValueException(driverId, name, subKey, defaultValue, value, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public short GetValueShort(string driverId, string name, string subKey, string defaultValue)
|
||||||
|
{
|
||||||
|
var value = _profile.GetValue(driverId, name, subKey, defaultValue);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return short.Parse(value, CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new GetValueException(driverId, name, subKey, defaultValue, value, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool GetValueBool(string driverId, string name, string subKey, string defaultValue)
|
||||||
|
{
|
||||||
|
var value = _profile.GetValue(driverId, name, subKey, defaultValue);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return bool.Parse(value);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new GetValueException(driverId, name, subKey, defaultValue, value, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double GetValueDouble(string driverId, string name, string subKey, string defaultValue)
|
||||||
|
{
|
||||||
|
var value = _profile.GetValue(driverId, name, subKey, defaultValue);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return double.Parse(value, CultureInfo.InvariantCulture);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
throw new GetValueException(driverId, name, subKey, defaultValue, value, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteValue(string driverId, string name, string value, string subKey)
|
public void WriteValue(string driverId, string name, string value, string subKey)
|
||||||
|
|||||||
Reference in New Issue
Block a user