예제 #1
0
 public InteractiveTextBox()
     : base()
 {
     try
     {
         var catalog = new PackageCatalog();
         catalog.AddPackage(Package.Current);
         var container = new CompositionContainer(catalog);
         container.ComposeParts(this);
     }
     catch (Exception exc)
     {
         throw new Exception("The application is missing an IDefineCommand and/or IPerformCommand component. Make sure the application refers to projects that implement these. ", exc);
     }
 }
예제 #2
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public PluginLoader()
        {
            _catalog.Catalogs.Add(new DirectoryCatalog(Application.StartupPath + "\\Plugins"));

            try
            {
                _container = new CompositionContainer(_catalog);
                _container.ComposeParts(this);
                ParsePlugins();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + Environment.NewLine + e.StackTrace, "Error Loading Plug-in");
            }
        }
    public void Load()
    {
        var catalog    = new AggregateCatalog();
        var assembly   = GetType().Assembly;                //Assembly of our executable program
        var dllCatalog = new AssemblyCatalog(assembly);

        catalog.Catalogs.Add(dllCatalog);
        var pluginAssembly = Assembly.LoadFrom(Path.Combine(dir, name));          //We have to explicit point which assembly will be loaded
        var pluginCatalog  = new AssemblyCatalog(pluginAssembly);                 //pass it to catalog to let framework know each vital information about this .dll

        catalog.Catalogs.Add(pluginCatalog);
        CompositionContainer container = new CompositionContainer(catalog);

        container.ComposeParts(this);     //and it works!
    }
예제 #4
0
        /// <summary>
        /// Import the MEF-based file managers
        /// </summary>
        public void ImportFileReaders()
        {
            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();

            //Adds all the parts found in all assemblies in
            //the same directory as the executing program
            catalog.Catalogs.Add(new DirectoryCatalog(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)));

            //Create the CompositionContainer with the parts in the catalog
            CompositionContainer container = new CompositionContainer(catalog);

            //Fill the imports of this object
            container.ComposeParts(this);
        }
예제 #5
0
        private void Compose()
        {
            var catalog = new AggregateCatalog();

            // Add a catalog for the current assembly to the AggregateCatalog
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            // Add a catalog that reads all assemblies from a directory
            catalog.Catalogs.Add(new DirectoryCatalog(@".\Extensions"));

            // Make an instance of a CompositionContainer and give it a reference to the AggregateCatalog
            var container = new CompositionContainer(catalog, CompositionOptions.DisableSilentRejection);

            // Finally call composeparts to connect the Import with Export.
            container.ComposeParts(this);
        }
예제 #6
0
파일: Graze.cs 프로젝트: yevhen/graze
        private void SetExtras()
        {
            if (Extras != null && Extras.Count() != 0)
            {
                return;
            }

            var extrasFolderCatalog    = new DirectoryCatalog(_parameters.ExtrasFolder);
            var currentAssemblyCatalog = new AssemblyCatalog(typeof(Program).Assembly);
            var aggregateCatalog       = new AggregateCatalog(extrasFolderCatalog, currentAssemblyCatalog);

            var container = new CompositionContainer(aggregateCatalog);

            container.ComposeParts(this);
        }
예제 #7
0
        public BotsManager()
        {
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(BotsManager).Assembly));
            _container = new CompositionContainer(catalog);
            try
            {
                _container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }
        }
예제 #8
0
        ///<inheritdoc />
        public void RunStarted(
            object automationObject,
            Dictionary <string, string> replacementsDictionary,
            WizardRunKind runKind,
            object[] customParams)
        {
            var             provider = (IServiceProvider)automationObject;
            IComponentModel model    = (IComponentModel)provider.QueryService <SComponentModel>();

            using (var container = new CompositionContainer(model.DefaultExportProvider))
            {
                container.ComposeParts(this);
            }
            _wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams);
        }
        public NewCommandHandler(XRDesignMdiController xrDesigner, CompositionContainer container)
        {
            if (xrDesigner == null)
            {
                throw new ArgumentNullException("xrDesigner");
            }

            if (container == null)
            {
                throw new ArgumentNullException("container");
            }

            _xrDesigner = xrDesigner;
            container.ComposeParts(this);
        }
