Esempio 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;
        }
Esempio 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;
        }
Esempio 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;
        }