Example #1
0
        public void WriteFile(ChatHistoryData data)
        {
            if (!Directory.Exists(folderName))
            {
                Directory.CreateDirectory(folderName);
            }

            string folderNameWithID = folderName + "//" + data.id;

            if (!Directory.Exists(folderNameWithID))
            {
                Directory.CreateDirectory(folderNameWithID);
            }

            if (data == null)
            {
                return;
            }

            System.DateTime dt       = EB.Time.FromPosixTime(data.ts).ToLocalTime();
            string          fileName = dt.ToString("yyyyMMdd");

            EB.Debug.Log("write yyyymmdd format fileName={0}", fileName);
            FileStream   fs = new FileStream(folderNameWithID + "//" + fileName, FileMode.Append);
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(System.Text.Encoding.UTF8.GetByteCount(data.content));
            bw.Write(System.Text.Encoding.UTF8.GetBytes(data.content));
            bw.Close();
            fs.Close();
            fs.Dispose();

            EB.Debug.Log("WriteFile targetId={0}--------over", data.id);
        }
Example #2
0
 public void SaveData(EB.Sparx.ChatMessage msg)
 {
     if (AddChatHistory(msg))
     {
         ChatHistoryData hd = new ChatHistoryData();
         hd.id      = LTChatManager.Instance.GetTargetId(msg.uid, msg.privateUid);
         hd.content = EB.JSON.Stringify(msg.json);
         hd.ts      = msg.ts;
         SaveData(hd);
     }
 }
Example #3
0
        public List <ChatHistoryData> ReadFile(Queue <string> fileNames)
        {
            List <ChatHistoryData> dataList = new List <ChatHistoryData>();

            while (fileNames.Count > 0)
            {
                string       fileName = fileNames.Dequeue();
                FileStream   fs       = new FileStream(fileName, FileMode.Open);
                BinaryReader br       = new BinaryReader(fs);

                if (fs == null)
                {
                    br.Close();
                    fs.Close();
                    fs.Dispose();
                    EB.Debug.LogError("fs=null filename={0}", fileName);
                    continue;
                }
                try
                {
                    while (true)
                    {
                        ChatHistoryData data          = new ChatHistoryData();
                        int             contentLength = br.ReadInt32();
                        data.content = System.Text.Encoding.UTF8.GetString(br.ReadBytes(contentLength));
                        dataList.Add(data);
                    }
                }
                catch (Exception)
                {
                    EB.Debug.Log("ReadFile:{0}----done!", fileName);
                }
                br.Close();
                fs.Close();
                fs.Dispose();
            }
            return(dataList);
        }
Example #4
0
 public void SaveData(ChatHistoryData data)
 {
     m_writeThreadQueue.Enqueue(data);
     ThreadUpdate();
 }