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


C# RavenJObject.WriteTo方法代码示例

本文整理汇总了C#中RavenJObject.WriteTo方法的典型用法代码示例。如果您正苦于以下问题:C# RavenJObject.WriteTo方法的具体用法?C# RavenJObject.WriteTo怎么用?C# RavenJObject.WriteTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RavenJObject的用法示例。


在下文中一共展示了RavenJObject.WriteTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
			}
		}
开发者ID:bbqchickenrobot,项目名称:ravendb,代码行数:29,代码来源:Lists.cs

示例2: AddAttachment

		public Guid AddAttachment(string key, Guid? etag, Stream data, RavenJObject headers)
		{
			AssertValidEtag(key, etag, "PUT");

			if(data	== null)
			{
				var attachment = GetAttachment(key);
				if(attachment == null)
					throw new InvalidOperationException("When adding new attachment, the attachment data must be specified");
				attachment.Metadata = headers;
				return AddAttachment(key, etag, attachment.Data(), headers);
			}

			var ms = new MemoryStream();
			headers.WriteTo(ms);
			data.CopyTo(ms);
			var newEtag = generator.CreateSequentialUuid();
			var result = storage.Attachments.Put(new RavenJObject
			{
				{"key", key},
				{"etag", newEtag.ToByteArray()}
			}, ms.ToArray());
		   if (result == false)
			   throw new ConcurrencyException("PUT attempted on attachment '" + key + "' while it was locked by another transaction");
			logger.Debug("Adding attachment {0}", key);
			return newEtag;
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:27,代码来源:AttachmentsStorageActions.cs

示例3: PutMappedResult

		public void PutMappedResult(string view, string docId, string reduceKey, RavenJObject data)
		{
			Etag etag = uuidGenerator.CreateSequentialUuid(UuidType.MappedResults);
			using (var update = new Update(session, MappedResults, JET_prep.Insert))
			{
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["view"], view, Encoding.Unicode);
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["document_key"], docId, Encoding.Unicode);
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["reduce_key"], reduceKey, Encoding.Unicode);
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["hashed_reduce_key"], HashReduceKey(reduceKey));
				var mapBucket = IndexingUtil.MapBucket(docId);
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["bucket"], mapBucket);

				using (Stream stream = new BufferedStream(new ColumnStream(session, MappedResults, tableColumnsCache.MappedResultsColumns["data"])))
				{
					using (var dataStream = documentCodecs.Aggregate(stream, (ds, codec) => codec.Value.Encode(reduceKey, data, null, ds)))
					{
						data.WriteTo(dataStream);
						dataStream.Flush();
					}
				}

				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["etag"], etag.TransformToValueForEsentSorting());
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["timestamp"], SystemTime.UtcNow.ToBinary());

				update.Save();
			}
		}
开发者ID:KyleGobel,项目名称:ravendb,代码行数:27,代码来源:MappedResults.cs

示例4: PutReducedResult

		public void PutReducedResult(string view, string reduceKey, int level, int sourceBucket, int bucket, RavenJObject data)
		{
			Guid etag = uuidGenerator.CreateSequentialUuid();

			using (var update = new Update(session, ReducedResults, JET_prep.Insert))
			{
				Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["view"], view, Encoding.Unicode);
				Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["level"], level);
				Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["reduce_key"], reduceKey, Encoding.Unicode);
				Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["hashed_reduce_key"], HashReduceKey(reduceKey));
				Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["bucket"], bucket);
				Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["source_bucket"], sourceBucket);

				using (Stream stream = new BufferedStream(new ColumnStream(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["data"])))
				{
					using (var dataStream = documentCodecs.Aggregate(stream, (ds, codec) => codec.Value.Encode(reduceKey, data, null, ds)))
					{
						data.WriteTo(dataStream);
						dataStream.Flush();
					}
				}

				Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["etag"], etag.TransformToValueForEsentSorting());
				Api.SetColumn(session, ReducedResults, tableColumnsCache.ReduceResultsColumns["timestamp"], SystemTime.UtcNow);

				update.Save();
			}
		}
开发者ID:Trebornide,项目名称:ravendb,代码行数:28,代码来源:MappedResults.cs

示例5: Set

		public void Set(string name, string key, RavenJObject data, UuidType type)
		{
			var memoryStream = new MemoryStream();
			data.WriteTo(memoryStream);
			
			storage.Lists.Put(new RavenJObject
			{
				{"name", name},
				{"key", key},
				{"etag", generator.CreateSequentialUuid(type).ToByteArray()}
			}, memoryStream.ToArray());
		}
开发者ID:925coder,项目名称:ravendb,代码行数:12,代码来源:ListsStorageActions.cs

