本文整理汇总了C#中IHttpContext.ReadBsonArray方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContext.ReadBsonArray方法的具体用法?C# IHttpContext.ReadBsonArray怎么用?C# IHttpContext.ReadBsonArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpContext
的用法示例。
在下文中一共展示了IHttpContext.ReadBsonArray方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Respond
public override void Respond(IHttpContext context)
{
var src = context.Request.QueryString["from"];
if (string.IsNullOrEmpty(src))
{
context.SetStatusToBadRequest();
return;
}
while (src.EndsWith("/"))
src = src.Substring(0, src.Length - 1);// remove last /, because that has special meaning for Raven
if (string.IsNullOrEmpty(src))
{
context.SetStatusToBadRequest();
return;
}
var array = context.ReadBsonArray();
using (Database.DisableAllTriggersForCurrentThread())
{
Database.TransactionalStorage.Batch(actions =>
{
Etag lastEtag = Etag.Empty;
foreach (RavenJObject attachment in array)
{
var metadata = attachment.Value<RavenJObject>("@metadata");
if (metadata[Constants.RavenReplicationSource] == null)
{
// not sure why, old attachment from when the user didn't have replication
// that we suddenly decided to replicate, choose the source for that
metadata[Constants.RavenReplicationSource] = RavenJToken.FromObject(src);
}
lastEtag = Etag.Parse(attachment.Value<byte[]>("@etag"));
var id = attachment.Value<string>("@id");
ReplicateAttachment(actions, id, metadata, attachment.Value<byte[]>("data"), lastEtag, src);
}
var replicationDocKey = Constants.RavenReplicationSourcesBasePath + "/" + src;
var replicationDocument = Database.Get(replicationDocKey, null);
Etag lastDocId = null;
if (replicationDocument != null)
{
lastDocId =
replicationDocument.DataAsJson.JsonDeserialization<SourceReplicationInformation>().
LastDocumentEtag;
}
Database.Put(replicationDocKey, null,
RavenJObject.FromObject(new SourceReplicationInformation
{
Source = src,
LastDocumentEtag = lastDocId,
LastAttachmentEtag = lastEtag,
ServerInstanceId = Database.TransactionalStorage.Id
}),
new RavenJObject(), null);
});
}
}
示例2: Respond
public override void Respond(IHttpContext context)
{
var src = context.Request.QueryString["from"];
if (string.IsNullOrEmpty(src))
{
context.SetStatusToBadRequest();
return;
}
while (src.EndsWith("/"))
src = src.Substring(0, src.Length - 1);// remove last /, because that has special meaning for Raven
if (string.IsNullOrEmpty(src))
{
context.SetStatusToBadRequest();
return;
}
var array = context.ReadBsonArray();
using (ReplicationContext.Enter())
{
Database.TransactionalStorage.Batch(actions =>
{
byte[] lastEtag = Guid.Empty.ToByteArray();
foreach (JObject attachment in array)
{
var metadata = attachment.Value<JObject>("@metadata");
if(metadata[ReplicationConstants.RavenReplicationSource] == null)
{
// not sure why, old attachment from when the user didn't have replciation
// that we suddenly decided to replicate, choose the source for that
metadata[ReplicationConstants.RavenReplicationSource] = JToken.FromObject(src);
}
lastEtag = attachment.Value<byte[]>("@etag");
var id = attachment.Value<string>("@id");
ReplicateAttachment(actions, id, metadata, attachment.Value<byte[]>("data"), new Guid(lastEtag), src);
}
var replicationDocKey = ReplicationConstants.RavenReplicationSourcesBasePath + "/" + src;
var replicationDocument = Database.Get(replicationDocKey,null);
var lastDocId = Guid.Empty;
if(replicationDocument != null)
{
lastDocId =
replicationDocument.DataAsJson.JsonDeserialization<SourceReplicationInformation>().
LastDocumentEtag;
}
Database.Put(replicationDocKey, null,
JObject.FromObject(new SourceReplicationInformation
{
LastDocumentEtag = lastDocId,
LastAttachmentEtag = new Guid(lastEtag)
}),
new JObject(), null);
});
}
}