public static void UploadParam <TResult, P1, P2, P3, P4>(this UpStreamItemController <TResult> controller, P1 param1, P2 param2, P3 param3, P4 param4) { controller.UploadParam <P1>(controller.streamingIds[0], param1); controller.UploadParam <P2>(controller.streamingIds[1], param2); controller.UploadParam <P3>(controller.streamingIds[2], param3); controller.UploadParam <P4>(controller.streamingIds[3], param4); }
public UpStreamItemController <TResult> GetUpStreamController <TResult>(string target, int paramCount, bool downStream = false) { Future <TResult> future = new Future <TResult>(); future.BeginProcess(); long invocationId = System.Threading.Interlocked.Increment(ref this.lastInvocationId); string[] streamIds = new string[paramCount]; for (int i = 0; i < paramCount; i++) { streamIds[i] = System.Threading.Interlocked.Increment(ref this.lastStreamId).ToString(); } var controller = new UpStreamItemController <TResult>(this, invocationId, streamIds, future); Action <Message> callback = (Message msg) => { switch (msg.type) { // StreamItem message contains only one item. case MessageTypes.StreamItem: { if (controller.IsCanceled) { break; } TResult item = (TResult)this.Protocol.ConvertTo(typeof(TResult), msg.item); future.AssignItem(item); break; } case MessageTypes.Completion: { bool isSuccess = string.IsNullOrEmpty(msg.error); if (isSuccess) { // While completion message must not contain any result, this should be future-proof if (!controller.IsCanceled && msg.result != null) { TResult result = (TResult)this.Protocol.ConvertTo(typeof(TResult), msg.result); future.AssignItem(result); } future.Finish(); } else { var ex = new Exception(msg.error); future.Fail(ex); } break; } } }; var messageToSend = new Message { type = downStream ? MessageTypes.StreamInvocation : MessageTypes.Invocation, invocationId = invocationId.ToString(), target = target, arguments = new object[0], streamIds = streamIds, nonblocking = false, }; SendMessage(messageToSend); this.invocations.Add(invocationId, new InvocationDefinition { callback = callback, returnType = typeof(TResult) }); return(controller); }
public static void UploadParam <TResult, P1, P2>(this UpStreamItemController <TResult> controller, P1 param1, P2 param2) { controller.UploadParam <P1>(controller.streamingIds[0], param1); controller.UploadParam <P2>(controller.streamingIds[1], param2); }
public static void UploadParam <TResult, P1>(this UpStreamItemController <TResult> controller, P1 item) { controller.UploadParam <P1>(controller.streamingIds[0], item); }