示例6: PutMappedResult

 public void PutMappedResult(string view, string docId, string reduceKey, RavenJObject data, byte[] viewAndReduceKeyHashed)
 {
     var ms = new MemoryStream();
     data.WriteTo(ms);
 	var byteArray = generator.CreateSequentialUuid().ToByteArray();
 	var key = new RavenJObject
 	{
 		{"view", view},
 		{"reduceKey", reduceKey},
 		{"docId", docId},
 		{"etag", byteArray},
 		{"timestamp", DateTime.Now}
 	};
 	storage.MappedResults.Put(key, ms.ToArray());
 }
开发者ID:nzdunic,项目名称:ravendb,代码行数:15,代码来源:MappedResultsStorageAction.cs

示例7: ExportAttachmentsDeletion

 public Task<Etag> ExportAttachmentsDeletion(JsonTextWriter jsonWriter, Etag startAttachmentsDeletionEtag, Etag maxAttachmentEtag)
 {
     var lastEtag = startAttachmentsDeletionEtag;
     database.TransactionalStorage.Batch(accessor =>
     {
         foreach (var listItem in accessor.Lists.Read(Constants.RavenPeriodicExportsAttachmentsTombstones, startAttachmentsDeletionEtag, maxAttachmentEtag, int.MaxValue))
         {
             var o = new RavenJObject
             {
                 {"Key", listItem.Key}
             };
             o.WriteTo(jsonWriter);
             lastEtag = listItem.Etag;
         }
     });
     return new CompletedTask<Etag>(lastEtag);
 }
开发者ID:ricardobrandao,项目名称:ravendb,代码行数:17,代码来源:SmugglerEmbeddedDatabaseOperations.cs

示例8: AddDocumentInTransaction

		public Etag AddDocumentInTransaction(string key, Etag etag, RavenJObject data, RavenJObject metadata, TransactionInformation transactionInformation)
		{
			var readResult = storage.Documents.Read(new RavenJObject { { "key", key } });
			if (readResult != null) // update
			{
				StorageHelper.AssertNotModifiedByAnotherTransaction(storage, this, key, readResult, transactionInformation);
				AssertValidEtag(key, readResult, storage.DocumentsModifiedByTransactions.Read(new RavenJObject { { "key", key } }), etag, "DELETE");

				var ravenJObject = ((RavenJObject)readResult.Key.CloneToken());
				ravenJObject["txId"] = transactionInformation.Id.ToByteArray();
				if (storage.Documents.UpdateKey(ravenJObject) == false)
					throw new ConcurrencyException("PUT attempted on document '" + key +
												   "' that is currently being modified by another transaction");
			}
			else
			{
				readResult = storage.DocumentsModifiedByTransactions.Read(new RavenJObject { { "key", key } });
				StorageHelper.AssertNotModifiedByAnotherTransaction(storage, this, key, readResult, transactionInformation);
			}

			storage.Transactions.UpdateKey(new RavenJObject
			                               	{
			                               		{"txId", transactionInformation.Id.ToByteArray()},
			                               		{"timeout", SystemTime.UtcNow.Add(transactionInformation.Timeout)}
			                               	});

			var ms = new MemoryStream();

			metadata.WriteTo(ms);
			using (var stream = documentCodecs.Aggregate<Lazy<AbstractDocumentCodec>, Stream>(ms, (memoryStream, codec) => codec.Value.Encode(key, data, metadata, memoryStream)))
			{
				data.WriteTo(stream);
				stream.Flush();
			}
			var newEtag = generator.CreateSequentialUuid(UuidType.DocumentTransactions);
			storage.DocumentsModifiedByTransactions.Put(new RavenJObject
			                                            	{
			                                            		{"key", key},
			                                            		{"etag", newEtag.ToByteArray()},
			                                            		{"modified", SystemTime.UtcNow},
			                                            		{"txId", transactionInformation.Id.ToByteArray()}
			                                            	}, ms.ToArray());

			return newEtag;
		}
开发者ID:samueldjack,项目名称:ravendb,代码行数:45,代码来源:TransactionStorageActions.cs

示例9: AddAttachment

        public Guid AddAttachment(string key, Guid? etag, byte[] data, RavenJObject headers)
        {
            AssertValidEtag(key, etag, "PUT");

            var ms = new MemoryStream();
            headers.WriteTo(ms);
            ms.Write(data,0,data.Length);
            var newEtag = generator.CreateSequentialUuid();
			var result = storage.Attachments.Put(new RavenJObject
			{
				{"key", key},
				{"etag", newEtag.ToByteArray()}
			}, ms.ToArray());
           if (result == false)
               throw new ConcurrencyException("PUT attempted on attachment '" + key + "' while it was locked by another transaction");
            logger.Debug("Adding attachment {0}", key);
            return newEtag;
        }
