//===========================[ History Messages Utilities ]=========================//
        private HistoryMessageResult BuildHistoryMessageResult(Answer answer)
        {
            HistoryMessageResult result = new HistoryMessageResult();

            result.count     = answer.Want <int>("num");
            result.lastId    = answer.Want <long>("lastid");
            result.beginMsec = answer.Want <long>("begin");
            result.endMsec   = answer.Want <long>("end");
            result.messages  = new List <HistoryMessage>();

            List <object> messages = (List <object>)answer.Want("msgs");

            foreach (List <object> items in messages)
            {
                bool deleted = (bool)Convert.ChangeType(items[4], TypeCode.Boolean);
                if (deleted)
                {
                    continue;
                }

                HistoryMessage message = new HistoryMessage();
                message.id      = (long)Convert.ChangeType(items[0], TypeCode.Int64);
                message.fromUid = (long)Convert.ChangeType(items[1], TypeCode.Int64);
                message.mtype   = (byte)Convert.ChangeType(items[2], TypeCode.Byte);
                message.mid     = (long)Convert.ChangeType(items[3], TypeCode.Int64);

                if (message.mtype == MessageMType_Audio)
                {
                    if (CheckBinaryType(items[5]))
                    {
                        message.binaryMessage = (byte[])items[5];
                    }
                    else
                    {
                        message.binaryMessage = ConvertStringToByteArray((string)Convert.ChangeType(items[5], TypeCode.String));
                    }
                }
                else
                {
                    if (!CheckBinaryType(items[5]))
                    {
                        message.stringMessage = (string)Convert.ChangeType(items[5], TypeCode.String);
                    }
                    else
                    {
                        message.binaryMessage = (byte[])items[5];
                    }
                }

                message.attrs = (string)Convert.ChangeType(items[6], TypeCode.String);
                message.mtime = (long)Convert.ChangeType(items[7], TypeCode.Int64);

                result.messages.Add(message);
            }
            result.count = result.messages.Count;
            return(result);
        }
예제 #2
0
        /*
         * internal static byte[] ConvertStringToByteArray(string data)
         * {
         *  //-- Please refer com.fpnn.msgpack.MsgPacker::UnpackString(...)
         *
         *  UTF8Encoding utf8Encoding = new UTF8Encoding(false, true);     //-- NO BOM.
         *  return utf8Encoding.GetBytes(data);
         * }
         */

        //===========================[ History Messages Utilities ]=========================//
        private HistoryMessageResult BuildHistoryMessageResult(long toId, Answer answer)
        {
            HistoryMessageResult result = new HistoryMessageResult();

            result.count        = answer.Want <int>("num");
            result.lastCursorId = answer.Want <long>("lastid");
            result.beginMsec    = answer.Want <long>("begin");
            result.endMsec      = answer.Want <long>("end");
            result.messages     = new List <HistoryMessage>();

            List <object> messages = (List <object>)answer.Want("msgs");

            foreach (List <object> items in messages)
            {
                bool deleted = (bool)Convert.ChangeType(items[4], TypeCode.Boolean);
                if (deleted)
                {
                    continue;
                }

                HistoryMessage message = new HistoryMessage();
                message.cursorId    = (long)Convert.ChangeType(items[0], TypeCode.Int64);
                message.fromUid     = (long)Convert.ChangeType(items[1], TypeCode.Int64);
                message.toId        = toId;
                message.messageType = (byte)Convert.ChangeType(items[2], TypeCode.Byte);
                message.messageId   = (long)Convert.ChangeType(items[3], TypeCode.Int64);

                if (!CheckBinaryType(items[5]))
                {
                    message.stringMessage = (string)Convert.ChangeType(items[5], TypeCode.String);
                }
                else
                {
                    message.binaryMessage = (byte[])items[5];
                }

                message.attrs        = (string)Convert.ChangeType(items[6], TypeCode.String);
                message.modifiedTime = (long)Convert.ChangeType(items[7], TypeCode.Int64);

                if (message.messageType >= 40 && message.messageType <= 50)
                {
                    RTMClient.BuildFileInfo(message, errorRecorder);
                }

                result.messages.Add(message);
            }
            result.count = result.messages.Count;
            return(result);
        }