Example #1
0
 public void Send(INotMsg msg) {
   Request req;
   //Response resp;
   if((req = msg as Request) != null) {
     string header;
     if(req.msgId == -1) {
       header = "42";
     } else {
       req.msgId = System.Threading.Interlocked.Increment(ref _respCnt);
       lock(_reqs) {
         _reqs.AddFirst(req);
       }
       header = "42" + req.msgId.ToString();
     }
     this.Send(header + JSL.JSON.stringify(req.data, null, null));
   //} else if((resp = msg as Response) != null) {
   //  if(resp.req == null) {
   //    throw new ArgumentNullException("msg.req");
   //  }
   //  if(resp.req.msgId == -1) {
   //    return;         // response is not required
   //  }
   //  this.Send((resp.error?"44":"43") + resp.req.msgId.ToString() + JSL.JSON.stringify(resp.data, null, null));
   } else {
     throw new ArgumentException("msg");
   }
 }
Example #2
0
 public void Publish(string path, JSC.JSValue value, INotMsg req) {
   var arr = new JSL.Array(3);
   arr[0] = 6;
   arr[1] = path;
   arr[2] = value;
   this.Send(new SioClient.Request(0, arr, req));
 }
Example #3
0
 public void Request(string path, int mask, INotMsg req) {
   var arr = new JSL.Array(3);
   arr[0] = 4;
   arr[1] = path;
   arr[2] = mask;
   this.Send(new SioClient.Request(0, arr, req));
 }
Example #4
0
 internal static void PostMsg(INotMsg msg)
 {
     _msgs.Enqueue(msg);
     if (_msgProcessBusy == 1)
     {
         mainWindow.Dispatcher.BeginInvoke(_msgProcessFunc, System.Windows.Threading.DispatcherPriority.DataBind);
     }
 }
Example #5
0
 internal void Create(string path, string schemaName, JSC.JSValue value, INotMsg req) {
   JSL.Array arr;
   arr = new JSL.Array(value == null?3:4);
   arr[0] = 8;
   arr[1] = path;
   arr[2] = schemaName;
   if(value != null) {
     arr[3] = value;
   }
   this.Send(new SioClient.Request(0, arr, req));
 }
Example #6
0
        public void SendReq(int cmd, INotMsg req, params JSC.JSValue[] arg)
        {
            int mid = Interlocked.Increment(ref _msgId);
            var arr = new JSL.Array(arg.Length + 2);

            arr[0] = cmd;
            arr[1] = mid;
            for (int i = 0; i < arg.Length; i++)
            {
                arr[i + 2] = arg[i] ?? JSC.JSValue.Undefined;
            }
            this.Send(new ClRequest(mid, arr, req));
        }
Example #7
0
 private void Send(INotMsg msg) {
   lock(_connEvnt) {
     if(_st == State.Ready) {
       _sio.Send(msg);
     } else if(_st == State.BadAuth) {
       var arr = new JSL.Array(2);
       arr[0] = url.ToString();
       arr[1] = "Bad username or password";
       msg.Response(null, false, arr);
       DWorkspace.This.AddMsg(msg);
     } else {
       _connEvnt.Add(new WaitConnect(msg, this));
     }
   }
 }
Example #8
0
 private void Send(INotMsg msg)
 {
     if (Status == ClientState.Ready)
     {
         ClRequest req;
         if ((req = msg as ClRequest) != null)
         {
             if (req.msgId >= 0)
             {
                 lock (_reqs) {
                     _reqs.AddFirst(req);
                 }
             }
             _socket.SendArr(req.data);
         }
         else
         {
             throw new ArgumentException("msg");
         }
     }
     else if (Status == ClientState.BadAuth)
     {
         msg.Response(false, new JSL.Array {
             this.ToString(), "Bad username or password"
         });
         App.PostMsg(msg);
     }
     else
     {
         lock (_connEvnt) {
             _connEvnt.Add(new WaitConnect(msg, this));
         }
         if (Status == ClientState.Idle || Status == ClientState.Offline)
         {
             this.Connect();
         }
     }
 }
Example #9
0
 public void AddMsg(INotMsg msg) {
   _msgs.Enqueue(msg);
 }
Example #10
0
 public WaitConnect(INotMsg req, Client client)
 {
     _req    = req;
     _client = client;
 }
Example #11
0
 public ClRequest(int msgId, JSL.Array jo, INotMsg req)
 {
     this.msgId = msgId;
     this.data  = jo;
     this._req  = req;
 }
Example #12
0
 public Request(long msgId, JSL.Array jo, INotMsg req) {
   this.msgId = msgId;
   this.data = jo;
   this._req = req;
 }
Example #13
0
 private void ProcessMessage(SioClient.Event e, INotMsg msg) {
   switch(e) {
   case SioClient.Event.Connected:
     if(string.IsNullOrEmpty(url.UserInfo)) {
       _st = State.Ready;
       ReportConnectState(true, null);
     }
     break;
   case SioClient.Event.Disconnected:
     break;
   case SioClient.Event.Ack:
   case SioClient.Event.Error:
     if(msg != null) {
       DWorkspace.This.AddMsg(msg);
     }
     break;
   case SioClient.Event.Event: {
       var ev = msg as DTopic.Event;
       if(ev != null) {
         ev.client = this;
         DWorkspace.This.AddMsg(ev);
       }
     }
     break;
   }
 }
Example #14
0
 public WaitConnect(INotMsg req, A04Client client) {
   _req = req;
   _client = client;
 }