Exemplo n.º 1
0
        /// <summary>
        /// Установить размер.
        /// </summary>
        /// <param name="tt">Транзакция таблицы.</param>
        /// <param name="item">Элемент.</param>
        public void SetFileSize(TableTransaction tt, SizeCacheEsentItem item)
        {
            Api.JetSetCurrentIndex(tt.Session, tt.Table, null);
            Api.MakeKey(tt.Session, tt.Table, item.FileId, Encoding.Unicode, MakeKeyGrbit.NewKey);
            if (Api.TrySeek(tt.Session, tt.Table, SeekGrbit.SeekEQ))
            {
                Api.JetDelete(tt.Session, tt.Table);
            }
            using (var updater = new Update(tt.Session, tt.Table, JET_prep.Insert))
            {
                var columnId = Api.GetTableColumnid(tt.Session, tt.Table, "FileId");
                Api.SetColumn(tt.Session, tt.Table, columnId, item.FileId, Encoding.Unicode);

                var columnSize = Api.GetTableColumnid(tt.Session, tt.Table, "Size");
                Api.SetColumn(tt.Session, tt.Table, columnSize, item.Size);

                var columnDTicks = Api.GetTableColumnid(tt.Session, tt.Table, "DTicks");
                Api.SetColumn(tt.Session, tt.Table, columnDTicks, item.DTicks);

                var columnOTicks = Api.GetTableColumnid(tt.Session, tt.Table, "OTicks");
                Api.SetColumn(tt.Session, tt.Table, columnOTicks, item.OTicks);

                updater.Save();
            }
        }
 /// <summary>
 /// Конструктор.
 /// </summary>
 /// <param name="transaction">Транзакция.</param>
 /// <param name="adapter">Адаптер.</param>
 /// <param name="id">Идентификатор.</param>
 public EsentStorageSizeCache(TableTransaction transaction, ISizeCacheAdapter adapter, string id)
 {
     this.transaction = transaction;
     this.adapter = adapter;
     this.Id = id;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Получить общий размер.
        /// </summary>
        /// <param name="tt">Транзакция таблицы.</param>
        /// <returns>Общий размер.</returns>
        public ulong GetTotalSize(TableTransaction tt)
        {
            Api.JetSetCurrentIndex(tt.Session, tt.Table, null);

            ulong result = 0;

            Api.JetSetTableSequential(tt.Session, tt.Table, Windows7Grbits.Forward);
            try
            {
                if (Api.TryMoveFirst(tt.Session, tt.Table))
                {
                    do
                    {
                        var columnSize = Api.GetTableColumnid(tt.Session, tt.Table, "Size");
                        result += Api.RetrieveColumnAsUInt64(tt.Session, tt.Table, columnSize) ?? 0;
                    } while (Api.TryMoveNext(tt.Session, tt.Table));
                }
            }
            finally
            {
                Api.JetResetTableSequential(tt.Session, tt.Table, ResetTableSequentialGrbit.None);
            }

            return result;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Удалить все элементы.
 /// </summary>
 /// <param name="tt">Транзакция таблицы.</param>
 public void DeleteAllItems(TableTransaction tt)
 {
     Api.JetSetCurrentIndex(tt.Session, tt.Table, null);
     Api.JetSetTableSequential(tt.Session, tt.Table, Windows7Grbits.Forward);
     try
     {
         if (Api.TryMoveFirst(tt.Session, tt.Table))
         {
             do
             {
                 Api.JetDelete(tt.Session, tt.Table);
             } while (Api.TryMoveNext(tt.Session, tt.Table));
         }
     }
     finally
     {
         Api.JetResetTableSequential(tt.Session, tt.Table, ResetTableSequentialGrbit.None);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Получить количество элементов.
 /// </summary>
 /// <param name="tt">Транзакция таблицы.</param>
 /// <returns>Количество элементов.</returns>
 public int GetCount(TableTransaction tt)
 {
     int count = 0;
     Api.JetSetCurrentIndex(tt.Session, tt.Table, null);
     Api.JetSetTableSequential(tt.Session, tt.Table, Windows7Grbits.Forward);
     try
     {
         if (Api.TryMoveFirst(tt.Session, tt.Table))
         {
             do
             {
                 count++;
             } while (Api.TryMoveNext(tt.Session, tt.Table));
         }
     }
     finally
     {
         Api.JetResetTableSequential(tt.Session, tt.Table, ResetTableSequentialGrbit.None);
     }
     return count;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Проверить наличие элемента.
 /// </summary>
 /// <param name="tt">Транзакция таблицы.</param>
 /// <param name="fileId">Идентификатор файла.</param>
 /// <returns>Результат проверки.</returns>
 public bool IsItemPresent(TableTransaction tt, string fileId)
 {
     Api.JetSetCurrentIndex(tt.Session, tt.Table, null);
     Api.MakeKey(tt.Session, tt.Table, fileId, Encoding.Unicode, MakeKeyGrbit.NewKey);
     return Api.TrySeek(tt.Session, tt.Table, SeekGrbit.SeekEQ);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Получить элемент.
        /// </summary>
        /// <param name="tt">Транзакция таблицы.</param>
        /// <param name="fileId">Идентификатор файла.</param>
        /// <returns>Элемент.</returns>
        public SizeCacheEsentItem? GetItem(TableTransaction tt, string fileId)
        {
            Api.JetSetCurrentIndex(tt.Session, tt.Table, null);
            Api.MakeKey(tt.Session, tt.Table, fileId, Encoding.Unicode, MakeKeyGrbit.NewKey);
            if (Api.TrySeek(tt.Session, tt.Table, SeekGrbit.SeekEQ))
            {
                var columnId = Api.GetTableColumnid(tt.Session, tt.Table, "FileId");
                var columnSize = Api.GetTableColumnid(tt.Session, tt.Table, "Size");
                var columnDTicks = Api.GetTableColumnid(tt.Session, tt.Table, "DTicks");
                var columnOTicks = Api.GetTableColumnid(tt.Session, tt.Table, "OTicks");

                var id = Api.RetrieveColumnAsString(tt.Session, tt.Table, columnId, Encoding.Unicode);
                var size = Api.RetrieveColumnAsUInt64(tt.Session, tt.Table, columnSize) ?? 0;
                var dticks = Api.RetrieveColumnAsInt64(tt.Session, tt.Table, columnDTicks) ?? 0;
                var oticks = Api.RetrieveColumnAsInt64(tt.Session, tt.Table, columnOTicks) ?? 0;

                return new SizeCacheEsentItem()
                {
                    FileId = id,
                    Size = size,
                    DTicks = dticks,
                    OTicks = oticks
                };
            }
            return null;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Удалить элемент.
 /// </summary>
 /// <param name="tt">Транзакция таблицы.</param>
 /// <param name="fileId">Идентификатор файла.</param>
 public void DeleteItem(TableTransaction tt, string fileId)
 {
     Api.JetSetCurrentIndex(tt.Session, tt.Table, null);
     Api.MakeKey(tt.Session, tt.Table, fileId, Encoding.Unicode, MakeKeyGrbit.NewKey);
     if (Api.TrySeek(tt.Session, tt.Table, SeekGrbit.SeekEQ))
     {
         Api.JetDelete(tt.Session, tt.Table);
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// Полчить все идентификаторы.
 /// </summary>
 /// <param name="tt">Транзакция таблицы.</param>
 /// <returns>Все идентификаторы.</returns>
 public IEnumerable<string> GetFileAllIds(TableTransaction tt)
 {
     Api.JetSetCurrentIndex(tt.Session, tt.Table, null);
     Api.JetSetTableSequential(tt.Session, tt.Table, Windows7Grbits.Forward);
     try
     {
         if (Api.TryMoveFirst(tt.Session, tt.Table))
         {
             do
             {
                 var columnId = Api.GetTableColumnid(tt.Session, tt.Table, "FileId");
                 var id = Api.RetrieveColumnAsString(tt.Session, tt.Table, columnId, Encoding.Unicode, RetrieveColumnGrbit.RetrieveFromIndex);
                 yield return id;
             } while (Api.TryMoveNext(tt.Session, tt.Table));
         }
     }
     finally
     {
         Api.JetResetTableSequential(tt.Session, tt.Table, ResetTableSequentialGrbit.None);
     }
 }
Exemplo n.º 10
0
        /// <summary>
        /// Получить все элементы.
        /// </summary>
        /// <param name="tt">Транзакция таблицы.</param>
        /// <returns>Все элементы.</returns>
        public IEnumerable<SizeCacheEsentItem> GetAllItems(TableTransaction tt)
        {
            Api.JetSetCurrentIndex(tt.Session, tt.Table, null);
            Api.JetSetTableSequential(tt.Session, tt.Table, Windows7Grbits.Forward);
            try
            {
                if (Api.TryMoveFirst(tt.Session, tt.Table))
                {
                    do
                    {
                        var columnId = Api.GetTableColumnid(tt.Session, tt.Table, "FileId");
                        var columnSize = Api.GetTableColumnid(tt.Session, tt.Table, "Size");
                        var columnDTicks = Api.GetTableColumnid(tt.Session, tt.Table, "DTicks");
                        var columnOTicks = Api.GetTableColumnid(tt.Session, tt.Table, "OTicks");

                        var id = Api.RetrieveColumnAsString(tt.Session, tt.Table, columnId, Encoding.Unicode);
                        var size = Api.RetrieveColumnAsUInt64(tt.Session, tt.Table, columnSize) ?? 0;
                        var dticks = Api.RetrieveColumnAsInt64(tt.Session, tt.Table, columnDTicks) ?? 0;
                        var oticks = Api.RetrieveColumnAsInt64(tt.Session, tt.Table, columnOTicks) ?? 0;

                        yield return new SizeCacheEsentItem()
                        {
                            FileId = id,
                            Size = size,
                            DTicks = dticks,
                            OTicks = oticks
                        };
                    } while (Api.TryMoveNext(tt.Session, tt.Table));
                }
            }
            finally
            {
                Api.JetResetTableSequential(tt.Session, tt.Table, ResetTableSequentialGrbit.None);
            }
        }