Exemplo n.º 1
0
        public IEnumerable <T> Find <T>(string tablename, string key) where T : new()
        {
            string          tablefile = GetTableFile(tablename);
            EntityTableMeta meta      = GetMetaData(tablename);
            Dictionary <long, EntityTableIndexItem> arr = null;
            EntityTableIndexItem indexitem = null;

            if (keyindexdic[tablename].TryGetValue(key, out arr))
            {
                //先找到offset
                using (ObjTextReader otw = ObjTextReader.CreateReader(tablefile))
                {
                    foreach (var o in arr)
                    {
                        indexitem = (EntityTableIndexItem)o.Value;
                        if (!indexitem.Del)
                        {
                            otw.SetPostion(indexitem.Offset);

                            var readobj = otw.ReadObject <EntityTableItem <T> >();
                            if (readobj == null)
                            {
                                yield return(default(T));
                            }
                            else
                            {
                                yield return(readobj.Data);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void ProcessBadQueue(T last)
        {
            if (_queueReader == null)
            {
                return;
            }
            var oldpostion = _queueReader.ReadedPostion();

            while (true)
            {
                if (_queueReader.PostionNextSplitChar())
                {
                    var newpostion = _queueReader.ReadedPostion();

                    if (_queueReader.ReadObject <T>() != default(T))
                    {
                        _queueReader.SetPostion(newpostion);
                        OnProcessError(last, new Exception(string.Format("队列损环,将尝试读取下一个队列。损坏位置{0},恢复位置{1},损坏长度:{2}kb。", oldpostion, newpostion, (newpostion - oldpostion) / 1000)));

                        break;
                    }
                }
                else
                {
                    throw new Exception("队列已损坏,无法恢复。");
                }
            }
        }