예제 #1
0
            public void Call(params object[] args)
            {
                if (sent[0])
                {
                    return;
                }
                sent[0] = true;
                var log      = LogManager.GetLogger(GlobalHelper.CallerName());
                var jsonArgs = Packet.Args2JArray(args);

                log.Info(string.Format("sending ack {0}", args.Length != 0 ? jsonArgs.ToString() : "null"));

                var parserType = HasBinaryData.HasBinary(args) ? Parser.BINARY_ACK : Parser.ACK;
                var packet     = new Packet(parserType, jsonArgs);

                packet.Id = Id;
                socket.PacketProcess(packet);
            }
예제 #2
0
        public override Emitter Emit(string eventString, params object[] args)
        {
            var log = LogManager.GetLogger(GlobalHelper.CallerName());

            if (Events.Contains(eventString))
            {
                base.Emit(eventString, args);
                return(this);
            }

            var _args = new List <object> {
                eventString
            };

            _args.AddRange(args);

            var jsonArgs = Packet.Args2JArray(_args);

            var parserType = HasBinaryData.HasBinary(jsonArgs) ? Parser.BINARY_EVENT : Parser.EVENT;
            var packet     = new Packet(parserType, jsonArgs);

            var lastArg = _args[_args.Count - 1];

            if (lastArg is IAck)
            {
                log.Info(string.Format("emitting packet with ack id {0}", Ids));
                Acks.TryAdd(Ids, (IAck)lastArg);
                jsonArgs    = Packet.Remove(jsonArgs, jsonArgs.Count - 1);
                packet.Data = jsonArgs;
                packet.Id   = Ids++;
            }

            if (Connected)
            {
                log.Info(string.Format("Already connected for {0}... proceeding with packets", Ids));
                PacketProcess(packet);
            }
            else
            {
                log.Info(string.Format("NOT connected for {0}... adding packet to queue", Ids));
                SendBuffer.Enqueue(packet);
            }
            return(this);
        }