本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.ToBytes方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.ToBytes方法的具体用法?C# JObject.ToBytes怎么用?C# JObject.ToBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JObject
的用法示例。
在下文中一共展示了JObject.ToBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDocumentInTransaction
public Guid AddDocumentInTransaction(string key, Guid? etag, JObject data, JObject metadata, TransactionInformation transactionInformation)
{
Api.JetSetCurrentIndex(session, Documents, "by_key");
Api.MakeKey(session, Documents, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
var isUpdate = Api.TrySeek(session, Documents, SeekGrbit.SeekEQ);
if (isUpdate)
{
EnsureNotLockedByTransaction(key, transactionInformation.Id);
EnsureDocumentEtagMatchInTransaction(key, etag);
using (var update = new Update(session, Documents, JET_prep.Replace))
{
Api.SetColumn(session, Documents, tableColumnsCache.DocumentsColumns["locked_by_transaction"], transactionInformation.Id.ToByteArray());
update.Save();
}
}
else
{
EnsureDocumentIsNotCreatedInAnotherTransaction(key, transactionInformation.Id);
}
EnsureTransactionExists(transactionInformation);
Guid newEtag = uuidGenerator.CreateSequentialUuid();
Api.JetSetCurrentIndex(session, DocumentsModifiedByTransactions, "by_key");
Api.MakeKey(session, DocumentsModifiedByTransactions, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
var isUpdateInTransaction = Api.TrySeek(session, DocumentsModifiedByTransactions, SeekGrbit.SeekEQ);
var bytes = documentCodecs.Aggregate(data.ToBytes(), (current, codec) => codec.Encode(key, data, metadata, current));
using (var update = new Update(session, DocumentsModifiedByTransactions, isUpdateInTransaction ? JET_prep.Replace : JET_prep.Insert))
{
Api.SetColumn(session, DocumentsModifiedByTransactions, tableColumnsCache.DocumentsModifiedByTransactionsColumns["key"], key, Encoding.Unicode);
Api.SetColumn(session, DocumentsModifiedByTransactions, tableColumnsCache.DocumentsModifiedByTransactionsColumns["data"], bytes);
Api.SetColumn(session, DocumentsModifiedByTransactions,
tableColumnsCache.DocumentsModifiedByTransactionsColumns["etag"],
newEtag.TransformToValueForEsentSorting());
Api.SetColumn(session, DocumentsModifiedByTransactions, tableColumnsCache.DocumentsModifiedByTransactionsColumns["metadata"], metadata.ToBytes());
Api.SetColumn(session, DocumentsModifiedByTransactions, tableColumnsCache.DocumentsModifiedByTransactionsColumns["last_modified"], DateTime.UtcNow);
Api.SetColumn(session, DocumentsModifiedByTransactions, tableColumnsCache.DocumentsModifiedByTransactionsColumns["delete_document"], false);
Api.SetColumn(session, DocumentsModifiedByTransactions, tableColumnsCache.DocumentsModifiedByTransactionsColumns["locked_by_transaction"], transactionInformation.Id.ToByteArray());
update.Save();
}
logger.DebugFormat("Inserted a new document with key '{0}', update: {1}, in transaction: {2}",
key, isUpdate, transactionInformation.Id);
return newEtag;
}
示例2: AddDocumentInTransaction
public Guid AddDocumentInTransaction(string key, Guid? etag, JObject data, JObject metadata, TransactionInformation transactionInformation)
{
var readResult = storage.Documents.Read(new JObject { { "key", key } });
if (readResult != null) // update
{
StorageHelper.AssertNotModifiedByAnotherTransaction(storage, this, key, readResult, transactionInformation);
AssertValidEtag(key, readResult, storage.DocumentsModifiedByTransactions.Read(new JObject{{"key", key}}), etag);
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 JObject { { "key", key } });
StorageHelper.AssertNotModifiedByAnotherTransaction(storage, this, key, readResult, transactionInformation);
}
storage.Transactions.UpdateKey(new JObject
{
{"txId", transactionInformation.Id.ToByteArray()},
{"timeout", DateTime.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 JObject
{
{"key", key},
{"etag", newEtag.ToByteArray()},
{"modified", DateTime.UtcNow},
{"txId", transactionInformation.Id.ToByteArray()}
}, ms.ToArray());
return newEtag;
}
示例3: PutMappedResult
public void PutMappedResult(string view, string docId, string reduceKey, JObject data, byte[] viewAndReduceKeyHashed)
{
Api.JetSetCurrentIndex(session, MappedResults, "by_pk");
Api.MakeKey(session, MappedResults, view, Encoding.Unicode, MakeKeyGrbit.NewKey);
Api.MakeKey(session, MappedResults, docId, Encoding.Unicode, MakeKeyGrbit.None);
Api.MakeKey(session, MappedResults, reduceKey, Encoding.Unicode, MakeKeyGrbit.None);
var isUpdate = Api.TrySeek(session, MappedResults, SeekGrbit.SeekEQ);
Guid etag = DocumentDatabase.CreateSequentialUuid();
using (var update = new Update(session, MappedResults, isUpdate ? JET_prep.Replace : 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);
Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["data"], data.ToBytes());
Api.SetColumn(session, MappedResults, tableColumnsCache.MappedResultsColumns["etag"], etag.TransformToValueForEsentSorting());
update.Save();
}
}
示例4: AddDocument
public Guid AddDocument(string key, Guid? etag, JObject data, JObject metadata)
{
Api.JetSetCurrentIndex(session, Documents, "by_key");
Api.MakeKey(session, Documents, key, Encoding.Unicode, MakeKeyGrbit.NewKey);
var isUpdate = Api.TrySeek(session, Documents, SeekGrbit.SeekEQ);
if (isUpdate)
{
EnsureNotLockedByTransaction(key, null);
EnsureDocumentEtagMatch(key, etag, "PUT");
}
else
{
EnsureDocumentIsNotCreatedInAnotherTransaction(key, Guid.NewGuid());
if (Api.TryMoveFirst(session, Details))
Api.EscrowUpdate(session, Details, tableColumnsCache.DetailsColumns["document_count"], 1);
}
Guid newEtag = uuidGenerator.CreateSequentialUuid();
var bytes = documentCodecs.Aggregate(data.ToBytes(), (current, codec) => codec.Encode(key, data, metadata, current));
using (var update = new Update(session, Documents, isUpdate ? JET_prep.Replace : JET_prep.Insert))
{
Api.SetColumn(session, Documents, tableColumnsCache.DocumentsColumns["key"], key, Encoding.Unicode);
Api.SetColumn(session, Documents, tableColumnsCache.DocumentsColumns["data"], bytes);
Api.SetColumn(session, Documents, tableColumnsCache.DocumentsColumns["etag"], newEtag.TransformToValueForEsentSorting());
Api.SetColumn(session, Documents, tableColumnsCache.DocumentsColumns["last_modified"], DateTime.UtcNow);
Api.SetColumn(session, Documents, tableColumnsCache.DocumentsColumns["metadata"], metadata.ToBytes());
update.Save();
}
logger.DebugFormat("Inserted a new document with key '{0}', update: {1}, ",
key, isUpdate);
return newEtag;
}
示例5: AddDocument
public Guid AddDocument(string key, Guid? etag, JObject data, JObject metadata)
{
AssertValidEtag(key, etag, "PUT", null);
var ms = new MemoryStream();
metadata.WriteTo(ms);
var bytes = documentCodecs.Aggregate(data.ToBytes(), (current, codec) => codec.Encode(key, data, metadata, current));
ms.Write(bytes, 0, bytes.Length);
var newEtag = generator.CreateSequentialUuid();
storage.Documents.Put(new JObject
{
{"key", key},
{"etag", newEtag.ToByteArray()},
{"modified", DateTime.UtcNow},
{"id", GetNextDocumentId()},
{"entityName", metadata.Value<string>("Raven-Entity-Name")}
},ms.ToArray());
return newEtag;
}