开发者ID:wbinford,项目名称:ravendb,代码行数:18,代码来源:AttachmentsStorageActions.cs

示例10: Add

		public Guid Add(string key, string tag, Guid? etag, RavenJObject metadata, RavenJObject document)
		{
			EnsureEtagMatches(key, etag);

			var stream = new PooledMemoryStream();
			
			metadata.WriteTo(new BsonWriter(stream));
			document.WriteTo(new BsonWriter(stream));

			var newGuid = Guid.NewGuid();
			Storage.Documents.Put(new RavenJObject
			{
				{"key", key},
				{"tag", tag},
				{"etag", newGuid.ToByteArray()}
			}, stream);

			return newGuid;
		}
开发者ID:hibernating-rhinos,项目名称:Raven.Light,代码行数:19,代码来源:StorageActions.cs

示例11: AddDocumentInTransaction

		public Guid AddDocumentInTransaction(string key, Guid? etag, RavenJObject data, RavenJObject metadata, TransactionInformation transactionInformation)
		{
			var readResult = storage.Documents.Read(new RavenJObject {{"key", key}});
			if (readResult != null) // update
			{
				StorageHelper.AssertNotModifiedByAnotherTransaction(storage, this, key, readResult, transactionInformation);
				AssertValidEtag(key, readResult, storage.DocumentsModifiedByTransactions.Read(new RavenJObject { { "key", key } }), etag);

				((RavenJObject)readResult.Key)["txId"] = transactionInformation.Id.ToByteArray();
				if (storage.Documents.UpdateKey(readResult.Key) == false)
					throw new ConcurrencyException("PUT attempted on document '" + key +
												   "' that is currently being modified by another transaction");
			}
			else
			{
				readResult = storage.DocumentsModifiedByTransactions.Read(new RavenJObject { { "key", key } });
				StorageHelper.AssertNotModifiedByAnotherTransaction(storage, this, key, readResult, transactionInformation);
			}

			storage.Transactions.UpdateKey(new RavenJObject
			                               	{
			                               		{"txId", transactionInformation.Id.ToByteArray()},
			                               		{"timeout", SystemTime.UtcNow.Add(transactionInformation.Timeout)}
			                               	});

			var ms = new MemoryStream();

			metadata.WriteTo(ms);
			var dataBytes = documentCodecs.Aggregate(data.ToBytes(), (bytes, codec) => codec.Encode(key, data, metadata, bytes));
			ms.Write(dataBytes, 0, dataBytes.Length);

			var newEtag = generator.CreateSequentialUuid();
			storage.DocumentsModifiedByTransactions.Put(new RavenJObject
			                                            	{
			                                            		{"key", key},
			                                            		{"etag", newEtag.ToByteArray()},
			                                            		{"modified", SystemTime.UtcNow},
			                                            		{"txId", transactionInformation.Id.ToByteArray()}
			                                            	}, ms.ToArray());

			return newEtag;
		}
开发者ID:nhsevidence,项目名称:ravendb,代码行数:42,代码来源:TransactionStorageActions.cs

示例12: PutMappedResult

		public void PutMappedResult(string view, string docId, string reduceKey, RavenJObject data)
		{
			var ms = new MemoryStream();

			using (var stream = documentCodecs.Aggregate((Stream)ms, (ds, codec) => codec.Value.Encode(reduceKey, data, null, ds)))
			{
				data.WriteTo(stream);
			}
			var byteArray = generator.CreateSequentialUuid(UuidType.MappedResults).ToByteArray();
			var key = new RavenJObject
			{
				{"view", view},
				{"reduceKey", reduceKey},
				{"docId", docId},
				{"etag", byteArray},
				{"bucket", IndexingUtil.MapBucket(docId)},
				{"timestamp", SystemTime.UtcNow}
			};
			storage.MappedResults.Put(key, ms.ToArray());
		}
开发者ID:robashton,项目名称:ravendb,代码行数:20,代码来源:MappedResultsStorageAction.cs

示例13: PutMappedResult

		public void PutMappedResult(string view, string docId, string reduceKey, RavenJObject data, byte[] viewAndReduceKeyHashed)
		{
	        Guid etag = uuidGenerator.CreateSequentialUuid();

			using (var update = new Update(session, MappedResults, JET_prep.Insert))
			{
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["view"], view, Encoding.Unicode);
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["document_key"], docId, Encoding.Unicode);
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["reduce_key"], reduceKey, Encoding.Unicode);
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["reduce_key_and_view_hashed"], viewAndReduceKeyHashed);

				using (var stream = new BufferedStream(new ColumnStream(session, MappedResults, tableColumnsCache.MappedResultsColumns["data"])))
				{
					data.WriteTo(stream);
					stream.Flush();
				}

				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["etag"], etag.TransformToValueForEsentSorting());
				Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["timestamp"], SystemTime.Now);

				update.Save();
			}
		}
