コード例 #1
0
ファイル: Plugin.cs プロジェクト: CodeFork/SimplePlugins
        //This is the main execution entry point for the plugin.
        public override PluginParameters Main(PluginParameters args)
        {
            //Assigns parameters passed from the pluggable app to public members
            this.Param1 = (string)args.Get("Param1");
            this.Param2 = (DateTime)args.Get("Param2");
            this.Param3 = (double)args.Get("Param3");

            //Creates a window wrapper for the pluggable app's main window.
            //This is only to ensure that the plugin form always stays in front of the pluggable app main window
            IntPtr handle = Process.GetCurrentProcess().MainWindowHandle;
            WindowWrapper wr = null;
            if (handle != IntPtr.Zero)
                wr = new WindowWrapper(handle);

            Application.Run(new MainView()); //This starts a new message loop for the plugin window. pluginForm.ShowDialog() may also be used instead.

            if(this.UnhandledException == null)
                args.Add("ReturnValue", "Success"); // Demonstrates how serializeable/primitive types can be passed back to the pluggable app
            else
                args.Add("ReturnValue", "Failed");

            //returned values will be available in the pluggable app via PluginLoaderBase.PluginUnloaded event

            return args;
        }
コード例 #2
0
ファイル: MainView.cs プロジェクト: CodeFork/SimplePlugins
        private void lbPlugins_DoubleClick(object sender, EventArgs e)
        {
            if (lbPlugins.SelectedItem != null)
            {
                //Get the PluginInfo object selected by the user for execution.
                PluginInfo template = (PluginInfo)lbPlugins.SelectedItem;
                try
                {
                    //Create a PluginParameters object and add any parameters to be passed to the plugin
                    PluginParameters args = new PluginParameters();
                    args.Add("Param1", "The quick brown fox jumped over the lazy dog");
                    args.Add("Param2", DateTime.Now);
                    args.Add("Param3", 7.321);

                    //Tell the plugin loader to load and execute the plugin
                    this.PluginLoader.Load(template.PluginFileName, args);
                }
                catch (PluginException ex)
                {
                    Console.WriteException(ex);
                }
            }
        }