• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Interop.ColumnStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ColumnStream类属于Microsoft.Isam.Esent.Interop命名空间,在下文中一共展示了ColumnStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: 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


示例2: 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


示例3: SerializeObjectToColumn

 /// <summary>
 /// Write a serialized form of an object to a column.
 /// </summary>
 /// <param name="sesid">The session to use.</param>
 /// <param name="tableid">The table to write to. An update should be prepared.</param>
 /// <param name="columnid">The column to write to.</param>
 /// <param name="value">The object to write. The object must be serializable.</param>
 public static void SerializeObjectToColumn(JET_SESID sesid, JET_TABLEID tableid, JET_COLUMNID columnid, object value)
 {
     if (null == value)
     {
         Api.SetColumn(sesid, tableid, columnid, null);
     }
     else
     {
         using (var stream = new ColumnStream(sesid, tableid, columnid))
         {
             var serializer = new BinaryFormatter
             {
                 Context = new StreamingContext(StreamingContextStates.Persistence)
             };
             serializer.Serialize(stream, value);
         }
     }
 }
开发者ID:ayende,项目名称:managed-esent,代码行数:25,代码来源:SetColumnHelpers.cs


示例4: VerifySeekFromEndThrowsExceptionOnOverflow

 public void VerifySeekFromEndThrowsExceptionOnOverflow()
 {
     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.Write(new byte[10], 0, 10);
         try
         {
             stream.Seek(Int64.MaxValue, SeekOrigin.End);
             Assert.Fail("Expected OverflowException");
         }
         catch (OverflowException)
         {
             // expected
         }
     }
 }
开发者ID:jtmueller,项目名称:ravendb,代码行数:18,代码来源:ColumnStreamTests.cs


示例5: AddSignature

		public void AddSignature(string name, int level, Action<Stream> action)
		{
			using (var update = new Update(session, Signatures, JET_prep.Insert))
			{
				Api.SetColumn(session, Signatures, tableColumnsCache.SignaturesColumns["name"], name, Encoding.Unicode);
				Api.SetColumn(session, Signatures, tableColumnsCache.SignaturesColumns["level"], level);
				Api.SetColumn(session, Signatures, tableColumnsCache.SignaturesColumns["created_at"], DateTime.UtcNow);

				using (var stream = new ColumnStream(session, Signatures, tableColumnsCache.SignaturesColumns["data"]))
				using (var buffer = new BufferedStream(stream))
				{
					action(buffer);
					buffer.Flush();
					stream.Flush();
				}

				update.Save();
			}
		}
开发者ID:hibernating-rhinos,项目名称:RavenFS,代码行数:19,代码来源:StorageActionsAccessor.cs


示例6: InsertPage

		public int InsertPage(byte[] buffer, int size)
		{
			var key = new HashKey(buffer, size);

			Api.JetSetCurrentIndex(session, Pages, "by_keys");

			Api.MakeKey(session, Pages, key.Weak, MakeKeyGrbit.NewKey);
			Api.MakeKey(session, Pages, key.Strong, MakeKeyGrbit.None);

			if (Api.TrySeek(session, Pages, SeekGrbit.SeekEQ))
			{
				Api.EscrowUpdate(session, Pages, tableColumnsCache.PagesColumns["usage_count"], 1);
				return Api.RetrieveColumnAsInt32(session, Pages, tableColumnsCache.PagesColumns["id"]).Value;
			}

            var bookMarkBuffer = new byte[bookmarkMost];
			var actualSize = 0;
			using (var update = new Update(session, Pages, JET_prep.Insert))
			{
				Api.SetColumn(session, Pages, tableColumnsCache.PagesColumns["page_strong_hash"], key.Strong);
				Api.SetColumn(session, Pages, tableColumnsCache.PagesColumns["page_weak_hash"], key.Weak);

				using (var columnStream = new ColumnStream(session, Pages, tableColumnsCache.PagesColumns["data"]))
				{
					using (Stream stream = new BufferedStream(columnStream))
					using (var finalStream = fileCodecs.Aggregate(stream, (current, codec) => codec.EncodePage(current)))
					{
						finalStream.Write(buffer, 0, size);
						finalStream.Flush();
					}
				}

				try
				{
					update.Save(bookMarkBuffer, bookMarkBuffer.Length, out actualSize);
				}
				catch (EsentKeyDuplicateException)
				{
					// it means that page is being inserted by another thread
					throw new ConcurrencyException("The same file page is being created");
				}
			}

			Api.JetGotoBookmark(session, Pages, bookMarkBuffer, actualSize);

			return Api.RetrieveColumnAsInt32(session, Pages, tableColumnsCache.PagesColumns["id"]).Value;
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:47,代码来源:StorageActionsAccessor.cs


示例7: WriteThrowsExceptionWhenBufferOffsetIsNegative

 public void WriteThrowsExceptionWhenBufferOffsetIsNegative()
 {
     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))
     {
         var buffer = new byte[10];
         stream.Write(buffer, -1, 1);
     }
 }
开发者ID:ayende,项目名称:managed-esent,代码行数:10,代码来源:ColumnStreamTests.cs


示例8: WriteAtNonZeroOffset

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

            var data = Any.BytesOfLength(1024);
            int offset = data.Length / 2;

            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, offset, data.Length - offset);
                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))
            {
                var retrieved = new byte[data.Length - offset];
                stream.Read(retrieved, 0, retrieved.Length);
                for (int i = 0; i < retrieved.Length; ++i)
                {
                    Assert.AreEqual(retrieved[i], data[i + offset]);
                }
            }
        }
