/*-------------------------------------------------------------------------
// UNCLASSIFIED
/*-------------------------------------------------------------------------
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
COMPANY.
THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
GOVERNMENT.
UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/
using NLog;
using Raytheon.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Reflection;
namespace Raytheon.Instruments.PowerSupplies
{
[ExportInstrumentFactory(ModelNumber = "PowerSupplyKeysightN67xxFactory")]
public class KeysightN67xxPowerFactory : IInstrumentFactory
{
///
/// The supported interfaces
///
private readonly List _supportedInterfaces = new List();
private static ILogger _logger;
private readonly IConfigurationManager _configurationManager;
private const string DefaultConfigPath = @"C:\ProgramData\Raytheon\InstrumentManagerService";
private static string DefaultPath;
public KeysightN67xxPowerFactory(string defaultConfigPath = DefaultConfigPath)
: this(null, defaultConfigPath)
{
}
///
/// COECommDeviceInstrumentFactory injection constructor
///
///
///
///
[ImportingConstructor]
public KeysightN67xxPowerFactory([Import(AllowDefault = false)] IConfigurationManager configManager,
[Import(AllowDefault = true)] string defaultConfigPath = null)
{
DefaultPath = defaultConfigPath;
_logger = LogManager.GetCurrentClassLogger();
if (NLog.LogManager.Configuration == null)
{
var assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration(assemblyFolder + "\\nlog.config");
}
_configurationManager = configManager ?? GetConfigurationManager();
_supportedInterfaces.Add(typeof(PowerSupply));
}
///
/// Gets the instrument
///
///
///
public IInstrument GetInstrument(string name)
{
return null;
}
///
/// Gets the instrument
///
///
///
public object GetInstrument(string name, bool simulateHw)
{
try
{
if (simulateHw)
return new PowerSupplySim(name, _configurationManager, _logger);
else
return new KeysightN67xxPowerSupply(name, _configurationManager, _logger);
}
catch (Exception ex)
{
_logger.Error(ex, $"Unable to construct {name} instrument instance");
return null;
}
}
///
/// Gets supported interfaces
///
///
public ICollection GetSupportedInterfaces()
{
return _supportedInterfaces.ToArray();
}
///
/// returns confiuration based on the predefined path or default path c:/ProgramData/Raytheon/InstrumentManagerService
///
///
private static IConfigurationManager GetConfigurationManager()
{
return string.IsNullOrEmpty(DefaultPath) ? new RaytheonConfigurationManager() : new RaytheonConfigurationManager(DefaultPath);
}
}
}