public ICommandResponse Execute(ICommandExecutionContext context) { var request = context.Request as ExecuteStoredProcedureRequest; if (request == null) throw new InvalidCommandRequestTypeException(typeof(ExecuteStoredProcedureRequest), context.Request.GetType()); return new CommandResponseString( MessageProcessStatusFlags.Success, string.Format("Stored Procedure '{0}' executed successfully.", request.StoredProcedureName) ); }
public void Execute(AbstractCommand command, ICommandExecutionContext context) { var commandType = command.GetType(); dynamic handler; if (!handlers.TryGetValue(commandType, out handler)) { throw new InvalidOperationException(string.Format("No handler for {0} registered.", commandType.AssemblyQualifiedName)); } dynamic dynamicCommand = command; handler.Handle(dynamicCommand, context); }
public void ExecuteCommands(ObjectId targetObjectId, ICommandExecutor commandExecutor, ICommandExecutionContext context) { List<AbstractCommand> commandsForObject; if (!commands.TryGetValue(targetObjectId, out commandsForObject)) { return; } foreach (var command in commandsForObject) { commandExecutor.Execute(command, context); } }
public void Handle(TestingCommand command, ICommandExecutionContext context) { }
public Task Execute(ICommandExecutionContext context) { this.Result = this.FirstParameter + this.SecondParameter; return Task.FromResult(Type.Missing); }
public ICommandResponse Execute(ICommandExecutionContext context) { return(new CommandResponseString(MessageProcessStatusFlags.Success, "Database Updated Successfully")); }
public void Handle(AbstractCommand command, ICommandExecutionContext context) { }
public static void Attach <TCommand, TTarget, TValue>(this ICommandExecutionContext context, ITypedCommandHandler <TCommand, TTarget> handler, Expression <Func <TTarget, IEnumerable <TValue> > > propertyExpression, ObjectId refereeId) where TCommand : TypedCommand <TTarget> { DoAttach(propertyExpression, context, refereeId); }
public Task Execute(CreatePostAsDraft command, ICommandExecutionContext context) { throw new System.NotImplementedException(); }
public static IEventService GetEventService(this ICommandExecutionContext context) { return(context.DependencyResolver.Get <IEventService>()); }
public Task Execute(UpdatePostTitle command, ICommandExecutionContext context) { throw new System.NotImplementedException(); }
public void Handle(CreateHierarchyNodeCommand command, ICommandExecutionContext context) { context.Create(this); context.Attach(this, x => x.Unit, command.UnitId); context.Attach(this, x => x.Context, command.HierarchyId); }
public void Handle(CreateUnitCommand command, ICommandExecutionContext context) { context.Create(this); context.ModifyAttribute(this, x => x.Name, command.Name); context.ModifyAttribute(this, x => x.Address, command.Address); }
public abstract Task Execute(ICommandExecutionContext context);
/// <summary> /// Executes a long-running command using the specified <see cref="ICommandExecutionContext"/>. /// </summary> /// <param name="context">The <see cref="ICommandExecutionContext"/> to use to run this command module.</param> /// <returns></returns> public ICommandResponse Execute(ICommandExecutionContext context) { // This technique allows us to optionally take a command request. If they just want to run the default settings, they can just pass an empty string and we'll supply the default values. var stringRequest = context.Request as CommandRequestString; if (stringRequest == null) { throw new InvalidCommandRequestTypeException(typeof(CommandRequestString), context.Request.GetType()); } // Test if we have a command request string. If we have a non-blank request string, then try to deserialize it var request = new LongRunningCommandTestRequest(); if (!string.IsNullOrWhiteSpace(stringRequest.RequestString)) { context.Activity.Track("Request string found. Attempting deserialization of request object."); request = ((ICommandRequestSerializer) new NetDataContractRequestSerializer <LongRunningCommandTestRequest>()).Deserialize(stringRequest.RequestString) as LongRunningCommandTestRequest; // Now that we've tried to deserialize it manually, if the request couldn't be deserialized into the expected, we can throw the invalid command request type exception. if (request == null) { throw new InvalidCommandRequestTypeException(typeof(LongRunningCommandTestRequest), context.Request.GetType()); } } var totalRunTime = request.TotalRunTime ?? DefaultTotalRunTime; var minSleepMilliseconds = (int)Math.Min(int.MaxValue, (request.MinimumSleepInterval ?? DefaultMinimumSleepInterval).TotalMilliseconds); var maxSleepMilliseconds = (int)Math.Min(int.MaxValue, (request.MaximumSleepInterval ?? DefaultMaximumSleepInterval).TotalMilliseconds); var stopwatch = new Stopwatch(); var rand = new Random(); var progressReportCount = 0; context.Activity.Track("Starting long-running command test."); stopwatch.Start(); while (stopwatch.ElapsedMilliseconds < totalRunTime.TotalMilliseconds && !context.Token.IsCancellationRequested) { // Capture the remaining run time. Smart check for max size for an Int32. var remainingMilliseconds = (int)Math.Min(int.MaxValue, totalRunTime.TotalMilliseconds - stopwatch.ElapsedMilliseconds); // Try to sleep for at least the minimum time span unless there is less time remaining. Don't sleep for more than the maximum time span var sleepMilliseconds = rand.Next( Math.Min(minSleepMilliseconds, remainingMilliseconds), Math.Min(maxSleepMilliseconds, remainingMilliseconds) ); try { Task.WaitAll( new [] { Task.Delay(sleepMilliseconds, context.Token) }, context.Token ); // Avoid reporting more than 100% or reporting 100% multiple times if (stopwatch.ElapsedMilliseconds < totalRunTime.TotalMilliseconds) { context.Activity.Track( $"Progress update {++progressReportCount}.", stopwatch.ElapsedMilliseconds, totalRunTime.TotalMilliseconds ); } } catch (OperationCanceledException) { break; // break on cancel } } stopwatch.Stop(); if (context.Token.IsCancellationRequested) { context.Activity.Track($"Cancellation requested after {stopwatch.Elapsed}."); } else { // Otherwise, we completed successfully, so show 100% context.Activity.Track( $"Progress update {++progressReportCount}.", totalRunTime.TotalMilliseconds, totalRunTime.TotalMilliseconds ); } return(new CommandResponse(MessageProcessStatusFlags.Success)); }
public void Handle(CreateObjectCommand command, ICommandExecutionContext context) { context.Create(command.ObjectTypeId); }
public ICommandResponse Execute(ICommandExecutionContext context) { return new CommandResponseString(MessageProcessStatusFlags.Success, "Database Updated Successfully"); }
public void Handle(ModifyAttributeCommand command, ICommandExecutionContext context) { context.ModifyAttribute(command.AttributeName, command.Value); }
public static IdGenerator GetIdGenerator(this ICommandExecutionContext context) { return(context.DependencyResolver.Get <IdGenerator>()); }
public ICommandResponse Execute(ICommandExecutionContext context) { return new CommandResponseString(MessageProcessStatusFlags.Success, GetType().FullName + " executed successfully"); }
public void Handle(MoveUnitCommand command, ICommandExecutionContext context) { context.ModifyAttribute(this, x => x.Address, command.NewAddress); }
public Task Execute(PublishPost command, ICommandExecutionContext context) { throw new System.NotImplementedException(); }
public static IEnumerable <ObjectId> GetRelated <TCommand, TTarget, TValue>(this ICommandExecutionContext context, ITypedCommandHandler <TCommand, TTarget> handler, Expression <Func <TTarget, TValue> > propertyExpression) where TCommand : TypedCommand <TTarget> { return(context.GetRelated(GetRelationName(propertyExpression))); }
public void Handle(CreateHierarchyCommand command, ICommandExecutionContext context) { context.Create(this); }
public void Handle(DetachChildCommand command, ICommandExecutionContext context) { context.Detach(this, x => x.Children, command.ChildNodeId); }
public ICommandResponse Execute(ICommandExecutionContext context) { return(new CommandResponseString(MessageProcessStatusFlags.Success, GetType().FullName + " executed successfully")); }