private void Application_Startup(object sender, StartupEventArgs e)
        {
            var assembly =
               new AssemblyCatalog(Assembly.GetEntryAssembly());


            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(assembly);
            catalog.Catalogs.Add(new DirectoryCatalog("."));


            var compositionContainer
                = new CompositionContainer(catalog);
            compositionContainer.ComposeParts(this);

            var locator = new MefServiceLocator(compositionContainer);
            ServiceLocator.SetLocatorProvider(() => locator);


            ViewModelManager.ViewModelShowEvent
                += vm => ViewManager.ViewShow(vm);
            ViewModelManager.ViewModelCloseEvent
                += vm => ViewManager.ViewClose(vm);

            var mainWindowViewModel = new MainWindowViewModel();
            compositionContainer.ComposeParts(mainWindowViewModel);
           
            MainWindow mainWindow = new MainWindow {DataContext = mainWindowViewModel};
            mainWindow.Show();
        }
Exemple #2
0
        /// <summary>
        /// This method loads the plugins.
        /// </summary>
        private void AssembleComponents()
        {
            var catalog = new AggregateCatalog();

            //Note: we load not only from the plugins folder, but from this assembly as well.
            var executingAssemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            if (Directory.Exists(Environment.CurrentDirectory + "\\Plugins"))
            {
                catalog.Catalogs.Add(new DirectoryCatalog("Plugins"));
            }

            catalog.Catalogs.Add(executingAssemblyCatalog);

            var container = new CompositionContainer(catalog);

            try
            {
                container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                _dialogService.ShowMessageAsync(_mainVm, "Error", string.Format("There was an error loading plugins: {0}", compositionException)).Forget();
            }
        }
        public void TestMefStatusReportable()
        {
            string dir = AssemblyDirectory;

            //Lets get the nlog status reportable from MEF directory..
            CompositionContainer _container;
            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();
            //Adds all the parts found in the same assembly as the Program class
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(TestMEF).Assembly));
            catalog.Catalogs.Add(new DirectoryCatalog(AssemblyDirectory));

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

            //Fill the imports of this object
            try
            {
               _container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }

            reporter.Report(2,1,"Test Report");
        }
        /// <summary>
        /// Default private constructor.
        /// </summary>
        private ExtensionManager()
        {
            if (!Config.DisableComposition)
            {
                // Let MEF scan for imports
                var catalog = new AggregateCatalog();

                catalog.Catalogs.Add(Config.DisableCatalogSearch ? new DirectoryCatalog("Bin", "Piranha*.dll") : new DirectoryCatalog("Bin"));

            #if !NET40
                if (!System.Web.Compilation.BuildManager.IsPrecompiledApp)
                {
            #endif
                    try
                    {
                        // This feature only exists for Web Pages
                        catalog.Catalogs.Add(new AssemblyCatalog(Assembly.Load("App_Code")));
                    }
                    catch { }
            #if !NET40
                }
            #endif

                Container = new CompositionContainer(catalog);
                Container.ComposeParts(this);
            }
        }
Exemple #5
0
		public static void Main (string[] args)
		{
			var bootStrapper = new Bootstrapper();

            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();
            //Adds all the parts found in same directory where the application is running!
            var currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(MainClass)).Location) ?? "./";
            catalog.Catalogs.Add(new DirectoryCatalog(currentPath));

            //Create the CompositionContainer with the parts in the catalog
            var container = new CompositionContainer(catalog);
            
            //Fill the imports of this object
            try
            {
                container.ComposeParts(bootStrapper);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }

            //Prints all the languages that were found into the application directory
            var i = 0;
            foreach (var language in bootStrapper.Languages)
            {
                Console.WriteLine("[{0}] {1} by {2}.\n\t{3}\n", language.Version, language.Name, language.Author, language.Description);
                i++;
            }
            Console.WriteLine("It has been found {0} supported languages",i);
            Console.ReadKey();
		}
        /// <summary>
        /// Initializes the MEF Container.
        /// </summary>
        /// <param name="root">The root.</param>
        public static void Initialize(object root)
        {
            if (root == null)
            throw new NullReferenceException("MEF root");

             if (_instance == null) {
            lock (_syncRoot) {
               if (_instance == null) {
                  string exePath = null;
                  string path = null;
                  if (Assembly.GetEntryAssembly() != null) {
                     exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                  } else {
                     exePath = Path.GetDirectoryName(root.GetType().Assembly.Location);
                  }
                  path = Path.Combine(exePath, "\\plugins");
                  if (!Directory.Exists(path))
                     Directory.CreateDirectory(path);

                  var catalog = new AggregateCatalog();
                  if (path != null)
                     catalog.Catalogs.Add(new DirectoryCatalog(path));
                  if (exePath != null)
                     catalog.Catalogs.Add(new DirectoryCatalog(exePath));
                  catalog.Catalogs.Add(new AssemblyCatalog(root.GetType().Assembly));

                  _instance = new CompositionContainer(catalog);
                  _instance.ComposeParts(root);

               }
            }
             }
        }
