private Tuple <ICommandOperation, ISubscriptionOperation, RESPObject[]> Pack <T>(ExecutionPlan plan, T parameters) where T : class { var respCommand = plan.Bind(parameters); var responsesPlaceholder = new RESPObject[respCommand.Length]; ICommandOperation commandOperation = null; ISubscriptionOperation subOp = null; var hasSubscriptions = false; var hasCommands = false; IdentifyOperationMainRoute(respCommand, ref hasCommands, ref hasSubscriptions); if (!hasCommands && !hasSubscriptions) { throw new RedisClientParsingException("The given RESP commands do not contain Redis commands."); } if (hasCommands) { commandOperation = new CommandOperation(respCommand, responsesPlaceholder, _procedures); } if (hasSubscriptions) { if (_subscriber == null) { _subscriber = _subscribers.Provide(); } subOp = new SubscriptionOperation(this, respCommand, responsesPlaceholder, _subscriber.Subscriptions); } return(new Tuple <ICommandOperation, ISubscriptionOperation, RESPObject[]>(commandOperation, subOp, responsesPlaceholder)); }
internal ExecutionToken(ICommandOperation commandOperation, ISubscriptionOperation subscriptionOperation) { Contract.Assert(commandOperation != null || subscriptionOperation != null, "In ExecutionToken both operations cannot be null."); CommandOperation = commandOperation; SubscriptionOperation = subscriptionOperation; if (commandOperation != null) { _signalingsNeeded++; } if (subscriptionOperation != null) { _signalingsNeeded++; } }
public void Enqueue(ICommandOperation operation) { _commandOperations.Enqueue(operation); }
internal CommandBlock(string tag, TInput input, TState state, IStackEvents <TOperationEvent> stackEvents, ICommandOperation <TOperationEvent> commandOperation) : base(tag, input, state, stackEvents) { if (commandOperation.SupportsAsync && commandOperation.PreferAsync) { executor = () => { ICommandResult <TOperationEvent> r; if (commandOperation is ICommandOperationWithState <TState, TOperationEvent> operationWithState) { r = operationWithState.Execute(state); } else { r = commandOperation.Execute(); } this.Append(r); return(resultDispatcher.Return()); } } ; else { executorAsync = async() => { ICommandResult <TOperationEvent> r; if (commandOperation is ICommandOperationWithState <TState, TOperationEvent> operationWithState) { r = operationWithState.Execute(state); } else { r = await commandOperation.ExecuteAsync().ConfigureAwait(false); } this.Append(r); return(resultDispatcher.Return()); } }; } //internal CommandBlock(string tag, TInput input, TState state, IStackEvents<TOperationEvent> stackEvents, ICommandOperationWithState<TState, TOperationEvent> commandOperation) // : base(tag, input, state, stackEvents) //{ // if (commandOperation.SupportsAsync && commandOperation.PreferAsync) // executor = () => { var r = commandOperation.Execute(state); this.Append(r); this.StackState = (TState)r.StackState; return resultDispatcher.Return(); }; // else // executorAsync = async () => { var r = await commandOperation.ExecuteAsync(state).ConfigureAwait(false); this.Append(r); this.StackState = (TState)r.StackState; return resultDispatcher.Return(); }; //} BlockResultVoid IResultVoidDispatcher <TState> .Fail() { return(resultDispatcher.Fail()); } BlockResultVoid IResultVoidDispatcher <TState> .Fail(OperationEvent error) { return(resultDispatcher.Fail(error)); } BlockResultVoid IResultVoidDispatcher <TState> .Complete() { return(resultDispatcher.Complete()); } BlockResultVoid IResultVoidDispatcher <TState> .Complete(object overrideResult) { return(resultDispatcher.Complete(overrideResult)); } BlockResultVoid IResultVoidDispatcher <TState> .Reset() { return(resultDispatcher.Reset()); } BlockResultVoid IResultVoidDispatcher <TState> .Reset(TState state) { return(resultDispatcher.Reset(state)); } BlockResultVoid IResultVoidDispatcher <TState> .Restart() { return(resultDispatcher.Restart()); } BlockResultVoid IResultVoidDispatcher <TState> .Return() { return(resultDispatcher.Return()); } BlockResultVoid IResultVoidDispatcher <TState> .Goto(string tag) { return(resultDispatcher.Goto(tag)); } BlockResultVoid IResultVoidDispatcher <TState> .Goto(string tag, object overrideInput) { return(resultDispatcher.Goto(tag, overrideInput)); } BlockResultVoid IResultVoidDispatcher <TState> .Goto(int index) { return(resultDispatcher.Goto(index)); } BlockResultVoid IResultVoidDispatcher <TState> .Goto(int index, object overrideInput) { return(resultDispatcher.Goto(index, overrideInput)); } BlockResultVoid IResultVoidDispatcher <TState> .Skip(int i) { return(resultDispatcher.Skip(i)); } BlockResultVoid IResultVoidDispatcher <TState> .Skip(int i, object overrideInput) { return(resultDispatcher.Skip(i, overrideInput)); } BlockResultVoid IResultVoidDispatcher <TState> .Retry() { return(resultDispatcher.Retry()); } BlockResultVoid IResultVoidDispatcher <TState> .Retry(object overrideInput) { return(resultDispatcher.Retry(overrideInput)); } }
internal SyncExecutionToken(ICommandOperation commandOperation, ISubscriptionOperation subscriptionOperation) : base(commandOperation, subscriptionOperation) { _reset = new ManualResetEventSlim(false); }
internal AsyncExecutionToken(ICommandOperation commandOperation, ISubscriptionOperation subscriptionOperation) : base(commandOperation, subscriptionOperation) { _completion = new TaskCompletionSource <Object>(); }
public StackBlockSpecBase <TInput, TState, TOperationEvent> BuildCommand <Tin>(string tag, int index, ICommandOperation <TOperationEvent> operation) { tag = HandleOperationTagName(tag, index); return(new StackBlockSpecOperation <TInput, TState, TOperationEvent, Tin>(tag, index, (TInput stackInput, TState state, IStackEvents <TOperationEvent> stackEvents, IEmptyable input) => new CommandBlock <TInput, TState, TOperationEvent, Tin>(tag, stackInput, state, stackEvents, input.ConvertTo <Tin>(), operation), BlockSpecTypes.Operation)); }
internal NoWaitExecutionToken(ICommandOperation commandOperation, ISubscriptionOperation subscriptionOperation) : base(commandOperation, subscriptionOperation) { }