/// <summary>Initialized method to be called once in each application session by the caller planning to use the preprocessors. /// This will try to load the plugins from the plugin folder, and try to initialize each of them. /// Will report progess to the log information action.</summary> /// <param name="pluginPath">The plugin path</param> /// <param name="logManager">The log Manager.</param> /// <param name="timeMeasure">The time Measure.</param> private void Initialize(string pluginPath, LogManager logManager, ITimeMeasure timeMeasure) { timeMeasure.Start(false, SectionIdParts.Preprocessing, SectionIdParts.Initialize); logManager.Information(ResourceStrings.PreprocessingInitializeStart.InvariantFormat(pluginPath)); // If no plugin path was provided, we use the assembly path. if (string.IsNullOrWhiteSpace(pluginPath)) { var assemblyFilInfo = new FileInfo(Assembly.GetCallingAssembly().FullName); pluginPath = assemblyFilInfo.DirectoryName; } if (!string.IsNullOrWhiteSpace(pluginPath)) { if (!Directory.Exists(pluginPath)) { logManager.Error( new DirectoryNotFoundException(pluginPath), ResourceStrings.PreprocessingCouldNotFindThePluginPath.InvariantFormat(pluginPath)); return; } // And now use MEF to load all possible plugins. logManager.Information(ResourceStrings.PreprocessingPluginPath.InvariantFormat(pluginPath)); using (var addInCatalog = new AggregateCatalog()) { addInCatalog.Catalogs.Add(new DirectoryCatalog(pluginPath)); using (var addInContainer = new CompositionContainer(addInCatalog)) { // Fill the imports of this object try { addInContainer.ComposeParts(this); } catch (CompositionException compositionException) { logManager.Error(compositionException, ResourceStrings.PreprocessingLoadingError); } foreach (var registeredPreprocessingEngine in this.registeredPreprocessingEngines) { logManager.Information( ResourceStrings.PreprocessingEngineFound.InvariantFormat(registeredPreprocessingEngine.Name)); } } } } logManager.Information(ResourceStrings.PreprocessingInitializeEnd); timeMeasure.End(false, SectionIdParts.Preprocessing, SectionIdParts.Initialize); }
internal void Enter(object[] args) { lock (_locker) { if (_inUse) { throw new Exception("can't repeat enter to active section"); } _inUse = true; _args = args; _timeMeasure.Start(); } }