Exemple #7
0
        public void Start()
        {
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(SearchDemo).Assembly));
            var container = new CompositionContainer(catalog);
            container.ComposeParts();

            try
            {
                var component = container.GetExport<ITestComponent>();
                if (component != null)
                    Console.WriteLine(component.Value.Message);
            }
            catch (Exception exp)
            {
                //Why does our call to 'GetExport' throw an exception?

                //Search for the string "Test" on the container variable
                //You'll find 3 instances in the Catalog.
                //Then search for ITestComponent.
                //You'll need to click "Search Deeper" to expand the search.

                //Another way to do this is to view "container.Catalog.Parts", right click it,
                //select 'Edit Filter' and enter the following predicate:
                //         [obj].Exports(typoef(ITestComponent)

                MessageBox.Show(exp.Message, "Exception caught!");
            }
        }
        private void Compose()
        {
            var container = new CompositionContainer();

            // In this example we will use the MessageSender Part to fill the catalog
            container.ComposeParts(this, new ConsoleMessageSender());
        }
        private void Bootstrap()
        {
            _jobModelRegistry = new ConcurrentDictionary<string, JobModel>();

            _compositionContainer = new CatalogConfigurator()
               .AddAssembly(Assembly.GetExecutingAssembly())
               .AddNestedDirectory(Config.JobsFolderName)
               .BuildContainer();


            _compositionContainer.ComposeParts(this);

            InitTasksRegistry();

            _appContainerBuilder = new ContainerBuilder();
            _appContainerBuilder.RegisterModule<WorkerModule>();
            _appContainerBuilder.RegisterModule<HostingModule>();
            _appContainer = _appContainerBuilder.Build();

            //TODO: make onchanged to an event
            _fileSystemWatcher = new JobsWatcher { OnChanged = OnChanged };
            _fileSystemWatcher.Watch(TasksFolderPath);

            _logger = _appContainer.Resolve<ILogger>();

            _logger.Info("[START] PanteonEngine");

            Task.Run(() => MountApi());
        }
Exemple #10
0
        private bool compose()
        {
            try {
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new DirectoryCatalog(@".\plugins"));
            catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
            var container = new CompositionContainer(catalog);
            container.ComposeParts(this);

            var builder = new ContainerBuilder();
            builder.Register((c, p) => new JsonGopherConfigReader(gopherRepositoryManager)).As<IConfigReader>();
            Container = builder.Build(Autofac.Builder.ContainerBuildOptions.Default);

            return true;
              } catch (CompositionException ex) {
            if (Logger != null) {
              Logger.ErrorException("Unable to compose", ex);
            }
            System.Console.WriteLine(ex);
            return false;
              } catch (Exception ex) {
            if (Logger != null) {
              Logger.ErrorException("Unable to compose", ex);
            }
            System.Console.WriteLine(ex);
            return false;
              }
        }
#pragma warning restore 649

		private CodeProcessorProvider() {
			var catalog = new AggregateCatalog();
			catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
			catalog.Catalogs.Add(new DirectoryCatalog("."));
			var container = new CompositionContainer(catalog);
			container.ComposeParts(this);
		}
 public static void MyClassInitialize(TestContext testContext)
 {
   // set uo IoC container to use MyRootFakeData
   var container = new CompositionContainer();
   container.ComposeParts(new MyRootFakeData());
   CslaContrib.MEF.Ioc.InjectContainer(container);
 }
