示例#1
0
 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);
 }
        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.");
        }
		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);
			}
		}
        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;
        }
 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));
 }
        /// <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);
        }
示例#7
0
 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;
 }
 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);
 }
示例#9
0
        /// <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();
        }
示例#10
0
 public RateLimiter(IRuntimeContext context)
 {
     if (context.Settings?.RateLimit != null)
     {
         this.enabled = true;
         this.interval = context.Settings.RateLimit.Interval;
         this.changes = context.Settings.RateLimit.Changes;
     }
 }
 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);
 }
        public bool Trigger(IRuntimeContext context)
        {
            if (!string.IsNullOrEmpty(targetCaller) && targetCaller != context.Caller)
            {
                return false;
            }

	        Interlocked.Increment(ref calledTimes);

			return calledTimes <= n;
        }
示例#13
0
		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
0
 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
0
 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);
 }
示例#16
0
 public IEnumerable<string> ToSql(IProvider provider, IRuntimeContext context)
 {
     AlterTableCommand parentAlterTableCommand;
     AlterColumnCommand parentAlterColumnCommand;
     AlterPrimaryKeyCommand parentAlterPrimaryKeyCommand;
     if ((parentAlterTableCommand = Parent as AlterTableCommand) != null)
     {
         return provider.RenameTable(parentAlterTableCommand.TableName, _newName);
     }
     else if ((parentAlterColumnCommand = Parent as AlterColumnCommand) != null)
     {
         return provider.RenameColumn(parentAlterColumnCommand.Parent.TableName, parentAlterColumnCommand.ColumnName, _newName);
     }
     else if ((parentAlterPrimaryKeyCommand = Parent as AlterPrimaryKeyCommand) != null)
     {
         return provider.RenamePrimaryKey(parentAlterPrimaryKeyCommand.Parent.TableName, parentAlterPrimaryKeyCommand.ConstraintName, _newName);
     }
     else
     {
         throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Unknown parent command of a RenameCommand: {0}.", Parent.GetType()));
     }
 }
示例#17
0
 public IEnumerable<string> ToSql(IProvider provider, IRuntimeContext context)
 {
     AlterTableCommand parentAlterTableCommand;
     AlterColumnCommand parentAlterColumnCommand;
     AlterPrimaryKeyCommand parentAlterPrimaryKeyCommand;
     AlterIndexCommand parentAlterIndexCommand;
     AlterUniqueConstraintCommand parentAlterUniqueConstraintCommand;
     AlterForeignKeyCommand parentAlterForeignKeyCommand;
     if ((parentAlterTableCommand = Parent as AlterTableCommand) != null)
     {
         return provider.DropTable(parentAlterTableCommand.TableName);
     }
     else if ((parentAlterColumnCommand = Parent as AlterColumnCommand) != null)
     {
         return provider.DropColumn(parentAlterColumnCommand.Parent.TableName, parentAlterColumnCommand.ColumnName);
     }
     else if ((parentAlterPrimaryKeyCommand = Parent as AlterPrimaryKeyCommand) != null)
     {
         string effectiveConstraintName = DefaultObjectNameProvider.GetPrimaryKeyConstraintName(parentAlterPrimaryKeyCommand.Parent.TableName, parentAlterPrimaryKeyCommand.ConstraintName);
         return provider.DropPrimaryKey(parentAlterPrimaryKeyCommand.Parent.TableName, effectiveConstraintName);
     }
     else if ((parentAlterIndexCommand = Parent as AlterIndexCommand) != null)
     {
         return provider.DropIndex(parentAlterIndexCommand.Parent.TableName, parentAlterIndexCommand.IndexName);
     }
     else if ((parentAlterUniqueConstraintCommand = Parent as AlterUniqueConstraintCommand) != null)
     {
         return provider.DropUniqueConstraint(parentAlterUniqueConstraintCommand.Parent.TableName, parentAlterUniqueConstraintCommand.ConstraintName);
     }
     else if ((parentAlterForeignKeyCommand = Parent as AlterForeignKeyCommand) != null)
     {
         return provider.DropForeignKey(parentAlterForeignKeyCommand.Parent.TableName, parentAlterForeignKeyCommand.ConstraintName);
     }
     else
     {
         throw new InvalidOperationException("Unsupported parent command of a DropCommand.");
     }
 }
 JsExpression IRuntimeLibrary.FromNullable(JsExpression expression, IRuntimeContext context)
 {
     return(FromNullable(expression, context));
 }
 JsExpression IRuntimeLibrary.LiftedBooleanOr(JsExpression a, JsExpression b, IRuntimeContext context)
 {
     return(LiftedBooleanOr(a, b, context));
 }
 JsExpression IRuntimeLibrary.InstantiateType(IType type, IRuntimeContext context)
 {
     return(InstantiateType(type, context));
 }
 JsExpression IRuntimeLibrary.Upcast(JsExpression expression, IType sourceType, IType targetType, IRuntimeContext context)
 {
     return(Upcast(expression, sourceType, targetType, context));
 }
 JsExpression IRuntimeLibrary.InstantiateGenericMethod(JsExpression type, IEnumerable <IType> typeArguments, IRuntimeContext context)
 {
     return(InstantiateGenericMethod(type, typeArguments, context));
 }
 JsExpression IRuntimeLibrary.BindFirstParameterToThis(JsExpression function, IRuntimeContext context)
 {
     return(BindFirstParameterToThis(function, context));
 }
 JsExpression IRuntimeLibrary.MakeEnumerator(IType yieldType, JsExpression moveNext, JsExpression getCurrent, JsExpression dispose, IRuntimeContext context)
 {
     return(MakeEnumerator(yieldType, moveNext, getCurrent, dispose, context));
 }
 JsExpression IRuntimeLibrary.BindBaseCall(IMethod method, JsExpression @this, IRuntimeContext context)
 {
     return(BindBaseCall(method, @this, context));
 }
 JsExpression IRuntimeLibrary.CallBase(IMethod method, IEnumerable <JsExpression> thisAndArguments, IRuntimeContext context)
 {
     return(CallBase(method, thisAndArguments, context));
 }
 JsExpression IRuntimeLibrary.CloneDelegate(JsExpression source, IType sourceType, IType targetType, IRuntimeContext context)
 {
     return(CloneDelegate(source, sourceType, targetType, context));
 }
 JsExpression IRuntimeLibrary.CreateArray(IType elementType, IEnumerable <JsExpression> size, IRuntimeContext context)
 {
     return(CreateArray(elementType, size, context));
 }
 JsExpression IRuntimeLibrary.Default(IType type, IRuntimeContext context)
 {
     return(Default(type, context));
 }
