private ChorusFileTypeHandlerCollection(
			Expression<Func<ComposablePartDefinition, bool>> filter = null,
			string[] additionalAssemblies = null)
        {
            using (var aggregateCatalog = new AggregateCatalog())
            {
                aggregateCatalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
                aggregateCatalog.Catalogs.Add(new DirectoryCatalog(".", "*-ChorusPlugin.dll"));
                if (additionalAssemblies != null)
                {
                    foreach (var assemblyPath in additionalAssemblies)
                        aggregateCatalog.Catalogs.Add(new AssemblyCatalog(assemblyPath));
                }

                ComposablePartCatalog catalog;
                if (filter != null)
                    catalog = new FilteredCatalog(aggregateCatalog, filter);
                else
                    catalog = aggregateCatalog;

                using (var container = new CompositionContainer(catalog))
                {
                    container.ComposeParts(this);
                }
            }
        }
            public DependenciesTraversal(FilteredCatalog catalog, Func<ImportDefinition, bool> importFilter)
            {
                Assumes.NotNull(catalog);
                Assumes.NotNull(importFilter);

                this._parts = catalog._innerCatalog;
                this._importFilter = importFilter;
            }
        /// <summary>
        /// Disposes of the instance.
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (filter != null)
            {
                filter.Dispose();
                filter = null;
            }

            if (aggregate != null)
            {
                aggregate.Dispose();
                aggregate = null;
            }
        }
            public DependentsTraversal(FilteredCatalog catalog, Func <ImportDefinition, bool> importFilter)
            {
                ArgumentNullException.ThrowIfNull(catalog);
                ArgumentNullException.ThrowIfNull(importFilter);

                _parts        = catalog._innerCatalog;
                _importFilter = importFilter;
            }
Beispiel #5
0
            public DependentsTraversal(FilteredCatalog catalog, Func <ImportDefinition, bool> importFilter)
            {
                Assumes.NotNull(catalog);
                Assumes.NotNull(importFilter);

                _parts        = catalog._innerCatalog;
                _importFilter = importFilter;
            }
Beispiel #6
0
        public void Parts()
        {
            var originalCatalog = this.CreateCatalog();

            using (FilteredCatalog catalog = new FilteredCatalog(originalCatalog, p => p.Exports <IContract1>()))
            {
                var parts = catalog.Parts;
                Assert.Equal(2, parts.Count());
            }
        }
Beispiel #7
0
        public void GetExports_Throws_WhenDisposed()
        {
            var             originalCatalog = this.CreateCatalog();
            FilteredCatalog catalog         = new FilteredCatalog(originalCatalog, p => p.Exports <IContract1>());

            catalog.Dispose();

            ExceptionAssert.ThrowsDisposed(catalog, () =>
            {
                var p = catalog.GetExports <IContract1>();
            });
        }
Beispiel #8
0
        public void Complement_ComplementOfComplement()
        {
            var originalCatalog = this.CreateCatalog();

            using (FilteredCatalog catalog = new FilteredCatalog(originalCatalog, p => p.Exports <IContract1>()))
            {
                var c1 = catalog.Complement;
                var c2 = c1.Complement;

                Assert.Same(catalog, c2);
            }
        }
Beispiel #9
0
        public void Complement_Repeatable_Read()
        {
            var originalCatalog = this.CreateCatalog();

            using (FilteredCatalog catalog = new FilteredCatalog(originalCatalog, p => p.Exports <IContract1>()))
            {
                var c1 = catalog.Complement;
                var c2 = catalog.Complement;

                Assert.AreSame(c1, c2);
            }
        }
Beispiel #10
0
        public void GetExports()
        {
            var originalCatalog = this.CreateCatalog();

            using (FilteredCatalog catalog = new FilteredCatalog(originalCatalog, p => p.Exports <IContract1>()))
            {
                var parts1 = catalog.GetExports <IContract1>();
                Assert.Equal(2, parts1.Count());

                var parts2 = catalog.GetExports <IContract2>();
                Assert.Equal(0, parts2.Count());
            }
        }
            public DependenciesTraversal(FilteredCatalog catalog, Func <ImportDefinition, bool> importFilter)
            {
                if (catalog == null)
                {
                    throw new ArgumentNullException(nameof(catalog));
                }

                if (importFilter == null)
                {
                    throw new ArgumentNullException(nameof(importFilter));
                }
                _parts        = catalog._innerCatalog;
                _importFilter = importFilter;
            }
Beispiel #12
0
        public void GetExportsWithGenerics()
        {
            var originalCatalog = new TypeCatalog(typeof(GenericExporter <,>), typeof(Exporter11), typeof(Exporter22));

            using (FilteredCatalog catalog = new FilteredCatalog(originalCatalog, p => p.Exports <IContract1>()).IncludeDependents())
            {
                var parts1 = catalog.GetExports <IContract1>();
                Assert.Equal(1, parts1.Count());

                using (var container = new CompositionContainer(catalog))
                {
                    var results = container.GetExports <IGenericContract <string, string> >();
                    Assert.Equal(1, results.Count());
                }
            }
        }
Beispiel #13
0
        internal FilteredCatalog(ComposablePartCatalog catalog, Func<ComposablePartDefinition, bool> filter, FilteredCatalog complement)
        {
            Requires.NotNull(catalog, "catalog");
            Requires.NotNull(filter, "filter");

            this._innerCatalog = catalog;
            this._filter = (p) => filter.Invoke(p.GetGenericPartDefinition() ?? p);
            this._complement = complement;

            INotifyComposablePartCatalogChanged notifyCatalog = this._innerCatalog as INotifyComposablePartCatalogChanged;
            if (notifyCatalog != null)
            {
                notifyCatalog.Changed += this.OnChangedInternal;
                notifyCatalog.Changing += this.OnChangingInternal;
            }
        }
