示例#1
0
        private void CallMethod(Context context)
        {
            if (!context.ChannelStore.Methods.ContainsKey(context.MethodId))
            {
                //TODO: tratar
                return;
            }

            var methodInfo = context.ChannelStore.Methods[context.MethodId];
            var parms      = new List <object>();

            foreach (var param in methodInfo.Params)
            {
                parms.Add(param.Read(context.Msg));
            }

            var data = new ThreadLocal <Context>();

            data.Value = context;

            var channel = context.ChannelStore.GetChannelInstance();

            if (methodInfo.Return == null)
            {
                try
                {
                    methodInfo.Method.Invoke(channel, parms.ToArray());
                }
                catch (Exception err)
                {
                    //TODO: tratar
                }
            }
            else
            {
                try
                {
                    var ret   = methodInfo.Method.Invoke(channel, parms.ToArray());
                    var write = new MessageWriter();
                    write.WriteUInt16(context.ChannelId);
                    write.WriteUInt16(context.MethodId);
                    methodInfo.Return.Write(write, ret);
                    context.WebSocket.SendMessage(write.GetBytes());
                }
                catch (Exception err)
                {
                    //TODO: tratar
                }
            }
        }
示例#2
0
        /// <summary>
        /// Serializes this instance.
        /// </summary>
        /// <returns>The string representing this message.</returns>
        public static byte[] Serialize(params BackplaneMessage[] messages)
        {
            NotNullOrEmpty(messages, nameof(messages));

            // calc size
            var size = 0;

            for (var i = 0; i < messages.Length; i++)
            {
                size += MessageWriter.GetEstimatedSize(messages[i], i != 0);
            }

            var writer = new MessageWriter(size);

            for (var i = 0; i < messages.Length; i++)
            {
                SerializeMessage(writer, messages[i], i != 0);
            }

            return(writer.GetBytes());
        }