コード例 #1
0
ファイル: App.xaml.cs プロジェクト: PeterMilovcik/Beeffective
        public App()
        {
            SyncfusionLicenseProvider.RegisterLicense("##SyncfusionLicense##");
            var catalog = new ApplicationCatalog();

            Container = new CompositionContainer(catalog);
        }
コード例 #2
0
        private void AssembleComponents()
        {
            try
            {
                //Step 1: Initializes a new instance of the
                //        System.ComponentModel.Composition.Hosting.AssemblyCatalog
                //        class with the current executing assembly.
                var acatalog = new ApplicationCatalog();

                //the following should be removed outside of dev environments. it is only added so the library containing the downloader
                //and other parts can be found, as they live in a seperate project and the dll is in a different folder
                string currpath = Environment.CurrentDirectory;
                currpath = currpath.Replace("DotaMatchAnalyzerClient", "OpenDotaInterface");
                var nothercatalog = new DirectoryCatalog(currpath);
                var catalog       = new AggregateCatalog(acatalog, nothercatalog);

                //Step 2: The assemblies obtained in step 1 are added to the
                //CompositionContainer
                var container = new CompositionContainer(catalog);

                //Step 3: Composable parts are created here i.e.
                //the Import and Export components
                //        assembles here
                container.ComposeParts(this);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
 static int Main(string[] args)
 {
     using (var catalogue = new ApplicationCatalog())
         using (var container = new CompositionContainer(catalogue))
         {
             return(container.GetExportedValue <Program>().Run(args));
         }
 }
コード例 #4
0
 public void Run()
 {
     using (var catalogue = new ApplicationCatalog())
         using (var container = new CompositionContainer(catalogue))
         {
             container.GetExportedValue <IGenericService <string> >().Print("asdf"); // System.String:asdf
             container.GetExportedValue <IGenericService <int> >().Print(123);       // System.Int32:123
         }
 }
コード例 #5
0
        public static void Main(string[] args)
        {
            var catalog   = new ApplicationCatalog();
            var container = new CompositionContainer(catalog);

            var converter = container.GetExportedValue <Converter>();
            var y         = "1.5";
            var x         = converter.Convert <float, string>(y);

            Console.ReadLine();
        }
コード例 #6
0
    private void Run()
    {
        var catalog   = new ApplicationCatalog();
        var container = CreateCompositionContainer(catalog);

        container.ComposeParts(this);
        foreach (var pair in this.basket.GetAppleDictionary())
        {
            Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
        }
    }
コード例 #7
0
    /// <summary>
    ///     Initialises a new instance of the <see cref="Classes"/> class.
    /// </summary>
    public Classes()
    {
        // NOTE: This is a generic application catalogue, for demonstration purposes.
        //       It is likely you'd rather use a Directory or Assembly catalogue
        //       instead, to make the application more scalable, in line with the MEF
        //       ideology.
        var catalogue = new ApplicationCatalog();
        var container = new CompositionContainer(catalogue);

        container.ComposeParts(this);
    }
コード例 #8
0
ファイル: ApplicationCatalogTests.cs プロジェクト: zqb971/mef
 public void Dispose_ShouldNotThrow()
 {
     using (var app = new Application())
     {
         app.AppMain(() =>
         {
             using (var catalog = new ApplicationCatalog())
             {
             }
         });
     }
 }
コード例 #9
0
ファイル: ApplicationCatalogTests.cs プロジェクト: zqb971/mef
 public void ToString_WhenCatalogDisposed_ShouldNotThrow()
 {
     using (var app = new Application())
     {
         app.AppMain(() =>
         {
             var catalog = new ApplicationCatalog();
             catalog.Dispose();
             catalog.ToString();
         });
     }
 }
コード例 #10
0
ファイル: ApplicationCatalogTests.cs プロジェクト: zqb971/mef
 public void ICompositionElementOrigin_WhenCatalogDisposed_ShouldNotThrow()
 {
     using (var app = new Application())
     {
         app.AppMain(() =>
         {
             var catalog = new ApplicationCatalog();
             catalog.Dispose();
             var origin = ((ICompositionElement)catalog).Origin;
         });
     }
 }
コード例 #11
0
ファイル: ApplicationCatalogTests.cs プロジェクト: zqb971/mef
 public void ICompositionElementDisplayName_WhenCatalogDisposed_ShouldNotThrow()
 {
     using (var app = new Application())
     {
         app.AppMain(() =>
         {
             var catalog = new ApplicationCatalog();
             catalog.Dispose();
             var displayName = ((ICompositionElement)catalog).DisplayName;
         });
     }
 }
コード例 #12
0
ファイル: ApplicationCatalogTests.cs プロジェクト: zqb971/mef
 public void Dispose_CanBeCalledMultipleTimes()
 {
     using (var app = new Application())
     {
         app.AppMain(() =>
         {
             var catalog = new ApplicationCatalog();
             catalog.Dispose();
             catalog.Dispose();
             catalog.Dispose();
         });
     }
 }
コード例 #13
0
ファイル: Containers.cs プロジェクト: jamestharpe/Utilla
        /// <summary>
        /// Creates a <see cref="CompositionContainer"/> with an <see cref="ApplicationCatalog"/> a
        /// <see cref="ConfigurationExportProvider"/>. The
        /// <see cref="ConfigurationExportProvider"/> is reads from the application's config file,
        /// either an App.Config or Web.Config file.
        /// </summary>
        /// <param name="additionalProviders"></param>
        /// <returns></returns>
        public static CompositionContainer CreateApplicationAndConfigFileContainer(params ExportProvider[] additionalProviders)
        {
            var applicationCatalog   = new ApplicationCatalog();
            var configExportProvider = new ConfigurationExportProvider(new FileConfigurationSource());

            var exportProviders = new ExportProvider[1 + additionalProviders.Length];

            exportProviders[0] = configExportProvider;
            Array.Copy(additionalProviders, 0, exportProviders, 1, additionalProviders.Length);

            var result = new CompositionContainer(applicationCatalog, configExportProvider);

            return(result);
        } // TODO: Test
コード例 #14
0
ファイル: ApplicationCatalogTests.cs プロジェクト: zqb971/mef
 public void GetExports_NullAsConstraintArgument_ShouldThrowArgumentNull()
 {
     ExceptionAssert.ThrowsArgument <ArgumentNullException>("definition", () =>
     {
         using (var app = new Application())
         {
             app.AppMain(() =>
             {
                 var catalog = new ApplicationCatalog();
                 catalog.GetExports((ImportDefinition)null);
             });
         }
     });
 }
コード例 #15
0
ファイル: ApplicationCatalogTests.cs プロジェクト: zqb971/mef
 public void GetEnumerator_WhenCatalogDisposed_ShouldThrowObjectDisposed()
 {
     ExceptionAssert.Throws <ObjectDisposedException>(RetryMode.DoNotRetry, () =>
     {
         using (var app = new Application())
         {
             app.AppMain(() =>
             {
                 var catalog = new ApplicationCatalog();
                 catalog.Dispose();
                 var enumerator = catalog.GetEnumerator();
             });
         }
     });
 }
コード例 #16
0
    public static void Main(string[] args)
    {
        var catalog   = new ApplicationCatalog();
        var container = new CompositionContainer(catalog);
        IDictionary <int, IApple> dict = new Dictionary <int, IApple>();

        for (int i = 0; i < 10; i++)
        {
            dict.Add(i, container.GetExportedValue <IApple>());
        }
        foreach (var pair in dict)
        {
            Console.WriteLine("{0}: {1}", pair.Key, pair.Value);
        }
    }
コード例 #17
0
        /// <summary>
        /// Defines the entry point of the application. See AssemblyInfo.cs for example of how to set service name, display name, and description.
        /// </summary>
        /// <param name="args">The arguments.</param>
        /// <returns>System.Int32.</returns>
        internal static int Main(string[] args)
        {
            // Important Note: You should run as Administrator to interact with the service control manager.

            // Override the passed arguments for testing purposes. Use '-', '--', '/', or '//' as flags.
            // Uncomment one to test the service control arguments.

            //args = new[] { "-i" }; // or "install"
            //args = new[] { "-u" }; // or "uninstall"
            //args = new[] { "-s" }; // or "start"
            //args = new[] { "-t" }; // or "stop"

            using (var catalog = new ApplicationCatalog())
                using (var container = new CompositionContainer(catalog))
                    using (var service = container.GetExport <ExtensibleServiceBase>()?.Value as Service)
                    {
                        if (service == null)
                        {
                            return(1);
                        }

                        Console.Title         = "Sample Console";
                        Console.CursorVisible = false;

                        var argumentsToInject = container.GetExportedValues <IArgument>();
                        var arguments         = global::Arguments.Arguments.NewArguments(args, argumentsToInject);
                        arguments.Process();

                        if (Environment.UserInteractive)
                        {
                            service.OnStart(args);

                            Console.WriteLine();
                            Console.WriteLine("This application will run as a console application and a service application.");
                            Console.WriteLine();
                            Console.WriteLine("Press any key to exit.");
                            Console.ReadKey();

                            service.OnStop();
                        }
                        else
                        {
                            Run(service);
                        }
                    }

            return(0);
        }
コード例 #18
0
ファイル: AppBootstrapper.cs プロジェクト: notTJ/AO-Workbench
        protected override void Configure()
        {
            Contract.Ensures(this.container != null);

            var catalog = new ApplicationCatalog();

            this.container = new CompositionContainer(catalog);

            var batch = new CompositionBatch();

            batch.AddExportedValue <IBus>(new Bus(new CmAdapter()));
            batch.AddExportedValue(this.container);
            batch.AddExportedValue(catalog);

            this.container.Compose(batch);
        }
コード例 #19
0
        private ComposablePartCatalog GetInterceptionCatalog()
        {
            _applicationCatalog      = new ApplicationCatalog();
            _adapterdirectoryCatalog = new DirectoryCatalog(AdaptersDirectory);
            _pluginsdirectoryCatalog = new DirectoryCatalog(PluginsDirectory);

            var catalog = new AggregateCatalog(_applicationCatalog, _adapterdirectoryCatalog, _pluginsdirectoryCatalog);

            var cfg = new InterceptionConfiguration().AddInterceptionCriteria(
                new PredicateInterceptionCriteria(
                    new CopyConfigInterceptor(_robot.Settings),
                    def => def.ExportDefinitions.First().ContractName.Contains("IAdapter") ||
                    def.ExportDefinitions.First().ContractName.Contains("IRobotPlugin")));

            return(new InterceptingCatalog(catalog, cfg));
        }
コード例 #20
0
ファイル: ApplicationCatalogTests.cs プロジェクト: zqb971/mef
        public void GetExports_WhenCatalogDisposed_ShouldThrowObjectDisposed()
        {
            ExceptionAssert.Throws <ObjectDisposedException>(RetryMode.DoNotRetry, () =>
            {
                using (var app = new Application())
                {
                    app.AppMain(() =>
                    {
                        var catalog = new ApplicationCatalog();
                        catalog.Dispose();

                        var definition = ImportDefinitionFactory.Create();
                        catalog.GetExports(definition);
                    });
                }
            });
        }
コード例 #21
0
        public ExtensionManager(string pluginFolder)
        {
            var directoryCatalog = new DirectoryCatalog(pluginFolder);
            var domainCatalog    = new ApplicationCatalog();
            var aggregateCatalog = new AggregateCatalog(directoryCatalog, domainCatalog);

            _container = new CompositionContainer(aggregateCatalog);

            try
            {
                _container.ComposeParts(this);
            }
            catch (CompositionException compositionException)
            {
                Console.WriteLine(compositionException.ToString());
            }
        }
コード例 #22
0
ファイル: ApplicationCatalogTests.cs プロジェクト: zqb971/mef
 public void Test_GetEnumerator()
 {
     using (var app = new Application())
     {
         app.AppMain(() =>
         {
             using (var catalog = new ApplicationCatalog())
             {
                 var result = catalog.Count();
                 //Cross AppDomain AssertFailedException does not marshall
                 if (result < 0)
                 {
                     throw new Exception("Assert.IsTrue(result > 0);");
                 }
             }
         });
     }
 }