本文整理汇总了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);
}
示例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();
}
示例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}!");
}
示例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>());
}
示例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;
}
示例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);
}
示例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>());
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}