//文字列形式から作成
        public static PluginManifest CreateByText(string text)
        {
            PluginManifest m = new PluginManifest();

            m._data = new TextStructuredTextReader(new StringReader(text)).Read();
            return(m);
        }
Beispiel #2
0
        //文字列形式から作成
        public static PluginManifest CreateByText(string text)
        {
            PluginManifest m = new PluginManifest();

            StructuredText s = new TextStructuredTextReader(new StringReader(text)).Read();

            if (s.Name == "manifest")
            {
                foreach (object manifestChild in s.Children)
                {
                    StructuredText assemblyEntryNode = manifestChild as StructuredText;
                    if (assemblyEntryNode != null)
                    {
                        PluginManifest.AssemblyEntry entry = m.AddAssembly(assemblyEntryNode.Name);
                        foreach (object assemblyEntryChild in assemblyEntryNode.Children)
                        {
                            StructuredText.Entry pluginEntry = assemblyEntryChild as StructuredText.Entry;
                            if (pluginEntry != null && pluginEntry.name == "plugin")
                            {
                                entry.AddPluginType(pluginEntry.value);
                            }
                        }
                    }
                }
            }

            return(m);
        }
        //ファイルシステムを読んで作成
        public static PluginManifest CreateByFileSystem(string base_dir)
        {
            PluginManifest m  = new PluginManifest();
            StructuredText st = new StructuredText("manifest");

            //自分のディレクトリにある.dllを検索。アプリケーション版では不要だが、開発時のデバッグ実行時には必要
            string[] dlls = Directory.GetFiles(base_dir, "*.dll");
            foreach (string dll in dlls)
            {
                st.AddChild(dll);
            }

            //子ディレクトリ直下のみ検索。
            string[] dirs = Directory.GetDirectories(base_dir);
            foreach (string dir in dirs)
            {
                dlls = Directory.GetFiles(dir, "*.dll");
                foreach (string dll in dlls)
                {
                    st.AddChild(dll);
                }
            }

            m._data = st;
            return(m);
        }
        public void Test1_DLLList()
        {
            PluginManifest           pm   = PluginManifest.CreateByFileSystem(PoderosaAppDir());
            TextWriter               strm = new StringWriter();
            TextStructuredTextWriter wr   = new TextStructuredTextWriter(strm);

            wr.Write(pm.RawData);
            strm.Close();
            UnitTestUtil.Trace(strm.ToString());
            //NOTE これはさすがに目視しかないか
        }
Beispiel #5
0
 public PoderosaStartupContext(PluginManifest pluginManifest, string home_directory, string profile_home, string[] args, string open_file)
 {
     _instance             = this;
     _homeDirectory        = AdjustDirectory(home_directory);
     _profileHomeDirectory = AdjustDirectory(profile_home);
     _initialOpenFile      = open_file;
     _args = args;
     Debug.Assert(pluginManifest != null);
     _pluginManifest     = pluginManifest;
     _preferenceFileName = Path.Combine(_profileHomeDirectory, "options.conf");
     _preferences        = BuildPreference(_preferenceFileName);
 }
        public static IPoderosaApplication CreatePoderosaApplication(string[] args)
        {
            string         home_directory  = AppDomain.CurrentDomain.BaseDirectory;
            string         preference_home = ResolveProfileDirectory("appdata");
            string         open_file       = null;
            PluginManifest pm = PluginManifest.CreateByFileSystem(home_directory);

            //コマンドライン引数を読む
            int i = 0;

            while (i < args.Length)
            {
                string t = args[i];
                string v = i < args.Length - 1? args[i + 1] : "";
                switch (t)
                {
                case "-p":
                case "--profile":
                    preference_home = ResolveProfileDirectory(v);
                    i += 2;
                    break;

                case "-a":
                case "--addasm":
                    pm.AddAssembly(home_directory, v.Split(';'));
                    i += 2;
                    break;

                case "-r":
                case "--remasm":
                    pm.RemoveAssembly(home_directory, v.Split(';'));
                    i += 2;
                    break;

                case "-open":
                    open_file = v;
                    i        += 2;
                    break;

                default:
                    i++;
                    break;
                }
            }

            if (open_file != null && TryToSendOpenFileMessage(open_file))
            {
                return(null);                                                       //別インスタンスに送信
            }
            PoderosaStartupContext ctx = new PoderosaStartupContext(pm, home_directory, preference_home, args, open_file);

            return(new InternalPoderosaWorld(ctx));
        }
        public void Test4_TypeNotFound()
        {
            ITracer        tracer = CreateDefaultTracer();
            PluginManifest pm     = PluginManifest.CreateByText(String.Format("manifest {{\r\n  {0}\\Core\\Core.dll {{\r\n plugin=NotFoundPlugin\r\n}}\r\n}}\r\n", PoderosaAppDir()));

            foreach (StructuredText t in pm.Children)
            {
                PluginManifest.AssemblyNode node = pm.LoadAssemblyNode(t);
                node.TryToBind(tracer);
                Assert.AreEqual(0, node.PluginTypes.Length);
                CheckOneErrorMessage(tracer.Document, String.Format(_stringResource.GetString("PluginManager.Messages.TypeLoadError"), node.Assembly.CodeBase, "NotFoundPlugin"));
            }
        }
