|
Revision 412, 1.7 kB
(checked in by tomoyo, 4 months ago)
|
|
アドインの仕組みを取り込んで、いくつかの機能をアドインの機構にのる形にした。
|
-
Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 | using System; |
|---|
| 2 | using System.Collections.Generic; |
|---|
| 3 | using System.IO; |
|---|
| 4 | using System.Text; |
|---|
| 5 | using System.Reflection; |
|---|
| 6 | using System.Diagnostics; |
|---|
| 7 | |
|---|
| 8 | using Misuzilla.Applications.TwitterIrcGateway.AddIns; |
|---|
| 9 | |
|---|
| 10 | namespace Misuzilla.Applications.TwitterIrcGateway |
|---|
| 11 | { |
|---|
| 12 | class AddInManager |
|---|
| 13 | { |
|---|
| 14 | private List<IAddIn> _addIns = new List<IAddIn>(); |
|---|
| 15 | |
|---|
| 16 | public void Load(Server server, Session session) |
|---|
| 17 | { |
|---|
| 18 | LoadAddInFromAssembly(Assembly.GetExecutingAssembly()); |
|---|
| 19 | |
|---|
| 20 | String addinsBase = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "AddIns"); |
|---|
| 21 | if (Directory.Exists(addinsBase)) |
|---|
| 22 | { |
|---|
| 23 | foreach (String fileName in Directory.GetFiles(addinsBase, "*.dll")) |
|---|
| 24 | { |
|---|
| 25 | try |
|---|
| 26 | { |
|---|
| 27 | Assembly asm = Assembly.LoadFile(fileName); |
|---|
| 28 | LoadAddInFromAssembly(asm); |
|---|
| 29 | } |
|---|
| 30 | catch (Exception e) |
|---|
| 31 | { |
|---|
| 32 | } |
|---|
| 33 | } |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | foreach (IAddIn addIn in _addIns) |
|---|
| 37 | addIn.Initialize(server, session); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | private void LoadAddInFromAssembly(Assembly asm) |
|---|
| 41 | { |
|---|
| 42 | Type addinType = typeof(IAddIn); |
|---|
| 43 | foreach (Type t in asm.GetTypes()) |
|---|
| 44 | { |
|---|
| 45 | if (addinType.IsAssignableFrom(t) && !t.IsAbstract && t.IsClass) |
|---|
| 46 | { |
|---|
| 47 | Trace.WriteLine(String.Format("Load AddIn: {0}", t)); |
|---|
| 48 | IAddIn addIn = Activator.CreateInstance(t) as IAddIn; |
|---|
| 49 | |
|---|
| 50 | _addIns.Add(addIn); |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | } |
|---|
| 55 | } |
|---|