本文整理汇总了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();
}
}
示例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;
}
示例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);
}
}
示例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));
}
示例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);
}
}
示例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);
}
}