Ejemplo n.º 1
0
        public static MiqiMessage BuildFromString(string message)
        {
            string command;
            string protocol = "";

            string[] lines = message.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            if (lines.Length <= 0)
                throw new ArgumentException("Invalid Miqi message");

            string[] cmds = lines[0].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (cmds.Length <= 0)
                throw new ArgumentException("No message command");

            command = cmds[0].Trim().ToUpper();
            if (command.Length == 0)
                throw new ArgumentException("No message command");

            if (cmds.Length > 1)
                protocol = cmds[1].Trim().ToUpper();

            if (protocol.Length == 0)
                protocol = MiqiMessage.DEFAULT_MIQI_PROTOCOL;

            MiqiMessage miqiMsg = new MiqiMessage(command, protocol);

            for (int i = 1; i < lines.Length; i++)
            {
                int index = lines[i].IndexOf(':');
                if (index > 0) {
                    string left = lines[i].Substring(0, index).Trim();
                    string right = lines[i].Substring(index + 1).Trim();
                    miqiMsg.AddHeader(left, right);
                }
            }

            return miqiMsg;
        }
Ejemplo n.º 2
0
        public static MiqiMessage BuildGetSeverInfoResponse(string hosts, int port, string clientId)
        {
            MiqiMessage miqiMsg = new MiqiMessage(MiqiMessage.GET_SERVER_INFO_RESP,
                                    MiqiMessage.DEFAULT_MIQI_PROTOCOL);

            miqiMsg.AddHeader("Hosts", hosts);
            miqiMsg.AddHeader("Port", "" + port);
            miqiMsg.AddHeader("ClientId", clientId);

            return miqiMsg;
        }
Ejemplo n.º 3
0
        public static MiqiMessage BuildSetCredential(MiqiMessage message)
        {
            MiqiMessage miqiMsg = new MiqiMessage(MiqiMessage.SET_CREDENTIAL,
                                    MiqiMessage.DEFAULT_MIQI_PROTOCOL);

            miqiMsg.AddHeader("UserName", message.GetHeader("UserName"));
            miqiMsg.AddHeader("Password", message.GetHeader("Password"));

            return miqiMsg;
        }
 public void HandleMessage(WebSocketClient client, MiqiMessage message)
 {
     MiqiMessageHandler msgDelegate = messageHandlers[message.Command];
     msgDelegate(client, message);
 }
Ejemplo n.º 5
0
 private void HandleSetCredentialMessage(WebSocketClient client, MiqiMessage message)
 {
     string reqClientId = message.GetHeader("ClientId");
     WebSocketClient reqClient = m_server.GetClientById(reqClientId);
     if (reqClient != null) {
         reqClient.Send(MiqiMessage.BuildSetCredential(message).ToString());
         client.Disconnect();
     } else {
         m_logForm.Log("Cannot find the client: {0}", reqClientId);
     }
 }
Ejemplo n.º 6
0
 private void HandleGetServerInfoMessage(WebSocketClient client, MiqiMessage message)
 {
     MiqiMessage resp = MiqiMessage.BuildGetSeverInfoResponse(m_ipAddresses, m_port, client.Id);
     client.Send(resp.ToString());
 }