当前位置: 首页>>代码示例>>C#>>正文


C# Configuration.AddCommandLine方法代码示例

本文整理汇总了C#中Microsoft.Framework.ConfigurationModel.Configuration.AddCommandLine方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.AddCommandLine方法的具体用法?C# Configuration.AddCommandLine怎么用?C# Configuration.AddCommandLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Framework.ConfigurationModel.Configuration的用法示例。


在下文中一共展示了Configuration.AddCommandLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public Task<int> Main(string[] args)
        {
            //Add command line configuration source to read command line parameters.
            var config = new Configuration();
            config.AddCommandLine(args);

            var serviceCollection = new ServiceCollection();
            serviceCollection.Add(HostingServices.GetDefaultServices(config));
            var services = serviceCollection.BuildServiceProvider(_hostServiceProvider);

            var context = new HostingContext()
            {
                Services = services,
                Configuration = config,
                ServerName = "Microsoft.AspNet.Server.WebListener",
                ApplicationName = "BugTracker"
            };

            var engine = services.GetService<IHostingEngine>();
            if (engine == null)
            {
                throw new Exception("TODO: IHostingEngine service not available exception");
            }

            using (engine.Start(context))
            {
                Console.WriteLine("Started the server..");
                Console.WriteLine("Press any key to stop the server");
                Console.ReadLine();
            }
            return Task.FromResult(0);
        }
开发者ID:jack4it,项目名称:BugTracker,代码行数:32,代码来源:Program.cs

示例2: Main

        public void Main(string[] args)
        {
            var config = new Configuration();
            if (File.Exists(HostingIniFile))
            {
                config.AddIniFile(HostingIniFile);
            }
            config.AddEnvironmentVariables();
            config.AddCommandLine(args);

            var context = new HostingContext()
            {
                Configuration = config,
                ServerFactoryLocation = config.Get("server"),
                ApplicationName = config.Get("app")
            };

            var engine = new HostingEngine(_serviceProvider);

            var serverShutdown = engine.Start(context);
            var loggerFactory = context.ApplicationServices.GetRequiredService<ILoggerFactory>();
            var appShutdownService = context.ApplicationServices.GetRequiredService<IApplicationShutdown>();
            var shutdownHandle = new ManualResetEvent(false);

            appShutdownService.ShutdownRequested.Register(() =>
            {
                try
                {
                    serverShutdown.Dispose();
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger<Program>();
                    logger.LogError("Dispose threw an exception.", ex);
                }
                shutdownHandle.Set();
            });

            var ignored = Task.Run(() =>
            {
                Console.WriteLine("Started");
                Console.ReadLine();
                appShutdownService.RequestShutdown();
            });

            shutdownHandle.WaitOne();
        }
开发者ID:Guruanth,项目名称:Hosting,代码行数:47,代码来源:Program.cs

示例3: Main

        public void Main(string[] args)
        {
            var configuration = new Configuration();
            Console.WriteLine("Initial Config Sources: " + configuration.Sources.Count());

            var defaultSettings = new MemoryConfigurationSource();
            defaultSettings.Set("username", "Guest");
            configuration.Add(defaultSettings);
            Console.WriteLine("Added Memory Source. Sources: " + configuration.Sources.Count());

            configuration.AddCommandLine(args);
            Console.WriteLine("Added Command Line Source. Sources: " + configuration.Sources.Count());

            string username = configuration.Get("username");

            Console.WriteLine($"Hello, {username}!");
        }
开发者ID:bigfont,项目名称:Docs,代码行数:17,代码来源:Program.cs