Exemple #13
0
 public void Run()
 {
     CompositionContainer _CompositionContainer = new CompositionContainer(new ConfigExportProvider());
     _CompositionContainer.ComposeParts(this);
     CodeCamp.DataServerInterface.IDataServer _DataServer = DataServer;// new DataServer();
     Person _Person = new Person();
     Sponsor _Sponsor = new Sponsor();
     _DataServer.Add<Sponsor>(_Sponsor);
     _DataServer.Add<Person>(_Person);
     _DataServer.Commit();
     IQueryable<Sponsor> _Sponsors = _DataServer.GetTable<Sponsor>();
     Console.WriteLine(_Sponsors.ToList().Count().ToString());
     //
     IQueryable<Person> _Persons = _DataServer.GetTable<Person>();
     Console.WriteLine(_Persons.ToList().Count().ToString());
     //modify a persom
     string _NewName = "Changed:" + DateTime.Now.ToString();
     _Persons.First().Name = _NewName;
     _DataServer.Commit();
     _Person = _DataServer.GetTable<Person>().Where(x => x.Name == _NewName).FirstOrDefault();
     if (_Person == null)
         throw new Exception("Person name not changed");
     Console.WriteLine(_Person.Name);
     Console.ReadLine();
 }
 /// <summary>
 /// Default constructor. Creates a new extension container and registers all
 /// exported objects.
 /// </summary>
 public ExtensionContainer()
 {
     var catalog = new AggregateCatalog() ;
     catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly())) ;
     Container = new CompositionContainer(catalog) ;
     Container.ComposeParts(this) ;
 }
Exemple #15
0
        public void Setup()
        {
            aggregateCatalog = new AggregateCatalog();
            container = new CompositionContainer(aggregateCatalog);

            container.ComposeParts(this);
        }
Exemple #16
0
        public void Compose()
        {
            AssemblyCatalog assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            string executionPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            string generatorsPath = Path.Combine(executionPath, "Generators");
            CreatePathIfRequied(generatorsPath);
            generatorsCatalog = new DirectoryCatalog(generatorsPath);

            string uiPath = Path.Combine(executionPath, "UI");
            CreatePathIfRequied(uiPath);
            UICatalog = new DirectoryCatalog(uiPath);

            AggregateCatalog catalog = new AggregateCatalog();
            catalog.Catalogs.Add(generatorsCatalog);
            catalog.Catalogs.Add(UICatalog);

            //Set the defaults....
            CatalogExportProvider mainProvider = new CatalogExportProvider(assemblyCatalog);
            CompositionContainer container = new CompositionContainer(catalog, mainProvider);
            mainProvider.SourceProvider = container;

            var batch = new CompositionBatch();
            batch.AddPart(this);

            RefreshCatalog refreshCatalog = new RefreshCatalog(generatorsCatalog, UICatalog);
            container.ComposeParts(refreshCatalog);
            container.Compose(batch);

            Logger.Write("Compose complete");
        }
        public LinkThumbnailScreenFactory(CompositionContainer compositionContainer, 
            Factories.ImageThumbnailScreenFactory imageThumbnailScreenFactory)
        {
            _imageThumbnailScreenFactory = imageThumbnailScreenFactory;

            compositionContainer.ComposeParts(this);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PluginController"/> class. 
        /// </summary>
        public PluginController()
        {
            var sensors = new AggregateCatalog();
            sensors.Catalogs.Add(new AssemblyCatalog(typeof(PluginController).Assembly));
            var directoryName = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            if (directoryName == null)
            {
                return;
            }

            var path = directoryName.Replace("file:\\", string.Empty);
            {
                sensors.Catalogs.Add(new DirectoryCatalog(path));
                var compositonContainer = new CompositionContainer(sensors);
                try
                {
                    compositonContainer.ComposeParts(this);
                }
                catch (CompositionException compositionException)
                {
                    Debug.WriteLine(compositionException.ToString());
                }
            }

            if (this.plugins != null)
            {
                this.loadedPlugins = new ReadOnlyCollection<IPlugin>(this.plugins.Select(plugin => plugin.Value).ToList());
            }

            if (this.menuPlugins != null)
            {
                this.menuCommandPlugins = new ReadOnlyCollection<IMenuCommandPlugin>(this.menuPlugins.Select(plugin => plugin.Value).ToList());
            }
        }
        private static void Compose()
        {
            CompositionContainer container;

            var pathToAddInns = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "AddInns");

            //if (!Directory.Exists(pathToAddInns))
            //    Directory.CreateDirectory(pathToAddInns);

            IEnumerable<DirectoryCatalog> directoryCatalogs = from i in Directory.EnumerateDirectories(pathToAddInns, "*", SearchOption.TopDirectoryOnly)
                                                              select new DirectoryCatalog(i,"*.dll");

               // var catalog = new DirectoryCatalog(pathToAddInns,"*.dll");

            var aggregateCatalog = new AggregateCatalog(directoryCatalogs);

            container = new CompositionContainer(aggregateCatalog);

            try
            {
                container.ComposeParts(importer);
            }
            catch (CompositionException compositionException)
            {

            }
        }