예제 #10
0
 private static Loger Compose()
 {
     try
     {
         var loger     = new Loger();
         var catalog   = new DirectoryCatalog(@"C:\Loger\LogerComponent\bin\Debug");
         var container = new CompositionContainer(catalog);
         container.ComposeParts(loger);
         return(loger);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
예제 #11
0
        public void AddDir(string dir, bool recursive)
        {
            // Ignore non editor directories to save performance.
            if (!dir.EndsWith(JobStdSubPath))
            {
                return;
            }

            var catalog = new DirectoryCatalog(dir);

            FContainer = new CompositionContainer(catalog, FExportProviders);
            FContainer.ComposeParts(this);

            FNodeInfoExports.AddRange(FChangingNodeInfoExports);
        }
예제 #12
0
        public KomPuppetmaster()
        {
            var catalog = new AggregateCatalog();

            ///使用当前程序集构造AssemblyCatalog,并添加
            ///AssemblyCatalog对于
            AssemblyCatalog assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            catalog.Catalogs.Add(assemblyCatalog);
            catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));
            var container = new CompositionContainer(catalog);

            container.ComposeParts(this);
            Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
        }
예제 #13
0
파일: Plugins.cs 프로젝트: ste10k1/Bridge
        public static IPlugins GetPlugins(ITranslator translator, IAssemblyInfo config)
        {
            var path     = GetPluginPath(translator, config);
            var catalogs = new List <ComposablePartCatalog>();

            if (System.IO.Directory.Exists(path))
            {
                catalogs.Add(new DirectoryCatalog(path, "*.dll"));
            }

            foreach (var reference in translator.References)
            {
                var assemblies = reference.MainModule.Resources.Where(res => res.Name.StartsWith("Bridge.Plugins."));

                if (assemblies.Any())
                {
                    foreach (var res_assembly in assemblies)
                    {
                        using (var resourcesStream = ((EmbeddedResource)res_assembly).GetResourceStream())
                        {
                            var ba = new byte[(int)resourcesStream.Length];
                            resourcesStream.Read(ba, 0, (int)resourcesStream.Length);

                            var assembly = Assembly.Load(ba);

                            catalogs.Add(new AssemblyCatalog(assembly));
                        }
                    }
                }
            }

            if (catalogs.Count == 0)
            {
                return(new Plugins()
                {
                    plugins = new IPlugin[0]
                });
            }

            var catalog = new AggregateCatalog(catalogs);

            CompositionContainer container = new CompositionContainer(catalog);
            var plugins = new Plugins();

            container.ComposeParts(plugins);

            return(plugins);
        }
예제 #14
0
        /// <summary>
        /// Forces a reloading of all the GeocodeService classes
        /// </summary>
        public void Refresh()
        {
            Components = new Dictionary <int, Lazy <T, TData> >();

            // Create the MEF Catalog
            var catalog = new AggregateCatalog();

            // Add the currently running assembly to the Catalog
            catalog.Catalogs.Add(new AssemblyCatalog(this.GetType().Assembly));

            // Add all the assemblies in the 'Plugins' subdirectory
            string pluginsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins");

            if (Directory.Exists(pluginsFolder))
            {
                catalog.Catalogs.Add(new DirectoryCatalog(pluginsFolder));
            }

            // Create the container from the catalog
            container = new CompositionContainer(catalog);

            // Compose the MEF container with any classes that export the same definition
            container.ComposeParts(this);

            // Create a temporary sorted dictionary of the classes so that they can be executed in a specific order
            var components = new SortedDictionary <int, List <Lazy <T, TData> > >();

            foreach (Lazy <T, TData> i in MEFComponents)
            {
                if (!components.ContainsKey(i.Value.Order))
                {
                    components.Add(i.Value.Order, new List <Lazy <T, TData> >());
                }

                components[i.Value.Order].Add(i);
            }

            // Add each class found through MEF into the Services property value in the correct order
            int id = 0;

            foreach (KeyValuePair <int, List <Lazy <T, TData> > > entry in components)
            {
                foreach (Lazy <T, TData> component in entry.Value)
                {
                    Components.Add(id++, component);
                }
            }
        }
