当前位置: 首页>>代码示例>>C#>>正文


C# IHttpContext.ReadBsonArray方法代码示例

本文整理汇总了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);
				});
			}
		}
开发者ID:samueldjack,项目名称:ravendb,代码行数:59,代码来源:AttachmentReplicationResponder.cs

示例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);
                });
            }
        }
开发者ID:philiphoy,项目名称:ravendb,代码行数:55,代码来源:AttachmentReplicationResponder.cs


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