///
/// Copyright © 2003-2008 JetBrains s.r.o.
/// You may distribute under the terms of the GNU General Public License, as published by the Free Software Foundation, version 2 (see License.txt in the repository root folder).
///
using System;
using System.Collection.Generic;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;
using System35;
using JetBrains.Annotations;
using JetBrains.Omea.OpenAPI;
using JetBrains.Omea.ResourceStore;
using JetBrains.UI.Util;
using JetBrains.Util;
using OmniaMea;
namespace JetBrains.Omea.Plugins
{
///
/// Loads and starts the plugins.
/// Controls the detection, disabling and enabling of the plugin DLLs.
///
public class PluginLoader // TODO: make sure the assembly/file name is case-sensitive
{
#region Data
///
/// A regex to check whether the file name is recognized as an Omea Plugin file.
///
[NotNull]
public static readonly Regex RegexOmeaPluginFile = new Regex(@"^.*\bOmeaPlugin\b.*(\.dll|\.exe)$", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Singleline);
private static readonly Regex _regexAssemblyNameToPluginDisplayName = new Regex(@"^(?.*)\.?OmeaPlugin\.?(?.*)$");
///
/// The list of default plugin folders.
/// Note: cannot be made static, as used for one of the folders might not be yet available when doing static init.
///
[NotNull]
public readonly PluginFolder[] PluginFolders = PluginFolder.CreateDefaultFolders();
///
/// The list of plugin assemblies for which the XML config hasn't been loaded yet.
///
[NotNull]
private readonly List _arAssembliesToLoadXmlConfigFrom = new List();
///
/// Full names of types of the loaded instances.
/// Prevent duplicate class names in separate assemblies.
///
private readonly HashSet _hashLoadedPluginTypes = new HashSet();
///
/// For the loaded plugins (), tracks the files they were loaded from, along with the possible load-time comments from the plugin loader.
///
[NotNull]
private readonly Dictionary _mapPluginFileInfo = new Dictionary();
///
/// Tracks errors on loading those assemblies that were considered valid Omea plugins and were attempted to be loaded (so their holds a clean record when enumerating the folders), but later failed the runtime checks.
/// Key: file full name.
/// Value: error text.
///
private readonly Dictionary _mapPluginLoadRuntimeErrors = new Dictionary();
///
/// The set of handlers for reading and applying the declarative XML config.
///
[NotNull]
private readonly Dictionary> _mapXmlConfigHandlers = new Dictionary>();
///
/// Loaded plugins.
///
[NotNull]
private readonly List _plugins = new List();
///
/// Service provider storage.
///
[NotNull]
private readonly List