public Addin GetAddin() { Assembly ass = this.instance.GetType().Assembly; string manifest = "manifest.xml"; object[] man = ass.GetCustomAttributes(typeof(ManifestAttribute), true); if (man.Length == 1) { if (man[0] != null) { var m = man[0] as ManifestAttribute; manifest = m.Name; } } Stream str = ass.GetManifestResourceStream(ass.GetName().Name + "." + manifest); if (str != null) { string r = new StreamReader(str).ReadToEnd(); Addin ad = new ManifestReader().Read(ass, r); ad.Icon = ad.IconPath != "" ? Image.FromStream(ass.GetManifestResourceStream(ass.GetName().Name + "." + ad.IconPath)) : null; return ad; } return null; }
public Addin GetAddin() { Assembly ass = this.instance.GetType().Assembly; string manifest = "manifest.xml"; object[] man = ass.GetCustomAttributes(typeof(ManifestAttribute), true); if (man.Length == 1) { if (man[0] != null) { var m = man[0] as ManifestAttribute; manifest = m.Name; } } Stream str = ass.GetManifestResourceStream(ass.GetName().Name + "." + manifest); if (str != null) { string r = new StreamReader(str).ReadToEnd(); Addin ad = new ManifestReader().Read(ass, r); ad.Icon = ad.IconPath != "" ? Image.FromStream(ass.GetManifestResourceStream(ass.GetName().Name + "." + ad.IconPath)) : null; return(ad); } return(null); }
public void LoadAddin(string dll) { dll = dll.Replace("[ApplicationData]", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); dll = dll.Replace("[StartupPath]", Application.StartupPath); try { Assembly ass; ass = Assembly.LoadFile(dll); var addAttr = ass.GetCustomAttributes(typeof(AddinAttribute), false) as AddinAttribute[]; if (addAttr != null && addAttr.Length != 0) { //domain.Load(ass.FullName); string manifest = "manifest.xml"; object[] man = ass.GetCustomAttributes(typeof(ManifestAttribute), true); if (man.Length == 1) { if (man[0] != null) { var m = man[0] as ManifestAttribute; manifest = m.Name; } } Stream str = ass.GetManifestResourceStream(ass.GetName().Name + "." + manifest); if (str != null) { string r = new StreamReader(str).ReadToEnd(); Addin ad = new ManifestReader().Read(ass, r); try { ad.Icon = ad.IconPath != "" ? Image.FromStream( ass.GetManifestResourceStream(ass.GetName().Name + "." + ad.IconPath)) : null; } catch (Exception) { } ad.Priority = addAttr[0].Priority; AppDomain domain = AppDomain.CreateDomain(ad.Name); foreach (var dependency in ad.Dependencies) { domain.Load(dependency); } ad.Domain = domain; this.Add(ad); } } } catch (Exception ex) { } }