Beispiel #14
0
        public void Complement()
        {
            var originalCatalog = this.CreateCatalog();

            using (FilteredCatalog catalog = new FilteredCatalog(originalCatalog, p => p.Exports <IContract1>()))
            {
                var c = catalog.Complement;
                Assert.IsNotNull(c);

                var parts1 = c.GetExports <IContract2>();
                Assert.AreEqual(2, parts1.Count());

                var parts2 = c.GetExports <IContract1>();
                Assert.AreEqual(0, parts2.Count());
            }
        }
Beispiel #15
0
        internal FilteredCatalog(ComposablePartCatalog catalog, Func <ComposablePartDefinition, bool> filter, FilteredCatalog complement)
        {
            Requires.NotNull(catalog, nameof(catalog));
            Requires.NotNull(filter, nameof(filter));

            _innerCatalog = catalog;
            _filter       = (p) => filter.Invoke(p.GetGenericPartDefinition() ?? p);
            _complement   = complement;

            INotifyComposablePartCatalogChanged notifyCatalog = _innerCatalog as INotifyComposablePartCatalogChanged;

            if (notifyCatalog != null)
            {
                notifyCatalog.Changed  += OnChangedInternal;
                notifyCatalog.Changing += OnChangingInternal;
            }
        }
Beispiel #16
0
        internal FilteredCatalog(ComposablePartCatalog catalog, Func <ComposablePartDefinition, bool> filter, FilteredCatalog complement)
        {
            Requires.NotNull(catalog, "catalog");
            Requires.NotNull(filter, "filter");

            this._innerCatalog = catalog;
            this._filter       = filter;
            this._complement   = complement;
            this._partsQuery   = this._innerCatalog.Parts.Where(this._filter).AsQueryable();

            INotifyComposablePartCatalogChanged notifyCatalog = this._innerCatalog as INotifyComposablePartCatalogChanged;

            if (notifyCatalog != null)
            {
                notifyCatalog.Changed  += this.OnChangedInternal;
                notifyCatalog.Changing += this.OnChangingInternal;
            }
        }
        public void CreateRequestContainer(IDictionary dictionary, IEnumerable<ExportProvider> additionalExportProviders = null, Action<CompositionContainer> containerCreated = null)
        {
            if (dictionary == null) throw new ArgumentNullException("dictionary");

            var catalog = new FilteredCatalog(_rootCatalog, def => GetAllWithinRequestScope(def));
            var exportProviders = new List<ExportProvider>()
            {
                ApplicationContainer
            };
            if(additionalExportProviders != null)
            {
                exportProviders.AddRange(additionalExportProviders);
            }

            var requestContainer = new CompositionContainer(catalog, false,exportProviders.ToArray());
            
            dictionary[MefContainerKey] = requestContainer;

            if(containerCreated != null)
            {
                containerCreated(requestContainer);
            }
        }
        public EmbeddedMessageContentHandlerRepository()
        {
            var libChorusAssembly = Assembly.GetExecutingAssembly();

            //Set the codebase variable appropriately depending on the OS
            var codeBase = libChorusAssembly.CodeBase.Substring(LinuxUtils.IsUnix ? 7 : 8);
            var baseDir = Path.GetDirectoryName(codeBase);

            // REVIEW: for some reason using *.* or *.dll didn't work - creating the catalogs in
            // unit tests (on Linux) failed with FileNotFoundException - don't know why.
            using (var aggregateCatalog = new AggregateCatalog(new DirectoryCatalog(baseDir, "Chorus.exe"),
                new AssemblyCatalog(libChorusAssembly)))
            using (var catalog = new FilteredCatalog(aggregateCatalog,
                def => !def.Metadata.ContainsKey("IsDefault")))
            using (var defaultExportProvider = new CatalogExportProvider(new TypeCatalog(typeof(IEmbeddedMessageContentHandler))))
            {
                using (var container = new CompositionContainer(catalog, defaultExportProvider))
                {
                    defaultExportProvider.SourceProvider = container;
                    container.ComposeParts(this);
                }
            }
        }
 /// <summary>
 /// Initializes a new instance. By default no instances from <paramref name="source"/> are exposed.
 /// </summary>
 /// <param name="source"></param>
 public DynamicFilteredCatalog(ComposablePartCatalog source)
 {
     aggregate = new AggregateCatalog(filter = source.Filter(i => false));
 }
Beispiel #20
0
 public DependenciesTraversal(FilteredCatalog catalog !!, Func <ImportDefinition, bool> importFilter !!)
		//TODO: catalog creation needs to be configurable
		public static CompositionContainer CreateContainer()
		{
			var defaultPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin");

			var directoryCatalog = new DirectoryCatalog(CatalogPath ?? defaultPath);
			var filteredCatalog = new FilteredCatalog(directoryCatalog, p => !p.IsShared());

			nonSharedCatalog = filteredCatalog;
			sharedCatalog = filteredCatalog.Complement;

			var container = new CompositionContainer(sharedCatalog, true);
			container.DisableSilentRejection = true;
			return container;
		}
 /// <summary>
 /// Adds a predicate condition that exposes additional instances from the source.
 /// </summary>
 /// <param name="predicate"></param>
 public void Or(Func<ComposablePartDefinition, bool> predicate)
 {
     // filter remainder of previous filter
     aggregate.Catalogs.Add(filter = filter.Complement.Filter(i => predicate(i)));
 }