void unloadAddInUIMenuItem_Click(object sender, RoutedEventArgs e) { // Stop displyaing add-in UI this.addInUIHostGrid.Children.Clear(); // Unload add-in AddInController addInController = AddInController.GetAddInController(this.wpfAddInHostView); addInController.Shutdown(); }
public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) { var module = (IModule)value; if (module == null) { return(0); } return(AddInController.GetAddInController(module).AddInEnvironment.Process.ProcessId); }
void cb_Unchecked(object sender, RoutedEventArgs e) { CalculatorBase calc = (CalculatorBase)((CheckBox)sender).Tag; AddInController controller = AddInController.GetAddInController(calc); AddInToken token = controller.Token; ((CheckBox)sender).Tag = token; UnloadAddIn(calc); calc = null; _toUnload.Add(controller.AppDomain); }
public void ActivatePlugins() { if (_plugins == null) { RefreshPluginStore(); } foreach (AddInToken addinToken in _plugins) { try { // Activate the add-in IMyPlugin addinInstance = addinToken.Activate <IMyPlugin>(AddInSecurityLevel.FullTrust); addinInstance.Initialize(this); //var d = addinToken.QualificationData[AddInSegmentType.AddIn]; // Use the add-in Console.WriteLine($"Add-in {addinToken.Name} Version {addinToken.Version}"); Console.WriteLine($"---------------------"); Console.WriteLine($"Plugin name: {addinInstance.Name}"); Console.WriteLine($"Plugin description: {addinInstance.Description}"); Console.WriteLine($"---------------------"); Console.WriteLine(); Console.WriteLine("Executing Operate: "); Console.WriteLine("Operate(10, 20) = " + addinInstance.Operate(10, 20)); Console.WriteLine(); Console.WriteLine("Executing SimpleMethod(): "); addinInstance.SimpleMethod(); Console.WriteLine(); Console.WriteLine("Executing SimpleMethod(\"This is some message from host\"): "); addinInstance.SimpleMethod("This is some message from host"); Console.WriteLine(); Console.WriteLine("Executing: SimpleMethod(\"Host message1\", \"Host message2\")"); Console.WriteLine(addinInstance.SimpleMethod("Host message1", "Host message2")); Console.WriteLine("----------------------------------------------------"); Console.WriteLine("''''''''''''''''''''''''''''''''''''''''''''''''''''"); Console.WriteLine("Shutting it down.....: ->"); AddInController.GetAddInController(addinInstance).Shutdown(); Console.WriteLine("Shut down.....: ->"); } catch (TargetInvocationException ex) { Console.WriteLine(ex.InnerException); } } }
public static ContractHandle ViewToContractAdapter(Object view) { if (view == null) { throw new ArgumentNullException("view"); } System.Diagnostics.Contracts.Contract.EndContractBlock(); AddInController controller = AddInController.GetAddInController(view); if (controller != null) { return(new ContractHandle(controller.AddInControllerImpl.GetContract())); } return(null); }
public UnhandledExceptionHelper(Calculator calc) { if (!AppDomain.CurrentDomain.IsDefaultAppDomain()) { throw new InvalidOperationException("This implementation can only be used in the default AppDomain"); } if (!s_initialized) { s_domains = new Dictionary <AppDomain, AddInToken>(); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); } AddInController controller = AddInController.GetAddInController(calc); s_domains.Add(controller.AppDomain, controller.Token); }
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(); }
static void Main(string[] args) { // <Snippet2> // In this example, the pipeline root is the current directory. String pipeRoot = Environment.CurrentDirectory; // Rebuild the cache of pipeline and add-in information. string[] warnings = AddInStore.Update(pipeRoot); if (warnings.Length > 0) { foreach (string one in warnings) { Console.WriteLine(one); } } // </Snippet2> // <Snippet3> // Find add-ins of type LibraryManager under the specified pipeline root directory. Collection <AddInToken> tokens = AddInStore.FindAddIns(typeof(LibraryManager), pipeRoot); // </Snippet3> // Determine which add-in to use. AddInToken selectedToken = ChooseAddIn(tokens); // <Snippet4> // Activate the selected AddInToken in a new // application domain with a specified security trust level. LibraryManager manager = selectedToken.Activate <LibraryManager>(AddInSecurityLevel.FullTrust); // </Snippet4> // Create a collection of books. IList <BookInfo> books = CreateBooks(); // Show the collection count. Console.WriteLine("Number of books: {0}", books.Count.ToString()); // Have the add-in process the books. // The add-in will discount computer books by $20 // and list their before and after prices. It // will also remove all horror books. manager.ProcessBooks(books); // List the genre of each book. There // should be no horror books. foreach (BookInfo bk in books) { Console.WriteLine(bk.Genre()); } Console.WriteLine("Number of books: {0}", books.Count.ToString()); Console.WriteLine(); // Have the add-in pass a BookInfo object // of the best selling book. BookInfo bestBook = manager.GetBestSeller(); Console.WriteLine("Best seller is {0} by {1}", bestBook.Title(), bestBook.Author()); // Have the add-in show the sales tax rate. manager.Data("sales tax"); // <Snippet6> AddInController ctrl = AddInController.GetAddInController(manager); ctrl.Shutdown(); // </Snippet6> Console.WriteLine("Press any key to exit."); Console.ReadLine(); }
public override void OnConnect() { m_Controller = new AddInController(this); }
public static Module GetModuleForInstance(IModule module) { return(Modules.First(m => AddInController.GetAddInController(module).Token.Equals(m._token))); }
public static void Kill(IModule instance) => AddInController.GetAddInController(instance).Shutdown();
public void Kill(IModule module) { AddInController.GetAddInController(module).Shutdown(); }