Example #1
0
        static void Main()
        {
            // Assume that the current directory is the application folder,
            // and that it contains the pipeline folder structure.
            //String addInRoot = Environment.CurrentDirectory + "\\Pipeline";
            const string addInRoot = @"..\..\..\Pipeline";

            // Update the cache files of the pipeline segments and add-ins.
            string[] warnings = AddInStore.Update(addInRoot);
            foreach (string warning in warnings)
            {
                Console.WriteLine(warning);
            }

            // Search for add-ins of type ICalculator (the host view of the add-in).
            Collection <AddInToken> tokens =
                AddInStore.FindAddIns(typeof(ICalculator), addInRoot);

            // Ask the user which add-in they would like to use.
            AddInToken calcToken = ChooseCalculator(tokens);

            // Activate the selected AddInToken in a new application domain
            // with the Internet trust level.
            ICalculator calc = calcToken.Activate <ICalculator>(AddInSecurityLevel.Internet);

            // Run the add-in.
            RunCalculator(calc);
        }
Example #2
0
        private static void Main(string[] args)
        {
            // Assume that the current directory is the application folder,
            // and that it contains the pipeline folder structure.
            string addInRoot = Environment.CurrentDirectory + "\\Pipeline";

            // Update the cache files of the pipeline segments and add-ins.
            string[] warnings = AddInStore.Rebuild(addInRoot);
            foreach (string warning in warnings)
            {
                Console.WriteLine(warning);
            }

            // Search for add-ins of type ICalculator (the host view of the add-in).
            Collection <AddInToken> tokens = AddInStore.FindAddIns(typeof(IV2), addInRoot);

            AddInToken token = null;

            if (tokens.Count > 1)
            {
                Console.WriteLine("Select a version:");

                for (int i = 0; i < tokens.Count; i++)
                {
                    Console.WriteLine("{0}: {1}", i, tokens[i].Name);
                }

                var key = Console.ReadKey();
                Console.WriteLine();

                if (key.KeyChar == '0')
                {
                    token = tokens[0];
                }
                else
                {
                    token = tokens[1];
                }
            }

            if (token != null)
            {
                // Activate the selected AddInToken in a new application domain
                // with the Internet trust level.
                IV2 v2 = token.Activate <IV2>(AddInSecurityLevel.Internet);
                v2.OnEvent += (sender, message) => { Console.WriteLine("Event Fired: {0}", message); };
                v2.Initialize(new CallbackHandler());

                // Run the add-in.
                v2.WriteToConsole("Hello World From Host!");
                Console.WriteLine(v2.GetName());

                //var test = (Stopwatch)v2.GetSource();

                //Task.Delay(500).Wait();

                //test.Stop();
                //Console.WriteLine(test.ElapsedTicks);
            }
        }
Example #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Get add-in pipeline folder (the folder in which this application was launched from)
            string appPath = System.IO.Path.Combine(Environment.CurrentDirectory, "AddIns");

            //update must use the host root folder
            AddInStore.Update(Environment.CurrentDirectory);

            if (System.IO.Directory.Exists(appPath))
            {
                // Rebuild visual add-in pipeline
                string[] warnings = AddInStore.RebuildAddIns(appPath);
                if (warnings.Length > 0)
                {
                    string msg = "Could not rebuild pipeline:";
                    foreach (string warning in warnings)
                    {
                        msg += "\n" + warning;
                    }
                    MessageBox.Show(msg);
                    return;
                }
            }

            // Activate add-in with Internet zone security isolation
            Collection <AddInToken> addInTokens = AddInStore.FindAddIns(typeof(IWPFAddInHostView), PipelineStoreLocation.ApplicationBase, new string[] { appPath });

            lstAddIns.ItemsSource = addInTokens;
        }
Example #4
0
        void loadAddInUIMenuItem_Click(object sender, RoutedEventArgs e)
        {
// Get add-in pipeline folder (the folder in which this application was launched from)
            string appPath = Environment.CurrentDirectory;

// Rebuild visual add-in pipeline
            string[] warnings = AddInStore.Rebuild(appPath);
            if (warnings.Length > 0)
            {
                string msg = "Could not rebuild pipeline:";
                foreach (string warning in warnings)
                {
                    msg += "\n" + warning;
                }
                MessageBox.Show(msg);
                return;
            }

// Activate add-in with Internet zone security isolation
            Collection <AddInToken> addInTokens = AddInStore.FindAddIns(typeof(WPFAddInHostView), appPath);
            AddInToken wpfAddInToken            = addInTokens[0];

            this.wpfAddInHostView = wpfAddInToken.Activate <WPFAddInHostView>(AddInSecurityLevel.Internet);

// Display add-in UI
            FrameworkElement addInMainUI = this.wpfAddInHostView;

            this.addInUIHostGrid.Children.Add(addInMainUI);

// Get and display add-in status UI
            FrameworkElement addInStatusUI = this.wpfAddInHostView.GetAddInStatusUI();

            this.addInStatusBar.Items.Add(addInStatusUI);
        }
