本文整理汇总了C#中IContext.ResolveService方法的典型用法代码示例。如果您正苦于以下问题:C# IContext.ResolveService方法的具体用法?C# IContext.ResolveService怎么用?C# IContext.ResolveService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContext
的用法示例。
在下文中一共展示了IContext.ResolveService方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
private void Configure(IContext context)
{
var configuration = context.ResolveService<IConfiguration>();
if (configuration == null)
throw new DatabaseConfigurationException("No configuration found in context.");
BasePath = configuration.GetString("store.dataFactory.scattering.basePath");
if (String.IsNullOrEmpty(BasePath))
BasePath = configuration.GetString("database.path");
if (String.IsNullOrEmpty(BasePath))
throw new DatabaseConfigurationException("No base path was set for the data factory.");
FileExtension = configuration.GetString("store.dataFactory.scattering.fileExtension", ".db");
// 1Gb by default
const int defaultMaxSliceSize = 16384*65536;
MaxSliceSize = configuration.GetInt32("store.dataFactory.scattering.maxSliceSize", defaultMaxSliceSize);
var fileSystemName = configuration.GetString("store.dataFactory.scattering.fileSystem");
if (String.IsNullOrEmpty(fileSystemName)) {
fileSystemName = configuration.GetString("store.fileSystem", "local");
}
FileSystem = context.ResolveService<IFileSystem>(fileSystemName);
if (FileSystem == null)
throw new DatabaseConfigurationException(String.Format("File system '{0}' was not found in context.", fileSystemName));
}
示例2: Parse
public static IEnumerable<SqlStatement> Parse(IContext context, SqlQuery query)
{
if (query == null)
throw new ArgumentNullException("query");
var compiler = DefaultCompiler;
if (context != null) {
compiler = context.ResolveService<ISqlCompiler>();
}
try {
var compileContext = new SqlCompileContext(context, query.Text);
var result = compiler.Compile(compileContext);
if (result.HasErrors)
{
var messages = new StringBuilder();
messages.AppendFormat("SqlParseException for '{0}'" + Environment.NewLine, query.Text);
foreach (var m in result.Messages)
{
messages.AppendFormat("Level: {0}", m.Level);
if (null != m.Location)
{
messages.AppendFormat(", Line: {0}, Column: {1}", m.Location.Line, m.Location.Column);
}
messages.AppendFormat(", Message: {0}", m.Text);
messages.AppendLine();
}
throw new SqlParseException(messages.ToString());
}
var statements = result.Statements.Cast<SqlStatement>();
foreach (var statement in statements) {
if (statement != null)
statement.SetSource(query);
}
return statements;
} catch (SqlParseException) {
throw;
} catch (Exception ex) {
var messages = new StringBuilder();
messages.AppendFormat ("The input string '{0}'" + Environment.NewLine, query.Text);
messages.AppendFormat (" cannot be parsed into SQL Statements, because of {0}" + Environment.NewLine, ex.ToString());
throw new SqlParseException(messages.ToString(), ex);
}
}
示例3: Parse
/// <summary>
/// Parses the given SQL string to an expression that can be evaluated.
/// </summary>
/// <param name="s">The string to parse.</param>
/// <param name="context"></param>
/// <returns>
/// Returns an instance of <seealso cref="SqlExpression"/> that represents
/// the given SQL string parsed.
/// </returns>
public static SqlExpression Parse(string s, IContext context)
{
// TODO: Get the expression compiler from the context
var parser = context.ResolveService<IExpressionParser>();
if (parser == null)
parser = new ExpressionParser();
return Parse(s, parser);
}