예제 #1
0
 public static void Upload <TResult, P1, P2, P3, P4>(this UploadItemController <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);
 }
예제 #2
0
        internal UploadItemController <TResult> Upload <TResult>(string target, int paramCount)
        {
            Future <TResult> future = new Future <TResult>();

            Action <Message> callback = (Message message) => {
                bool isSuccess = string.IsNullOrEmpty(message.error);
                if (isSuccess)
                {
                    future.Assign((TResult)this.Protocol.ConvertTo(typeof(TResult), message.result));
                }
                else
                {
                    future.Fail(new Exception(message.error));
                }
            };

            long invocationId = System.Threading.Interlocked.Increment(ref this.lastInvocationId);

            int[] streamIds = new int[paramCount];
            for (int i = 0; i < paramCount; i++)
            {
                streamIds[i] = System.Threading.Interlocked.Increment(ref this.lastStreamId);
            }

            var controller = new UploadItemController <TResult>(this, invocationId, streamIds, future);

            var messageToSend = new Message
            {
                type         = MessageTypes.Invocation,
                invocationId = invocationId.ToString(),
                target       = target,
                arguments    = new object[0],
                streamIds    = streamIds,
                nonblocking  = false,
            };

            SendMessage(messageToSend);

            this.invocations.Add(invocationId, callback);

            return(controller);
        }
예제 #3
0
 internal UploadChannel(UploadItemController <TResult> ctrl, int paramIdx)
 {
     this.Controller = ctrl;
     this.ParamIdx   = paramIdx;
 }
예제 #4
0
 public static void Upload <TResult, P1, P2>(this UploadItemController <TResult> controller, P1 param1, P2 param2)
 {
     controller.UploadParam <P1>(controller.streamingIds[0], param1);
     controller.UploadParam <P2>(controller.streamingIds[1], param2);
 }
예제 #5
0
 public static void Upload <TResult, P1>(this UploadItemController <TResult> controller, P1 item)
 {
     controller.UploadParam <P1>(controller.streamingIds[0], item);
 }
예제 #6
0
        internal UploadItemController <StreamItemContainer <TResult> > UploadStreamWithDownStream <TResult>(string target, int paramCount)
        {
            Future <StreamItemContainer <TResult> > future = new Future <StreamItemContainer <TResult> >();

            Action <Message> callback = (Message message) => {
                switch (message.type)
                {
                // StreamItem message contains only one item.
                case MessageTypes.StreamItem:
                {
                    StreamItemContainer <TResult> container = future.value;

                    if (container.IsCanceled)
                    {
                        break;
                    }

                    container.AddItem((TResult)this.Protocol.ConvertTo(typeof(TResult), message.item));

                    // (re)assign the container to raise OnItem event
                    future.AssignItem(container);
                    break;
                }

                case MessageTypes.Completion:
                {
                    bool isSuccess = string.IsNullOrEmpty(message.error);
                    if (isSuccess)
                    {
                        StreamItemContainer <TResult> container = future.value;

                        // While completion message must not contain any result, this should be future-proof
                        if (!container.IsCanceled && message.result != null)
                        {
                            TResult result = (TResult)this.Protocol.ConvertTo(typeof(TResult), message.result);

                            container.AddItem(result);
                        }

                        future.Assign(container);
                    }
                    else
                    {
                        future.Fail(new Exception(message.error));
                    }
                    break;
                }
                }
            };

            long invocationId = System.Threading.Interlocked.Increment(ref this.lastInvocationId);

            int[] streamIds = new int[paramCount];
            for (int i = 0; i < paramCount; i++)
            {
                streamIds[i] = System.Threading.Interlocked.Increment(ref this.lastStreamId);
            }

            var controller = new UploadItemController <StreamItemContainer <TResult> >(this, invocationId, streamIds, future);

            var messageToSend = new Message
            {
                type         = MessageTypes.StreamInvocation,
                invocationId = invocationId.ToString(),
                target       = target,
                arguments    = new object[0],
                streamIds    = streamIds,
                nonblocking  = false,
            };

            SendMessage(messageToSend);

            this.invocations.Add(invocationId, callback);

            future.BeginProcess(new StreamItemContainer <TResult>(invocationId));
            return(controller);
        }