Exemple #20
0
        public static IPlugins GetPlugins(ITranslator translator, IAssemblyInfo config)
        {
            string path = null;
            if (!string.IsNullOrWhiteSpace(config.PluginsPath))
            {
                path = Path.Combine(translator.FolderMode ? translator.Location : Path.GetDirectoryName(translator.Location), config.PluginsPath);
            }
            else
            {
                path = Path.Combine(translator.FolderMode ? translator.Location : Path.GetDirectoryName(translator.Location), "Bridge" + Path.DirectorySeparatorChar + "plugins");
            }

            if (!System.IO.Directory.Exists(path))
            {
                return new Plugins() { plugins = new IPlugin[0] };
            }

            DirectoryCatalog dirCatalog = new DirectoryCatalog(path, "*.dll");
            var catalog = new AggregateCatalog(dirCatalog);

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

            return plugins;
        }
        public ExtensionRuleStore(string path, ILogger logger)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException(Resource.ArgumentNotNullOrEmpty, "path");
            }

            using (var catalog = new AggregateCatalog())
            {
                try
                {
                    var directoryCatalog = new DirectoryCatalog(path);
                    catalog.Catalogs.Add(directoryCatalog);
                    using (var container = new CompositionContainer(catalog))
                    {
                        container.ComposeParts(this);
                    }
                }
                catch (Exception ex)
                {
                    if (!ExceptionHelper.IsCatchableExceptionType(ex))
                    {
                        throw;
                    }

                    RuntimeException.WrapAndLog(ex, Resource.InvalidExtensionRules + ":" + path, logger);
                }
            }
        }
Exemple #22
0
 private Program()
 {
     var catalog = new AggregateCatalog();
     catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly));
     catalog.Catalogs.Add(new DirectoryCatalog(Environment.CurrentDirectory));
     _container = new CompositionContainer(catalog);
     try
     {
         _container.ComposeParts(this);
     }
     catch (System.Reflection.ReflectionTypeLoadException v)
     {
         foreach (var c in v.LoaderExceptions)
             Console.WriteLine(c.ToString());
     }
     catch (CompositionException e) {
         Console.WriteLine(e.ToString());
     }
     if (plugins != null)
     {
         foreach (var q in plugins)
         {
             Console.WriteLine(q.Metadata.name);
         }
         PluginContainer.plugins= plugins;
     }
     else
         Console.WriteLine("No plugins loaded");
 }
