本文整理汇总了C#中Couchbase.Lite.Database.RememberAttachmentWriter方法的典型用法代码示例。如果您正苦于以下问题:C# Database.RememberAttachmentWriter方法的具体用法?C# Database.RememberAttachmentWriter怎么用?C# Database.RememberAttachmentWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Couchbase.Lite.Database
的用法示例。
在下文中一共展示了Database.RememberAttachmentWriter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InstallAttachmentBodies
/// <summary>
/// Goes through an _attachments dictionary and replaces any values that are Attachment objects
/// with proper JSON metadata dicts.
/// </summary>
/// <remarks>
/// Goes through an _attachments dictionary and replaces any values that are Attachment objects
/// with proper JSON metadata dicts. It registers the attachment bodies with the blob store and sets
/// the metadata 'digest' and 'follows' properties accordingly.
/// </remarks>
internal static IDictionary<string, object> InstallAttachmentBodies(IDictionary<String, Object> attachments, Database database)
{
var updatedAttachments = new Dictionary<string, object>();
foreach (string name in attachments.Keys)
{
object value;
attachments.TryGetValue(name, out value);
if (value is Attachment)
{
var attachment = (Attachment)value;
var metadataMutable = new AttachmentMetadataDictionary(attachment.Metadata);
var body = attachment.Body;
if (body != null)
{
// Copy attachment body into the database's blob store:
var writer = BlobStoreWriterForBody(body, database);
metadataMutable[AttachmentMetadataDictionaryKeys.Length] = (long)writer.GetLength();
metadataMutable[AttachmentMetadataDictionaryKeys.Digest] = writer.SHA1DigestString();
metadataMutable[AttachmentMetadataDictionaryKeys.Follows] = true;
var errMsg = metadataMutable.Validate();
if (errMsg != null) {
throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadAttachment, Tag,
"Error installing attachment body ({0})", errMsg);
}
database.RememberAttachmentWriter(writer, writer.SHA1DigestString());
}
attachment.Dispose();
updatedAttachments[name] = metadataMutable;
} else if (value is AttachmentInternal) {
throw Misc.CreateExceptionAndLog(Log.To.Database, StatusCode.BadParam, Tag,
"AttachmentInternal objects not expected here. Could indicate a bug");
} else {
if (value != null) {
updatedAttachments[name] = value;
}
}
}
return updatedAttachments;
}
示例2: InstallAttachmentBodies
/// <summary>
/// Goes through an _attachments dictionary and replaces any values that are Attachment objects
/// with proper JSON metadata dicts.
/// </summary>
/// <remarks>
/// Goes through an _attachments dictionary and replaces any values that are Attachment objects
/// with proper JSON metadata dicts. It registers the attachment bodies with the blob store and sets
/// the metadata 'digest' and 'follows' properties accordingly.
/// </remarks>
internal static IDictionary<string, object> InstallAttachmentBodies(IDictionary<String, Object> attachments, Database database)
{
var updatedAttachments = new Dictionary<string, object>();
foreach (string name in attachments.Keys)
{
object value;
attachments.TryGetValue(name, out value);
if (value is Attachment)
{
var attachment = (Attachment)value;
var metadataMutable = new Dictionary<string, object>(attachment.Metadata);
var body = attachment.Body;
if (body != null)
{
// Copy attachment body into the database's blob store:
var writer = BlobStoreWriterForBody(body, database);
metadataMutable["length"] = (long)writer.GetLength();
metadataMutable["digest"] = writer.SHA1DigestString();
metadataMutable["follows"] = true;
database.RememberAttachmentWriter(writer);
}
attachment.Dispose();
updatedAttachments[name] = metadataMutable;
}
else if (value is AttachmentInternal)
{
throw new ArgumentException("AttachmentInternal objects not expected here. Could indicate a bug");
}
else
{
if (value != null)
updatedAttachments[name] = value;
}
}
return updatedAttachments;
}
示例3: InstallAttachmentBodies
internal static IDictionary<string, object> InstallAttachmentBodies(IDictionary<string
, object> attachments, Database database)
{
IDictionary<string, object> updatedAttachments = new Dictionary<string, object>();
foreach (string name in attachments.Keys)
{
object value = attachments.Get(name);
if (value is Couchbase.Lite.Attachment)
{
Couchbase.Lite.Attachment attachment = (Couchbase.Lite.Attachment)value;
IDictionary<string, object> metadataMutable = new Dictionary<string, object>();
metadataMutable.PutAll(attachment.GetMetadata());
InputStream body = attachment.GetBodyIfNew();
if (body != null)
{
// Copy attachment body into the database's blob store:
BlobStoreWriter writer = BlobStoreWriterForBody(body, database);
metadataMutable.Put("length", (long)writer.GetLength());
metadataMutable.Put("digest", writer.MD5DigestString());
metadataMutable.Put("follows", true);
database.RememberAttachmentWriter(writer);
}
updatedAttachments.Put(name, metadataMutable);
}
else
{
if (value is AttachmentInternal)
{
throw new ArgumentException("AttachmentInternal objects not expected here. Could indicate a bug"
);
}
else
{
if (value != null)
{
updatedAttachments.Put(name, value);
}
}
}
}
return updatedAttachments;
}
示例4: InstallAttachmentBodies
/// <summary>
/// Goes through an _attachments dictionary and replaces any values that are Attachment objects
/// with proper JSON metadata dicts.
/// </summary>
/// <remarks>
/// Goes through an _attachments dictionary and replaces any values that are Attachment objects
/// with proper JSON metadata dicts. It registers the attachment bodies with the blob store and sets
/// the metadata 'digest' and 'follows' properties accordingly.
/// </remarks>
internal static IDictionary<string, object> InstallAttachmentBodies(IDictionary<String, Object> attachments, Database database)
{
var updatedAttachments = new Dictionary<string, object>();
foreach (string name in attachments.Keys)
{
object value;
attachments.TryGetValue(name, out value);
if (value is Attachment)
{
var attachment = (Attachment)value;
var metadataMutable = new AttachmentMetadataDictionary(attachment.Metadata);
var body = attachment.Body;
if (body != null)
{
// Copy attachment body into the database's blob store:
var writer = BlobStoreWriterForBody(body, database);
metadataMutable[AttachmentMetadataDictionary.LENGTH] = (long)writer.GetLength();
metadataMutable[AttachmentMetadataDictionary.DIGEST] = writer.SHA1DigestString();
metadataMutable[AttachmentMetadataDictionary.FOLLOWS] = true;
var errMsg = metadataMutable.Validate();
if (errMsg != null) {
throw new CouchbaseLiteException("Error installing attachment body ({0})", errMsg) { Code = StatusCode.BadAttachment };
}
database.RememberAttachmentWriter(writer);
}
attachment.Dispose();
updatedAttachments[name] = metadataMutable;
}
else if (value is AttachmentInternal)
{
throw new ArgumentException("AttachmentInternal objects not expected here. Could indicate a bug");
}
else
{
if (value != null)
updatedAttachments[name] = value;
}
}
return updatedAttachments;
}