public bool ActivatePlugin() { try { osae.AddToLog("Activating Plugin: " + PluginName, true); // Create application domain setup information. AppDomainSetup domaininfo = new AppDomainSetup(); domaininfo.ApplicationBase = osae.APIpath; //domaininfo.ApplicationTrust = AddInSecurityLevel.Host; // Create the application domain. AppDomain domain = AppDomain.CreateDomain(PluginName + "_Domain", null, domaininfo); // Write application domain information to the console. osae.AddToLog("Host domain: " + AppDomain.CurrentDomain.FriendlyName, true); osae.AddToLog("child domain: " + domain.FriendlyName, true); osae.AddToLog("Application base is: " + domain.SetupInformation.ApplicationBase, true); //_addin = _token.Activate<IOpenSourceAutomationAddIn>(domain); _process = new AddInProcess(Platform.AnyCpu); _addin = _token.Activate <IOpenSourceAutomationAddInv2>(process, AddInSecurityLevel.FullTrust); _enabled = true; return(true); } catch (Exception ex) { osae.AddToLog("Error activating plugin (" + _pluginName + "): " + ex.Message + " - " + ex.InnerException, true); _enabled = false; return(false); } catch { osae.AddToLog("Error activating plugin", true); return(false); } }
private void Button_Click(object sender, RoutedEventArgs e) { AddInToken wpfAddInToken = (AddInToken)lstAddIns.SelectedItem; this.Dispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException); // Start and external AddInProcess for this LayoutAnchorable var addInProcess = new AddInProcess(); addInProcess.Start(); // Get the AddInProcess and enable event handling. This allows us to remove this DockableContent if the process dies. var process = System.Diagnostics.Process.GetProcessById(addInProcess.ProcessId); process.EnableRaisingEvents = true; process.Exited += new EventHandler(AddInProcess_Exited); var wpfAddInHostView = wpfAddInToken.Activate <IWPFAddInHostView>(addInProcess, AddInSecurityLevel.FullTrust); // Get and display add-in UI FrameworkElement addInUI = wpfAddInHostView.GetAddInUI(); var tabItem = new TabItem(); tabItem.Content = addInUI; pluginTab.Items.Add(tabItem); pluginTab.SelectedIndex = pluginTab.Items.Count - 1; //pnlAddIn.Child = addInUI; }
public AddInProcess CreateAddInProcess(Platform platform) { var addInProcess = new AddInProcess(platform); _addInProcesses.Add(addInProcess); return(addInProcess); }
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(); }
public IModule Activate() { var proc = new AddInProcess(); var instance = _token.Activate <IModule>(proc, AddInSecurityLevel.FullTrust); instance.Initialize(Start9Host.Instance); Instances.Add(new ModuleInstance(instance, proc)); return(instance); }
public ModuleInstance(IModule instance, AddInProcess proc) { Instance = instance; Process = proc; proc.ShuttingDown += (sender, e) => { Module.GetModuleForInstance(Instance).Instances.Remove(this); }; }
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(); }
public static void ActivatePlugins() { if (!File.Exists("PipelineSegments.store")) { Rebuild(); return; } foreach (AddInToken addIn in AddInStore.FindAddIns(typeof(DataPlugin), PipelineStoreLocation.ApplicationBase)) { AddInProcess process = new AddInProcess(); process.KeepAlive = false; DataPlugin activeAddIn = addIn.Activate <DataPlugin>(process, AddInSecurityLevel.Host); plugins.Add(activeAddIn); } }
private void ActivateAddIn(object sender, RoutedEventArgs e) { var element = sender as FrameworkElement; Debug.Assert(element != null, "element != null"); var addIn = element.Tag as AddInToken; var process = new AddInProcess { KeepAlive = false }; if (addIn != null) { _activatedAddIn = addIn.Activate <Calculator>(process, AddInSecurityLevel.Internet); } ListOperations(); }
private void ActivateAddIn(object sender, RoutedEventArgs e) { FrameworkElement el = sender as FrameworkElement; Trace.Assert(el != null, "ActivateAddIn invoked from the wrong control type"); AddInToken addIn = el.Tag as AddInToken; Trace.Assert(el.Tag != null, String.Format("An AddInToken must be assigned to the Tag property of the control {0}", el.Name)); AddInProcess process = new AddInProcess(); process.KeepAlive = false; activeAddIn = addIn.Activate <Calculator>(process, AddInSecurityLevel.Internet); ListOperatons(); }
private void buttonExecute_Click(object sender, RoutedEventArgs e) { AddInToken t = comboBoxProvider.SelectedItem as AddInToken; AddInProcess addInProcess = new AddInProcess(); try { using (IAccessComposition iac = t.Activate <IAccessComposition>(addInProcess, AddInSecurityLevel.FullTrust)) { if (radioButtonLoad.IsChecked == true) { iac.Open(textBoxFile.Text); iac.LoadObjects(textBoxFolder.Text); iac.Close(); } else if (radioButtonSave.IsChecked == true) { iac.Open(textBoxFile.Text); iac.SaveObjects(textBoxFolder.Text); iac.Close(); } else if (radioButtonClear.IsChecked == true) { iac.Open(textBoxFile.Text); iac.ClearObjects(); iac.Close(); } } } catch (Exception ex) { MessageBox.Show(string.Format("Message: {0}\r\n\r\nStack Trace: {1}", ex.Message, ex.StackTrace), "Error"); } finally { if (!addInProcess.IsCurrentProcess) { addInProcess.Shutdown(); } } }
static void Main() { // <Snippet2> // Get path for the pipeline root. // Assumes that the current directory is the // pipeline directory structure root directory. String pipeRoot = Environment.CurrentDirectory; // <Snippet3> // Update the cache files of the // pipeline segments and add-ins. string[] warnings = AddInStore.Update(pipeRoot); foreach (string warning in warnings) { Console.WriteLine(warning); } // </Snippet3> // <Snippet4> // Search for add-ins of type Calculator (the host view of the add-in) // specifying the host's application base, instead of a path, // for the FindAddIns method. Collection <AddInToken> tokens = AddInStore.FindAddIns(typeof(Calculator), PipelineStoreLocation.ApplicationBase); // </Snippet4> // </Snippet2> // <Snippet5> //Ask the user which add-in they would like to use. AddInToken selectedToken = ChooseAddIn(tokens); //Activate the selected AddInToken in a new //application domain with the Internet trust level. Calculator CalcAddIn = selectedToken.Activate <Calculator>(AddInSecurityLevel.Internet); //Run the add-in using a custom method. RunCalculator(CalcAddIn); // </Snippet5> // <Snippet6> // Find a specific add-in. // Construct the path to the add-in. string addInFilePath = pipeRoot + @"\AddIns\P3AddIn2\P3AddIn2.dll"; // The fourth parameter, addinTypeName, takes the full name // of the type qualified by its namespace. Same as AddInToken.AddInFullName. Collection <AddInToken> tokenColl = AddInStore.FindAddIn(typeof(Calculator), pipeRoot, addInFilePath, "CalcAddIns.P3AddIn2"); Console.WriteLine("Found {0}", tokenColl[0].Name); // </Snippet6> // <Snippet8> // Get the AddInController of a // currently actived add-in (CalcAddIn). AddInController aiController = AddInController.GetAddInController(CalcAddIn); // Select another token. AddInToken selectedToken2 = ChooseAddIn(tokens); // Activate a second add-in, CalcAddIn2, in the same // appliation domain and process as the first add-in by passing // the first add-in's AddInEnvironment object to the Activate method. AddInEnvironment aiEnvironment = aiController.AddInEnvironment; Calculator CalcAddIn2 = selectedToken2.Activate <Calculator>(aiEnvironment); // Get the AddInController for the second add-in to compare environments. AddInController aiController2 = AddInController.GetAddInController(CalcAddIn2); Console.WriteLine("Add-ins in same application domain: {0}", aiController.AppDomain.Equals(aiController2.AppDomain)); Console.WriteLine("Add-ins in same process: {0}", aiEnvironment.Process.Equals(aiController2.AddInEnvironment.Process)); // </Snippet8> // <Snippet9> // Get the application domain // of an existing add-in (CalcAddIn). AddInController aiCtrl = AddInController.GetAddInController(CalcAddIn); AppDomain AddInAppDom = aiCtrl.AppDomain; // Activate another add-in in the same application domain. Calculator CalcAddIn3 = selectedToken2.Activate <Calculator>(AddInAppDom); // Show that CalcAddIn3 was loaded // into CalcAddIn's application domain. AddInController aic = AddInController.GetAddInController(CalcAddIn3); Console.WriteLine("Add-in loaded into existing application domain: {0}", aic.AppDomain.Equals(AddInAppDom)); // </Snippet9> // <Snippet10> // Create an external process. AddInProcess pExternal = new AddInProcess(); // Activate an add-in in the external process // with a full trust security level. Calculator CalcAddIn4 = selectedToken.Activate <Calculator>(pExternal, AddInSecurityLevel.FullTrust); // Show that the add-in is an external process // by verifying that it is not in the current (host's) process. AddInController AddinCtl = AddInController.GetAddInController(CalcAddIn4); Console.WriteLine("Add-in in host's process: {0}", AddinCtl.AddInEnvironment.Process.IsCurrentProcess); // </Snippet10> // <Snippet11> // Use qualification data to control // how an add-in should be activated. if (selectedToken.QualificationData[AddInSegmentType.AddIn]["Isolation"].Equals("NewProcess")) { // Create an external process. AddInProcess external = new AddInProcess(); // Activate an add-in in the new process // with the full trust security level. Calculator CalcAddIn5 = selectedToken.Activate <Calculator>(external, AddInSecurityLevel.FullTrust); Console.WriteLine("Add-in activated per qualification data."); } else { Console.WriteLine("This add-in is not designated to be activated in a new process."); } // </Snippet11> // <Snippet12> // Show the qualification data for each // token in an AddInToken collection. foreach (AddInToken token in tokens) { foreach (QualificationDataItem qdi in token) { Console.WriteLine("{0} {1}\n\t QD Name: {2}, QD Value: {3}", token.Name, qdi.Segment, qdi.Name, qdi.Value); } } // </Snippet12> }
static void Main(string[] args) { var errors = AddInStore.Rebuild(PipelinePath); if (errors.Length > 0) { foreach (var error in errors) { Console.WriteLine(error); } Console.ReadKey(); return; } errors = AddInStore.RebuildAddIns(PluginPath); if (errors.Length > 0) { foreach (var error in errors) { Console.WriteLine(error); } Console.ReadKey(); return; } var pluginTokens = AddInStore.FindAddIns(typeof(Plugin), PipelinePath, PluginPath); foreach (var token in pluginTokens) { Console.WriteLine(token.AddInFullName); foreach (var item in token) { Console.WriteLine($"\t{item.Name}:{item.Value}"); } } foreach (var pluginToken in pluginTokens) { var process = new AddInProcess { KeepAlive = false }; //var set = new PermissionSet(PermissionState.Unrestricted); //set.AddPermission(new FileIOPermission(FileIOPermissionAccess.AllAccess, Path.GetDirectoryName(t.AssemblyName.CodeBase))); var plugin = pluginToken.Activate <Plugin>(process, AddInSecurityLevel.Host); if (plugin != null) { plugin.SetDefaultLog(new FileLog(LogLevelEnum.All)); if (plugin.Configuration != null) { foreach (var configuration in plugin.Configuration) { Console.WriteLine(configuration.GetType().FullName); } } plugin.Execute(); plugin.Interrupt(); var controller = AddInController.GetAddInController(plugin); controller.Shutdown(); } } Console.ReadKey(); }