public FileAndPages GetFile(string filename, int start, int pagesToLoad)
		{
			Api.JetSetCurrentIndex(session, Files, "by_name");
			Api.MakeKey(session, Files, filename, Encoding.Unicode, MakeKeyGrbit.NewKey);
			if (Api.TrySeek(session, Files, SeekGrbit.SeekEQ) == false)
				throw new FileNotFoundException("Could not find file: " + filename);

			var fileInformation = new FileAndPages
				                      {
					                      TotalSize = GetTotalSize(),
					                      UploadedSize =
						                      BitConverter.ToInt64(
							                      Api.RetrieveColumn(session, Files, tableColumnsCache.FilesColumns["uploaded_size"]), 0),
					                      Metadata = RetrieveMetadata(),
					                      Name = filename,
					                      Start = start
				                      };

			if (pagesToLoad > 0)
			{
				Api.JetSetCurrentIndex(session, Usage, "by_name_and_pos");
				Api.MakeKey(session, Usage, filename, Encoding.Unicode, MakeKeyGrbit.NewKey);
				Api.MakeKey(session, Usage, start, MakeKeyGrbit.None);
				if (Api.TrySeek(session, Usage, SeekGrbit.SeekGE))
				{
					Api.MakeKey(session, Usage, filename, Encoding.Unicode, MakeKeyGrbit.NewKey);
					Api.JetSetIndexRange(session, Usage, SetIndexRangeGrbit.RangeInclusive);

					do
					{
						var name = Api.RetrieveColumnAsString(session, Usage, tableColumnsCache.UsageColumns["name"]);
						if (name != filename)
							continue;

						fileInformation.Pages.Add(new PageInformation
							                          {
								                          Size =
									                          Api.RetrieveColumnAsInt32(session, Usage, tableColumnsCache.UsageColumns["page_size"])
									                             .Value,
								                          Id =
									                          Api.RetrieveColumnAsInt32(session, Usage, tableColumnsCache.UsageColumns["page_id"])
									                             .Value
							                          });
					} while (Api.TryMoveNext(session, Usage) && fileInformation.Pages.Count < pagesToLoad);
				}
			}

			return fileInformation;
		}
Ejemplo n.º 2
0
		private void MovePageFrame(long offset)
		{
			offset = Math.Min(Length, offset);
			if (offset < currentPageFrameOffset || fileAndPages == null)
			{
				TransactionalStorage.Batch(accessor => fileAndPages = accessor.GetFile(Name, 0, PagesBatchSize));
				currentPageFrameOffset = 0;
			}
			while (currentPageFrameOffset + CurrentPageFrameSize - 1 < offset)
			{
				var lastPageFrameSize = CurrentPageFrameSize;
				var nextPageIndex = fileAndPages.Start + fileAndPages.Pages.Count;
				TransactionalStorage.Batch(accessor => fileAndPages = accessor.GetFile(Name, nextPageIndex, PagesBatchSize));
				if (fileAndPages.Pages.Count < 1)
				{
					fileAndPages.Start = 0;
					break;
				}
				currentPageFrameOffset += lastPageFrameSize;
			}
			currentOffset = offset;
		}