コード例 #1
0
        private long InvokeImp(string target, object[] args, Action <Messages.Message> callback, bool isStreamingInvocation = false)
        {
            if (this.State != ConnectionStates.Connected)
            {
                throw new Exception("Not connected yet!");
            }

            long invocationId = System.Threading.Interlocked.Increment(ref this.lastInvocationId);
            var  message      = new Messages.Message
            {
                type         = isStreamingInvocation ? Messages.MessageTypes.StreamInvocation : Messages.MessageTypes.Invocation,
                invocationId = invocationId.ToString(),
                target       = target,
                arguments    = args,
                nonblocking  = callback == null,
            };

            SendMessage(message);

            if (callback != null)
            {
                this.invocations.Add(invocationId, callback);
            }

            return(invocationId);
        }
コード例 #2
0
        public void CancelStream <T>(StreamItemContainer <T> container)
        {
            Messages.Message message = new Messages.Message {
                type         = Messages.MessageTypes.CancelInvocation,
                invocationId = container.id.ToString()
            };

            container.IsCanceled = true;

            SendMessage(message);
        }
コード例 #3
0
    /// <summary>
    /// This callback is called for every hub message. If false is returned, the plugin will cancel any further processing of the message.
    /// </summary>
    private bool Hub_OnMessage(HubConnection hub, BestHTTP.SignalRCore.Messages.Message message)
    {
        //UnityEngine.Debug.Log("Message Arrived: " + message.ToString());

        return(true);
    }
コード例 #4
0
        private void MessageArrived(Messages.Message message)
        {
            try
            {
                if (this.OnMessage != null && !this.OnMessage(this, message))
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                HTTPManager.Logger.Exception("HubConnection", "MessageArrived - OnMessage", ex);
            }

            try
            {
                switch (message.type)
                {
                case Messages.MessageTypes.Invocation:
                {
                    Subscription subscribtion = null;
                    if (this.subscriptions.TryGetValue(message.target, out subscribtion))
                    {
                        for (int i = 0; i < subscribtion.callbacks.Count; ++i)
                        {
                            var callbackDesc = subscribtion.callbacks[i];

                            var realArgs = this.Protocol.GetRealArguments(callbackDesc.ParamTypes, message.arguments);

                            callbackDesc.Callback.Invoke(realArgs);
                        }
                    }

                    break;
                }

                case Messages.MessageTypes.StreamItem:
                {
                    long invocationId;
                    if (long.TryParse(message.invocationId, out invocationId))
                    {
                        Action <Messages.Message> callback;
                        if (this.invocations.TryGetValue(invocationId, out callback) && callback != null)
                        {
                            callback(message);
                        }
                    }
                    break;
                }

                case Messages.MessageTypes.Completion:
                {
                    long invocationId;
                    if (long.TryParse(message.invocationId, out invocationId))
                    {
                        Action <Messages.Message> callback;
                        if (this.invocations.TryGetValue(invocationId, out callback) && callback != null)
                        {
                            callback(message);
                        }
                        this.invocations.Remove(invocationId);
                    }
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                HTTPManager.Logger.Exception("HubConnection", "MessageArrived", ex);
            }
        }
コード例 #5
0
 private void SendMessage(Messages.Message message)
 {
     byte[] encoded = this.Protocol.EncodeMessage(message);
     this.Transport.Send(encoded);
 }