开发者ID:neiz,项目名称:ravendb,代码行数:23,代码来源:MappedResults.cs

示例14: PutReducedResult

		public void PutReducedResult(string name, string reduceKey, int level, int sourceBucket, int bucket, RavenJObject data)
		{
			var ms = new MemoryStream();

			using (var stream = documentCodecs.Aggregate((Stream)ms, (ds, codec) => codec.Value.Encode(reduceKey, data, null, ds)))
			{
				data.WriteTo(stream);
			}

			var etag = generator.CreateSequentialUuid().ToByteArray();

			storage.ReduceResults.Put(new RavenJObject
			{
				{"view", name},
				{"etag", etag},
				{"reduceKey", reduceKey},
				{"level", level},
				{"sourceBucket", sourceBucket},
				{"bucket", bucket},
				{"timestamp", SystemTime.UtcNow}
			}, ms.ToArray());
		}
开发者ID:emertechie,项目名称:ravendb,代码行数:22,代码来源:MappedResultsStorageAction.cs

示例15: PutReducedResult

		public void PutReducedResult(int view, string reduceKey, int level, int sourceBucket, int bucket, RavenJObject data)
		{
			var reduceResultsByViewAndReduceKeyAndLevelAndSourceBucket =
				tableStorage.ReduceResults.GetIndex(Tables.ReduceResults.Indices.ByViewAndReduceKeyAndLevelAndSourceBucket);
			var reduceResultsByViewAndReduceKeyAndLevelAndBucket =
				tableStorage.ReduceResults.GetIndex(Tables.ReduceResults.Indices.ByViewAndReduceKeyAndLevelAndBucket);
			var reduceResultsByViewAndReduceKeyAndLevel =
				tableStorage.ReduceResults.GetIndex(Tables.ReduceResults.Indices.ByViewAndReduceKeyAndLevel);
			var reduceResultsByView =
				tableStorage.ReduceResults.GetIndex(Tables.ReduceResults.Indices.ByView);
			var reduceResultsData = tableStorage.ReduceResults.GetIndex(Tables.ReduceResults.Indices.Data);

            var ms = CreateStream();
			using (
				var stream = documentCodecs.Aggregate((Stream) new UndisposableStream(ms),
					(ds, codec) => codec.Value.Encode(reduceKey, data, null, ds)))
			{
				data.WriteTo(stream);
				stream.Flush();
			}

			var id = generator.CreateSequentialUuid(UuidType.MappedResults);
            var idAsSlice = (Slice)id.ToString();

			var reduceResult = new Structure<ReduceResultFields>(tableStorage.ReduceResults.Schema)
				.Set(ReduceResultFields.IndexId, view)
				.Set(ReduceResultFields.Etag, id.ToByteArray())
				.Set(ReduceResultFields.ReduceKey, reduceKey)
				.Set(ReduceResultFields.Level, level)
				.Set(ReduceResultFields.SourceBucket, sourceBucket)
				.Set(ReduceResultFields.Bucket, bucket)
				.Set(ReduceResultFields.Timestamp, SystemTime.UtcNow.ToBinary());

			tableStorage.ReduceResults.AddStruct(writeBatch.Value, idAsSlice, reduceResult, 0);

			ms.Position = 0;
			reduceResultsData.Add(writeBatch.Value, idAsSlice, ms, 0);

            var viewKey = CreateViewKey(view);
            var viewAndReduceKeyAndLevel = CreateReduceResultsKey(view,reduceKey, level);
            var viewAndReduceKeyAndLevelAndSourceBucket = CreateReduceResultsWithBucketKey(view, reduceKey, level, sourceBucket);
            var viewAndReduceKeyAndLevelAndBucket = CreateReduceResultsWithBucketKey(view, reduceKey, level, bucket);

            reduceResultsByViewAndReduceKeyAndLevelAndSourceBucket.MultiAdd(writeBatch.Value, viewAndReduceKeyAndLevelAndSourceBucket, idAsSlice);
            reduceResultsByViewAndReduceKeyAndLevel.MultiAdd(writeBatch.Value, viewAndReduceKeyAndLevel, idAsSlice);
            reduceResultsByViewAndReduceKeyAndLevelAndBucket.MultiAdd(writeBatch.Value, viewAndReduceKeyAndLevelAndBucket, idAsSlice);
            reduceResultsByView.MultiAdd(writeBatch.Value, viewKey, idAsSlice);
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:48,代码来源:MappedResultsStorageActions.cs


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