예제 #15
0
        /// <summary>
        ///   load workflow plugins and bind them to this host.
        /// </summary>
        private void Compose()
        {
            var catalog    = new AggregateCatalog();
            var assemblies =
                AppDomain.CurrentDomain.GetAssemblies().Where(
                    a =>
                    !a.IsDynamic && !a.FullName.StartsWith("System.") && !a.FullName.StartsWith("Microsoft.") &&
                    !a.FullName.StartsWith("DotNet"));


            assemblies.ForEach(entry =>
            {
                _log.InfoFormat("Workflow host adding plugins from assembly {0}", entry.FullName);
                catalog.Catalogs.Add(new AssemblyCatalog(entry));
            });

            var lfm = Catalog.Factory.Resolve <ILocalFileMirror>();
            var di  = new DirectoryInfo(Path.Combine(lfm.TargetPath, lfm.TargetFolder));

            if (!di.Exists)
            {
                di.Create();
            }
            var dirCat = new DirectoryCatalog(lfm.TargetPath, "*wf.dll");

            _log.InfoFormat("Workflow host adding plugins from local file mirror: {0}",
                            string.Join(",", dirCat.LoadedFiles.ToArray()));

            if (dirCat.LoadedFiles.Any())
            {
                catalog.Catalogs.Add(dirCat);
            }

            _container = new CompositionContainer(catalog);

            try
            {
                _container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                var es = string.Format("Exception loading workflow plugins: {0}", compositionException.Message);
                _log.Error(es);
                var on = Catalog.Factory.Resolve <IApplicationAlert>();
                on.RaiseAlert(ApplicationAlertKind.Unknown, es);
                _log.Error(compositionException.Message, compositionException);
            }
        }
예제 #16
0
        public Extension()
        {
            try
            {
                AggregateCatalog catalog = new AggregateCatalog();
                string           dir     = Folder.Startup + "Extensions";

                if (Directory.Exists(dir))
                {
                    string[] knownExtensions = { "RatingExtension", "ScriptingExtension" };

                    foreach (string extDir in Directory.GetDirectories(dir))
                    {
                        if (knownExtensions.Contains(Path.GetFileName(extDir)))
                        {
                            catalog.Catalogs.Add(new DirectoryCatalog(extDir, Path.GetFileName(extDir) + ".dll"));
                        }
                        else
                        {
                            ConsoleHelp.WriteError("Failed to load extension:\n\n" + extDir +
                                                   "\n\nOnly extensions that ship with mpv.net are allowed in <startup>\\extensions" +
                                                   "\n\nUser extensions have to use <config folder>\\extensions" +
                                                   "\n\nNever copy or install a new mpv.net version over a old mpv.net version.");
                        }
                    }
                }

                dir = core.ConfigFolder + "extensions";

                if (Directory.Exists(dir))
                {
                    foreach (string extDir in Directory.GetDirectories(dir))
                    {
                        catalog.Catalogs.Add(new DirectoryCatalog(extDir, Path.GetFileName(extDir) + ".dll"));
                    }
                }

                if (catalog.Catalogs.Count > 0)
                {
                    CompositionContainer = new CompositionContainer(catalog);
                    CompositionContainer.ComposeParts(this);
                }
            }
            catch (Exception ex)
            {
                App.ShowException(ex);
            }
        }
예제 #17
0
        private void UpdateControllerList()
        {
            AggregateCatalog aggCat = new AggregateCatalog();

            foreach (String pluginDirectory in _pluginDirectories)
            {
                DirectoryCatalog cat = new DirectoryCatalog(pluginDirectory);
                aggCat.Catalogs.Add(cat);
            }

            _compositionContainer = new CompositionContainer(aggCat);
            try
            {
                _compositionContainer.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }

            _components = new List <IParseable>();
            // For older configuration files. At some point, we will need to take this out and just say screw it.
            if (_configDoc.SelectNodes("Configuration/Components").Count > 0)
            {
                foreach (IParseable component in ParseChildrenComponents(_configDoc.SelectSingleNode("Configuration/Components"), ParseableElementType.IOInterface))
                {
                    AddComponent(component);
                }
            }

            // For newer configuration files for the IO interfaces.
            if (_configDoc.SelectNodes("Configuration/IOInterfaces").Count > 0)
            {
                foreach (IParseable component in ParseChildrenComponents(_configDoc.SelectSingleNode("Configuration/IOInterfaces"), ParseableElementType.IOInterface))
                {
                    AddComponent(component);
                }
            }

            // Reads in the apps.
            foreach (IParseable component in ParseChildrenComponents(_configDoc.SelectSingleNode("Configuration/Apps"), ParseableElementType.App))
            {
                AddComponent(component);
            }

            _components.ForEach(component => InitializeComponents(component));
            OnInitializationComplete();
        }
