当前位置: 首页>>代码示例>>C#>>正文


C# ColumnStream.SetLength方法代码示例

本文整理汇总了C#中Microsoft.Isam.Esent.Interop.ColumnStream.SetLength方法的典型用法代码示例。如果您正苦于以下问题:C# ColumnStream.SetLength方法的具体用法?C# ColumnStream.SetLength怎么用?C# ColumnStream.SetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Isam.Esent.Interop.ColumnStream的用法示例。


在下文中一共展示了ColumnStream.SetLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Set

		public void Set(string name, string key, RavenJObject data, UuidType uuidType)
		{
			Api.JetSetCurrentIndex(session, Lists, "by_name_and_key");
			Api.MakeKey(session, Lists, name, Encoding.Unicode, MakeKeyGrbit.NewKey);
			Api.MakeKey(session, Lists, key, Encoding.Unicode, MakeKeyGrbit.None);

			var exists = Api.TrySeek(session, Lists, SeekGrbit.SeekEQ);


			using (var update = new Update(session, Lists, exists ? JET_prep.Replace : JET_prep.Insert))
			{
				Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["name"], name, Encoding.Unicode);
				Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["key"], key, Encoding.Unicode);
				Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["etag"], uuidGenerator.CreateSequentialUuid(uuidType).TransformToValueForEsentSorting());
				Api.SetColumn(session, Lists, tableColumnsCache.ListsColumns["created_at"], SystemTime.UtcNow);

				using (var columnStream = new ColumnStream(session, Lists, tableColumnsCache.ListsColumns["data"]))
				{
					if (exists)
						columnStream.SetLength(0);
					using (Stream stream = new BufferedStream(columnStream))
					{
						data.WriteTo(stream);
						stream.Flush();
					}
				}
				update.Save();
			}
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:29,代码来源:Lists.cs

示例2: AddAttachment

		public Etag AddAttachment(string key, Etag etag, Stream data, RavenJObject headers)
		{
			Api.JetSetCurrentIndex(session, Files, "by_name");
			Api.MakeKey(session, Files, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
			var isUpdate = Api.TrySeek(session, Files, SeekGrbit.SeekEQ);
			if (isUpdate)
			{
				var existingEtag = Etag.Parse(Api.RetrieveColumn(session, Files, tableColumnsCache.FilesColumns["etag"]));
				if (existingEtag != etag && etag != null)
				{
					throw new ConcurrencyException("PUT attempted on attachment '" + key +
						"' using a non current etag")
					{
						ActualETag = existingEtag,
						ExpectedETag = etag
					};
				}
			}
			else
			{
				if (data == null)
					throw new InvalidOperationException("When adding new attachment, the attachment data must be specified");

				if (Api.TryMoveFirst(session, Details))
					Api.EscrowUpdate(session, Details, tableColumnsCache.DetailsColumns["attachment_count"], 1);
			}

			Etag newETag = uuidGenerator.CreateSequentialUuid(UuidType.Attachments);
			using (var update = new Update(session, Files, isUpdate ? JET_prep.Replace : JET_prep.Insert))
			{
				Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["name"], key, Encoding.Unicode);
				if (data != null)
				{
					long written;
					using (var columnStream = new ColumnStream(session, Files, tableColumnsCache.FilesColumns["data"]))
					{
						if (isUpdate)
							columnStream.SetLength(0);
						using (var stream = new BufferedStream(columnStream))
						{
							data.CopyTo(stream);
							written = stream.Position;
							stream.Flush();
						}
					}
					if (written == 0) // empty attachment
					{
						Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["data"], new byte[0]);
					}
				}

				Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["etag"], newETag.TransformToValueForEsentSorting());
				Api.SetColumn(session, Files, tableColumnsCache.FilesColumns["metadata"], headers.ToString(Formatting.None), Encoding.Unicode);

				update.Save();
			}
			logger.Debug("Adding attachment {0}", key);

			return newETag;
		}
