Example #1
0
        private void assertExportsAndDispose(MefSingletonComposer composer)
        {
            int         composedCount = 0;
            MefComposer lastComposer  = null;
            ComposerEventArgs <ContainerConfiguration> lastComposedEventArgs = null;

            composer.Composed += (s, e) =>
            {
                ++composedCount;
                lastComposer          = s as MefComposer;
                lastComposedEventArgs = e;
            };

            Assert.AreSame(composer.Compose(), lastComposedEventArgs.Target);
            Assert.AreEqual(1, composedCount);
            Assert.IsNotNull(lastComposedEventArgs);
            Assert.IsNotNull(lastComposedEventArgs.Target);
            Assert.IsNotNull(lastComposer);
            Assert.AreSame(composer, lastComposer);

            IParent[] exports
                = composer.ExportsList.OfType <IParent>()
                  .ToArray();
            Helper.AssertValidParents(exports);
            composer.Dispose();
            if (composer.DisposeCompositionHostsWithThis)
            {
                Helper.AssertDisposedParents(exports);
            }
            else
            {
                Helper.AssertValidParents(exports);
            }
        }
Example #2
0
        void Compose()
        {
            StaticPart.App = App;             // store in static property

            try
            {
                Composer = MefComposer.ComposeWithPlugins(this);
            }
            catch (Exception ex)
            {
                Logger.Log(string.Format("Error loading with plugins: {0}", ex.Message));

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

                try
                {
                    Logger.Log("Loading without plugins.");
                    Composer = MefComposer.ComposeWithoutPlugins(this);
                }
                catch (Exception ex2)
                {
                    Logger.Log(string.Format("Error loading: {0}", ex2.Message));

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

                    Composer = null;
                }
            }
        }
Example #3
0
        private void assertExportsAndDispose(MefComposer composer)
        {
            int         composedCount = 0;
            MefComposer lastComposer  = null;
            ComposerEventArgs <ContainerConfiguration> lastComposedEventArgs = null;

            composer.Composed += (s, e) =>
            {
                ++composedCount;
                lastComposer          = s as MefComposer;
                lastComposedEventArgs = e;
            };

            Assert.AreSame(composer.Compose(), lastComposedEventArgs.Target);
            Assert.AreEqual(1, composedCount);
            Assert.IsNotNull(lastComposedEventArgs);
            Assert.IsNotNull(lastComposedEventArgs.Target);
            Assert.IsNotNull(lastComposer);
            Assert.AreSame(composer, lastComposer);

            CompositionHost compositionHost = lastComposedEventArgs.Target.CreateContainer();
            List <IParent>  parts           = new List <IParent>(3);

            parts.AddRange(compositionHost.GetExports <IParent>());
            Assert.AreEqual(3, parts.Count);

            Helper.AssertValidParents(parts);
            composer.Dispose();
            Helper.AssertValidParents(parts);
            compositionHost.Dispose();
            Helper.AssertDisposedParents(parts);
        }
Example #4
0
        public void TestMefDirectoryPartWatcher()
        {
            using (Helper.GetTempDir(
                       nameof(MefComposerTests.TestMefDirectoryPartWatcher),
                       out string tempDir)) {
                // Shared
                MefComposer composer = new MefComposer(Helper.NewParentConventions(true));
                assertWithMefDirectoryPartWatcher(
                    new MefDirectoryPartWatcher(new DirectoryWatcher(tempDir, "*.dll")),
                    composer);

                // Not Shared
                composer = new MefComposer(Helper.NewParentConventions(false));
                assertWithMefDirectoryPartWatcher(
                    new MefDirectoryPartWatcher(new DirectoryWatcher(tempDir, "*.dll")),
                    composer);
            }
        }
Example #5
0
        public void TestMefAssemblyPartProvider()
        {
            // Shared
            MefComposer composer = new MefComposer(Helper.NewParentConventions(true));

            composer.Participate(
                new MefAssemblyPartProvider(
                    GetType()
                    .Assembly.AsSingle()));
            assertExportsAndDispose(composer);

            // Not Shared
            composer = new MefComposer(Helper.NewParentConventions(false));
            composer.Participate(
                new MefAssemblyPartProvider(
                    GetType()
                    .Assembly.AsSingle()));
            assertExportsAndDispose(composer);
        }
Example #6
0
        static void Main(string[] args)
        {
            string path;

            if (args.Length > 0)
            {
                var currentDirectory = Environment.CurrentDirectory;

                path = Path.Combine(currentDirectory, args[0]);
            }
            else
            {
                path = "test.my.less";
            }

            var chirp = MefComposer
                        .CreateComposerWithPlugins()
                        .GetExport <Chirp>();

            Console.WriteLine(chirp.Value.RunDependencies(path));

            Console.ReadLine();
        }
Example #7
0
        private void assertWithMefDirectoryPartWatcher(MefDirectoryPartWatcher contributor, MefComposer composer)
        {
            int compositionRequestedCount = 0;

            contributor.CompositionRequested += (sender, compositionEventArgs) => ++ compositionRequestedCount;
            composer.Participate(contributor);
            assertExportsAndDispose(composer);
            Assert.AreEqual(0, compositionRequestedCount);             // Zero in both cases
        }