예제 #1
0
        private void _hwsClient_DataReceived(object sender, DataReceivedEventArgs e)
        {
            var strMsg = Encoding.UTF8.GetString(GZip.Decompress(e.Data));

            if (strMsg.Contains("state.update") || strMsg.Contains("state.updateall") || strMsg.Contains("pong"))
            {
                return;
            }

            if (strMsg.Contains("status") && strMsg.Contains("success"))
            {
                var updateModel = JSONHelper.ConvertToObject <HotbitUpdateModel>(strMsg);
                if (updateModel.id == SUB_REQ_ID)
                {
                    OnConnectionOpened?.Invoke(this, this.SubItemName);
                }
                else if (updateModel.id == SUB_AUTH_ID)
                {
                    var authModel = this.SubModel as AuthSubscribeModel;
                    authModel.reqList.ForEach(p => _hwsClient.Send(p.ToJson()));
                }
                return;
            }

            //_logger.Info($"recieve@{strMsg}@{Title}");

            if (this.SubscribeType == "ASSET" && strMsg.Contains("result"))
            {
                strMsg = strMsg.Replace("error", "method").Replace("null", "\"asset.update\"").Replace("result", "params");
                strMsg = strMsg.Replace("\"params\":", "\"params\":[").Replace("}}", "}}]");
                strMsg = strMsg.Replace("}, ", "}},{");
            }

            OnRecieveMessage?.Invoke(this, strMsg);
        }
예제 #2
0
 // call when client connect to server successful
 static void ConnectionOpened(Connection connection)
 {
     Unity.Console.DebugLog("Connected to", connection.FullUrl);
     if (!OnConnectionOpened.IsNull())
     {
         OnConnectionOpened(connection);
     }
 }
예제 #3
0
 void ConnectionOpened(Response response)
 {
     Unity.Console.DebugLog("ApiManager class", Unity.Console.SetMagentaColor("Regular Callback:"), "ConnectionOpened()");
     InitializeApi(LoginApi.Create(this));
     response.SendResultData <string>(url => {
         if (OnConnectionOpened != null)
         {
             OnConnectionOpened.Invoke(url);
         }
     });
 }
예제 #4
0
        public void OpenConnection(string ip)
        {
            socket = IO.Socket(String.IsNullOrEmpty(ip) ? CONNECTION_URL + ":" + CONNECTION_PORT : "http://" + ip);
            socket.On(Socket.EVENT_CONNECT, () =>
            {
                socket.Emit("connection", "AudioLightClient");
                OnConnectionOpened.Invoke(this, new EventArgs());
            });

            socket.On(Socket.EVENT_CONNECT_ERROR, () =>
            {
                OnFailedConnection.Invoke(this, new EventArgs());
            });
        }
예제 #5
0
 public void OpenConnection(string port)
 {
     try
     {
         serialPort.PortName = String.IsNullOrEmpty(port) ? PORT_NAME : port;
         serialPort.Open();
         OnConnectionOpened?.Invoke(this, new EventArgs());
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         OnFailedConnection?.Invoke(this, new EventArgs());
     }
 }
예제 #6
0
 private void OpenConnection()
 {
     if (connection == null)
     {
         connection = CreateConnection();
     }
     if (connection.State != ConnectionState.Open)
     {
         connection.ConnectionString = ConnectionString;
         connection.Open();
         if (!Schema.IsEmpty())
         {
             SetSchema(connection, Schema);
         }
         OnConnectionOpened?.Invoke(this);
     }
 }
예제 #7
0
 private void ConnectionOpened(Response response)
 {
     CustomTools.Console.DebugLog("EchoApiManager class", CustomTools.Console.LogMagentaColor("Regular Callback:"), "ConnectionOpened()");
     InitializeApi(LoginApi.Create(this));
     response.SendResultData <string>(url => OnConnectionOpened.SafeInvoke(url), null);
 }
예제 #8
0
 protected override void OnOpen()
 {
     OnConnectionOpened?.Invoke(this);
 }
 // call when client connect to server successful
 private static void ConnectionOpened(Connection connection)
 {
     CustomTools.Console.DebugLog("Connected to", connection.FullUrl);
     OnConnectionOpened.SafeInvoke(connection);
 }