开发者ID:925coder,项目名称:ravendb,代码行数:60,代码来源:DocumentStorageActions.cs

示例3: ShrinkColumnStream

        public void ShrinkColumnStream()
        {
            var bookmark = new byte[SystemParameters.BookmarkMost];
            int bookmarkSize;

            const int Length = 1345;
            var data = Any.BytesOfLength(Length);

            using (var transaction = new Transaction(this.sesid))
            using (var update = new Update(this.sesid, this.tableid, JET_prep.Insert))
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                stream.Write(data, 0, data.Length);
                stream.Write(data, 0, data.Length);
                Assert.AreEqual(Length * 2, stream.Length);

                stream.SetLength(Length);
                Assert.AreEqual(Length, stream.Length);

                update.Save(bookmark, bookmark.Length, out bookmarkSize);
                transaction.Commit(CommitTransactionGrbit.LazyFlush);
            }

            Api.JetGotoBookmark(this.sesid, this.tableid, bookmark, bookmarkSize);
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                Assert.AreEqual(Length, stream.Length);
                var buffer = new byte[Length];
                stream.Read(buffer, 0, buffer.Length);
                CollectionAssert.AreEqual(data, buffer);
            }
        }
开发者ID:ayende,项目名称:managed-esent,代码行数:32,代码来源:ColumnStreamTests.cs

示例4: SetColumnStreamToZeroLength

        public void SetColumnStreamToZeroLength()
        {
            var bookmark = new byte[SystemParameters.BookmarkMost];
            int bookmarkSize;

            using (var transaction = new Transaction(this.sesid))
            using (var update = new Update(this.sesid, this.tableid, JET_prep.Insert))
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                byte[] data = Any.Bytes;
                stream.Write(data, 0, data.Length);

                stream.SetLength(0);
                Assert.AreEqual(0, stream.Length);

                update.Save(bookmark, bookmark.Length, out bookmarkSize);
                transaction.Commit(CommitTransactionGrbit.LazyFlush);
            }

            Api.JetGotoBookmark(this.sesid, this.tableid, bookmark, bookmarkSize);
            CollectionAssert.AreEqual(new byte[0], Api.RetrieveColumn(this.sesid, this.tableid, this.columnidLongText));
        }
开发者ID:ayende,项目名称:managed-esent,代码行数:22,代码来源:ColumnStreamTests.cs

示例5: SetColumnStreamLength

        public void SetColumnStreamLength()
        {
            var bookmark = new byte[SystemParameters.BookmarkMost];
            int bookmarkSize;

            const long Length = 1345;

            using (var transaction = new Transaction(this.sesid))
            using (var update = new Update(this.sesid, this.tableid, JET_prep.Insert))
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                stream.SetLength(Length);
                Assert.AreEqual(Length, stream.Length);

                update.Save(bookmark, bookmark.Length, out bookmarkSize);
                transaction.Commit(CommitTransactionGrbit.LazyFlush);
            }

            Api.JetGotoBookmark(this.sesid, this.tableid, bookmark, bookmarkSize);
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                Assert.AreEqual(Length, stream.Length);
            }
        }
开发者ID:ayende,项目名称:managed-esent,代码行数:24,代码来源:ColumnStreamTests.cs

示例6: ColumnStreamSetLengthThrowsExceptionWhenLengthIsTooLong

 public void ColumnStreamSetLengthThrowsExceptionWhenLengthIsTooLong()
 {
     using (var t = new Transaction(this.sesid))
     using (var u = new Update(this.sesid, this.tableid, JET_prep.Insert))
     using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
     {
         stream.SetLength(0x800000000);
     }
 }
开发者ID:ayende,项目名称:managed-esent,代码行数:9,代码来源:ColumnStreamTests.cs


注:本文中的Microsoft.Isam.Esent.Interop.ColumnStream.SetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。