Beispiel #8
0
 public PoderosaStartupContext(PluginManifest pluginManifest, string home_directory, StructuredText preference, string[] args, string open_file)
 {
     _instance             = this;
     _homeDirectory        = AdjustDirectory(home_directory);
     _profileHomeDirectory = _homeDirectory;
     _initialOpenFile      = open_file;
     _args = args;
     Debug.Assert(pluginManifest != null);
     _pluginManifest = pluginManifest;
     Debug.Assert(preference != null);
     _preferenceFileName = null;
     _preferences        = preference;
 }
        public void Test2_NormalLoad()
        {
            ITracer        tracer = CreateDefaultTracer();
            PluginManifest pm     = PluginManifest.CreateByText(String.Format("manifest {{\r\n  {0}\\Core\\Core.dll {{\r\n plugin=Poderosa.Preferences.PreferencePlugin\r\n}}\r\n}}\r\n", PoderosaAppDir()));
            int            count  = 0;

            foreach (StructuredText t in pm.Children)
            {
                PluginManifest.AssemblyNode node = pm.LoadAssemblyNode(t);
                node.TryToBind(tracer);
                Assert.AreEqual(1, node.PluginTypes.Length); //これに失敗するときは型が見つからない
                Assert.AreEqual("Poderosa.Preferences.PreferencePlugin", node.PluginTypes[0].FullName);
                count++;
            }
            Assert.AreEqual(1, count); //アセンブリ指定は1個しかないので
        }
Beispiel #10
0
        public void Test2_NormalLoad()
        {
            ITracer tracer = CreateDefaultTracer();

            Poderosa.Boot.PluginManifest pm = PluginManifest.CreateByText(String.Format("manifest {{\r\n  {0}\\Core.dll {{\r\n plugin=Poderosa.Preferences.PreferencePlugin\r\n}}\r\n}}\r\n", PoderosaAppDir()));
            int count = 0;

            foreach (PluginManifest.AssemblyEntry ent in pm.Entries)
            {
                Assert.AreEqual(1, ent.PluginTypeCount);
                Assert.AreEqual(1, ent.PluginTypes.Count());
                Assert.AreEqual("Poderosa.Preferences.PreferencePlugin", ent.PluginTypes.First());
                count++;
            }
            Assert.AreEqual(1, count); //アセンブリ指定は1個しかないので
        }
        public void Test3_AssemblyLoadError()
        {
            ITracer        tracer = CreateDefaultTracer();
            PluginManifest pm     = PluginManifest.CreateByText(String.Format("manifest {{\r\n  {0}\\notexist.dll {{\r\n  }}\r\n}}\r\n", PoderosaAppDir()));

            try {
                foreach (StructuredText t in pm.Children)
                {
                    PluginManifest.AssemblyNode node = pm.LoadAssemblyNode(t);
                    Assert.Fail("we expect exception");
                }
            }
            catch (Exception ex) {
                tracer.Trace(ex);
                Console.Out.WriteLine(ex.Message);
            }
        }
Beispiel #12
0
        //ファイルシステムを読んで作成
        public static PluginManifest CreateByFileSystem(string base_dir)
        {
            PluginManifest m = new PluginManifest();

            //自分のディレクトリにある.dllを検索。アプリケーション版では不要だが、開発時のデバッグ実行時には必要
            string[] dlls = Directory.GetFiles(base_dir, "*.dll");
            foreach (string dll in dlls)
            {
                m.AddAssembly(dll);
            }

            //子ディレクトリ直下のみ検索。
            string[] dirs = Directory.GetDirectories(base_dir);
            foreach (string dir in dirs)
            {
                dlls = Directory.GetFiles(dir, "*.dll");
                foreach (string dll in dlls)
                {
                    m.AddAssembly(dll);
                }
            }

            return(m);
        }
Beispiel #13
0
 public static PluginManifest CreateEmptyManifest() {
     PluginManifest m = new PluginManifest();
     return m;
 }
Beispiel #14
0
        //ファイルシステムを読んで作成
        public static PluginManifest CreateByFileSystem(string base_dir) {
            PluginManifest m = new PluginManifest();

            //自分のディレクトリにある.dllを検索。アプリケーション版では不要だが、開発時のデバッグ実行時には必要
            string[] dlls = Directory.GetFiles(base_dir, "*.dll");
            foreach (string dll in dlls)
                m.AddAssembly(dll);

            //子ディレクトリ直下のみ検索。
            string[] dirs = Directory.GetDirectories(base_dir);
            foreach (string dir in dirs) {
                dlls = Directory.GetFiles(dir, "*.dll");
                foreach (string dll in dlls)
                    m.AddAssembly(dll);
            }

            return m;
        }
