/// <summary> /// Initialize /// </summary> public static void Initialize() { var updater = new AppUpdater(); if (updater.TryUpdate()) { // [...] } updater.Dispose(); // adding a process-specific environment path (either bin/x86 or bin/amd64) // ensures that unmanaged native dependencies can be resolved successfully. SetPrivateEnvPath(); DynamicModuleUtility.RegisterModule(typeof(AutofacRequestLifetimeHttpModule)); using (Locker.GetWriteLock()) { // TODO: Add verbose exception handling / raising here since this is happening on app startup and could // prevent app from starting altogether var pluginFolderPath = CommonHelper.MapPath(_pluginsPath); _shadowCopyFolder = new DirectoryInfo(CommonHelper.MapPath(_shadowCopyPath)); var incompatiblePlugins = new List <string>(); _clearShadowDirectoryOnStartup = !String.IsNullOrEmpty(ConfigurationManager.AppSettings["ClearPluginsShadowDirectoryOnStartup"]) && Convert.ToBoolean(ConfigurationManager.AppSettings["ClearPluginsShadowDirectoryOnStartup"]); try { var installedPluginSystemNames = PluginFileParser.ParseInstalledPluginsFile(_installedPluginsFilePath); Debug.WriteLine("Creating shadow copy folder and querying for dlls"); //ensure folders are created Directory.CreateDirectory(pluginFolderPath); Directory.CreateDirectory(_shadowCopyFolder.FullName); // get list of all files in bin var binFiles = _shadowCopyFolder.GetFiles("*", SearchOption.AllDirectories); if (_clearShadowDirectoryOnStartup) { // clear out shadow copied plugins foreach (var f in binFiles) { Debug.WriteLine("Deleting " + f.Name); try { File.Delete(f.FullName); } catch (Exception exc) { Debug.WriteLine("Error deleting file " + f.Name + ". Exception: " + exc); } } } // determine all plugin folders var pluginPaths = from x in Directory.EnumerateDirectories(pluginFolderPath) where !x.IsMatch("bin") && !x.IsMatch("_Backup") select Path.Combine(pluginFolderPath, x); // now activate all plugins foreach (var pluginPath in pluginPaths) { var result = LoadPluginFromFolder(pluginPath); if (result.IsIncompatible) { incompatiblePlugins.Add(result.Descriptor.SystemName); } else if (result.Success) { _referencedPlugins[result.Descriptor.SystemName] = result.Descriptor; } } } catch (Exception ex) { var msg = string.Empty; for (var e = ex; e != null; e = e.InnerException) { msg += e.Message + Environment.NewLine; } var fail = new Exception(msg, ex); Debug.WriteLine(fail.Message, fail); throw fail; } IncompatiblePlugins = incompatiblePlugins.AsReadOnly(); } }