Example #5
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();
        }
Example #6
0
 private void RebuildStore(object sender, RoutedEventArgs e)
 {
     string[] messages = AddInStore.Rebuild(Settings.Default.PipelinePath);
     if (messages.Length != 0)
     {
         MessageBox.Show(string.Join("\n", messages), "AddInStore Warnings", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
        private void OnHostAppWindowLoaded(object sender, RoutedEventArgs e)
        {
            var addInPath = Environment.CurrentDirectory;

            AddInStore.Update(addInPath);
            IList <AddInToken> tokens = AddInStore.FindAddIns(typeof(ImageProcessorHostView), addInPath);

            AddInListBox.ItemsSource = tokens;
        }
Example #8
0
        public static void Find()
        {
            string             path   = Environment.CurrentDirectory;
            IList <AddInToken> tokens = AddInStore.FindAddIns(typeof(ViewNodeHostView), path);

            var addin = tokens[0].Activate <ViewNodeHostView>(AddInSecurityLevel.Internet);

            addin.View();
        }
Example #9
0
 private static IComponentScanner GetPipelineScanner(string xnaFrameworkVersion)
 {
     if (string.IsNullOrEmpty(xnaFrameworkVersion))
     {
         XBuilderWindowPane.WriteLine(Resources.PipelineAddInMissingVersionProperty, new object[0]);
     }
     else
     {
         string pipelineAddInRootPath = GetPipelineAddInRootPath();
         if (!string.IsNullOrEmpty(pipelineAddInRootPath))
         {
             try
             {
                 foreach (AddInToken token in AddInStore.FindAddIns(typeof(IComponentScanner), pipelineAddInRootPath, new string[0]))
                 {
                     string addInFrameworkVersion;
                     if (token.QualificationData[AddInSegmentType.AddIn].TryGetValue("XnaFrameworkVersion", out addInFrameworkVersion) &&
                         addInFrameworkVersion != null && addInFrameworkVersion == xnaFrameworkVersion)
                     {
                         try
                         {
                             return(token.Activate <IComponentScanner>(AppDomain.CurrentDomain));
                         }
                         catch (TargetInvocationException exception)
                         {
                             string message = string.Empty;
                             if (exception.InnerException != null)
                             {
                                 message = exception.InnerException.Message;
                             }
                             XBuilderWindowPane.WriteLine(
                                 "An error occurred while instantiating the content pipeline component scanner for version '{0}': {1}",
                                 new object[] { xnaFrameworkVersion, message });
                             continue;
                         }
                     }
                 }
                 XBuilderWindowPane.WriteLine(
                     "XNA Framework version '{0}' is not supported by this installation of XNA Game Studio, or a required component is missing.",
                     new object[] { xnaFrameworkVersion });
             }
             catch (InvalidOperationException ex)
             {
                 XBuilderWindowPane.WriteLine(Resources.PipelineAddInInvalidPipeline, new object[] { ex.Message });
             }
             catch (DirectoryNotFoundException ex)
             {
                 XBuilderWindowPane.WriteLine(Resources.PipelineAddInInvalidPipeline, new object[] { ex.Message });
             }
             catch (InvalidPipelineStoreException ex)
             {
                 XBuilderWindowPane.WriteLine(Resources.PipelineAddInInvalidPipeline, new object[] { ex.Message });
             }
         }
     }
     return(null);
 }
Example #10
0
 public static void Rebuild()
 {
     string[] messages = AddInStore.Rebuild(PipelineStoreLocation.ApplicationBase);
     if (messages.Length != 0)
     {
         KryptonMessageBox.Show(string.Join("\n", messages),
                                "AddInStore Warnings", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
     }
 }
Example #11
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string path = Environment.CurrentDirectory;

            AddInStore.Update(path);

            IList <AddInToken> tokens = AddInStore.FindAddIns(typeof(HostView.ImageProcessorHostView), path);

            lstAddIns.ItemsSource = tokens;
        }
        private void OnUpdateStore(object sender, RoutedEventArgs e)
        {
            var messages = AddInStore.Update(_DefaultPipelinePath);

            if (messages.Length != 0)
            {
                MessageBox.Show(string.Join(Environment.NewLine, messages), "AddInStore Warnings", MessageBoxButton.OK,
                                MessageBoxImage.Warning);
            }
        }
        private static AddInToken getRemoteScriptManagerToken(string remoteScriptManagerName)
        {
            string addInRoot = Environment.CurrentDirectory;

            AddInStore.Rebuild(addInRoot);
            Collection <AddInToken> addInTokens = AddInStore.FindAddIns(typeof(IRemoteScriptManager), addInRoot);

            AddInToken token = addInTokens.First <AddInToken>(currentToken => currentToken.Name == remoteScriptManagerName);

            return(token);
        }
Example #14
0
 void FindAddIns()
 {
     try
     {
         this.listAddIns.DataContext = AddInStore.FindAddIns(typeof(Calculator), Settings.Default.PipelinePath);
     }
     catch (DirectoryNotFoundException)
     {
         MessageBox.Show("Verify the pipeline directory in the config file");
         Application.Current.Shutdown();
     }
 }
Example #15
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="plugindir"></param>
 /// <param name="plugis"></param>
 /// <param name="loaded"></param>
 public Plugin(DirectoryInfo plugindir, Plugins plugis, string name, int[] version, bool loaded)
 {
     this.PluginDir = plugindir;
     this.Plugins = plugis;
     this.Name = name;
     this.Version = version;
     this.DefaultLoad = loaded;
     appDomainToPlugin.Add(plugindir.FullName, this);
     attributeStore = new AssemblyStore();
     attributeStore.Update(plugindir);
     addinstore = new AddInStore(attributeStore);
 }
        private void OnHostAppWindowLoaded(object sender, RoutedEventArgs e)
        {
            var path = Environment.CurrentDirectory;

            AddInStore.Update(path);

            IList <AddInToken> tokens = AddInStore.FindAddIns(typeof(ImageProcessorHostView), path);

            AddInListBox.ItemsSource = tokens;

            _automationHost = new AutomationHost(AddInProcessProgressBar);
        }
        public static TView ContractToViewAdapter <TView>(ContractHandle contract, PipelineStoreLocation location)
        {
            if (location != PipelineStoreLocation.ApplicationBase)
            {
                throw new ArgumentException(Res.InvalidPipelineStoreLocation, "location");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            String appBase = AddInStore.GetAppBase();

            return(ContractToViewAdapterImpl <TView>(contract, appBase, false));
        }
        private static TView ContractToViewAdapterImpl <TView>(ContractHandle contract, String pipelineRoot, bool demand)
        {
            if (contract == null)
            {
                throw new ArgumentNullException("contract");
            }
            if (pipelineRoot == null)
            {
                throw new ArgumentNullException("pipelineRoot");
            }
            if (String.IsNullOrEmpty(pipelineRoot))
            {
                throw new ArgumentException(Res.PathCantBeEmpty);
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            if (demand)
            {
                new FileIOPermission(FileIOPermissionAccess.Read, pipelineRoot).Demand();
            }

            Type     havType     = typeof(TView);
            TypeInfo havTypeInfo = new TypeInfo(havType);

            List <PartialToken> partialTokens = AddInStore.GetPartialTokens(pipelineRoot);

            foreach (PartialToken partialToken in partialTokens)
            {
                if (AddInStore.Contains(partialToken.HostAdapter.HostAddinViews, havTypeInfo))
                {
                    partialToken.PipelineRootDirectory = pipelineRoot;

                    //Ask for something that can implement the contract in this partial token.  The result will
                    //either be null, the addin adapter itself, or another addin adapter
                    IContract subcontract = contract.Contract.QueryContract(partialToken._contract.TypeInfo.AssemblyQualifiedName);
                    if (subcontract != null)
                    {
                        //Instantiate the adapter and pass in the addin to its constructor
                        TView hav = AddInActivator.ActivateHostAdapter <TView>(partialToken, subcontract);
                        return(hav);
                    }
                }
            }

            // Don't let the ref count go to zero too soon, before we increment it in ActivateHostAdapter
            // This is important when QueryContract returns the addIn adapter itself.  A GC at that point
            // may collect the ContractHandle and decrement the ref count to zero before we have a chance to increment it
            System.GC.KeepAlive(contract);

            // return null.  Compiler makes us return default(TView), which will be null
            return(default(TView));
        }
Example #19
0
        public void Load()
        {
            // Get add-in pipeline folder (the folder in which this application was launched from)
            var appPath = System.IO.Path.Combine(Environment.CurrentDirectory, "core");

            // Rebuild visual add-in pipeline
            var warnings = AddInStore.Rebuild(appPath);

            if (warnings.Length > 0)
            {
                var msg = warnings.Aggregate(LanguageHelper.ShortNameToString("PipelineRebuildFail"),
                                             (current, warning) => current + ("\n" + warning));
                log.Error(msg);
                MessageBox.Show(msg);
                return;
            }

            //Load the IcyWind.Core add-in
            var addInTokens =
                AddInStore.FindAddIn(typeof(IMainHostView), appPath,
                                     System.IO.Path.Combine(appPath, "AddIns", "IcyWind.Core", "IcyWind.Core.dll"),
                                     "IcyWind.Core.IcyWind");

            //Prevent other add-ins from being loaded and block start if add-ins are in wrong place
            if (addInTokens.Count > 1)
            {
                MessageBox.Show(LanguageHelper.ShortNameToString("MoreOneCore"),
                                "IcyWind Error", MessageBoxButton.OK, MessageBoxImage.Error);
                log.Fatal("More than one IcyWind Core installed.");
                Environment.Exit(1);
            }
            else
            {
                var dirs = System.IO.Directory.GetFiles(System.IO.Path.Combine(appPath, "AddIns"));
                if (dirs.Length > 1)
                {
                    MessageBox.Show(LanguageHelper.ShortNameToString("PluginWrongLocation"));
                    log.Warn("Plugin installed in wrong location.");
                    Environment.Exit(1);
                }
            }
            //Get the addin
            var mainpage = addInTokens.First();
            //Give the add-in full trust to the system
            var hostview = mainpage.Activate <IMainHostView>(AddInSecurityLevel.FullTrust);

            // Get and display add-in UI
            FrameworkElement addInUi = hostview.Run("English");

            //AddInController controller = AddInController.GetAddInController(addInUi);
            MainContent.Content = addInUi;
        }
Example #20
0
        public static void UpdateInstalledModules()
        {
            AddInStore.Update(AddInPipelineRoot);
            var addins = AddInStore.FindAddIns(typeof(IModule), AddInPipelineRoot);

            foreach (var token in addins)
            {
                if (!Modules.Any(m => m._token.Equals(token)))
                {
                    Modules.Add(new Module(token));
                }
            }
        }
Example #21
0
        private void AddInsInit()
        {
            string strAddInPath = Environment.CurrentDirectory;

            AddInStore.Update(strAddInPath);

            tokens = AddInStore.FindAddIns(typeof(HostView.KPICaculaterHostView), strAddInPath);
            AddInList.ItemsSource = tokens;
            if (tokens.Count > 0)
            {
                AddInList.SelectedIndex = 0;
            }
        }
Example #22
0
        private void BuildListPlugins()
        {
            this.listPlugins.Items.Clear();
            foreach (var addIn in AddInStore.FindAddIns(typeof(DataPlugin), PipelineStoreLocation.ApplicationBase))
            {
                this.listPlugins.Items.Add(addIn);
            }

            if (this.listPlugins.Items.Count > 0)
            {
                this.listPlugins.SelectedItem = this.listPlugins.Items[0];
            }
        }
Example #23
0
        /// <summary>
        /// Loads a list of all available AddIns
        /// </summary>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string path = Environment.CurrentDirectory;

            AddInStore.Update(path);

            string[] s = AddInStore.RebuildAddIns(path);

            IList <AddInToken> tokens = AddInStore.FindAddIns(typeof(HostView.NumberProcessorHostView), path);

            lstAddIns.ItemsSource = tokens;
            automationHost        = new AutomationHost(progressBar);
        }
Example #24
0
        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();
        }
Example #25
0
        public static Collection <AddInToken> GetAddInTokens(string addInRoot, string moduleName)
        {
            // rebuild the cache files of the pipeline segments and add-ins.
            string[] warnings = AddInStore.Rebuild(addInRoot);

            foreach (string warning in warnings)
            {
                Console.WriteLine(warning);
            }

            // Search for add-ins of type VModule
            Collection <AddInToken> tokens = AddInStore.FindAddIns(typeof(VModule), addInRoot);

            return(tokens);
        }
Example #26
0
        private static AddInToken GetToken()
        {
            String addInRoot = Environment.CurrentDirectory;

            //Check to see if new AddIns have been installed
            AddInStore.Rebuild(addInRoot);

            //Look for Calculator AddIns in our root directory and store the results
            Collection <AddInToken> tokens = AddInStore.FindAddIns(typeof(Calculator), addInRoot);

            //Ask the user which AddIn they would like to use
            AddInToken calcToken = ChooseCalculator(tokens);

            return(calcToken);
        }
        public IList <T> ActivateAddIns <T>(Func <AddInFacade, AddInToken, Platform, T> factory, Func <AddInToken, bool> predicate)
        {
            var result  = new List <T>();
            var typeOfT = typeof(T);
            var tokens  = AddInStore.FindAddIns(typeOfT, _pipelineFolder.FullName);

            if (tokens.Count == 0)
            {
                const string template = "No Add-Ins of type '{0}' were found!";
                var          message  = String.Format(template, typeOfT.Name);
                Log.Warn(message);
            }
            foreach (var token in tokens)
            {
                if (predicate == null || predicate(token))
                {
                    var addInQualificationData = token.QualificationData[AddInSegmentType.AddIn];
                    var addInProcessPlatform   = Platform.Host;
                    if (addInQualificationData.ContainsKey(PlatformQualificationDataKey))
                    {
                        var potentialPlatform = addInQualificationData[PlatformQualificationDataKey];
                        if (!Enum.TryParse(potentialPlatform, true, out addInProcessPlatform))
                        {
                            // default to "Host" if the qualification data value couldn't be parsed
                            addInProcessPlatform = Platform.Host;
                        }
                    }
                    const string template =
                        "Add-in named '{0}', version {2}, published by '{1}' and described as '{3}' will be activated out-of-process under platform {4}.";
                    var message = String.Format(template, token.Name, token.Publisher, token.Version, token.Description, addInProcessPlatform);
                    Log.Info(message);

                    var currentToken = token;
                    T   addInOfT;
                    try
                    {
                        addInOfT = factory(this, currentToken, addInProcessPlatform);
                    }
                    catch (InvalidOperationException e)
                    {
                        Log.Error(e.Message, e);
                        continue;
                    }
                    result.Add(addInOfT);
                }
            }
            return(new ReadOnlyCollection <T>(result));
        }
Example #28
0
        public IDriver GetDriverForImage(FirmwareImage image)
        {
            IDriver result = null;

            if (image != null)
            {
                var tokens      = AddInStore.FindAddIns(typeof(IDriver), _addInRoot);
                var driverToken = tokens.FirstOrDefault(x => x.Name == image.DriverName);
                if (driverToken != null)
                {
                    result = driverToken.Activate <IDriver>(AddInSecurityLevel.FullTrust);
                    // use AddInController.GetAddInController(result) to manage/unload/etc
                }
            }
            return(result);
        }
Example #29
0
        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 string[] RebuildPipeline()
        {
            var warnings = AddInStore.Rebuild(_pipelineFolder.FullName);

            if (warnings.Any())
            {
                const string template = "There were {0} warnings rebuilding the Add-In Store.";
                var          message  = String.Format(template, warnings.Length);
                Log.Warn(message);
                foreach (var warning in warnings)
                {
                    Log.Warn(warning);
                }
            }
            return(warnings);
        }
Example #31
0
        private TPlugin LoadPlugin <TPlugin>() where TPlugin : class, IHostViewAddIn
        {
            Collection <AddInToken> tokens = AddInStore.FindAddIns(typeof(ISightstonePlugin), _addInRootPath);

            IList <PluginTokenBase> pluginTokens = tokens.OrderBy(p => p.Version).Select(p => (PluginTokenBase)(new PluginToken <TPlugin>(p))).ToList();

            _plugins[typeof(TPlugin)] = pluginTokens;

            var pluginToken = pluginTokens.FirstOrDefault() as PluginToken <TPlugin>;

            if (pluginToken == null)
            {
                throw new InvalidOperationException("The plugin has not been found");
            }

            return(pluginToken.Plugin);
        }