Beispiel #15
0
        //文字列形式から作成
        public static PluginManifest CreateByText(string text) {
            PluginManifest m = new PluginManifest();

            StructuredText s = new TextStructuredTextReader(new StringReader(text)).Read();

            if (s.Name == "manifest") {
                foreach (object manifestChild in s.Children) {
                    StructuredText assemblyEntryNode = manifestChild as StructuredText;
                    if (assemblyEntryNode != null) {
                        PluginManifest.AssemblyEntry entry = m.AddAssembly(assemblyEntryNode.Name);
                        foreach(object assemblyEntryChild in assemblyEntryNode.Children) {
                            StructuredText.Entry pluginEntry = assemblyEntryChild as StructuredText.Entry;
                            if (pluginEntry != null && pluginEntry.name == "plugin") {
                                entry.AddPluginType(pluginEntry.value);
                            }
                        }
                    }
                }
            }

            return m;
        }
Beispiel #16
0
 public PoderosaStartupContext(PluginManifest pluginManifest, string home_directory, StructuredText preference, string[] args, string open_file) {
     _instance = this;
     _homeDirectory = AdjustDirectory(home_directory);
     _profileHomeDirectory = _homeDirectory;
     _initialOpenFile = open_file;
     _args = args;
     Debug.Assert(pluginManifest != null);
     _pluginManifest = pluginManifest;
     Debug.Assert(preference != null);
     _preferenceFileName = null;
     _preferences = preference;
 }
Beispiel #17
0
 public PoderosaStartupContext(PluginManifest pluginManifest, string home_directory, string profile_home, string[] args, string open_file) {
     _instance = this;
     _homeDirectory = AdjustDirectory(home_directory);
     _profileHomeDirectory = AdjustDirectory(profile_home);
     _initialOpenFile = open_file;
     _args = args;
     Debug.Assert(pluginManifest != null);
     _pluginManifest = pluginManifest;
     _preferenceFileName = Path.Combine(_profileHomeDirectory, "options.conf");
     _preferences = BuildPreference(_preferenceFileName);
 }
Beispiel #18
0
        private void ListPlugins(PluginManifest manifest)
        {
            foreach (PluginManifest.AssemblyEntry entry in manifest.Entries) {
                Assembly assembly;
                try {
                    assembly = Assembly.LoadFrom(entry.AssemblyName);
                }
                catch (Exception) {
                    _tracer.Trace("PluginManager.Messages.AssemblyLoadError", entry.AssemblyName);
                    continue;
                }

                if (entry.PluginTypeCount == 0) {
                    _allPlugins.AddRange(EnumeratePlugins(this, assembly, _tracer));
                }
                else {
                    _allPlugins.AddRange(EnumeratePlugins(this, assembly, entry, _tracer));
                }
            }
        }
Beispiel #19
0
        // Enumerate plugins according to the specified node.
        private IEnumerable<Plugin> EnumeratePlugins(PluginManager manager, Assembly assembly, PluginManifest.AssemblyEntry assemblyEntry, ITracer tracer)
        {
            foreach (string pluginTypeName in assemblyEntry.PluginTypes) {
                Type pluginType;
                try {
                    pluginType = assembly.GetType(pluginTypeName);
                }
                catch (Exception) {
                    tracer.Trace("PluginManager.Messages.TypeLoadError", assembly.CodeBase, pluginTypeName);
                    continue;
                }

                if (pluginType == null) {
                    tracer.Trace("PluginManager.Messages.TypeLoadError", assembly.CodeBase, pluginTypeName);
                    continue;
                }

                Plugin plugin = new Plugin(manager, assembly, pluginType);

                yield return plugin;
            }
        }
Beispiel #20
0
        public static PluginManifest CreateEmptyManifest()
        {
            PluginManifest m = new PluginManifest();

            return(m);
        }
Beispiel #21
0
        //�t�@�C���V�X�e����ǂ�ō쐬
        public static PluginManifest CreateByFileSystem(string base_dir)
        {
            PluginManifest m = new PluginManifest();

            //�����̃f�B���N�g���ɂ���.dll������B�A�v���P�[�V�����łł͕s�v�����A�J�����̃f�o�b�O���s���ɂ͕K�v
            string[] dlls = Directory.GetFiles(base_dir, "*.dll");
            foreach (string dll in dlls)
                m.AddAssembly(dll);

            //�q�f�B���N�g�������̂݌����B
            string[] dirs = Directory.GetDirectories(base_dir);
            foreach (string dir in dirs) {
                dlls = Directory.GetFiles(dir, "*.dll");
                foreach (string dll in dlls)
                    m.AddAssembly(dll);
            }

            return m;
        }
Beispiel #22
0
        public static IPoderosaApplication CreatePoderosaApplication(string plugin_manifest, StructuredText preference, string[] args)
        {
            string home_directory   = Directory.GetCurrentDirectory();
            InternalPoderosaWorld w = new InternalPoderosaWorld(new PoderosaStartupContext(PluginManifest.CreateByText(plugin_manifest), home_directory, preference, args, null));

            return(w);
        }