public void CanLoadType() { string TypeName = typeof(NPerf.DevHelpers.PerfTestSuiteSample).Name; string AssemblyName = typeof(NPerf.DevHelpers.PerfTestSuiteSample).Assembly.Location; var instance = AssemblyLoader.CreateInstance(AssemblyName, TypeName); instance.Should().NotBeNull(); instance.GetType().Name.Should().Be(TypeName); }
/// <summary> /// Creates a new instance of the TLV description described by <paramref name="tlvDesc"/> /// </summary> /// <param name="tlvDesc">Description of the tag</param> /// <returns>A new instance of the TLV object</returns> public static AbstractTlvObject CreateInstance(TlvDescription tlvDesc) { var dll = ""; if (tlvDesc.DllName != null) { dll = (tlvDesc.PathToDll ?? String.Empty) + tlvDesc.DllName; } return(AssemblyLoader.CreateInstance <AbstractTlvObject>(dll, tlvDesc.ClassName)); }
private void FillProducts() { _ltProducts = new List <LTProductDescription>(); AssemblyLoader assemblyLoader = new AssemblyLoader(); assemblyLoader.BaseClass = "LTProductDescription"; assemblyLoader.Path = Path.GetDirectoryName(Application.ExecutablePath); foreach (Type type in assemblyLoader.Types) { LTProductDescription assemblyDescription = (LTProductDescription)assemblyLoader.CreateInstance(type); _ltProducts.Add(assemblyDescription); } }
public override void Initialize(IBrokerHost brokerHost, AuthenticationProvider authProvider) { base.Initialize(brokerHost, authProvider); authProvider.AllowAutoTrading = true; AssemblyLoader assemblyLoader = new AssemblyLoader(); assemblyLoader.BaseClass = "LTBrokerProvider"; assemblyLoader.Path = Path.GetDirectoryName(Application.ExecutablePath); foreach (Type type in assemblyLoader.Types) { try { LTBrokerProvider assemblyDescription = (LTBrokerProvider)assemblyLoader.CreateInstance(type); assemblyDescription.Initialize(); if (assemblyDescription.Enable) { assemblyDescription.AccountUpdate += AccountUpdate; assemblyDescription.OrderUpdate += OrderStatusUpdate; _providers.Add(assemblyDescription); _routes.Add(assemblyDescription.ProviderName); } } catch (Exception ex) { _logger.Error(ex); if (ex.InnerException != null) { _logger.Error(ex.InnerException); } } } }
/// <summary> /// /// </summary> /// <param name="prefix"></param> /// <param name="manager_path"></param> public ManagerEngine(string prefix, string manager_path) { this.rootPaths = new StringList(); this.rootNames = new NameValueCollection(); this.plugins = new PluginList(); this.fileSystems = new FileFactoryDictionary(); this.langPack = null; this.logger = new Logger(); this.pluginLookup = new Hashtable(); if (manager_path != null) { this.ManagerPath = manager_path; } else { this.ManagerPath = System.Web.HttpContext.Current.Server.MapPath(".."); } this.Plugins.Add(new CorePlugin()); ManagerConfig coreConfig = (ManagerConfig)System.Web.HttpContext.Current.GetConfig("CorePlugin"); this.prefix = prefix; // Add instance of each plugin foreach (string className in coreConfig.Plugins) { IPlugin plugin = (IPlugin)InstanceFactory.CreateInstance(className); if (plugin == null) { throw new ManagerException("Could not create instance of plugin class: " + className); } this.Plugins.Add(plugin); } this.DispatchEvent(EventType.PreInit, prefix); this.SetupConfigItems(); // Setup logger if (!this.Config.GetBool("log.enabled", false)) { this.logger.Level = LoggerLevel.Fatal; } else { this.logger.LevelName = this.Config.Get("log.level", "fatal"); } this.logger.Path = this.ToAbsPath(this.Config.Get("log.path", "logs")); this.logger.FileFormat = this.Config.Get("log.filename", "{level}.log"); this.logger.Format = this.Config.Get("log.format", "[{time}] [{level}] {message}"); this.logger.MaxSize = this.Config.Get("log.max_size", "100k"); this.logger.MaxFiles = this.Config.GetInt("log.max_files", 10); // Add instance of each plugin AssemblyLoader loader = new AssemblyLoader(); foreach (string className in this.Config.Plugins) { IPlugin plugin = (IPlugin)loader.CreateInstance(className); if (plugin == null) { throw new Exception("Could not create instance of plugin class: " + className); } this.Plugins.Add(plugin); // Add by class name and by short name this.pluginLookup[className] = plugin; if (plugin.ShortName != null) { this.pluginLookup[plugin.ShortName] = plugin; } } }