Ejemplo n.º 1
0
 public override void LoadPlugin(string filePath)
 {
     Assembly reflectAssembly = Assembly.ReflectionOnlyLoadFrom(filePath);
        PluginInstance instance = new PluginInstance(reflectAssembly, null);
        Type typePlugin = null;
        foreach (Type type in instance.Assembly.GetExportedTypes())
        {
     Type typeInterface = type.GetInterface("Eraser.Manager.Plugin.IPlugin", true);
     if (typeInterface != null)
     {
      typePlugin = type;
      break;
     }
        }
        if (typePlugin == null)
     return;
        lock (plugins)
     plugins.Add(instance);
        IDictionary<Guid, bool> approvals = ManagerLibrary.Settings.PluginApprovals;
        if ((reflectAssembly.GetName().GetPublicKey().Length == 0 ||
     !MsCorEEApi.VerifyStrongName(filePath) ||
     instance.AssemblyAuthenticode == null) &&
     !approvals.ContainsKey(instance.AssemblyInfo.Guid))
        {
     return;
        }
        instance.Assembly = Assembly.LoadFrom(filePath);
        if (reflectAssembly.GetName().GetPublicKey().Length ==
     Assembly.GetExecutingAssembly().GetName().GetPublicKey().Length)
        {
     bool sameKey = true;
     byte[] reflectAssemblyKey = reflectAssembly.GetName().GetPublicKey();
     byte[] thisAssemblyKey = Assembly.GetExecutingAssembly().GetName().GetPublicKey();
     for (int i = 0, j = reflectAssemblyKey.Length; i != j; ++i)
      if (reflectAssemblyKey[i] != thisAssemblyKey[i])
      {
       sameKey = false;
       break;
      }
     if (sameKey)
     {
      object[] attr = instance.Assembly.GetCustomAttributes(typeof(CoreAttribute), true);
      if (attr.Length != 0)
       instance.IsCore = true;
     }
        }
        if (approvals.ContainsKey(instance.AssemblyInfo.Guid) &&
     !approvals[instance.AssemblyInfo.Guid] && !instance.IsCore)
        {
     return;
        }
        IPlugin pluginInterface = (IPlugin)Activator.CreateInstance(
     instance.Assembly.GetType(typePlugin.ToString()));
        pluginInterface.Initialize(this);
        instance.Plugin = pluginInterface;
        OnPluginLoaded(this, new PluginLoadedEventArgs(instance));
 }
Ejemplo n.º 2
0
 public PluginLoadedEventArgs(PluginInstance instance)
 {
     Instance = instance;
 }