コード例 #1
0
        /// <summary cref="Notify(string, object, int)">
        /// </summary>
        public void Notify(string route, object msg, int timeout = -1)
        {
            IPitayaSerializer serializer = SerializerFactory.CreateJsonSerializer();

            if (msg is IMessage)
            {
                serializer = SerializerFactory.CreateProtobufSerializer(_binding.ClientSerializer(_client));
            }
            NotifyInternal(route, msg, serializer, timeout);
        }
コード例 #2
0
        /// <summary cref="Request&lt;TResponse&gt;(string, object, Action&lt;TResponse&gt;, Action&lt;PitayaError&gt;, int)">
        /// </summary>
        public void Request <TResponse>(string route, object msg, Action <TResponse> action, Action <PitayaError> errorAction, int timeout = -1)
        {
            IPitayaSerializer serializer = SerializerFactory.CreateJsonSerializer();

            if (msg is IMessage)
            {
                serializer = SerializerFactory.CreateProtobufSerializer(_binding.ClientSerializer(_client));
            }
            RequestInternal(route, msg, timeout, serializer, action, errorAction);
        }
コード例 #3
0
        /// <summary cref="OnRoute&lt;T&gt;(string, Action&lt;T&gt;)">
        /// </summary>
        public void OnRoute <T>(string route, Action <T> action)
        {
            IPitayaSerializer serializer = SerializerFactory.CreateJsonSerializer();

            if (typeof(IMessage).IsAssignableFrom(typeof(T)))
            {
                serializer = SerializerFactory.CreateProtobufSerializer(_binding.ClientSerializer(_client));
            }

            OnRouteInternal(route, action, serializer);
        }
コード例 #4
0
        private void OnRouteInternal <T>(string route, Action <T> action, IPitayaSerializer serializer)
        {
            Action <byte[]> responseAction = res => { action(serializer.Decode <T>(res)); };

            _eventManager.AddOnRouteEvent(route, responseAction);
        }
コード例 #5
0
 private void NotifyInternal(string route, object msg, IPitayaSerializer serializer, int timeout = -1)
 {
     _binding.Notify(_client, route, serializer.Encode(msg), timeout);
 }
コード例 #6
0
        void RequestInternal <TResponse, TRequest>(string route, TRequest msg, int timeout, IPitayaSerializer serializer, Action <TResponse> action, Action <PitayaError> errorAction)
        {
            _reqUid++;

            Action <byte[]> responseAction = res => { action(serializer.Decode <TResponse>(res)); };

            _eventManager.AddCallBack(_reqUid, responseAction, errorAction);

            _binding.Request(_client, route, serializer.Encode(msg), _reqUid, timeout);
        }