Exemple #23
0
    public void Init() {
      Topic.root.Subscribe("/etc/PLC/#", L_dummy);
      Topic.root.Subscribe("/etc/declarers/#", L_dummy);
      string path=Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
      _id=Topic.root.Get<string>("/local/cfg/id");

      #region Load statements
      var catalog = new AggregateCatalog();
      catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
      catalog.Catalogs.Add(new DirectoryCatalog(path));
      var _container = new CompositionContainer(catalog);
      try {
        _container.ComposeParts(this);
      }
      catch(CompositionException ex) {
        Log.Error("Load statements - {0}", ex.ToString());
        return;
      }
      #endregion Load statements

      foreach(var i in _statement) {
        PiStatement.AddStatemen(i.Metadata.declarer, i.Value.GetType());
        i.Value.Load();
      }
      _statement=null;
    }
 public void ComposeParts(object target)
 {
     var path = PathProvider.BinaryPath;
     var directoryCatalog = new DirectoryCatalog(path);
     var container = new CompositionContainer(directoryCatalog);
     container.ComposeParts(target);
 }
        public void Initialize()
        {
            try
            {
                directoryCatalog = new DirectoryCatalog(PluginPath);

                var catalog = new AggregateCatalog();
                catalog.Catalogs.Add(directoryCatalog);
                container = new CompositionContainer(catalog);
                container.ComposeParts(this);
            }
            catch (ReflectionTypeLoadException ex)
            {
                if (ex.LoaderExceptions.Length == 1)
                {
                    throw ex.LoaderExceptions[0];
                }
                var sb = new StringBuilder();
                var i = 1;
                sb.AppendLine("Multiple Exception Occured Attempting to Intialize the Plugin Manager");
                foreach (var exception in ex.LoaderExceptions)
                {
                    sb.AppendLine("Exception " + i++);
                    sb.AppendLine(exception.ToString());
                    sb.AppendLine();
                    sb.AppendLine();
                }

                throw new ReflectionTypeLoadException(ex.Types, ex.LoaderExceptions, sb.ToString());
            }
        }
        public void Initialize()
        {
            var catalog = new AggregateCatalog();

            //Adds the program's assembly
            catalog.Catalogs.Add(new AssemblyCatalog(typeof(PluginInfrastructureImports).Assembly));


            string programassembly = System.Reflection.Assembly.GetAssembly(typeof(PluginInfrastructureImports)).Location;

            string programpath = Path.GetDirectoryName(programassembly);

            //add the program's path
            catalog.Catalogs.Add(new DirectoryCatalog(programpath));

            _container = new CompositionContainer(catalog);

            try
            {
                //Initialize types found and assign new instances to Plugins
                _container.ComposeParts(this);

            }
            catch (CompositionException compositionException)
            {
                throw;
            }
        }
 public StyleOptionsFactory()
 {
     var catalog = new AggregateCatalog(
         new AssemblyCatalog(Assembly.GetExecutingAssembly()));
     var container = new CompositionContainer(catalog);
     container.ComposeParts(this);
 }
Exemple #28
0
        public void DoImport()
        {
            //An aggregate catalog that combines multiple catalogs
            var catalog = new AggregateCatalog();

            directoryCatalog = new DirectoryCatalog(GetDirectory());
            directoryCatalog.Changing += directoryCatalog_Changing;
            directoryCatalog.Changed += directoryCatalog_Changed;

            //Adds all the parts found in all assemblies in 
            //the same directory as the executing program
            catalog.Catalogs.Add(directoryCatalog);

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

            try
            {
                //Fill the imports of this object
                container.ComposeParts(this);
            }
            catch (Exception ex)
            {
                Out.WriteLine("Unable to load plugins: {0}", ex.Message);
            }

        }
Exemple #29
0
        public PluginContainer()
        {
            var registration = new RegistrationBuilder();

            registration.ForTypesDerivedFrom<BasicPlugin>()
                .SetCreationPolicy(CreationPolicy.Shared)
                .Export<BasicPlugin>();

            bool tryAgain = true;

            while (tryAgain)
            {
                try
                {
                    DirectoryCatalog dircat = new DirectoryCatalog(PluginDirectory, registration);
                    tryAgain = false;

                    Container = new CompositionContainer(dircat, CompositionOptions.DisableSilentRejection | CompositionOptions.IsThreadSafe);
                    Container.ComposeParts();
                }
                catch (DirectoryNotFoundException)
                {
                    Directory.CreateDirectory(PluginDirectory);
                }
            }
        }
        public void LoadPlugins(IEnumerable<ComposablePartCatalog> catalogs = null)
        {
            var catalog = new AggregateCatalog();
            catalog.Catalogs.Add(new AssemblyCatalog(GetType().Assembly));

            if (catalogs != null)
            {
                foreach (var additionalCatalog in catalogs)
                {
                    catalog.Catalogs.Add(additionalCatalog);
                }
            }

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

            //Fill the imports of this object
            try
            {
                Container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }
        }
Exemple #31
0
 public static void ComposeParts(params object[] attributedParts)
 {
     lock (syncRoot)
     {
         try
         {
             container.ComposeParts(attributedParts);
         }
         catch (CompositionException compositionException)
         {
             Debug.WriteLine(compositionException.ToString());
             throw;
         }
     }
 }