// ****************************************************************************************** // ** ** // ** 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. ** // ** ** // ** WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE ** // ** EXPORT OR DISCLOSURE TO NON-U.S.PERSONS, WHEREVER LOCATED, IS RESTRICTED ** // ** BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R.SECTION ** // ** 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS(EAR) (15 C.F.R.SECTION ** // ** 730-774). THIS DOCUMENT CANNOT BE EXPORTED(E.G., PROVIDED TO A SUPPLIER ** // ** OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S.PERSON, WHEREVER ** // ** LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS ** // ** BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S.GOVERNMENT ** // ** APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL ** // ** PENALTIES. ** // ** ** // ** CAPITAL EQUIPMENT/SOFTWARE: THIS TECHNICAL DATA WAS DEVELOPED OR ACQUIRED ** // ** EXCLUSIVELY AT CONTRACTOR EXPENSE AND IS INTENDED FOR USE ON MULTIPLE ** // ** PROJECTS/PROGRAMS. ** // ** ** // ******************************************************************************************* using System; using System.Collections.Generic; using System.Linq; using System.Text; using Raytheon.Communication; using Raytheon.Communication.Rpc; using System.Globalization; namespace Raytheon.Instruments { /// /// Generic (and abstract) proxy factory for helping to do all of the work that needs to /// be done in proxy factories. All that needs implementation is the GetSupportedInterfaces /// method, this will be up to the impl /// /// What shall be done is a proxy factory for every interface should be declared in /// a dll. Then a consumer would import via MEF all the factories and use them appropriately /// public abstract class InstrumentProxyFactory : IInstrumentProxyFactory where T : class { #region Private Fields //as of right now these do not appear to need access to the implementing class private IUms _UmsHost; private IUmsClientFactory _UmsClientFactory; //Added a GetProxy method for access to a specific proxy private Dictionary> _Proxies; #endregion #region IInstrumentProxyFactory Members /// /// This must be called to initialize a factory with a media port to create the client /// /// host for the client factory to use to create the proxy /// client factory to use to create proxies public virtual void Initialize(IUms umsHost, IUmsClientFactory umsClientFactory) { _Proxies = new Dictionary>(); _UmsClientFactory = umsClientFactory; _UmsHost = umsHost; } /// /// This is the call any client rpc instrument manager would use to get the proxy /// it will return the specific instrument proxy which can be cast to a generic /// IInstrument if needed, the only way to cast to a derived type is to return one /// in the first place since they are proxies /// /// instrument name /// the Type proxy (not the IInstrument) public virtual IInstrument GetInstrument(string name) { return GetSpecificInstrument(name) as IInstrument; } /// /// Implementing class must provide the interfaces it supports /// Since this is purely an interface driven proxy the acutal implementation /// under the hood of the Interfaces matters not /// /// collection of interfaces it can create proxies to public abstract ICollection GetSupportedInterfaces(); #endregion #region Protected Methods /// /// returns the specific instruments proxy, this is a generic operation so put into abstract class /// /// instrument name /// the specific instruments proxy protected virtual T GetSpecificInstrument(string name) { if (null == _Proxies) { string message = typeof(T).FullName + " Factory not initialized, proxy container not created"; throw new InstrumentException(message); } if (!_Proxies.ContainsKey(name)) { var proxy = CreateProxy(name); _Proxies.Add(name, proxy); } return _Proxies[name].Contract; } /// /// added to allow an implementing class to get access to proxies so that it may add properties or /// whatever else needs to be done to the objects /// /// instrument name /// the proxy to that specific instrument protected IUmsClient GetProxy(string proxyName) { IUmsClient proxy = null; _Proxies.TryGetValue(proxyName, out proxy); return proxy; } /// /// creates the proxy, this is a generic operation, so put into the abstract class /// /// instrument name /// the proxy to the given instrument protected virtual IUmsClient CreateProxy(string proxyName) { if (null == _UmsClientFactory || null == _UmsHost) { string message = typeof(T).FullName + " Factory not initialized, ums information is null"; throw new InstrumentException(message); } IUmsClient proxy = _UmsClientFactory.GetClient(_UmsHost); proxy.AddProperty("instName", proxyName); proxy.Open(); return proxy; } #endregion } }