开发者ID:ayende,项目名称:managed-esent,代码行数:28,代码来源:ColumnStreamTests.cs


示例9: SettingPositionThrowsExceptionWhenPositionIsTooLong

 public void SettingPositionThrowsExceptionWhenPositionIsTooLong()
 {
     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.Position = 0x800000000;
     }
 }
开发者ID:ayende,项目名称:managed-esent,代码行数:9,代码来源:ColumnStreamTests.cs


示例10: SetColumnStreamPosition

        public void SetColumnStreamPosition()
        {
            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))
            {
                stream.Write(Any.BytesOfLength(1024), 0, 1024);
                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))
            {
                stream.Position = 10;
                Assert.AreEqual(10, stream.Position);
            }
        }
开发者ID:ayende,项目名称:managed-esent,代码行数:21,代码来源:ColumnStreamTests.cs


示例11: 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


示例12: ColumnStreamCanSerializeObject

        public void ColumnStreamCanSerializeObject()
        {
            var expected = new Dictionary<string, long> { { "foo", 1 }, { "bar", 2 }, { "baz", 3 } };

            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))
            {
                var serializer = new BinaryFormatter();
                serializer.Serialize(stream, expected);
                u.Save();
                t.Commit(CommitTransactionGrbit.LazyFlush);
            }

            Api.JetMove(this.sesid, this.tableid, JET_Move.First, MoveGrbit.None);
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                var deseriaizer = new BinaryFormatter();
                var actual = (Dictionary<string, long>) deseriaizer.Deserialize(stream);
                CollectionAssert.AreEqual(expected, actual);
            }
        }
开发者ID:ayende,项目名称:managed-esent,代码行数:22,代码来源:ColumnStreamTests.cs


示例13: ColumnStreamCanSerializeBasicType

        public void ColumnStreamCanSerializeBasicType()
        {
            var expected = Any.Int64;

            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))
            {
                var serializer = new BinaryFormatter
                {
                    Context = new StreamingContext(StreamingContextStates.Persistence)
                };
                serializer.Serialize(stream, expected);
                u.Save();
                t.Commit(CommitTransactionGrbit.LazyFlush);
            }

            Api.JetMove(this.sesid, this.tableid, JET_Move.First, MoveGrbit.None);
            using (var stream = new ColumnStream(this.sesid, this.tableid, this.columnidLongText))
            {
                var deseriaizer = new BinaryFormatter();
                var actual = (long)deseriaizer.Deserialize(stream);
                Assert.AreEqual(expected, actual);
            }
        }
开发者ID:ayende,项目名称:managed-esent,代码行数:25,代码来源:ColumnStreamTests.cs


示例14: ReadThrowsExceptionWhenNumberOfBytesIsNegative

 public void ReadThrowsExceptionWhenNumberOfBytesIsNegative()
 {
     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))
     {
         var buffer = new byte[10];
         stream.Read(buffer, 0, -1);
     }
 }
开发者ID:jtmueller,项目名称:ravendb,代码行数:10,代码来源:ColumnStreamTests.cs


示例15: ReadThrowsExceptionWhenBufferOffsetIsTooBig

 public void ReadThrowsExceptionWhenBufferOffsetIsTooBig()
 {
     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))
     {
         var buffer = new byte[10];
         stream.Read(buffer, buffer.Length, 1);
     }
 }
开发者ID:jtmueller,项目名称:ravendb,代码行数:10,代码来源:ColumnStreamTests.cs


示例16: SetAndRetrieveMultiValueColumnStream

        public void SetAndRetrieveMultiValueColumnStream()
        {
            string[] data = { Any.String, Any.String, Any.String, Any.String, Any.String, Any.String };

            Api.JetBeginTransaction(this.sesid);
            Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert);
            for (int i = 0; i < data.Length; ++i)
            {
                var column = new ColumnStream(this.sesid, this.tableid, this.columnidLongText);
                column.Itag = i + 1;
                using (var writer = new StreamWriter(column))
                {
                    writer.WriteLine(data[i]);
                }
            }

            this.UpdateAndGotoBookmark();
            Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);

            for (int i = 0; i < data.Length; ++i)
            {
                var column = new ColumnStream(this.sesid, this.tableid, this.columnidLongText);
                column.Itag = i + 1;
                using (var reader = new StreamReader(column))
                {
                    string actual = reader.ReadLine();
                    Assert.AreEqual(data[i], actual);
                }
            }
        }
开发者ID:ayende,项目名称:managed-esent,代码行数:30,代码来源:ColumnStreamTests.cs


示例17: 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


示例18: ColumnStreamSupportsWrite

 public void ColumnStreamSupportsWrite()
 {
     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))
     {
         Assert.IsTrue(stream.CanWrite);
     }
 }
开发者ID:ayende,项目名称:managed-esent,代码行数:9,代码来源:ColumnStreamTests.cs


示例19: 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


示例20: ColumnStreamThrowsExceptionWhenSeekOffsetIsTooLarge

 public void ColumnStreamThrowsExceptionWhenSeekOffsetIsTooLarge()
 {
     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.Seek(0x800000000, SeekOrigin.Begin);
     }
 }
开发者ID:ayende,项目名称:managed-esent,代码行数:9,代码来源:ColumnStreamTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Interop.Instance类代码示例发布时间:2022-05-26
下一篇:
C# ActiveDirectory.UserIdentifier类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap