本文整理汇总了C#中RavenJObject.Add方法的典型用法代码示例。如果您正苦于以下问题:C# RavenJObject.Add方法的具体用法?C# RavenJObject.Add怎么用?C# RavenJObject.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RavenJObject
的用法示例。
在下文中一共展示了RavenJObject.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: can_update_a_doc_within_transaction_scope
public void can_update_a_doc_within_transaction_scope()
{
using (var documentStore = NewDocumentStore(requestedStorage: "esent"))
{
EnsureDtcIsSupported(documentStore);
var id1 = Guid.NewGuid();
RavenJObject dummy = null;
using (TransactionScope trnx = new TransactionScope())
{
using (var session = documentStore.OpenSession())
{
dummy = new RavenJObject();
dummy.Add("Name", "This is the object content");
dummy.Add("Id", RavenJToken.FromObject(id1));
session.Store(dummy);
session.SaveChanges();
}
using (var session = documentStore.OpenSession())
{
session.Store(dummy);
session.SaveChanges();
}
trnx.Complete();
}
}
}
示例2: CloningTestsStoresValues
public void CloningTestsStoresValues()
{
var f = new RavenJObject();
f.Add("test", "Test");
f.Add("2nd", "second");
Assert.True(f.Count == 2);
}
示例3: HandleConflictDocuments
public static RavenJToken HandleConflictDocuments(RavenJObject metadata)
{
if (metadata == null)
return null;
if (metadata.ContainsKey(Constants.RavenReplicationConflictDocument))
metadata.Add(Constants.RavenReplicationConflictDocumentForcePut, true);
if (metadata.ContainsKey(Constants.RavenReplicationConflict))
metadata.Add(Constants.RavenReplicationConflictSkipResolution, true);
return metadata;
}
示例4: Execute
public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
int count = 0;
foreach (var partition in rows.Partition(Constants.BatchSize))
{
var cmds = new List<ICommandData>();
foreach (var votesForPost in partition.GroupBy(row => row["PostId"]))
{
var votes = new List<RavenJToken>();
foreach (var row in votesForPost)
{
var vote = new RavenJObject(new[]
{
new KeyValuePair<string, RavenJToken>("VoteTypeId", new RavenJValue(row["VoteTypeId"])),
new KeyValuePair<string, RavenJToken>("CreationDate", new RavenJValue(row["CreationDate"]))
});
switch ((long) row["VoteTypeId"])
{
case 5L:
vote.Add("UserId", new RavenJValue("users/" + row["UserId"]));
break;
case 9L:
vote.Add("BountyAmount", new RavenJValue(row["BountyAmount"]));
break;
}
votes.Add(vote);
}
cmds.Add(new PatchCommandData
{
Key = "posts/" + votesForPost.Key,
Patches = new[]
{
new PatchRequest
{
Name = "Votes",
Type = PatchCommandType.Set,
Value = new RavenJArray(votes)
},
}
});
}
count++;
WriteCommandsTo("Votes #" + count.ToString("00000") + ".json", cmds);
}
yield break;
}
示例5: RavenSessionStateTest
protected RavenSessionStateTest()
{
MockDocumentSession = new Mock<IDocumentSession>();
MockDocumentStore = new Mock<IDocumentStore>();
MockSyncAdvancedSessionOperation = new Mock<ISyncAdvancedSessionOperation>();
MockDocumentSession.SetupGet(cmd => cmd.Advanced).Returns(MockSyncAdvancedSessionOperation.Object);
MockDocumentStore.Setup(cmd => cmd.OpenSession()).Returns(MockDocumentSession.Object);
Subject = new RavenSessionStateStoreProvider{ApplicationName = ApplicationName, SessionStateConfig = new SessionStateSection
{
Timeout = Timeout
}};
Subject.Initialize("", new NameValueCollection(), MockDocumentStore.Object);
if (PreExistingSessionStateDocument != null)
{
PersistedSessionStateDocument = PreExistingSessionStateDocument.ShallowCopy();
}
MockDocumentSession.Setup(cmd => cmd.Load<SessionStateDocument>(It.IsAny<string>()))
.Returns(PersistedSessionStateDocument);
RavenJObject ravenJObject = new RavenJObject();
ravenJObject.Add("Raven-Expiration-Date", null);
MockSyncAdvancedSessionOperation.Setup(cmd => cmd.GetMetadataFor(It.IsAny<SessionStateDocument>()))
.Returns(ravenJObject);
}
开发者ID:CorporateActionMan,项目名称:RavenDbSessionStateStoreProvider,代码行数:25,代码来源:RavenSessionStateTest.cs
示例6: ToJson
/// <summary>
/// Translates this instance to a Json object.
/// </summary>
/// <returns>RavenJObject representing the command.</returns>
public RavenJObject ToJson()
{
var ret = new RavenJObject
{
{"Key", Key},
{"Method", Method},
{"Patch", new RavenJObject
{
{ "Script", Patch.Script },
{ "Values", RavenJObject.FromObject(Patch.Values)}
}},
{"DebugMode", DebugMode},
{"AdditionalData", AdditionalData},
{"Metadata", Metadata}
};
if (Etag != null)
ret.Add("Etag", Etag.ToString());
if (PatchIfMissing != null)
{
ret.Add("PatchIfMissing", new RavenJObject
{
{ "Script", PatchIfMissing.Script },
{ "Values", RavenJObject.FromObject(PatchIfMissing.Values)}
});
}
return ret;
}
示例7: Execute
public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
int count = 0;
foreach (var partitionedRows in rows.Partition(Constants.BatchSize))
{
List<PutCommandData> commands = new List<PutCommandData>();
foreach(var row in partitionedRows)
{
RavenJObject obj = new RavenJObject();
foreach(object key in row.Keys)
{
obj.Add((string)key, RavenJToken.FromObject(row[key]));
}
commands.Add(new PutCommandData()
{
Document = obj,
Metadata = new RavenJObject
{
{"Raven-Entity-Name", new RavenJValue(collection)}
},
Key = generateKey(obj)
});
}
count++;
WriteCommandsTo(collection + " #" + count.ToString("00000") + ".json", commands);
}
yield break;
}
示例8: DisableVersioning
public static RavenJToken DisableVersioning(RavenJObject metadata)
{
if (metadata != null)
metadata.Add(Constants.RavenIgnoreVersioning, true);
return metadata;
}
示例9: ToJson
/// <summary>
/// Translates this instance to a Json object.
/// </summary>
/// <returns>RavenJObject representing the command.</returns>
public RavenJObject ToJson()
{
var ret = new RavenJObject
{
{"Key", Key},
{"Method", Method},
{"Patches", new RavenJArray(Patches.Select(x => x.ToJson()))},
{"Metadata", Metadata},
{"AdditionalData", AdditionalData},
{"SkipPatchIfEtagMismatch", SkipPatchIfEtagMismatch}
};
if (Etag != null)
ret.Add("Etag", Etag.ToString());
if (PatchesIfMissing != null && PatchesIfMissing.Length > 0)
ret.Add("PatchesIfMissing", new RavenJArray(PatchesIfMissing.Select(x => x.ToJson())));
return ret;
}
示例10: BeforeStore
public bool BeforeStore(string key, object entityInstance, RavenJObject metadata, RavenJObject original)
{
var document = entityInstance as IDocument;
if (document == null) {
return false;
}
metadata.Add("IsRoutable", true);
return true;
}
示例11: ToJson
/// <summary>
/// Translate this instance to json
/// </summary>
public RavenJObject ToJson()
{
var jObject = new RavenJObject
{
{"Type", new RavenJValue(Type.ToString())},
{"Value", Value},
{"Name", new RavenJValue(Name)}
};
if (Position != null)
jObject.Add("Position", new RavenJValue(Position.Value));
if (Nested != null)
jObject.Add("Nested", new RavenJArray(Nested.Select(x => x.ToJson())));
if (AllPositions != null)
jObject.Add("AllPositions", new RavenJValue(AllPositions.Value));
if (PrevVal != null)
jObject.Add("PrevVal", PrevVal);
return jObject;
}
示例12: OnRead
public override void OnRead(string key, RavenJObject document, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation)
{
var linkName = metadata.Value<string>("Raven-Link-Name");
var link = metadata.Value<string>("Raven-Link");
if (link == null)
return;
var linkedDocument = Database.Get(link, transactionInformation);
document.Add(linkName, linkedDocument.ToJson());
}
示例13: OnPut
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
// leave raven system docs alone
if (key.StartsWith("Raven/"))
return;
RavenJToken lastModified;
if (!metadata.TryGetValue("Last-Modified", out lastModified))
metadata.Add("Created", SystemTime.UtcNow);
}
示例14: ReleaseItemExclusive_when_lock_id_matches
public ReleaseItemExclusive_when_lock_id_matches()
{
RavenJObject ravenJObject = new RavenJObject();
ravenJObject.Add("Raven-Expiration-Date", null);
MockSyncAdvancedSessionOperation.Setup(cmd => cmd.GetMetadataFor(It.IsAny<SessionStateDocument>()))
.Returns(ravenJObject);
//call ReleaseItemExclusive with matching lockId
Subject.ReleaseItemExclusive(null, SessionId, LockIdExisting);
ExpiryExisting = DateTime.UtcNow;
}
开发者ID:CorporateActionMan,项目名称:RavenDbSessionStateStoreProvider,代码行数:10,代码来源:ReleaseItemExclusive_when_lock_id_matches.cs
示例15: Store
public void Store(object entity, string id)
{
var metadata = new RavenJObject();
var tag = documentStore.Conventions.GetTypeTagName(entity.GetType());
if (tag != null)
metadata.Add(Constants.RavenEntityName, tag);
var data = entityToJson.ConvertEntityToJson(id, entity, metadata);
operation.Write(id, metadata, data);
}