95 lines
2.9 KiB
C#
95 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.Composition;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using NLog;
|
|
using Raytheon.Common;
|
|
|
|
namespace Raytheon.Instruments
|
|
{
|
|
[ExportInstrumentFactory(ModelNumber = "CommDeviceSimFactory")]
|
|
public class CommDeviceSimFactory : IInstrumentFactory
|
|
{
|
|
private readonly List<Type> _supportedInterfaces = new List<Type>();
|
|
|
|
private readonly IConfigurationManager _configurationManager;
|
|
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
|
|
private static string DefaultPath;
|
|
|
|
public CommDeviceSimFactory(string defaultConfigPath = DefaultConfigPath)
|
|
: this(null, defaultConfigPath)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// COECommDeviceInstrumentFactory injection constructor
|
|
/// </summary>
|
|
[ImportingConstructor]
|
|
public CommDeviceSimFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
|
|
[Import(AllowDefault = true)] string defaultConfigPath = null)
|
|
{
|
|
DefaultPath = defaultConfigPath;
|
|
|
|
if (LogManager.Configuration == null)
|
|
{
|
|
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
|
|
}
|
|
|
|
_configurationManager = configManager ?? GetConfigurationManager();
|
|
_supportedInterfaces.Add(typeof(ICommDevice));
|
|
}
|
|
/// <summary>
|
|
/// Gets the instrument
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
/// <returns></returns>
|
|
public IInstrument GetInstrument(string name)
|
|
{
|
|
try
|
|
{
|
|
return new CommDeviceSim(name, _configurationManager);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the instrument
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
/// <returns></returns>
|
|
public object GetInstrument(string name, bool simulateHw)
|
|
{
|
|
try
|
|
{
|
|
return new CommDeviceSim(name, _configurationManager);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets supported interfaces
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public ICollection<Type> GetSupportedInterfaces()
|
|
{
|
|
return _supportedInterfaces.ToArray();
|
|
}
|
|
|
|
/// <summary>
|
|
/// returns configuration based on the predefined path or default path c:/ProgramData/Raytheon/InstrumentManagerService
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private static IConfigurationManager GetConfigurationManager()
|
|
{
|
|
return string.IsNullOrEmpty(DefaultPath) ? new RaytheonConfigurationManager() : new RaytheonConfigurationManager(DefaultPath);
|
|
}
|
|
}
|
|
} |