void Common.IContainer.RegisterSingleton(Type lookupType, object instance) { container.Configure(x => x.For(lookupType) .Singleton() .Use(instance)); PluginCache.AddFilledType(lookupType); }
static void Main(string[] args) { Log.Logger = CreateLogConfig().CreateLogger(); var genericHostBuilder = OrleansSiloBuilderExtension.CreateHostBuilder(args, configFilePrefix: "appsettings").ApplySerilog(); #if DEBUG genericHostBuilder.UseEnvironment(Environments.Development); #endif try { var genericHost = genericHostBuilder.Build(); PluginCache = OrleansSiloBuilderExtension.PlugInLoaderCache; genericHost.Run(); } catch (OperationCanceledException ex) { //do nothing Log.Information(ex, "Temporary error occurred."); } catch (Exception ex) { Log.Error(ex, "Orleans Silo Host error"); throw; } finally { PluginCache.Dispose(); } }
public void SetUp() { PluginCache.ResetAll(); _locator = new RhinoMocksAAAServiceLocator(); _container = new AutoMockedContainer(_locator); }
/// <summary>加载完成后</summary> protected override void OnLoaded() { if (TempPath.IsNullOrEmpty()) { if (Runtime.IsWeb) { TempPath = "..\\XTemp"; } else { TempPath = "XTemp"; } } #if !__MOBILE__ if (PluginCache.IsNullOrWhiteSpace()) { // 兼容Linux Mono var sys = Environment.SystemDirectory; if (sys.IsNullOrEmpty()) { sys = "/"; } PluginCache = Path.GetPathRoot(sys).CombinePath("X", "Cache"); } #endif if (PluginServer.IsNullOrWhiteSpace() || PluginServer.StartsWithIgnoreCase("ftp://")) { PluginServer = "http://x.newlifex.com/"; } base.OnLoaded(); }
public void BuildUp(object target) { Type pluggedType = target.GetType(); IConfiguredInstance instance = _pipelineGraph.GetDefault(pluggedType) as IConfiguredInstance ?? new ConfiguredInstance(pluggedType); IInstanceBuilder builder = PluginCache.FindBuilder(pluggedType); var arguments = new Arguments(instance, this); builder.BuildUp(arguments, target); }
public void SetFilledTypes_3() { PluginCache.ResetAll(); PluginCache.AddFilledType(typeof(IGateway)); Plugin plugin = PluginCache.GetPlugin(typeof(ClassWithProperties)); plugin.Setters.IsMandatory("Engine").ShouldBeFalse(); plugin.Setters.IsMandatory("Car").ShouldBeFalse(); plugin.Setters.IsMandatory("Gateway").ShouldBeTrue(); }
/// <summary> /// Inline definition of a dependency on an Array of the CHILD type. I.e. CHILD[]. /// This method can be used for either constructor arguments or setter properties /// </summary> /// <typeparam name="CHILD"></typeparam> /// <returns></returns> public ArrayDefinitionExpression <CHILD> EnumerableOf <CHILD>() { if (typeof(CHILD).IsArray) { throw new ApplicationException("Please specify the element type in the call to TheArrayOf"); } Plugin plugin = PluginCache.GetPlugin(typeof(T)); string propertyName = plugin.FindArgumentNameForEnumerableOf(typeof(CHILD)); return(TheArrayOf <CHILD>(propertyName)); }
public void TestLoadDifferentPluginTypes() { var cache = new PluginCache(_pluginLoader.Object); cache.LoadAllOfType <ILogFileOutlinePlugin>(); _pluginLoader.Verify(x => x.LoadAllOfTypeWithDescription <ILogFileOutlinePlugin>(), Times.Once); _pluginLoader.Verify(x => x.LoadAllOfTypeWithDescription <ILogEntryParserPlugin>(), Times.Never); cache.LoadAllOfType <ILogEntryParserPlugin>(); _pluginLoader.Verify(x => x.LoadAllOfTypeWithDescription <ILogFileOutlinePlugin>(), Times.Once); _pluginLoader.Verify(x => x.LoadAllOfTypeWithDescription <ILogEntryParserPlugin>(), Times.Once); }
public void SetUp() { PluginCache.ResetAll(); builder = PluginCache.FindBuilder(typeof(ClassWithMixOfSetters)); instance = new SmartInstance <ClassWithMixOfSetters>().WithCtorArg("Age").EqualTo(34); _session = new BuildSession(); TheDefaultGateway = new DefaultGateway(); _session.RegisterDefault(typeof(IGateway), TheDefaultGateway); _target = null; }
public void TestLoadDifferentPluginTypes() { var cache = new PluginCache(_pluginLoader.Object); cache.LoadAllOfType <IWidgetPlugin>(); _pluginLoader.Verify(x => x.LoadAllOfType <IWidgetPlugin>(), Times.Once); _pluginLoader.Verify(x => x.LoadAllOfType <ILogAnalyserPlugin>(), Times.Never); cache.LoadAllOfType <ILogAnalyserPlugin>(); _pluginLoader.Verify(x => x.LoadAllOfType <IWidgetPlugin>(), Times.Once); _pluginLoader.Verify(x => x.LoadAllOfType <ILogAnalyserPlugin>(), Times.Once); }
public void TestLoadPluginOnlyOnce() { var cache = new PluginCache(_pluginLoader.Object); cache.LoadAllOfType <IWidgetPlugin>(); _pluginLoader.Verify(x => x.LoadAllOfType <IWidgetPlugin>(), Times.Once); _pluginLoader.Verify(x => x.LoadAllOfType <ILogAnalyserPlugin>(), Times.Never); cache.LoadAllOfType <IWidgetPlugin>(); _pluginLoader.Verify(x => x.LoadAllOfType <IWidgetPlugin>(), Times.Once, "because the cache should not have queried the plugin loader again"); _pluginLoader.Verify(x => x.LoadAllOfType <ILogAnalyserPlugin>(), Times.Never); }
private Plugin getPluginByType(PluginFamily family) { string pluggedTypeName = getPluggedType(); if (string.IsNullOrEmpty(pluggedTypeName)) { return(null); } Type pluggedType = new TypePath(pluggedTypeName).FindType(); return(PluginCache.GetPlugin(pluggedType)); }
public void TestLoadPluginOnlyOnce() { var cache = new PluginCache(_pluginLoader.Object); cache.LoadAllOfType <ILogFileOutlinePlugin>(); _pluginLoader.Verify(x => x.LoadAllOfTypeWithDescription <ILogFileOutlinePlugin>(), Times.Once); _pluginLoader.Verify(x => x.LoadAllOfTypeWithDescription <ILogEntryParserPlugin>(), Times.Never); cache.LoadAllOfType <ILogFileOutlinePlugin>(); _pluginLoader.Verify(x => x.LoadAllOfTypeWithDescription <ILogFileOutlinePlugin>(), Times.Once, "because the cache should not have queried the plugin loader again"); _pluginLoader.Verify(x => x.LoadAllOfTypeWithDescription <ILogEntryParserPlugin>(), Times.Never); }
public void fill_all_properties_matching_a_certain_name() { var container = new Container( x => { x.SetAllProperties(policy => { policy.NameMatches(name => name.EndsWith("Name")); }); }); Plugin plugin = PluginCache.GetPlugin(typeof(ClassWithNamedProperties)); plugin.Setters.IsMandatory("Age").ShouldBeFalse(); plugin.Setters.IsMandatory("FirstName").ShouldBeTrue(); plugin.Setters.IsMandatory("LastName").ShouldBeTrue(); plugin.Setters.IsMandatory("Gateway").ShouldBeFalse(); plugin.Setters.IsMandatory("Service").ShouldBeFalse(); }
public void fill_all_properties_of_types_in_namespace_by_generic() { var container = new Container( x => { x.SetAllProperties(policy => { policy.WithAnyTypeFromNamespaceContainingType <IService>(); }); }); Plugin plugin = PluginCache.GetPlugin(typeof(ClassWithNamedProperties)); plugin.Setters.IsMandatory("Age").ShouldBeFalse(); plugin.Setters.IsMandatory("FirstName").ShouldBeFalse(); plugin.Setters.IsMandatory("LastName").ShouldBeFalse(); plugin.Setters.IsMandatory("Gateway").ShouldBeTrue(); plugin.Setters.IsMandatory("Service").ShouldBeTrue(); }
public CreatePluginFamilyExpression <PLUGINTYPE> AddConcreteType <PLUGGEDTYPE>() { if (!PluginCache.GetPlugin(typeof(PLUGGEDTYPE)).CanBeAutoFilled) { throw new StructureMapException(231); } _alterations.Add(family => { string name = PluginCache.GetPlugin(typeof(PLUGGEDTYPE)).ConcreteKey; SmartInstance <PLUGGEDTYPE> instance = new SmartInstance <PLUGGEDTYPE>().WithName(name); family.AddInstance(instance); }); return(this); }
public void SaveRecord(string type, string davcnastevilka, string companyyear, string oznaka, string recno) { PluginCache rec = new PluginCache { Type = type, Davcnastevilka = davcnastevilka, // without biro Companyyear = companyyear, Oznaka = oznaka, Datumvnosa = "", Toprocess = true, Processed = false, Recno = recno }; biromaster.PluginCache.Add(rec); biromaster.SaveChanges(); }
/// <summary>加载完成后</summary> protected override void OnLoaded() { #if !__MOBILE__ if (PluginCache.IsNullOrWhiteSpace()) { // 兼容Linux Mono var sys = Environment.SystemDirectory; if (sys.IsNullOrEmpty()) { sys = "/"; } PluginCache = Path.GetPathRoot(sys).CombinePath("X", "Cache"); } #endif //if (PluginServer.IsNullOrWhiteSpace() || PluginServer.EqualIgnoreCase("http://x.newlifex.com/")) PluginServer = "ftp://ftp.newlifex.com/x/"; base.OnLoaded(); }
private static IPluginLoader CreatePluginSystem(PluginArchiveLoader pluginScanner) { // Currently, we deploy some well known "plugins" via the installer and they're // not available as *.tvp files just yet (which means the PluginArchiveLoader won't find them). // Therefore we register those at a PluginRegistry. var wellKnownPlugins = LoadWellKnownPlugins(); // Even though we're dealing with the limitation above, the rest of the application should not need // to care, which is why we make both of those types of plugin accessible from one loader var pluginLoader = new AggregatedPluginLoader(pluginScanner, wellKnownPlugins); // Last but not least, the PluginArchiveLoader doesn't cache anything which means // that multiple Load requests would result in the same plugin being loaded many times. // we don't want that (unnecessary work, waste of CPU time, etc..), so that's why there's a cache. var pluginCache = new PluginCache(pluginLoader); return(pluginCache); }
private void EnsureSettings() { if (_settings == null) { // Guard for null SiteCache if (PluginCache == null) { throw new PluginException(null, "The PluginCache property is null for {0} when it should be injected by the DI container. " + "If you're unit testing, set the PluginCache and Repository properties with stubs before calling the Settings properties.", GetType().FullName); } _settings = PluginCache.GetPluginSettings(this); if (_settings == null) { // Guard for null Repository if (Repository == null) { throw new PluginException(null, "The Repository property is null for {0} and it wasn't found in the cache - it should be injected by the DI container. " + "If you're unit testing, set the PluginCache and Repository properties with stubs before calling the Settings properties.", GetType().FullName); } // Load from the database _settings = Repository.GetTextPluginSettings(this.DatabaseId); // If this is the first time the plugin has been used, new up the settings if (_settings == null) { EnsureIdIsValid(); string version = EnsureValidVersion(); _settings = new Settings(Id, version); // Allow derived classes to add custom setting values OnInitializeSettings(_settings); // Update the repository Repository.SaveTextPluginSettings(this); } // Cache the settings PluginCache.UpdatePluginSettings(this); } } }
public void fill_all_properties_of_a_certain_type() { var container = new Container(x => { x.SetAllProperties(policy => { policy.OfType <string>(); policy.OfType <IGateway>(); }); }); Plugin plugin = PluginCache.GetPlugin(typeof(ClassWithNamedProperties)); plugin.Setters.IsMandatory("Age").ShouldBeFalse(); plugin.Setters.IsMandatory("FirstName").ShouldBeTrue(); plugin.Setters.IsMandatory("LastName").ShouldBeTrue(); plugin.Setters.IsMandatory("Gateway").ShouldBeTrue(); plugin.Setters.IsMandatory("Service").ShouldBeFalse(); }
public CreatePluginFamilyExpression <PLUGINTYPE> TheDefaultIsConcreteType <CONCRETETYPE>() where CONCRETETYPE : PLUGINTYPE { Type concreteType = typeof(CONCRETETYPE); ExpressionValidator.ValidatePluggabilityOf(concreteType).IntoPluginType(_pluginType); if (!PluginCache.GetPlugin(concreteType).CanBeAutoFilled) { throw new StructureMapException(231); } return(alterAndContinue(family => { ConfiguredInstance instance = new ConfiguredInstance(concreteType).WithName(concreteType.AssemblyQualifiedName); family.AddInstance(instance); family.DefaultInstanceKey = instance.Name; })); }
/// <summary>加载完成后</summary> protected override void OnLoaded() { #if !Android if (PluginCache.IsNullOrWhiteSpace()) { // 兼容Linux Mono var sys = Environment.SystemDirectory; if (sys.IsNullOrEmpty()) { sys = "/"; } PluginCache = Path.GetPathRoot(sys).CombinePath("X", "Cache"); } #endif if (PluginServer.IsNullOrWhiteSpace()) { PluginServer = "http://www.newlifex.com/showtopic-51.aspx"; } base.OnLoaded(); }
public RavenRegistry() { var store = new DocumentStore { ConnectionStringName = "RavenDB" }; store.Initialize(); ObjectFactory.Configure(c => { c.ForSingletonOf <IDocumentStore>() .Use(store); c.For <IDocumentSession>() .Use(OpenSession); PluginCache.AddFilledType(typeof(IDocumentSession)); c.For <IManageUnitsOfWork>() .Use <RavenUnitOfWork>(); }); }
public RavenRegistry() { var store = new DocumentStore { ConnectionStringName = "RavenDB" }; store.Initialize(); ObjectFactory.Configure(c => { c.ForSingletonOf <IDocumentStore>() .Use(store); c.ForSingletonOf <DocumentStore>() .Use(store); c.For <IDocumentSession>() .HybridHttpOrThreadLocalScoped() .Use(OpenSession); PluginCache.AddFilledType(typeof(IDocumentSession)); }); }
static void Main(string[] args) { Log.Logger = CreateLogConfig().CreateLogger(); var genericHostBuilder = OrleansSiloBuilderExtension.CreateHostBuilder(args, configFilePrefix: "appsettings") .ApplySerilog() .UseOrleans(siloBuilder => { siloBuilder.ConfigureApplicationParts(parts => { parts.AddDynamicPart(typeof(HelloGrain).Assembly).WithCodeGeneration(LoggerFactory.Create(builder => { builder.AddSerilog(dispose: true); })); }); }); #if DEBUG genericHostBuilder.UseEnvironment(Environments.Development); #endif try { var genericHost = genericHostBuilder.Build(); PluginCache = OrleansSiloBuilderExtension.PlugInLoaderCache; genericHost.Run(); } catch (OperationCanceledException) { //do nothing } catch (Exception ex) { Log.Error(ex, "Orleans Silo Host error"); throw; } finally { PluginCache.Dispose(); } }
/// <summary>加载完成后</summary> protected override void OnLoaded() { var web = Runtime.IsWeb; if (LogPath.IsNullOrEmpty()) { LogPath = web ? "..\\Log" : "Log"; } if (TempPath.IsNullOrEmpty()) { TempPath = web ? "..\\XTemp" : "XTemp"; } if (LogFileFormat.IsNullOrEmpty()) { LogFileFormat = "{0:yyyy_MM_dd}.log"; } #if !__MOBILE__ if (PluginCache.IsNullOrWhiteSpace()) { // 兼容Linux Mono var sys = Environment.SystemDirectory; if (sys.IsNullOrEmpty()) { sys = "/"; } PluginCache = Path.GetPathRoot(sys).CombinePath("X", "Cache"); } #endif if (PluginServer.IsNullOrWhiteSpace() || PluginServer.StartsWithIgnoreCase("ftp://")) { PluginServer = "http://x.newlifex.com/"; } base.OnLoaded(); }
public void Init() { var store = new DocumentStore { Url = "http://localhost:8082", DefaultDatabase = "MyDatabase" }; store.Initialize(); ObjectFactory.Configure(c => { c.For <IDocumentStore>() .Singleton() .Use(store); c.For <IDocumentSession>() .Use(ctx => ctx.GetInstance <IDocumentStore>() .OpenSession()); PluginCache.AddFilledType(typeof(IDocumentSession)); c.For <IManageUnitsOfWork>() .Use <MyRavenUnitOfWork>(); }); }
/// <summary> /// Use to programmatically select the constructor function of a concrete /// class. Applies globally to all Containers in a single AppDomain. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="expression"></param> public void SelectConstructor <T>(Expression <Func <T> > expression) { PluginCache.GetPlugin(typeof(T)).UseConstructor(expression); }
/// <summary> /// Directs StructureMap to always inject dependencies into any and all public Setter properties /// of the type PLUGINTYPE. /// </summary> /// <typeparam name="PLUGINTYPE"></typeparam> /// <returns></returns> public CreatePluginFamilyExpression <PLUGINTYPE> FillAllPropertiesOfType <PLUGINTYPE>() { PluginCache.AddFilledType(typeof(PLUGINTYPE)); return(ForRequestedType <PLUGINTYPE>()); }