示例#30
0
 public AppServiceCertificateController(IServiceProvider services, IRuntimeContext <AppServiceCertificate> runtimeContext)
     : base(services, runtimeContext)
 {
 }
 JsExpression IRuntimeLibrary.Coalesce(JsExpression a, JsExpression b, IRuntimeContext context)
 {
     return(Coalesce(a, b, context));
 }
 JsExpression IRuntimeLibrary.FloatToInt(JsExpression operand, IRuntimeContext context)
 {
     return(FloatToInt(operand, context));
 }
 JsExpression IRuntimeLibrary.MakeException(JsExpression operand, IRuntimeContext context)
 {
     return(MakeException(operand, context));
 }
 JsExpression IRuntimeLibrary.Bind(JsExpression function, JsExpression target, IRuntimeContext context)
 {
     return(Bind(function, target, context));
 }
 JsExpression IRuntimeLibrary.IntegerDivision(JsExpression numerator, JsExpression denominator, IRuntimeContext context)
 {
     return(IntegerDivision(numerator, denominator, context));
 }
		JsExpression IRuntimeLibrary.MakeEnumerable(IType yieldType, JsExpression getEnumerator, IRuntimeContext context) {
			return MakeEnumerable(yieldType, getEnumerator, context);
		}
		JsExpression IRuntimeLibrary.CreateTaskCompletionSource(IType taskGenericArgument, IRuntimeContext context) {
			return CreateTaskCompletionSource(taskGenericArgument, context);
		}
		JsExpression IRuntimeLibrary.SetAsyncException(JsExpression taskCompletionSource, JsExpression exception, IRuntimeContext context) {
			return SetAsyncException(taskCompletionSource, exception, context);
		}
 JsExpression IRuntimeLibrary.ReferenceNotEquals(JsExpression a, JsExpression b, IRuntimeContext context)
 {
     return(ReferenceNotEquals(a, b, context));
 }
		JsExpression IRuntimeLibrary.ApplyConstructor(JsExpression constructor, JsExpression argumentsArray, IRuntimeContext context) {
			return ApplyConstructor(constructor, argumentsArray, context);
		}
 JsExpression IRuntimeLibrary.InstantiateTypeForUseAsTypeArgumentInInlineCode(IType type, IRuntimeContext context)
 {
     return(InstantiateTypeForUseAsTypeArgumentInInlineCode(type, context));
 }
		JsExpression IRuntimeLibrary.GetMember(IMember member, IRuntimeContext context) {
			return GetMember(member, context);
		}
 JsExpression IRuntimeLibrary.TypeOf(IType type, IRuntimeContext context)
 {
     return(GetTypeOf(type, context));
 }
		JsExpression IRuntimeLibrary.CloneValueType(JsExpression value, IType type, IRuntimeContext context) {
			return CloneValueType(value, type, context);
		}
 JsExpression IRuntimeLibrary.MakeEnumerable(IType yieldType, JsExpression getEnumerator, IRuntimeContext context)
 {
     return(MakeEnumerable(yieldType, getEnumerator, context));
 }
 JsExpression IRuntimeLibrary.Lift(JsExpression expression, IRuntimeContext context)
 {
     return(Lift(expression, context));
 }
		JsExpression IRuntimeLibrary.MakeEnumerator(IType yieldType, JsExpression moveNext, JsExpression getCurrent, JsExpression dispose, IRuntimeContext context) {
			return MakeEnumerator(yieldType, moveNext, getCurrent, dispose, context);
		}
 JsExpression IRuntimeLibrary.SetMultiDimensionalArrayValue(JsExpression array, IEnumerable <JsExpression> indices, JsExpression value, IRuntimeContext context)
 {
     return(SetMultiDimensionalArrayValue(array, indices, value, context));
 }
		JsExpression IRuntimeLibrary.SetMultiDimensionalArrayValue(JsExpression array, IEnumerable<JsExpression> indices, JsExpression value, IRuntimeContext context) {
			return SetMultiDimensionalArrayValue(array, indices, value, context);
		}
 JsExpression IRuntimeLibrary.CreateTaskCompletionSource(IType taskGenericArgument, IRuntimeContext context)
 {
     return(CreateTaskCompletionSource(taskGenericArgument, context));
 }
		JsExpression IRuntimeLibrary.SetAsyncResult(JsExpression taskCompletionSource, JsExpression value, IRuntimeContext context) {
			return SetAsyncResult(taskCompletionSource, value, context);
		}
 JsExpression IRuntimeLibrary.SetAsyncResult(JsExpression taskCompletionSource, JsExpression value, IRuntimeContext context)
 {
     return(SetAsyncResult(taskCompletionSource, value, context));
 }
		JsExpression IRuntimeLibrary.GetTaskFromTaskCompletionSource(JsExpression taskCompletionSource, IRuntimeContext context) {
			return GetTaskFromTaskCompletionSource(taskCompletionSource, context);
		}
 JsExpression IRuntimeLibrary.SetAsyncException(JsExpression taskCompletionSource, JsExpression exception, IRuntimeContext context)
 {
     return(SetAsyncException(taskCompletionSource, exception, context));
 }
		JsExpression IRuntimeLibrary.ShallowCopy(JsExpression source, JsExpression target, IRuntimeContext context) {
			return ShallowCopy(source, target, context);
		}
 JsExpression IRuntimeLibrary.GetTaskFromTaskCompletionSource(JsExpression taskCompletionSource, IRuntimeContext context)
 {
     return(GetTaskFromTaskCompletionSource(taskCompletionSource, context));
 }
		JsExpression IRuntimeLibrary.GetExpressionForLocal(string name, JsExpression accessor, IType type, IRuntimeContext context) {
			return GetExpressionForLocal(name, accessor, type, context);
		}
 JsExpression IRuntimeLibrary.ApplyConstructor(JsExpression constructor, JsExpression argumentsArray, IRuntimeContext context)
 {
     return(ApplyConstructor(constructor, argumentsArray, context));
 }
		JsExpression IRuntimeLibrary.InitializeField(JsExpression jsMember, string scriptName, IMember member, JsExpression initialValue, IRuntimeContext context) {
			return InitializeField(jsMember, scriptName, member, initialValue, context);
		}
示例#60
0
        public PostsViewModel(INavigationService navigationService, IAuthenticationService authenticationService, IPostService postService, IRuntimeContext runtimeContext)
            : base(navigationService, runtimeContext)
        {
            _postService           = postService;
            _authenticationService = authenticationService;

            LikeCommand       = new Command <Guid>(async(id) => await Like(id), (id) => !IsBusy);
            CreatePostCommand = new Command(async() => await CreatePost(), () => !IsBusy);
            LogOutCommand     = new Command(async() => await LogOut(), () => !IsBusy);
            CommentCommand    = new Command <Guid>(async(id) => await Comment(id), (id) => !IsBusy);
            DeleteCommand     = new Command <Guid>(async(id) => await Delete(id), (id) => !IsBusy);
            EditCommand       = new Command <Guid>(async(id) => await Edit(id), (id) => !IsBusy);
            SearchCommand     = new Command(async() => await Search(), () => !IsBusy);
        }