Upgraded the Profile code to be contained inside a wrapper and started adding unit tests to cover.

This commit is contained in:
2019-10-21 21:16:09 +01:00
parent 438ec779b4
commit a155e27eac
7 changed files with 251 additions and 5 deletions
+2
View File
@@ -134,10 +134,12 @@
</Compile>
<Compile Include="GarbageCollection.cs" />
<Compile Include="LocalServer.cs" />
<Compile Include="ProfileFactory.cs" />
<Compile Include="ProfileProperties.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TelescopeList.cs" />
<Compile Include="Win32Utilities.cs" />
<Compile Include="Wrapper\IProfileWrapper.cs" />
<Compile Include="Wrapper\SharedResourcesWrapper.cs" />
<EmbeddedResource Include="frmMain.resx">
<SubType>Designer</SubType>
+18
View File
@@ -0,0 +1,18 @@
using ASCOM.Meade.net.Wrapper;
using ASCOM.Utilities;
namespace ASCOM.Meade.net
{
public interface IProfileFactory
{
IProfileWrapper Create();
}
public class ProfileFactory : IProfileFactory
{
public IProfileWrapper Create()
{
return new ProfileWrapper();
}
}
}
+11 -3
View File
@@ -18,6 +18,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using ASCOM.Meade.net.Wrapper;
using ASCOM.Utilities;
using ASCOM.Utilities.Interfaces;
@@ -68,6 +69,12 @@ namespace ASCOM.Meade.net
set => _sSharedSerial = value;
}
public static IProfileFactory ProfileFactory
{
get => _profileFactory ?? ( _profileFactory = new ProfileFactory());
set => _profileFactory = value;
}
public static void SendBlind(string message)
{
lock (LockObject)
@@ -132,12 +139,12 @@ namespace ASCOM.Meade.net
private const string TraceStateProfileName = "Trace Level";
private const string GuideRateProfileName = "Guide Rate Arc Seconds Per Second";
private const string PrecisionProfileName = "Precision";
public static void WriteProfile(ProfileProperties profileProperties)
{
lock (LockObject)
{
using (Profile driverProfile = new Profile())
using (IProfileWrapper driverProfile = ProfileFactory.Create())
{
driverProfile.DeviceType = "Telescope";
driverProfile.WriteValue(DriverId, TraceStateProfileName, profileProperties.TraceLogger.ToString());
@@ -158,7 +165,7 @@ namespace ASCOM.Meade.net
lock (LockObject)
{
ProfileProperties profileProperties = new ProfileProperties();
using (Profile driverProfile = new Profile())
using (IProfileWrapper driverProfile = ProfileFactory.Create())
{
driverProfile.DeviceType = "Telescope";
profileProperties.ComPort = driverProfile.GetValue(DriverId, ComPortProfileName, string.Empty, ComPortDefault);
@@ -222,6 +229,7 @@ namespace ASCOM.Meade.net
private static readonly Dictionary<string, DeviceHardware> ConnectedDevices = new Dictionary<string, DeviceHardware>();
private static readonly Dictionary<string, DeviceHardware> ConnectedDeviceIds = new Dictionary<string, DeviceHardware>();
private static IProfileFactory _profileFactory ;
/// <summary>
+139
View File
@@ -0,0 +1,139 @@
using System;
using System.Collections;
using ASCOM.Utilities;
using ASCOM.Utilities.Interfaces;
namespace ASCOM.Meade.net.Wrapper
{
public interface IProfileWrapper : IProfile, IProfileExtra, IDisposable
{
}
public class ProfileWrapper : IProfileWrapper
{
private readonly Profile _profile = new Profile();
public ArrayList RegisteredDevices(string DeviceType)
{
return _profile.RegisteredDevices(DeviceType);
}
public bool IsRegistered(string DriverID)
{
return _profile.IsRegistered(DriverID);
}
public void Register(string DriverID, string DescriptiveName)
{
_profile.Register(DriverID, DescriptiveName);
}
public void Unregister(string DriverID)
{
_profile.Unregister(DriverID);
}
public string GetValue(string DriverID, string Name, string SubKey, string DefaultValue)
{
return _profile.GetValue(DriverID, Name, SubKey, DefaultValue);
}
public void WriteValue(string DriverID, string Name, string Value, string SubKey)
{
_profile.WriteValue(DriverID, Name, Value);
}
public ArrayList Values(string DriverID, string SubKey)
{
return _profile.Values(DriverID, SubKey);
}
public void DeleteValue(string DriverID, string Name, string SubKey)
{
_profile.DeleteValue(DriverID, Name, SubKey);
}
public void CreateSubKey(string DriverID, string SubKey)
{
_profile.CreateSubKey(DriverID, SubKey);
}
public ArrayList SubKeys(string DriverID, string SubKey)
{
return _profile.SubKeys(DriverID, SubKey);
}
public void DeleteSubKey(string DriverID, string SubKey)
{
_profile.DeleteSubKey(DriverID, SubKey);
}
public string GetProfileXML(string deviceId)
{
return _profile.GetProfileXML(deviceId);
}
public void SetProfileXML(string deviceId, string xml)
{
_profile.SetProfileXML(deviceId, xml);
}
public string DeviceType
{
get => _profile.DeviceType;
set => _profile.DeviceType = value;
}
public ArrayList RegisteredDeviceTypes => _profile.RegisteredDeviceTypes;
public void MigrateProfile(string CurrentPlatformVersion)
{
_profile.MigrateProfile(CurrentPlatformVersion);
}
public void DeleteValue(string DriverID, string Name)
{
_profile.DeleteValue(DriverID, Name);
}
public string GetValue(string DriverID, string Name)
{
return _profile.GetValue(DriverID, Name);
}
public string GetValue(string DriverID, string Name, string SubKey)
{
return _profile.GetValue(DriverID, Name, SubKey);
}
public ArrayList SubKeys(string DriverID)
{
return _profile.SubKeys(DriverID);
}
public ArrayList Values(string DriverID)
{
return _profile.Values(DriverID);
}
public void WriteValue(string DriverID, string Name, string Value)
{
_profile.WriteValue(DriverID, Name, Value);
}
public ASCOMProfile GetProfile(string DriverId)
{
return _profile.GetProfile(DriverId);
}
public void SetProfile(string DriverId, ASCOMProfile XmlProfileKey)
{
_profile.SetProfile(DriverId, XmlProfileKey);
}
public void Dispose()
{
_profile.Dispose();
}
}
}