Exemple #1
0
 public async Task<MainIndexRow> AppendObject(string id, byte[] data)
 {
     return await Task.Run(() =>
     {
         this.objectLock.EnterWriteLock();
         try
         {
             this.objectStore.Add(data);
             var index = this.objectStore.IndexOf(data);
             var result = new MainIndexRow(id, index, data.Length, null);
             return result;
         }
         finally
         {
             this.objectLock.ExitWriteLock();
         }
     });
 }
Exemple #2
0
        public async Task AppendMainIndex(MainIndexRow item)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            await Task.Run(() =>
            {
                this.mainIndexLock.EnterWriteLock();
                try
                {
                    var data = item.ToSekvap(this.lang);
                    this.mainIndex.Add(data);
                }
                finally
                {
                    this.mainIndexLock.ExitWriteLock();
                }
            });
        }
Exemple #3
0
        public async Task<MainIndexRow> SeekLatestMainIndex(string id)
        {
            if (string.IsNullOrEmpty(id))
                throw new ArgumentException("The value cannot be empty", "id");

            return await Task.Run(() =>
            {
                this.mainIndexLock.EnterReadLock();
                try
                {
                    for (int i = 0; i < this.mainIndex.Count; i++)
                    {
                        var itemAsString = this.mainIndex[this.mainIndex.Count - i - 1];
                        var itemData = this.lang.Parse(itemAsString);
                        var row = new MainIndexRow(itemData);
                        if (row.Id.Equals(id, StringComparison.OrdinalIgnoreCase))
                        {
                            return row;
                        }
                    }

                    return null;
                }
                finally
                {
                    this.mainIndexLock.ExitReadLock();
                }
            });
        }
Exemple #4
0
 public async Task<byte[]> GetObject(MainIndexRow row)
 {
     var result = this.store.ReadObjectStore(row.ObjectStoreBeginIndex.Value, row.ObjectStoreLength.Value);
     return result;
 }
Exemple #5
0
        public async Task<byte[][]> GetObjects(MainIndexRow[] rows)
        {
            if (rows == null)
                throw new ArgumentNullException("rows");

            return await Task.Run(() =>
            {
                this.objectLock.EnterReadLock();
                try
                {
                    var result = new byte[rows.Length][];
                    for (int i = 0; i < rows.Length; i++)
                    {
                        var row = rows[i];
                        if (row != null)
                        {
                            var bytes = this.objectStore[checked((int)row.ObjectStoreBeginIndex)];
                            Debug.Assert(bytes.Length == row.ObjectStoreLength, "MemoryStore.GetObject: bytes.Length != row.ObjectStoreLength");
                            result[i] = bytes;
                        }
                    }

                    return result;
                }
                finally
                {
                    this.objectLock.ExitReadLock();
                }
            });
        }
Exemple #6
0
        internal MainIndexRow ReadMainIndex(int index)
        {
            if (index >= this.mainIndex.Count)
                return null;

            var itemAsString = this.mainIndex[this.mainIndex.Count - index - 1];
            var itemData = this.lang.Parse(itemAsString);
            var row = new MainIndexRow(itemData);
            return row;
        }
Exemple #7
0
        public async Task<byte[]> GetObject(MainIndexRow row)
        {
            if (row == null)
                throw new ArgumentNullException("row");

            return await Task.Run(() =>
            {
                this.objectLock.EnterReadLock();
                try
                {
                    var bytes = this.objectStore[checked((int)row.ObjectStoreBeginIndex)];
                    Debug.Assert(bytes.Length == row.ObjectStoreLength, "MemoryStore.GetObject: bytes.Length != row.ObjectStoreLength");
                    return bytes;
                }
                finally
                {
                    this.objectLock.ExitReadLock();
                }
            });
        }
Exemple #8
0
        public async Task<MainIndexRow[]> SeekLatestMainIndex(string[] ids)
        {
            if (ids == null)
                throw new ArgumentNullException("ids");

            return await Task.Run(() =>
            {
                this.mainIndexLock.EnterReadLock();
                try
                {
                    var result = new MainIndexRow[ids.Length];
                    for (int i = 0; i < this.mainIndex.Count; i++)
                    {
                        var itemAsString = this.mainIndex[this.mainIndex.Count - i - 1];
                        var itemData = this.lang.Parse(itemAsString);
                        var row = new MainIndexRow(itemData);

                        for (int j = 0; j < ids.Length; j++)
                        {
                            var id = ids[j];
                            if (id != null && row.Id.Equals(id, StringComparison.OrdinalIgnoreCase))
                            {
                                if (result[j] == null)
                                {
                                    result[j] = row;

                                    if (result.All(r => r != null))
                                    {
                                        return result;
                                    }
                                }
                            }
                        }
                    }

                    return result;
                }
                finally
                {
                    this.mainIndexLock.ExitReadLock();
                }
            });
        }
Exemple #9
0
 public Task<byte[][]> GetObjects(MainIndexRow[] rows)
 {
     throw new NotImplementedException();
 }
Exemple #10
0
 public async Task<byte[]> GetObject(MainIndexRow row)
 {
     this.GetObjectCount += 1;
     return await this.GetObjectDelegate(row);
 }
Exemple #11
0
 public async Task AppendMainIndex(MainIndexRow row)
 {
     this.AppendMainIndexCount += 1;
     await this.AppendMainIndexDelegate(row);
 }