예제 #18
0
        public Dictionary <string, ITransformation> Build(int pipeNumber)
        {
            var pipe = new Dictionary <string, ITransformation>();

            int count = 0;

            foreach (var tranConfig in _transactionElements)
            {
                count++;

                var tranName = tranConfig.Attribute("name")?.Value;

                if (string.IsNullOrWhiteSpace(tranName))
                {
                    throw new TransformationPipeException(string.Format("Incorrect Transformation Config : Missing Name : {0}", tranConfig));
                }

                string tranVersion = tranConfig.Attribute("version")?.Value ?? "";

                try
                {
                    var _transformationFactory = new MefFactory <ITransformation>();
                    _container.ComposeParts(_transformationFactory);

                    var tran = _transformationFactory.CreateComponent(tranName, tranVersion);

                    tran.Initialise(tranConfig, _globalData, _logger, pipeNumber);

                    pipe.Add(string.Format("{0} - {1}", tranName, count), tran);

                    if (pipeNumber > 1)
                    {
                        _logger.Debug(string.Format("Pipe {0}: Transformation {1} = {2}", pipeNumber, count, tranName));
                    }
                    else
                    {
                        _logger.Info(string.Format("Pipe {0}: Transformation {1} = {2}", pipeNumber, count, tranName));
                    }
                }
                catch (Exception ex)
                {
                    _logger.Fatal(string.Format("Pipe {0}: Unable to Create Transformation {1} : {2} ({3})", pipeNumber, count, tranName, ex.Message));
                    throw new TransformationPipeException(string.Format("Unable to Create Transformation {0} : {1}", tranName, ex.Message));
                }
            }

            return(pipe);
        }
예제 #19
0
        public static GoToWindowPluginsContainer LoadPlugins()
        {
            var catalog = new AggregateCatalog();

            try
            {
                catalog.Catalogs.Add(new DirectoryCatalog(PluginsFolderName));
            }
            catch (DirectoryNotFoundException exc)
            {
                HandleError(exc, ExitCodes.PluginDirectoryNotFound, "Plugins directory not found. Check that the Plugins directory is created and at least contains at least GoToWindow.Plugins.Core.dll can be found and restart GoToWindow.");
                return(null);
            }

            var container = new CompositionContainer(catalog);

            try
            {
                var pluginsContainer = new GoToWindowPluginsContainer();
                container.ComposeParts(pluginsContainer);

                DiagnosticCatalogComposition(catalog);

                if (pluginsContainer.Plugins == null || !pluginsContainer.Plugins.Any())
                {
                    HandleError(new Exception("No plugins were composed"), ExitCodes.NoPluginsFound, "No plug-ins found. Check that at least GoToWindow.Plugins.Core.dll can be found in the Plugins directory and restart GoToWindow.");
                    return(null);
                }

                pluginsContainer.Plugins = pluginsContainer.Plugins.OrderBy(plugin => plugin.Sequence).ToList();
                return(pluginsContainer);
            }
            catch (InstanceNotFoundException exc)
            {
                HandleError(exc, ExitCodes.NoPluginsFound, "No plug-ins found. Check that at least GoToWindow.Plugins.Core.dll can be found in the Plugins directory and restart GoToWindow.");
                return(null);
            }
            catch (ReflectionTypeLoadException exc)
            {
                HandleError(exc, ExitCodes.ErrorLoadingPluginsTypes, "An error occured while loading plugin types.", string.Join("; ", exc.LoaderExceptions.Select(e => e.Message)));
                return(null);
            }
            catch (Exception exc)
            {
                HandleError(exc, ExitCodes.ErrorLoadingPlugins, "An error occured while loading plug-ins. Try updating or removing plugins other than GoToWindow.Plugins.Core.dll from the Plugins directory and restart GoToWindow.");
                return(null);
            }
        }
예제 #20
0
        public void BeforeTest()
        {
            clipboardModule             = new ClipboardModule();
            clipboardCopyEventProducer  = new ClipboardCopyEventProducer();
            clipboardCutEventProducer   = new ClipboardCutEventProducer();
            clipboardPasteEventProducer = new ClipboardPasteEventProducer();

            container = new CompositionContainer();
            container.ComposeExportedValue(clipboardCopyEventProducer);
            container.ComposeExportedValue(clipboardCutEventProducer);
            container.ComposeExportedValue(clipboardPasteEventProducer);
            container.ComposeParts(clipboardModule);

            hookNativeMethods = new HookNativeMethodsMock();
            hookNativeMethods.Initialize();
        }
예제 #21
0
        /// <summary>
        /// Prevents a default instance of the <see cref="PluginHost"/> class from being created.
        /// </summary>
        private PluginHost()
        {
            AllPlugins = new List <PluginBase>();
            Plugins    = new List <PluginBase>();

            try
            {
                _catalog = new AggregateCatalog();
                _catalog.Catalogs.Add(new DirectoryCatalog("Plugins"));

                _container = new CompositionContainer(_catalog);
                _container.ComposeParts(this);
            }
            catch (Exception)
            { }
        }
