Ejemplo n.º 1
0
        //----------------------------------------------------------------------------------------------------
        // return message format

        void Send(string id, string msg, string data)
        {
            var sb = new StringBuilder();

            sb.Append("{");

            if (String.IsNullOrEmpty(id) == false)
            {
                sb.AppendFormat(@"""id"":{0},", JsonTypeConverters.EscapedString(id));
            }

            sb.AppendFormat(@"""{0}"":{1}", msg, data);

            sb.Append("}");

            mSocket.SendAsync(sb.ToString());
        }
Ejemplo n.º 2
0
        // unbind an event

        public void Unbind(string id)
        {
            var num = mListeners.Count;

            if (id == "*")
            {
                mListeners.ForEach(i => i.Unbind());
                mListeners.Clear();
            }
            else
            {
                mListeners.ForEach(i => { if (i.Message.id == id)
                                          {
                                              i.Unbind();
                                          }
                                   });
                mListeners.RemoveAll(i => i.Message.id == id);
            }

            if (mListeners.Count == num)
            {
                Send(id, "error", JsonTypeConverters.EscapedString("not found"));
            }
        }
Ejemplo n.º 3
0
        //----------------------------------------------------------------------------------------------------
        // handler interface

        // stop a repeater

        public void Stop(string id)
        {
            var num = mRepeaters.Count;

            if (id == "*")
            {
                mRepeaters.ForEach(r => r.Cancel());
                mRepeaters.Clear();
            }
            else
            {
                mRepeaters.ForEach(s => { if (s.ID == id)
                                          {
                                              s.Cancel();
                                          }
                                   });
                mRepeaters.RemoveAll(s => s.IsFinished);
            }

            if (mRepeaters.Count == num)
            {
                Send(id, "error", JsonTypeConverters.EscapedString("not found"));
            }
        }
Ejemplo n.º 4
0
 public void Error(ResponseCode code)
 {
     Socket.Send(id, "error", JsonTypeConverters.EscapedString(HttpUtils.CodeToString(code)));
 }
Ejemplo n.º 5
0
 public void Info(string msg)
 {
     Socket.Send(id, "info", JsonTypeConverters.EscapedString(msg));
 }
Ejemplo n.º 6
0
 public void Info(string msg)
 {
     SendImpl(ID, "info", JsonTypeConverters.EscapedString(msg));
 }