示例4: CommitConfiguration

        public void CommitConfiguration()
        {
            var toolMock = new Mock<MyMigrationTool>() { CallBase = true };
            var args
                = new[]
                      {
                          "--ConfigFile=MyConfig.ini",
                          "--ContextAssembly=EntityFramework.Design.Tests.dll",
                          "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext",
                          "--MigrationAssembly=EntityFramework.Design.Tests.dll",
                          "--MigrationNamespace=MyNamespace",
                          "--MigrationDirectory=MyDirectory",
                          "--References=Ref1;Ref2;Ref3"
                      };
            var configSourceMock = new Mock<IniFileConfigurationSource>("Foo") { CallBase = true };
            var tool = toolMock.Object;
            var configuration = new Configuration();

            configSourceMock
                .Setup(m => m.Load());

            configSourceMock
                .Setup(m => m.Commit())
                .Callback(
                    () =>
                    {
                        Assert.Equal(configSourceMock.Object.Data["ContextAssembly"], "EntityFramework.Design.Tests.dll");
                        Assert.Equal(configSourceMock.Object.Data["ContextType"], "Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext");
                        Assert.Equal(configSourceMock.Object.Data["MigrationAssembly"], "EntityFramework.Design.Tests.dll");
                        Assert.Equal(configSourceMock.Object.Data["MigrationNamespace"], "MyNamespace");
                        Assert.Equal(configSourceMock.Object.Data["MigrationDirectory"], "MyDirectory");
                        Assert.Equal(configSourceMock.Object.Data["References"], "Ref1;Ref2;Ref3");
                    });

            toolMock.Protected()
                .Setup<IniFileConfigurationSource>("CreateIniFileConfigurationSource", ItExpr.IsAny<string>())
                .Callback<string>(AssertConfigFileCallback1)
                .Returns(configSourceMock.Object);

            configuration.AddCommandLine(args);

            tool.CommitConfiguration(configuration);

            configSourceMock.Verify(m => m.Commit(), Times.Once);
            toolMock.Protected().Verify<IniFileConfigurationSource>("CreateIniFileConfigurationSource", Times.Once(), ItExpr.IsAny<string>());
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:46,代码来源:MigrationToolTest.cs

示例5: Startup

        public Startup()
        {
            var configuration = new Configuration()
                 .AddJsonFile("config.json");

            if (Program.Environment.OtherArgs != null)
            {
                configuration.AddCommandLine(Program.Environment.OtherArgs);
            }

            // Use the local omnisharp config if there's any in the root path
            if (File.Exists(Program.Environment.ConfigurationPath))
            {
                configuration.AddJsonFile(Program.Environment.ConfigurationPath);
            }

            configuration.AddEnvironmentVariables();

            Configuration = configuration;
        }
开发者ID:ryanrousseau,项目名称:omnisharp-roslyn,代码行数:20,代码来源:Startup.cs

示例6: Main

        public Task<int> Main(string[] args)
        {
            //Add command line configuration source to read command line parameters.
            var config = new Configuration();
            config.AddCommandLine(args);

            var context = new HostingContext()
            {
                Configuration = config,
                ServerFactoryLocation = "Microsoft.AspNet.Server.WebListener",
                ApplicationName = "MusicStore"
            };

            using (new HostingEngine().Start(context))
            {
                Console.WriteLine("Started the server..");
                Console.WriteLine("Press any key to stop the server");
                Console.ReadLine();
            }
            return Task.FromResult(0);
        }
开发者ID:alexandreana,项目名称:MusicStore,代码行数:21,代码来源:Program.cs

示例7: CommitConfiguration_with_default_config_file

        public void CommitConfiguration_with_default_config_file()
        {
            var toolMock = new Mock<MyMigrationTool>() { CallBase = true };
            var args
                = new[]
                      {
                          "--ContextAssembly=EntityFramework.Design.Tests.dll",
                      };
            var configSourceMock = new Mock<IniFileConfigurationSource>("Foo") { CallBase = true };
            var tool = toolMock.Object;
            var configuration = new Configuration();

            configSourceMock.Setup(m => m.Load());
            configSourceMock.Setup(m => m.Commit());

            toolMock.Protected()
                .Setup<IniFileConfigurationSource>("CreateIniFileConfigurationSource", ItExpr.IsAny<string>())
                .Callback<string>(AssertConfigFileCallback2)
                .Returns(configSourceMock.Object);

            configuration.AddCommandLine(args);

            tool.CommitConfiguration(configuration);

            toolMock.Protected().Verify<IniFileConfigurationSource>("CreateIniFileConfigurationSource", Times.Once(), ItExpr.IsAny<string>());
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:26,代码来源:MigrationToolTest.cs

示例8: LoadContext_throws_if_context_type_not_specified_and_multiple_DbContext_found_in_assembly

        public void LoadContext_throws_if_context_type_not_specified_and_multiple_DbContext_found_in_assembly()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
                    {
                        "--ContextAssembly=EntityFramework.Design.Tests.dll"
                    });

            Assert.Equal(
                Strings.FormatAssemblyContainsMultipleDbContext(Assembly.GetExecutingAssembly().FullName),
                Assert.Throws<InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:15,代码来源:MigrationToolTest.cs

示例9: LoadContext_throws_if_context_type_not_specified_and_no_DbContext_found_in_assembly

        public void LoadContext_throws_if_context_type_not_specified_and_no_DbContext_found_in_assembly()
        {
            var toolMock = new Mock<MyMigrationTool> { CallBase = true };
            var tool = toolMock.Object;
            var configuration = new Configuration();

            toolMock.Setup(t => t.GetContextTypes(It.IsAny<Assembly>())).Returns(new Type[0]);

            configuration.AddCommandLine(
                new[]
                    {
                        "--ContextAssembly=EntityFramework.Design.Tests.dll"
                    });

            Assert.Equal(
                Strings.FormatAssemblyDoesNotContainDbContext(Assembly.GetExecutingAssembly().FullName),
                Assert.Throws<InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:18,代码来源:MigrationToolTest.cs

示例10: CreateMigration_with_default_migration_directory

        public void CreateMigration_with_default_migration_directory()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
                    {
                        "--MigrationName=MyMigration", 
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext", 
                        "--MigrationAssembly=EntityFramework.Design.Tests.dll", 
                        "--MigrationNamespace=MyNamespace"
                    });

            var scaffoldedMigration = tool.CreateMigration(configuration);

            Assert.Equal("MyNamespace", scaffoldedMigration.MigrationNamespace);
            Assert.Equal("MyMigration", scaffoldedMigration.MigrationClass);
            Assert.Equal("MyContextModelSnapshot", scaffoldedMigration.SnapshotModelClass);
            Assert.True(scaffoldedMigration.MigrationFile.EndsWith("MyMigration.cs"));
            Assert.True(scaffoldedMigration.MigrationMetadataFile.EndsWith("MyMigration.Designer.cs"));
            Assert.True(scaffoldedMigration.SnapshotModelFile.EndsWith("MyContextModelSnapshot.cs"));
            Assert.True(Path.IsPathRooted(scaffoldedMigration.MigrationFile));
            Assert.True(Path.IsPathRooted(scaffoldedMigration.MigrationMetadataFile));
            Assert.True(Path.IsPathRooted(scaffoldedMigration.SnapshotModelFile));
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:27,代码来源:MigrationToolTest.cs

示例11: LoadContext_throws_if_context_type_not_found

        public void LoadContext_throws_if_context_type_not_found()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
                    {
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.Vuvuzelas"
                    });

            Assert.Equal(
                Strings.FormatAssemblyDoesNotContainType(
                    Assembly.GetExecutingAssembly().FullName,
                    "Microsoft.Data.Entity.Design.Tests.Vuvuzelas"),
                Assert.Throws<InvalidOperationException>(() => tool.LoadContext(configuration)).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:18,代码来源:MigrationToolTest.cs

示例12: LoadContext_loads_references_before_instantiating_context_type

        public void LoadContext_loads_references_before_instantiating_context_type()
        {
            var toolMock = new Mock<MyMigrationTool> { CallBase = true };
            var tool = toolMock.Object;
            var configuration = new Configuration();

            toolMock.Protected()
                .Setup<DbContext>("CreateContext", ItExpr.IsAny<Type>())
                .Callback(() => toolMock.Protected()
                    .Verify<Assembly>("LoadAssembly", Times.Exactly(4), ItExpr.IsAny<string>()));

            configuration.AddCommandLine(
                new[]
                    {
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext",
                        "--References=Ref1;Ref2;Ref3"
                    });

            tool.LoadContext(configuration);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:21,代码来源:MigrationToolTest.cs

示例13: UpdateDatabase_with_target_migration

        public void UpdateDatabase_with_target_migration()
        {
            var toolMock = new Mock<MyMigrationTool> { CallBase = true };
            var migratorMock = new Mock<Migrator>();
            var tool = toolMock.Object;
            var configuration = new Configuration();

            toolMock.Protected()
                .Setup<Migrator>("GetMigrator", ItExpr.IsAny<DbContextConfiguration>())
                .Returns(migratorMock.Object);

            configuration.AddCommandLine(
                new[]
                    {
                        "--TargetMigration=MyMigrationName",
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext"
                    });

            tool.UpdateDatabase(configuration);

            migratorMock.Verify(m => m.UpdateDatabase("MyMigrationName"), Times.Once);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:23,代码来源:MigrationToolTest.cs

示例14: GenerateScript_with_target_migration

        public void GenerateScript_with_target_migration()
        {
            var toolMock = new Mock<MyMigrationTool> { CallBase = true };
            var migratorMock = new Mock<Migrator>();
            var tool = toolMock.Object;
            var configuration = new Configuration();

            migratorMock.Setup(m => m.GenerateUpdateDatabaseSql(It.IsAny<string>())).Returns(
                new[]
                    {
                        new SqlStatement("Script")
                    });

            toolMock.Protected()
                .Setup<Migrator>("GetMigrator", ItExpr.IsAny<DbContextConfiguration>())
                .Returns(migratorMock.Object);

            configuration.AddCommandLine(
                new[]
                    {
                        "--TargetMigration=MyMigrationName",
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext"
                    });

            var statements = tool.GenerateScript(configuration);

            migratorMock.Verify(m => m.GenerateUpdateDatabaseSql("MyMigrationName"), Times.Once);
            Assert.Equal(1, statements.Count);
            Assert.Equal("Script", statements[0].Sql);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:31,代码来源:MigrationToolTest.cs

示例15: GetMigrations_throws_if_invalid_source

        public void GetMigrations_throws_if_invalid_source()
        {
            var tool = new MyMigrationTool();
            var configuration = new Configuration();

            configuration.AddCommandLine(
                new[]
                    {
                        "--ContextAssembly=EntityFramework.Design.Tests.dll", 
                        "--ContextType=Microsoft.Data.Entity.Design.Tests.MigrationToolTest+MyContext", 
                        "--MigrationSource=Foo"
                    });

            Assert.Equal(
                Strings.InvalidMigrationSource,
                Assert.Throws<InvalidOperationException>(() => tool.GetMigrations(configuration)).Message);
        }
开发者ID:Nyaoso,项目名称:EntityFramework,代码行数:17,代码来源:MigrationToolTest.cs


注:本文中的Microsoft.Framework.ConfigurationModel.Configuration.AddCommandLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。