Example #1
0
 void CheckDllFiles(string plugdir)
 {
     // プラグインフォルダのDLLを列挙
     string[] dlls = System.IO.Directory.GetFiles(plugdir, "*.dll");
     foreach (string dll in dlls)
     {
         // 例外をチェック
         string name = System.IO.Path.GetFileName(dll);
         name = name.ToLower();
         if (name == "libnako.dll")
         {
             continue;
         }
         if (name == "nakoplugin.dll")
         {
             continue;
         }
         // アセンブリを読み込む
         System.Reflection.Assembly asm;
         try
         {
             asm = System.Reflection.Assembly.LoadFrom(dll);
         }
         catch (Exception e)
         {
             throw new Exception("プラグイン読込みエラー。:" + dll + ":[" + e.GetType().Name + "]" + e.Message);
         }
         // 読み込んだアセンブリに含まれるクラスを取得する
         string curType = "*";
         try
         {
             foreach (Type t in asm.GetTypes())
             {
                 curType = t.Name;
                 if (t.IsClass && t.IsPublic && !t.IsAbstract &&
                     t.GetInterface(INakoPluginsPath) != null)
                 {
                     NakoPluginInfo info = new NakoPluginInfo();
                     info.Location  = dll;
                     info.ClassName = t.FullName;
                     plugins.Add(info);
                 }
             }
         }
         catch (System.Reflection.ReflectionTypeLoadException e)
         {
             string s = "";
             s += "{name:" + name + "}";
             foreach (Exception e2 in e.LoaderExceptions)
             {
                 s += e2.Message + ":";
             }
             throw new Exception("プラグイン読込みエラー。クラスの取得に失敗。:" + dll + ":" + curType + ":[" + e.GetType().Name + "] " + s);
         }
         catch (Exception e)
         {
             throw new Exception("プラグイン読込みエラー。クラスの取得に失敗。:" + dll + ":" + curType + ":[" + e.GetType().Name + "] " + e.Message);
         }
     }
 }
Example #2
0
 void CheckDllFiles(string plugdir)
 {
     // プラグインフォルダのDLLを列挙
     string[] dlls = System.IO.Directory.GetFiles(plugdir, "*.dll");
     foreach (string dll in dlls)
     {
         // 例外をチェック
         string name = System.IO.Path.GetFileName(dll);
         name = name.ToLower();
         if (name == "libnako.dll") continue;
         if (name == "nakoplugin.dll") continue;
         // アセンブリを読み込む
         System.Reflection.Assembly asm;
         try
         {
             asm = System.Reflection.Assembly.LoadFrom(dll);
         }
         catch (Exception e)
         {
             throw new Exception("プラグイン読込みエラー。:" + dll + ":[" + e.GetType().Name + "]" + e.Message);
         }
         // 読み込んだアセンブリに含まれるクラスを取得する
         string curType = "*";
         try
         {
             foreach (Type t in asm.GetTypes())
             {
                 curType = t.Name;
                 if (t.IsClass && t.IsPublic && !t.IsAbstract &&
                     t.GetInterface(INakoPluginsPath) != null)
                 {
                     NakoPluginInfo info = new NakoPluginInfo();
                     info.Location = dll;
                     info.ClassName = t.FullName;
                     plugins.Add(info);
                 }
             }
         }
         catch (System.Reflection.ReflectionTypeLoadException e)
         {
             string s = "";
             s += "{name:" + name + "}";
             foreach (Exception e2 in e.LoaderExceptions)
             {
                 s += e2.Message + ":";
             }
             throw new Exception("プラグイン読込みエラー。クラスの取得に失敗。:" + dll + ":" + curType + ":[" + e.GetType().Name + "] " + s);
         }
         catch (Exception e)
         {
             throw new Exception("プラグイン読込みエラー。クラスの取得に失敗。:" + dll + ":" + curType + ":[" + e.GetType().Name + "] " + e.Message);
         }
     }
 }