Beispiel #1
0
        public int AddIndex(long position, Guid MetaHash = default(Guid))
        {
            lock (_locker)
            {
                long currentposition = this.IndexStream.Length;
                // check to make sure it is the right position.
                var left = currentposition % 24;
                if (left != 0)
                {
                    var count = (int)currentposition / 24;
                    if (count * 8 > currentposition)
                    {
                        currentposition = count * 24;
                    }
                    else
                    {
                        currentposition = (count + 1) * 24;
                    }
                    this.IndexStream.SetLength(currentposition);
                }

                this.IndexStream.Position = currentposition;
                DocInfo info = new DocInfo()
                {
                    Position = position, MetaHash = MetaHash
                };

                this.IndexStream.Write(info.ToBytes(), 0, 24);
                int id = (int)(currentposition / 24);

                this.Docs[id] = info;
                return(id);
            }
        }
Beispiel #2
0
        public void UpdateIndex(int id, long newposition, string meta)
        {
            var  position = id * 24;
            Guid metahash = Lib.Security.Hash.ComputeGuidIgnoreCase(meta);
            var  total    = this.IndexStream.Length;

            if (total >= position + 24)
            {
                lock (_locker)
                {
                    if (this.Docs.ContainsKey(id))
                    {
                        this.IndexStream.Position = position;
                        DocInfo newinfo = new DocInfo()
                        {
                            Position = newposition, MetaHash = metahash
                        };
                        this.IndexStream.Write(newinfo.ToBytes(), 0, 24);
                        this.Docs[id] = newinfo;
                    }
                }
            }
        }