本文整理匯總了C#中Blob.AddReference方法的典型用法代碼示例。如果您正苦於以下問題:C# Blob.AddReference方法的具體用法?C# Blob.AddReference怎麽用?C# Blob.AddReference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Blob
的用法示例。
在下文中一共展示了Blob.AddReference方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateBlob
/// <summary>
/// Creates a in-memory binary blob as a <see cref="Blob"/> that will also be stored using the active <see cref="IOdbBackend"/>.
/// Even if <see cref="Blob"/> is new (not in the ODB), memory will be copied.
/// </summary>
/// <param name="data">The data.</param>
/// <param name="size">The size.</param>
/// <returns>The <see cref="Blob"/> containing given data, with its reference count incremented.</returns>
public Blob CreateBlob(IntPtr data, int size)
{
// Generate hash
ObjectId objectId;
var nativeMemoryStream = new NativeMemoryStream(data, size);
using (var digestStream = new DigestStream(Stream.Null))
{
nativeMemoryStream.CopyTo(digestStream);
objectId = digestStream.CurrentHash;
}
lock (LoadedBlobs)
{
var blob = Lookup(objectId);
// Blob doesn't exist yet, so let's create it and save it to ODB.
if (blob == null)
{
// Let's go back to beginning of stream after previous hash
nativeMemoryStream.Position = 0;
// Create blob
blob = new Blob(this, objectId, data, size);
blob.AddReference();
// Write to disk
backendWrite.Write(objectId, nativeMemoryStream, size, false);
// Add blob to cache
LoadedBlobs.Add(objectId, blob);
}
return blob;
}
}