本文整理汇总了C#中IConfiguration.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# IConfiguration.GetString方法的具体用法?C# IConfiguration.GetString怎么用?C# IConfiguration.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConfiguration
的用法示例。
在下文中一共展示了IConfiguration.GetString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Synchronize
public void Synchronize(IConfiguration configuration, ZipWriter zip, string fileName, string configKey)
{
var databaseName = configuration.GetString(configKey + "database");
var itemPath = configuration.GetString(configKey + "path");
var fieldsToWrite = configuration.GetString(configKey + "fields").Split(Constants.Comma, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim().ToLowerInvariant()).ToList();
var database = Factory.GetDatabase(databaseName);
using (new SecurityDisabler())
{
var item = database.GetItem(itemPath);
if (item == null)
{
return;
}
var writer = new StringWriter();
var output = new XmlTextWriter(writer)
{
Formatting = Formatting.Indented
};
WriteItem(output, item, fieldsToWrite, true);
zip.AddEntry(fileName, Encoding.UTF8.GetBytes(writer.ToString()));
}
}
示例2: Synchronize
public void Synchronize(IConfiguration configuration, ZipWriter zip, string fileName, string configKey)
{
var databaseName = configuration.GetString(configKey + "database");
var schemaNamespace = configuration.GetString(configKey + "namespace");
Synchronize(zip, fileName, databaseName, schemaNamespace);
}
示例3: CreateDbConnection
public static IDbConnection CreateDbConnection(this IDatabase database, IConfiguration configuration)
{
if (database == null)
throw new ArgumentNullException("database");
if (configuration == null)
throw new ArgumentNullException("configuration");
var dbName = configuration.GetString("database.name");
if (!String.IsNullOrEmpty(dbName) &&
!String.Equals(dbName, database.Name))
throw new ArgumentException(String.Format("The specified database name '{0}' differs from the original database name '{1}'.",
dbName, database.Name));
var dbHandler = database.System as IDatabaseHandler;
if (dbHandler == null)
dbHandler = new SingleDatabaseHandler(database);
var serverConnector = new EmbeddedServerConnector(dbHandler);
var clientConnector = new EmbeddedClientConnector(serverConnector);
var settings = BuildConnectionString(configuration);
if (String.IsNullOrEmpty(settings.Database))
settings.Database = database.Name;
return new DeveelDbConnection(clientConnector, settings);
}
示例4: CreateDatabase
private IDatabase CreateDatabase(IConfiguration configuration, IConfiguration dbConfig, string userName, string password, bool createIfNotExists)
{
var builder = SystemBuilder.Default.UseConfiguration(configuration);
var system = builder.Build();
var databaseName = dbConfig.GetString("database.name");
IDatabase database;
if (!system.DatabaseExists(databaseName)) {
if (!createIfNotExists)
throw new DeveelDbException(String.Format("The database '{0}' does not exist and it is not set to be created.",
databaseName));
database = system.CreateDatabase(dbConfig, userName, password);
} else {
database = system.OpenDatabase(dbConfig);
}
return database;
}
示例5: BuildConnectionString
private static DeveelDbConnectionStringBuilder BuildConnectionString(IConfiguration configuration)
{
var settings = new DeveelDbConnectionStringBuilder();
foreach (var pair in configuration) {
try {
switch (pair.Key.ToUpperInvariant()) {
case "DATABASE.NAME":
case "DBNAME":
settings.Database = configuration.GetString(pair.Key);
break;
case "USERNAME":
case "USERID":
case "USER.NAME":
case "USER.ID":
case "CONNECTION.USERNAME":
case "CONNECTION.USER":
case "CONNECTION.USERID":
settings.UserName = configuration.GetString(pair.Key);
break;
case "PASSWORD":
case "PASS":
case "USER.PASSWORD":
case "SECRET":
case "CONNECTION.PASSWORD":
case "CONNECTION.PASS":
settings.Password = configuration.GetString(pair.Key);
break;
case "PARAMETERSTYLE":
case "PARAMSTYLE":
case "CONNECTION.PARAMETERSTYLE":
settings.ParameterStyle = configuration.GetValue<QueryParameterStyle>(pair.Key);
break;
case "IGNORECASE":
case "CONNECTION.IGNORECASE":
case "IGNOREIDENTIFIERSCASE":
case "CONNECTION.IGNOREIDENTIFIERSCASE":
settings.IgnoreIdentifiersCase = configuration.GetBoolean(pair.Key);
break;
}
} catch (Exception ex) {
throw new ArgumentException(String.Format("An error occurred while setting the key '{0}' into the connection string.", pair.Key));
}
}
return settings;
}
示例6: Configure
private void Configure(IConfiguration config)
{
var basePath = config.GetString("database.basePath");
var fileName = config.GetString("database.fileName");
var fullPath = config.GetString("database.fullPath");
var fileSystemName = config.GetString("store.fileSystem", "local");
FileSystem = context.ResolveService<IFileSystem>(fileSystemName);
if (FileSystem == null)
throw new DatabaseConfigurationException(String.Format("The file-system '{0}' was not found in context.", fileSystemName));
if (String.IsNullOrEmpty(basePath)) {
if (String.IsNullOrEmpty(fullPath)) {
FileName = fileName;
} else {
FileName = fullPath;
}
} else if (String.IsNullOrEmpty(fileName)) {
if (!String.IsNullOrEmpty(basePath)) {
fileName = String.Format("{0}.{1}", context.DatabaseName(), DefaultFileExtension);
FileName = FileSystem.CombinePath(basePath, fileName);
} else if (!String.IsNullOrEmpty(fullPath)) {
FileName = fullPath;
}
} else if (String.IsNullOrEmpty(fullPath)) {
FileName = FileSystem.CombinePath(basePath, fileName);
}
if (String.IsNullOrEmpty(FileName))
throw new DatabaseConfigurationException("Could not configure the file name of the database.");
}
示例7: OpenDatabase
public IDatabase OpenDatabase(IConfiguration configuration)
{
lock (this) {
if (configuration == null)
throw new ArgumentNullException("configuration");
var databaseName = configuration.GetString("database.name");
if (String.IsNullOrEmpty(databaseName))
throw new ArgumentException("The configuration must specify a database name.");
Database database;
if (databases == null ||
!databases.TryGetValue(databaseName, out database))
throw new InvalidOperationException(String.Format("Database '{0}' does not exist in the system.", databaseName));
if (!database.IsOpen)
database.Open();
return database;
}
}
示例8: CreateDatabase
public IDatabase CreateDatabase(IConfiguration configuration, string adminUser, string identification, string token)
{
lock (this) {
if (configuration == null)
throw new ArgumentNullException("configuration");
var databaseName = configuration.GetString("database.name");
if (String.IsNullOrEmpty(databaseName))
throw new ArgumentException("The configuration must specify a database name.");
if (DatabaseExists(databaseName))
throw new InvalidOperationException(String.Format("Database '{0}' already exists in the system.", databaseName));
var dbContext = Context.CreateDatabaseContext(configuration);
var database = new Database(this, dbContext);
if (database.Exists)
throw new InvalidOperationException(String.Format("The database '{0}' was already created.", databaseName));
database.Create(adminUser, identification, token);
database.Open();
if (databases == null)
databases = new Dictionary<string, Database>();
databases[databaseName] = database;
return database;
}
}
示例9: GetIndicatorToken
protected string GetIndicatorToken(IConfiguration config)
{
return config.GetString(Constants.Configuration.IndicatorToken);
}
示例10: New
public static IDatabase New(IConfiguration config, string adminName, string adminPassword)
{
var dbName = config.GetString("database.name");
if (String.IsNullOrEmpty(dbName))
throw new ArgumentException("The database name is not specified in configuration");
return New(config, null, adminName, adminPassword);
}