예제 #22
0
        protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
        {
            var         export = _compositionContainer.GetExports(controllerType, null, null).SingleOrDefault();
            IController result;

            if (null != export)
            {
                result = export.Value as IController;
            }
            else
            {
                result = base.GetControllerInstance(requestContext, controllerType);
                _compositionContainer.ComposeParts(result);
            }
            return(result);
        }
예제 #23
0
        public void Start()
        {
            UrlZoneService.ClearUrlZonesInDirectory(sagaDirectory);

            var assemblyCatalog  = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            var directoryCatalog = new DirectoryCatalog(sagaDirectory);

            LogDirectoryCatalogueInfo(directoryCatalog);

            var catalog = new AggregateCatalog(assemblyCatalog, directoryCatalog);

            container = new CompositionContainer(catalog);
            container.ComposeParts(this);

            log.Debug("MEF container initialized");
        }
예제 #24
0
        public void RefreshExensions()
        {
            catalog.Refresh();
            calcExtensionImport = new CalculatorExtensionImport();
            calcExtensionImport.ImportsSatisfied += (sender, e) =>
            {
                vm.Status += String.Format("{0}\n", e.StatusMessage);
            };

            container.ComposeParts(calcExtensionImport);
            vm.CalcExtensions.Clear();
            foreach (var extension in calcExtensionImport.CalculatorExtensions)
            {
                vm.CalcExtensions.Add(extension);
            }
        }
예제 #25
0
        private void ImportAnalyzers()
        {
            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();

            string analyzerDir = Constants.Path.InstallDir + @"bin\Analyzers";

            //Get the directory catalog
            var catalogDir = new DirectoryCatalog(analyzerDir);

            //Create the CompositionContainer with the parts in the catalog.
            CompositionContainer container = new CompositionContainer(catalog);

            //Fill the imports of this object
            container.ComposeParts(this);
        }
        public void AnimalManager_GetDog_RetrievesDog()
        {
            // Mock the IDog interface for use in the composition part
            Mock <IDog> dog = new Mock <IDog>();

            // Create the concrete instance to compose into.
            AnimalManager        animalManager = new AnimalManager();
            CompositionContainer container     = new CompositionContainer();

            // Create an export composition of the mocked IDog interface
            container.ComposeExportedValue(dog.Object);

            // Actually compose the concrete animal manager instance.
            container.ComposeParts(animalManager);
            Assert.IsNotNull(animalManager.GetAnimal <IDog>());
        }
예제 #27
0
        private void Compose()
        {
            AssemblyCatalog cat       = new AssemblyCatalog(Assembly.GetExecutingAssembly());
            var             container = new CompositionContainer(cat);

            container.ComposeExportedValue("pakko");
            container.ComposeParts(this);

            // Diagnostic
            //var ci = new CompositionInfo(cat, container);
            //CompositionInfoTextFormatter.Write(ci, Console.Out);


            // For lazy loading
            //Console.WriteLine("START POINT");
        }
예제 #28
0
        static Propis()
        {
            var                  ass = Assembly.GetExecutingAssembly();
            AssemblyCatalog      ac  = new AssemblyCatalog(ass);
            CompositionContainer cc  = new CompositionContainer(ac);

            cc.ComposeParts();
            var e       = cc.GetExportedValues <ICurrencyPropis>();
            var exports = cc.GetExports <ICurrencyPropis, ICurrencyAttr>();

            currencies = new Dictionary <int, ICurrencyPropis>();
            foreach (var export in exports)
            {
                currencies.Add(export.Metadata.CurrencyID, export.Value);
            }
        }
        void Run()
        {
            var catalog   = new DirectoryCatalog(".");
            var container = new CompositionContainer(catalog);

            container.ComposeParts(this);

            ExportLifetimeContext <ICarContract> carA = carFactory.CreateExport();
            ExportLifetimeContext <ICarContract> carB = carFactory.CreateExport();

            carA.Value.DoSomething("carA");
            carB.Value.DoSomething("carB");

            carA.Dispose();
            carB.Dispose();
        }
예제 #30
0
        private TaxCalculator()
        {
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(TaxCalculator).Assembly));

            _container = new CompositionContainer(catalog);
            try
            {
                _container.ComposeParts(this);
            }
            catch (CompositionException e)
            {
                // TODO: error handling
            }
        }