Esempio n. 1
0
        public static LogItem Read(BinaryReader reader)
        {
            LogItem item = new LogItem();

            var header = reader.ReadBytesUntil(LogConstant.splitByte);

            var bs = header.Take(8).ToArray();
            item.timestamp = Convert.ToInt32(Encoding.UTF8.GetString(bs), 16);

            bs = header.Skip(8).Take(2).ToArray();
            item.type1 = Convert.ToInt32(Encoding.UTF8.GetString(bs), 16);

            bs = header.Skip(10).Take(2).ToArray();
            item.type2 = Convert.ToInt32(Encoding.UTF8.GetString(bs), 16);


            var desc = reader.ReadBytesUntil(LogConstant.splitByte);

            var descReader = new BinaryReader(new MemoryStream(desc));
            item.desc1 = ReadLogDesc(descReader);
            var content = descReader.ReadBytesUntil(LogConstant.begin, false);

            item.content = Encoding.UTF8.GetString(content);
            
            item.desc2 = ReadLogDesc(descReader);

            descReader.Close();
            descReader.Dispose();

            var count = CountContent(reader);

            content = reader.ReadBytes(count - 12);

            descReader = new BinaryReader(new MemoryStream(content));
            List<byte> tbs = new List<byte>();
            do 
            {
                int ch = descReader.PeekChar();
                if (ch == -1) 
                {
                    if (tbs.Count > 0) 
                    {
                        item.contents.Add(Encoding.UTF8.GetString(tbs.ToArray()));
                        tbs.Clear();
                    }
                    break;
                }
                if (ch == LogConstant.begin) 
                {
                    item.descs.Add(ReadLogDesc(descReader));

                    if (tbs.Count > 0) 
                    {
                        item.contents.Add(Encoding.UTF8.GetString(tbs.ToArray()));
                        tbs.Clear();
                    }
                } 
                else
                {
                    tbs.Add(descReader.ReadByte());
                }
            } while (true);

            descReader.Close();
            descReader.Dispose();

            return item;
        }
Esempio n. 2
0
        public LogBattleItem Analyse(LogItem item)
        {
            if (ignoreMainType.Contains(item.type1))
                return null;

            if (ignoreSubType.Contains(item.type2))
                return null;

            if (!regexDict.ContainsKey(item.type2))
            {
                throw new Exception(String.Format("{0},{1},{2}", item.type1, item.type2, item.AllContent));
            }

            var content = item.AllContent.Trim();
            bool matched = false;

            LogBattleItem lbi = null;
            foreach (var bi in regexDict[item.type2])
            {
                if (!bi.Match(content))
                    continue;

                matched = true;
                lbi = bi.GetItem();
                lbi.time = item.timestamp;
                break;    
            }

            if (!matched)
            {
                throw new Exception(String.Format("{0},{1},{2}", item.type1, item.type2, item.AllContent));
            }

            return lbi;
        }