Ejemplo n.º 1
0
 private EventArguments(SIO_Connection conn, long msgId, JSL.Array req) {
   this._conn=conn;
   this._msgId=msgId;
   this._request=req;
   this.Count=req.Count();
 }
Ejemplo n.º 2
0
 public static bool ParseEvent(SIO_Connection conn, string msg) {
   string sb;
   string tmpS;
   long msgId;
   int idx=msg.IndexOf('[', 2);
   if(idx<3 || !long.TryParse(msg.Substring(2, idx-2), out msgId)) {
     msgId=-1;
   }
   tmpS=msg.Substring(idx);
   sb=conn.ToString()+"\n  REQ  : "+tmpS;
   var jo=JSL.JSON.parse(tmpS, _JSON_Replacer) as JSL.Array;
   if(jo==null) {
     return false;
   }
   Action<EventArguments> f;
   lock(conn._events) {
     if(!conn._events.TryGetValue(JSL.JSON.stringify(jo[0], null, null), out f)) {
       f=null;
     }
   }
   if(f==null) {
     tmpS=string.Concat(msgId<0?string.Empty:msgId.ToString(), "[\"Not found\",", JSL.JSON.stringify(jo[0], null, null), "]");
     conn.Send("44"+tmpS);
     X13.Log.Warning("{0}ERROR: {1}", sb, tmpS);
     return false;
   }
   EventArguments ea=new EventArguments(conn, msgId, jo);
   try {
     f(ea);
     if(ea._msgId >= 0 || (ea._error && ea._response != null)) {
       tmpS = ea._response == null ? "[]" : JSL.JSON.stringify(ea._response, null, null);
       conn.Send(string.Concat("4", ea._error ? "4" : "3", msgId < 0 ? string.Empty : msgId.ToString(), tmpS));
       if(ea._error) {
         X13.Log.Warning("{0}\n  ERROR: {1}", sb, tmpS);
       } else {
         X13.Log.Debug("{0}\n  RESP : {1}", sb, tmpS);
       }
     } else {
       X13.Log.Debug("{0}", sb, tmpS);
     }
   }
   catch(Exception ex) {
     tmpS="[\"Internal error\"," + JSL.JSON.stringify(jo[0], null, null) + "]";
     conn.Send(string.Concat("44", msgId<0?string.Empty:msgId.ToString(), tmpS));
     X13.Log.Warning("{0}EXCEPTION: {1}", sb.ToString(), ex.ToString());
   }
   return true;
 }