本文整理汇总了C#中IRuntimeContext类的典型用法代码示例。如果您正苦于以下问题:C# IRuntimeContext类的具体用法?C# IRuntimeContext怎么用?C# IRuntimeContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IRuntimeContext类属于命名空间,在下文中一共展示了IRuntimeContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertAndUpdateRow
private static void InsertAndUpdateRow(IDbCommand command, string tableName, IRuntimeContext context)
{
command.CommandText = string.Format(CultureInfo.InvariantCulture, "INSERT INTO \"{0}\" ( \"Content\" ) VALUES ( 'First' )", tableName);
context.CommandExecutor.ExecuteNonQuery(command);
byte[] firstRowVersion;
if (IntegrationTestContext.IsScripting)
{
firstRowVersion = BitConverter.GetBytes(1L);
}
else
{
command.CommandText = string.Format(CultureInfo.InvariantCulture, "SELECT Version FROM \"{0}\"", tableName);
firstRowVersion = (byte[])command.ExecuteScalar();
}
command.CommandText = string.Format(CultureInfo.InvariantCulture, "UPDATE \"{0}\" SET Content = 'Updated'", tableName);
context.CommandExecutor.ExecuteNonQuery(command);
byte[] updatedRowVersion;
if (IntegrationTestContext.IsScripting)
{
updatedRowVersion = BitConverter.GetBytes(2L);
}
else
{
command.CommandText = string.Format(CultureInfo.InvariantCulture, "SELECT Version FROM \"{0}\"", tableName);
updatedRowVersion = (byte[])command.ExecuteScalar();
}
CollectionAssert.AreNotEqual(firstRowVersion, updatedRowVersion, "The row version was not updated.");
}
示例2: GetScriptType
private JsExpression GetScriptType(IType type, TypeContext typeContext, IRuntimeContext context) {
if (type.Kind == TypeKind.Delegate) {
return CreateTypeReferenceExpression(KnownTypeReference.Delegate);
}
else if (type is ParameterizedType) {
var pt = (ParameterizedType)type;
var def = pt.GetDefinition();
var sem = _metadataImporter.GetTypeSemantics(def);
if (sem.Type == TypeScriptSemantics.ImplType.NormalType && !sem.IgnoreGenericArguments)
return JsExpression.Invocation(JsExpression.Member(CreateTypeReferenceExpression(_systemScript), "makeGenericType"), CreateTypeReferenceExpression(type.GetDefinition()), JsExpression.ArrayLiteral(pt.TypeArguments.Select(a => GetScriptType(a, TypeContext.GenericArgument, context))));
else
return GetTypeDefinitionScriptType(type.GetDefinition(), typeContext);
}
else if (type.TypeParameterCount > 0) {
// This handles open generic types ( typeof(C<,>) )
return CreateTypeReferenceExpression(type.GetDefinition());
}
else if (type.Kind == TypeKind.Array) {
return CreateTypeReferenceExpression(KnownTypeReference.Array);
}
else if (type is ITypeParameter) {
return context.ResolveTypeParameter((ITypeParameter)type);
}
else if (type is ITypeDefinition) {
return GetTypeDefinitionScriptType((ITypeDefinition)type, typeContext);
}
else if (type.Kind == TypeKind.Anonymous || type.Kind == TypeKind.Null || type.Kind == TypeKind.Dynamic) {
return CreateTypeReferenceExpression(KnownTypeReference.Object);
}
else {
throw new InvalidOperationException("Could not determine the script type for " + type + ", context " + typeContext);
}
}
示例3: InsertUsingParameters
private static void InsertUsingParameters(IRuntimeContext ctx, string value)
{
IDbCommand command = ctx.CreateCommand();
IDataParameter parameter = command.AddParameter("@value", DbType.String, value);
command.CommandText = string.Format(CultureInfo.InvariantCulture, @"INSERT INTO ""Mig23b"" (""Data"") VALUES ({0})", ctx.ProviderMetadata.GetParameterSpecifier(parameter));
ctx.CommandExecutor.ExecuteNonQuery(command);
}
示例4: ToSql
public IEnumerable<string> ToSql(IProvider provider, IRuntimeContext context)
{
return provider.AlterColumn(Parent.Parent.TableName, new Column(
Parent.ColumnName,
new DataType(_type, Size, Scale),
_isNullable,
DefaultValue));
}
示例5: EventProcessor
/// <summary>
/// Initializes a new instance of the <see cref="EventProcessor"/> class.
/// </summary>
public EventProcessor(IWorkItemRepository workItemStore, IRuntimeContext runtime)
{
this.logger = runtime.Logger;
this.store = workItemStore;
this.settings = runtime.Settings;
this.engine = runtime.GetEngine(workItemStore);
}
示例6: Trigger
public bool Trigger(IRuntimeContext context)
{
// There is no control over how many times this will be called so
// there is no guarantee that rule will be triggered given Minimum times.
bool trigger = triggerCount < minTriggers || random.Next(0, 2) == 0;
if (trigger) triggerCount++;
return (triggerCount <= maxTriggers) && trigger;
}
示例7: ToSql
public IEnumerable<string> ToSql(IProvider provider, IRuntimeContext context)
{
if (_columnNames.Count == 0)
{
throw new InvalidCommandException("At least one column must be added to the AddPrimaryKey command.");
}
string effectiveConstraintName = GetEffectiveConstraintName();
return provider.AddPrimaryKey(Parent.TableName, _columnNames, effectiveConstraintName);
}
示例8: ToSql
public IEnumerable<string> ToSql(IProvider provider, IRuntimeContext context)
{
if (context != null) // the context == null, when recording the changes to the RecordingProvider for validation
{
Log.Verbose(LogCategory.Sql, "Performing call-back");
_action(context);
}
yield break;
}
示例9: RateLimiter
public RateLimiter(IRuntimeContext context)
{
if (context.Settings?.RateLimit != null)
{
this.enabled = true;
this.interval = context.Settings.RateLimit.Interval;
this.changes = context.Settings.RateLimit.Changes;
}
}
示例10: EventProcessor
/// <summary>
/// Initializes a new instance of the <see cref="EventProcessor"/> class.
/// </summary>
public EventProcessor(IRuntimeContext runtime)
{
this.logger = runtime.Logger;
this.settings = runtime.Settings;
this.limiter = runtime.RateLimiter;
this.store = runtime.GetWorkItemRepository();
this.engine = runtime.GetEngine();
}
示例11: ToSql
public IEnumerable<string> ToSql(IProvider provider, IRuntimeContext context)
{
if (_columnNames.Count == 0)
{
throw new InvalidCommandException("At least one column must be added to the AddForeignKeyTo command.");
}
string effectiveConstraintName = GetEffectiveConstraintName();
return provider.AddForeignKey(Parent.TableName, _referencedTableName, _columnNames.Select(p => new ColumnReference(p.Key, p.Value)), effectiveConstraintName, CascadeOnDelete);
}
示例12: Trigger
public bool Trigger(IRuntimeContext context)
{
if (!string.IsNullOrEmpty(targetCaller) && targetCaller != context.Caller)
{
return false;
}
Interlocked.Increment(ref calledTimes);
return calledTimes <= n;
}
示例13: OnInvoke
protected override void OnInvoke(IRuntimeInvocation runtimeInvocation, IRuntimeContext runtimeContext)
{
this.LastOperationName = string.Format("{0}::{1}", (object)runtimeInvocation.TargetType == null ? "<null>" : runtimeInvocation.TargetType.Name, (object)runtimeInvocation.TargetMethod == null ? "<null>" : runtimeInvocation.TargetMethod.Name);
if ((object)runtimeInvocation.TargetMethod != null)
{
if (runtimeInvocation.TargetMethod.DeclaringType == typeof(object) ||
runtimeInvocation.TargetMethod.DeclaringType == typeof(IDisposable) ||
runtimeInvocation.TargetMethod.DeclaringType == typeof(IMockCloneable))
runtimeInvocation.InvocationReturnValue = runtimeInvocation.TargetMethod.Invoke(this, runtimeInvocation.InvocationArguments);
}
throw new InvalidOperationException(string.Format("Method '{0}' not supported on '{1}'.", (object)runtimeInvocation.TargetMethod == null ? "<null>" : runtimeInvocation.TargetMethod.Name, runtimeInvocation.TargetType.FullName));
}
示例14: ToSql
public IEnumerable<string> ToSql(IProvider provider, IRuntimeContext context)
{
if (IsNullable && DefaultValue != null)
{
throw new InvalidCommandException("Adding nullable columns with default values is not supported: some database platforms (like SQL Server) leave missing values NULL and some update missing values to the default value. Consider adding the column first as not-nullable, and then altering it to nullable.");
}
string tableName = Parent.TableName;
var dataType = new DataType(Type, Size, Scale);
var column = new Column(ColumnName, dataType, IsNullable, DefaultValue, IsRowVersion);
IEnumerable<string> commands = provider.AddColumn(tableName, column);
if (DropThereafter)
{
commands = commands.Concat(provider.DropDefault(tableName, new Column(
column.Name,
column.DataType,
column.IsNullable,
null, false)));
}
return commands;
}
示例15: ToSql
public IEnumerable<string> ToSql(IProvider provider, IRuntimeContext context)
{
string effectivePkConstraintName = GetEffectivePkConstraintName();
List<CreateColumnCommand> createColumnCommands = GetCreateColumnCommands().ToList();
if (createColumnCommands.Count == 0)
{
throw new InvalidCommandException("At least one column must be added to the CreateTable command.");
}
return provider.CreateTable(
_tableName,
createColumnCommands.Select(c => new CreatedColumn(
c.ColumnName,
new DataType(c.Type, c.Size, c.Scale),
c.IsNullable,
c.IsPrimaryKey,
GetEffectiveUniqueConstraintName(c),
c.IsIdentity,
c.DefaultValue)),
effectivePkConstraintName);
}