示例#1
0
        static void Main(string[] args)
        {
            // Set the add-ins discovery root directory to be the current directory
            string addinRoot = Environment.CurrentDirectory;

            // Rebuild the add-ins cache and pipeline components cache.
            AddInStore.Rebuild(addinRoot);

            // Get registerd add-ins of type SimpleAddInHostView
            Collection<AddInToken> addins = AddInStore.FindAddIns(typeof(SayHelloHostView), addinRoot);

            Console.WriteLine("Main AppDomain: " + AppDomain.CurrentDomain.FriendlyName);

            AddInProcess process = new AddInProcess();
            process.Start();

            Console.WriteLine("External AddIn ProcessID=" + process.ProcessId);

            foreach (AddInToken addinToken in addins)
            {
                // Activate the add-in
                //SayHelloHostView addinInstance = addinToken.Activate<SayHelloHostView>(AddInSecurityLevel.Host);
                SayHelloHostView addinInstance = addinToken.Activate<SayHelloHostView>(process, AddInSecurityLevel.Host);

                // Use the add-in
                Console.WriteLine();
                Console.WriteLine(String.Format("Add-in {0} Version {1}",
                     addinToken.Name, addinToken.Version));

                Console.WriteLine(addinInstance.SayHello("Hello World from Plugin ;-)"));
            }

            Console.ReadKey();
        }
示例#2
0
 public static void LoadAddins()
 {
     try
     {
         string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
         AddInStore.Rebuild(baseDirectory);
         IList<AddInToken> list = (IList<AddInToken>)AddInStore.FindAddIns(typeof(CustomAddIn), baseDirectory, new string[0]);
         App.addIns = new List<CustomAddIn>();
         foreach (AddInToken addInToken in (IEnumerable<AddInToken>)list)
         {
             AddInProcess process = new AddInProcess(Platform.X86);
             process.Start();
             AddInStore.FindAddIns(typeof(CustomAddIn), PipelineStoreLocation.ApplicationBase);
             CustomAddIn customAddIn = addInToken.Activate<CustomAddIn>(process, AddInSecurityLevel.Host);
             App.addIns.Add(customAddIn);
         }
     }
     catch
     {
     }
 }
示例#3
0
文件: Program.cs 项目: Giten2004/MAF
        static void Main(string[] args)
        {
            //Init pipline, create PipelineSegments.store and AddIns.store
            string path = Environment.CurrentDirectory;
            AddInStore.Update(path);

            //string[] warnings = AddInStore.Update(path);
            //foreach (var tmp in warnings)
            //{
            //    Console.WriteLine(tmp);
            //}

            //发现, used the host side view(without attribute)
            var tokens = AddInStore.FindAddIns(typeof(HostSideView.HostSideView), path);
            Console.WriteLine("当前共有{0}个插件可以选择。它们分别为:", tokens.Count);

            var index = 1;
            foreach (var tmp in tokens)
            {
                Console.WriteLine(string.Format("[{4}]名称:{0},描述:{1},版本:{2},发布者:{3}", tmp.Name, tmp.Description, tmp.Version, tmp.Publisher, index++));
            }

            //[[ find addin in the another folder
            string anotherAddInPath = @"C:\OutPutForAddIn\Test";
            AddInStore.RebuildAddIns(anotherAddInPath);

            //todo: why there find the addin in the fist folder????
            IList<AddInToken> PluginList = AddInStore.FindAddIns(typeof(HostSideView.HostSideView), PipelineStoreLocation.ApplicationBase, anotherAddInPath);
            //]]

            var token = ChooseCalculator(tokens);

            //隔离和激活插件
            AddInProcess process = new AddInProcess();//(Platform.X64);
            process.Start();

            var addin = token.Activate<HostSideView.HostSideView>(process, AddInSecurityLevel.FullTrust);

            Console.WriteLine("PID:{0}", process.ProcessId);

            //调用插件
            Console.WriteLine(addin.Say());

            Console.ReadKey();
        }