/// <summary> Starts the Plug-in Service. </summary> public void Start() { if (_started) { return; } _log.Info("Starting plug-in service"); string currentDirectoryPath = Directory.GetCurrentDirectory(); string pluginDirectoryPath = $"{currentDirectoryPath}{PluginDirectoryPath}"; DirectoryInfo directoryInfo = new DirectoryInfo(pluginDirectoryPath); if (!directoryInfo.Exists) { throw new DirectoryNotFoundException(pluginDirectoryPath); } FileInfo[] marcFiles = directoryInfo.GetFiles("*.marc", SearchOption.TopDirectoryOnly); // Find all available plug-ins for (int i = -1; ++i < marcFiles.Length;) { FileInfo marcFile = marcFiles[i]; IBundle bundle = BundleFactory.Instance.CreateBundle(marcFile); IPluginInfo pluginInfo = RegisterBundle(bundle); if (pluginInfo == null) { continue; } _foundPlugins.AddLast(pluginInfo); // Handling additional resources string[] bundleResources = bundle.GetResources(@"includes/*"); for (int j = -1; ++j != bundleResources.Length;) { string rsx = bundleResources[j]; string[] split = rsx.Split('/'); string name = split.Last(); string bundlePath = rsx; IncludeMapping inclMap = new IncludeMapping { Name = name, BundlePath = bundlePath, Bundle = bundle }; _includeMappings.AddLast(inclMap); } } // Check dependencies using (LinkedList <IPluginInfo> .Enumerator enmtor = _foundPlugins.GetEnumerator()) { while (enmtor.MoveNext()) { IPluginInfo pluginInfo = enmtor.Current; bool dependenciesSatisfied = CheckDependencies(pluginInfo, _foundPlugins, out string missingDependencyName); if (!dependenciesSatisfied) { string message = $"Can not provide '{pluginInfo}' " + $"because of missing dependency '{missingDependencyName}'. " + "Plug-in will not be available!"; _log.Error(message); continue; } SetPluginState(pluginInfo, EPluginState.Provided); _providedPlugins.AddLast(pluginInfo); } } _started = true; _log.Info("Plug-in Service started"); }