ThreadHookPlugin(Communicator communicator, ThreadNotification threadHook) { if(communicator == null) { PluginInitializationException ex = new PluginInitializationException(); ex.reason = "Communicator cannot be null"; throw ex; } IceInternal.Instance instance = IceInternal.Util.getInstance(communicator); instance.setThreadHook(threadHook); }
ThreadHookPlugin(Communicator communicator, ThreadNotification threadHook) { if (communicator == null) { PluginInitializationException ex = new PluginInitializationException(); ex.reason = "Communicator cannot be null"; throw ex; } IceInternal.Instance instance = IceInternal.Util.getInstance(communicator); instance.setThreadHook(threadHook); }
LoggerPlugin(Communicator communicator, Logger logger) { if (communicator == null) { PluginInitializationException ex = new PluginInitializationException(); ex.reason = "Communicator cannot be null"; throw ex; } if (logger == null) { PluginInitializationException ex = new PluginInitializationException(); ex.reason = "Logger cannot be null"; throw ex; } communicator.setLogger(logger); }
public void Initializers_AreExecuted_AfterException() { ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2) }); PluginBootstrapper invoker = new PluginBootstrapper(typeFinder); PlugIn2.WasInitialized = false; ThrowingPlugin1.Throw = true; PluginInitializationException ex = ExceptionAssert.Throws <PluginInitializationException>(delegate { invoker.InitializePlugins(null, invoker.GetPluginDefinitions()); }); ThrowingPlugin1.Throw = false; Assert.That(PlugIn2.WasInitialized, Is.True); }
LoggerPlugin(Communicator communicator, Logger logger) { if (communicator == null) { PluginInitializationException ex = new PluginInitializationException(); ex.reason = "Communicator cannot be null"; throw ex; } if (logger == null) { PluginInitializationException ex = new PluginInitializationException(); ex.reason = "Logger cannot be null"; throw ex; } IceInternal.Instance instance = IceInternal.Util.getInstance(communicator); instance.setLogger(logger); }
LoggerPlugin(Communicator communicator, Logger logger) { if(communicator == null) { PluginInitializationException ex = new PluginInitializationException(); ex.reason = "Communicator cannot be null"; throw ex; } if(logger == null) { PluginInitializationException ex = new PluginInitializationException(); ex.reason = "Logger cannot be null"; throw ex; } IceInternal.Instance instance = IceInternal.Util.getInstance(communicator); instance.setLogger(logger); }
/// <summary> /// Private constructor for the singleton. /// </summary> private EventAggregator(IResolveInstances instanceResolver, bool preventLogging = false) { _preventLogging = preventLogging; _hookRegistry = new PrioritizedEventListenerDictionary <Type, EventListenerRegistration>(new EventListenerRegistrationComparer()); _commandRegistry = new Dictionary <string, List <ICommandListener> >(); // Get all instances and try to gather all event listeners. _plugins = instanceResolver.ResolveInstances <IPlugin>(); if (_plugins == null || _plugins.Count == 0) { LogUtility.Warning("[SK] No IPlugin instances found."); return; } foreach (var plugin in _plugins) { try { var authors = plugin.getAuthors(); var formatted = string.Join(", ", authors); var lastIndex = formatted.LastIndexOf(", "); if (lastIndex > 0) { formatted = formatted.Remove(lastIndex, 2); formatted = formatted.Insert(lastIndex, " & "); } LogUtility.Out("[SK] Loading plugin " + plugin.getPluginName() + " created by " + formatted); plugin.onLoad(); plugin.RegisterEventListeners(this); plugin.RegisterCommandListeners(this); } catch (Exception exception) { var wrappedException = new PluginInitializationException(plugin.GetType().AssemblyQualifiedName, exception.Message, exception); LogUtility.Exception(wrappedException); } } LogUtility.Out("[SK] EventAggregator initialized"); }
public void InnerException_IsInnerException_OfInitializationException() { ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2) }); mocks.ReplayAll(); PluginBootstrapper invoker = new PluginBootstrapper(typeFinder); PlugIn2.WasInitialized = false; ThrowingPlugin1.Throw = true; PluginInitializationException ex = ExceptionAssert.Throws <PluginInitializationException>(delegate { invoker.InitializePlugins(null, invoker.GetPluginDefinitions()); }); ThrowingPlugin1.Throw = false; Assert.That(ex.InnerException, Is.TypeOf(typeof(SomeException))); Assert.That(ex.Message.Contains("ThrowingPlugin1 isn't happy.")); }
public void InnerExceptions_AreAdded_ToInitializationException() { ITypeFinder typeFinder = new Fakes.FakeTypeFinder(new[] { typeof(ThrowingPlugin1), typeof(PlugIn2), typeof(ThrowingPlugin2) }); PluginBootstrapper invoker = new PluginBootstrapper(typeFinder); PlugIn2.WasInitialized = false; ThrowingPlugin1.Throw = true; ThrowingPlugin2.Throw = true; PluginInitializationException ex = ExceptionAssert.Throws <PluginInitializationException>(delegate { invoker.InitializePlugins(null, invoker.GetPluginDefinitions()); }); ThrowingPlugin1.Throw = false; ThrowingPlugin2.Throw = false; Assert.That(ex.InnerExceptions.Length, Is.EqualTo(2)); Assert.That(ex.Message.Contains("ThrowingPlugin1 isn't happy.")); Assert.That(ex.Message.Contains("ThrowingPlugin2 is really mad.")); }