本文整理汇总了C#中RavenJObject.Value方法的典型用法代码示例。如果您正苦于以下问题:C# RavenJObject.Value方法的具体用法?C# RavenJObject.Value怎么用?C# RavenJObject.Value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RavenJObject
的用法示例。
在下文中一共展示了RavenJObject.Value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FilterDocuments
public bool FilterDocuments(string destinationId, string key, RavenJObject metadata)
{
if (key.StartsWith("Raven/", StringComparison.InvariantCultureIgnoreCase)) // don't replicate system docs
{
if (key.StartsWith("Raven/Hilo/", StringComparison.InvariantCultureIgnoreCase) == false) // except for hilo documents
return false;
}
if (metadata.ContainsKey(Constants.NotForReplication) && metadata.Value<bool>(Constants.NotForReplication)) // not explicitly marked to skip
return false;
if (metadata[Constants.RavenReplicationConflict] != null) // don't replicate conflicted documents, that just propagate the conflict
return false;
if (metadata.Value<string>(Constants.RavenReplicationSource) == destinationId) // prevent replicating back to source
return false;
switch (ReplicationOptionsBehavior)
{
case TransitiveReplicationOptions.None:
var value = metadata.Value<string>(Constants.RavenReplicationSource);
var replicateDoc = value == null || (value == CurrentDatabaseId);
return replicateDoc;
}
return true;
}
示例2: ModifyResult
private static void ModifyResult(RavenJObject result)
{
var tags = result.Value<string>("Tags");
if (tags != null)
{
result["Tags"] =
new RavenJArray(tags.Split(new[] {' ', ',', ';'}, StringSplitOptions.RemoveEmptyEntries));
}
else
{
result["Tags"] = new RavenJArray();
}
var deps = result.Value<string>("Dependencies");
if (deps != null)
{
result["Dependencies"] =
new RavenJArray(deps.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries)
.Select(s =>
{
var strings = s.Split(':');
return RavenJObject.FromObject(new {Package = strings[0], Version = strings[1]});
}));
}
result["PackageId"] = result["Id"];
result.Remove("Id");
result.Remove("__metadata");
result.Remove("DownloadCount");
}
示例3: AfterPut
public override void AfterPut(string key, RavenJObject document, RavenJObject metadata, System.Guid etag, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/"))
{
return;
}
var entityName = metadata.Value<string>(Constants.RavenEntityName) + "/";
var properties = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);
if (properties == null || properties.Length <= 0)
return;
var constraintMetaObject = new RavenJObject { { Constants.IsConstraintDocument, true } };
constraintMetaObject.EnsureSnapshot();
foreach (var property in properties)
{
var propName = ((RavenJValue)property).Value.ToString();
var uniqueValue = document.Value<string>(propName);
if(uniqueValue == null)
continue;
string documentName = "UniqueConstraints/" + entityName + propName + "/" +Util.EscapeUniqueValue(uniqueValue);
Database.Put(
documentName,
null,
RavenJObject.FromObject(new { RelatedId = key }),
(RavenJObject)constraintMetaObject.CreateSnapshot(),
transactionInformation);
}
}
示例4: OnPut
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/", StringComparison.InvariantCultureIgnoreCase))
return;
if (metadata.Value<string>(VersioningUtil.RavenDocumentRevisionStatus) == "Historical")
return;
var versioningConfiguration = Database.GetDocumentVersioningConfiguration(metadata);
if (versioningConfiguration == null || versioningConfiguration.Exclude)
return;
using (Database.DisableAllTriggersForCurrentThread())
{
var copyMetadata = new RavenJObject(metadata);
copyMetadata[VersioningUtil.RavenDocumentRevisionStatus] = RavenJToken.FromObject("Historical");
copyMetadata[Constants.RavenReadOnly] = true;
copyMetadata.Remove(VersioningUtil.RavenDocumentRevision);
var parentRevision = metadata.Value<string>(VersioningUtil.RavenDocumentRevision);
if (parentRevision != null)
{
copyMetadata[VersioningUtil.RavenDocumentParentRevision] = key + "/revisions/" + parentRevision;
metadata[VersioningUtil.RavenDocumentParentRevision] = key + "/revisions/" + parentRevision;
}
PutResult newDoc = Database.Put(key + "/revisions/", null, document, copyMetadata,
transactionInformation);
int revision = int.Parse(newDoc.Key.Split('/').Last());
RemoveOldRevisions(key, revision, versioningConfiguration, transactionInformation);
metadata[VersioningUtil.RavenDocumentRevisionStatus] = RavenJToken.FromObject("Current");
metadata[VersioningUtil.RavenDocumentRevision] = RavenJToken.FromObject(revision);
}
}
示例5: AfterPut
public override void AfterPut(string key, RavenJObject document, RavenJObject metadata, System.Guid etag, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/"))
{
return;
}
var entityName = metadata.Value<string>(Constants.RavenEntityName) + "/";
var properties = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);
if (properties == null || properties.Count() <= 0)
return;
var constraintMetaObject = new RavenJObject { { Constants.IsConstraintDocument, true } };
foreach (var property in properties)
{
var propName = ((RavenJValue)property).Value.ToString();
Database.Put(
"UniqueConstraints/" + entityName + propName + "/" + document.Value<string>(propName),
null,
RavenJObject.FromObject(new { RelatedId = key }),
constraintMetaObject,
transactionInformation);
}
}
示例6: TransformToFullConflictHistory
private static List<HistoryItem> TransformToFullConflictHistory(RavenJObject metadata)
{
var version = metadata.Value<long>(SynchronizationConstants.RavenSynchronizationVersion);
var serverId = metadata.Value<string>(SynchronizationConstants.RavenSynchronizationSource);
var fullHistory = Historian.DeserializeHistory(metadata);
fullHistory.Add(new HistoryItem { ServerId = serverId, Version = version });
return fullHistory;
}
示例7: AllowPut
public override VetoResult AllowPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/"))
{
return VetoResult.Allowed;
}
var entityName = metadata.Value<string>(Constants.RavenEntityName);
if (string.IsNullOrEmpty(entityName))
{
return VetoResult.Allowed;
}
entityName += "/";
var properties = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);
if (properties == null || properties.Length <= 0)
return VetoResult.Allowed;
var invalidFields = new StringBuilder();
foreach (var property in properties)
{
var propName = property.Value<string>();
var prefix = "UniqueConstraints/" + entityName + property + "/";
var prop = document[propName];
if (prop == null || prop.Type == JTokenType.Null)
continue;
var array = prop as RavenJArray;
var checkKeys = array != null ? array.Select(p => p.Value<string>()) : new[] { prop.Value<string>() };
foreach (var checkKey in checkKeys)
{
var checkDoc = Database.Get(prefix + Util.EscapeUniqueValue(checkKey), transactionInformation);
if (checkDoc == null)
continue;
var checkId = checkDoc.DataAsJson.Value<string>("RelatedId");
if (checkId != key)
invalidFields.Append(property + ", ");
}
}
if (invalidFields.Length > 0)
{
invalidFields.Length = invalidFields.Length - 2;
return VetoResult.Deny("Ensure unique constraint violated for fields: " + invalidFields);
}
return VetoResult.Allowed;
}
示例8: AllowPut
public override VetoResult AllowPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/"))
{
return VetoResult.Allowed;
}
var entityName = metadata.Value<string>(Constants.RavenEntityName);
if (string.IsNullOrEmpty(entityName))
{
return VetoResult.Allowed;
}
entityName += "/";
var properties = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);
if (properties == null || properties.Length <= 0)
return VetoResult.Allowed;
var invalidFields = new StringBuilder();
foreach (var property in properties)
{
var constraint = Util.GetConstraint(property);
var prefix = "UniqueConstraints/" + entityName + constraint.PropName+ "/";
var prop = document[constraint.PropName];
string[] uniqueValues;
if (!Util.TryGetUniqueValues(prop, out uniqueValues))
continue;
foreach (var uniqueValue in uniqueValues)
{
var escapedUniqueValue = Util.EscapeUniqueValue(uniqueValue, constraint.CaseInsensitive);
var checkDocKey = prefix + escapedUniqueValue;
var checkDoc = Database.Documents.Get(checkDocKey, transactionInformation);
if (checkDoc == null)
continue;
var checkId = GetRelatedIdFromUniqueConstraintsDocument(checkDoc, escapedUniqueValue);
if (!string.IsNullOrEmpty(checkId) && checkId != key)
invalidFields.Append(constraint.PropName + ", ");
}
}
if (invalidFields.Length > 0)
{
invalidFields.Length = invalidFields.Length - 2;
return VetoResult.Deny("Ensure unique constraint violated for fields: " + invalidFields);
}
return VetoResult.Allowed;
}
示例9: GetLastModified
private static DateTimeOffset GetLastModified(RavenJObject metadata)
{
if (metadata.ContainsKey(Constants.LastModified))
return metadata.Value<DateTimeOffset>(Constants.LastModified);
if (metadata.ContainsKey(Constants.RavenLastModified))
return metadata.Value<DateTimeOffset>(Constants.RavenLastModified);
throw new InvalidOperationException("Could not find last modification date in metadata");
}
示例10: 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());
}
示例11: CreateCommand
public static ICommandData CreateCommand(RavenJObject jsonCommand, TransactionInformation transactionInformation)
{
var key = jsonCommand["Key"].Value<string>();
switch (jsonCommand.Value<string>("Method"))
{
case "PUT":
return new PutCommandData
{
Key = key,
Etag = GetEtagFromCommand(jsonCommand),
Document = jsonCommand["Document"] as RavenJObject,
Metadata = jsonCommand["Metadata"] as RavenJObject,
TransactionInformation = transactionInformation
};
case "DELETE":
return new DeleteCommandData
{
Key = key,
Etag = GetEtagFromCommand(jsonCommand),
TransactionInformation = transactionInformation
};
case "PATCH":
return new PatchCommandData
{
Key = key,
Etag = GetEtagFromCommand(jsonCommand),
TransactionInformation = transactionInformation,
Metadata = jsonCommand["Metadata"] as RavenJObject,
Patches = jsonCommand
.Value<RavenJArray>("Patches")
.Cast<RavenJObject>()
.Select(PatchRequest.FromJson)
.ToArray(),
PatchesIfMissing = jsonCommand["PatchesIfMissing"] == null ? null : jsonCommand
.Value<RavenJArray>("PatchesIfMissing")
.Cast<RavenJObject>()
.Select(PatchRequest.FromJson)
.ToArray(),
};
case "EVAL":
var debug = jsonCommand["DebugMode"].Value<bool>();
return new ScriptedPatchCommandData
{
Key = key,
Metadata = jsonCommand["Metadata"] as RavenJObject,
Etag = GetEtagFromCommand(jsonCommand),
TransactionInformation = transactionInformation,
Patch = ScriptedPatchRequest.FromJson(jsonCommand.Value<RavenJObject>("Patch")),
PatchIfMissing = jsonCommand["PatchIfMissing"] == null ? null : ScriptedPatchRequest.FromJson(jsonCommand.Value<RavenJObject>("PatchIfMissing")),
DebugMode = debug
};
default:
throw new ArgumentException("Batching only supports PUT, PATCH, EVAL and DELETE.");
}
}
示例12: ExtractDataAndDo
private void ExtractDataAndDo(RavenJObject result, Action<Employee, string> action)
{
var attachmentId = result.Value<string>("AttachmentId");
var employeeId = result.Value<string>("RelatedEntityId");
using (var session = DocumentStore.OpenSession())
{
var employee = session.Load<Employee>(employeeId);
action(employee, attachmentId);
session.SaveChanges();
}
}
示例13: AfterPut
public override void AfterPut(string key, RavenJObject document, RavenJObject metadata, Etag etag, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/"))
{
return;
}
var entityName = metadata.Value<string>(Constants.RavenEntityName) + "/";
var properties = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);
if (properties == null || properties.Length <= 0)
return;
foreach (var property in properties)
{
var constraint = Util.GetConstraint(property);
var prop = document[constraint.PropName];
string[] uniqueValues;
if (!Util.TryGetUniqueValues(prop, out uniqueValues))
continue;
var prefix = "UniqueConstraints/" + entityName + constraint.PropName + "/";
foreach (var uniqueValue in uniqueValues)
{
var escapedUniqueValue = Util.EscapeUniqueValue(uniqueValue, constraint.CaseInsensitive);
var uniqueConstraintsDocumentKey = prefix + escapedUniqueValue;
var uniqueConstraintsDocument = Database.Documents.Get(uniqueConstraintsDocumentKey, transactionInformation);
if (uniqueConstraintsDocument != null)
{
uniqueConstraintsDocument = DeepCloneDocument(uniqueConstraintsDocument);
ConvertUniqueConstraintsDocumentIfNecessary(uniqueConstraintsDocument, escapedUniqueValue); // backward compatibility
}
else
uniqueConstraintsDocument = new JsonDocument();
AddConstraintToUniqueConstraintsDocument(uniqueConstraintsDocument, escapedUniqueValue, key);
uniqueConstraintsDocument.Metadata[Constants.IsConstraintDocument] = true;
Database.Documents.Put(
uniqueConstraintsDocumentKey,
null,
uniqueConstraintsDocument.DataAsJson,
uniqueConstraintsDocument.Metadata,
transactionInformation);
}
}
}
示例14: AllowPut
public override VetoResult AllowPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/"))
{
return VetoResult.Allowed;
}
var entityName = metadata.Value<string>(Constants.RavenEntityName);
if (string.IsNullOrEmpty(entityName))
{
return VetoResult.Allowed;
}
entityName += "/";
var properties = metadata.Value<RavenJArray>(Constants.EnsureUniqueConstraints);
if (properties == null || properties.Length <= 0)
return VetoResult.Allowed;
var invalidFields = new StringBuilder();
foreach (var property in properties)
{
var propName = ((RavenJValue)property).Value.ToString();
var uniqueValue = document.Value<string>(propName);
if(uniqueValue == null)
continue;
var checkKey = "UniqueConstraints/" + entityName + propName + "/" +
Util.EscapeUniqueValue(uniqueValue);
var checkDoc = Database.Get(checkKey, transactionInformation);
if (checkDoc == null)
continue;
var checkId = checkDoc.DataAsJson.Value<string>("RelatedId");
if (checkId != key)
{
invalidFields.Append(property + ", ");
}
}
if (invalidFields.Length > 0)
{
invalidFields.Length = invalidFields.Length - 2;
return VetoResult.Deny("Ensure unique constraint violated for fields: " + invalidFields);
}
return VetoResult.Allowed;
}
示例15: FilterDocuments
public bool FilterDocuments(string destinationId, string key, RavenJObject metadata, out string reason)
{
if (IsSystemDocumentId(key))
{
reason = string.Format("Will not replicate document '{0}' to '{1}' because it is a system document", key, destinationId);
Log.Debug(reason);
return false;
}
if (metadata.ContainsKey(Constants.NotForReplication) && metadata.Value<bool>(Constants.NotForReplication))
// not explicitly marked to skip
{
reason = string.Format("Will not replicate document '{0}' to '{1}' because it was marked as not for replication", key, destinationId);
Log.Debug(reason);
return false;
}
if (metadata[Constants.RavenReplicationConflict] != null)
// don't replicate conflicted documents, that just propagate the conflict
{
reason = string.Format("Will not replicate document '{0}' to '{1}' because it a conflict document", key, destinationId);
Log.Debug(reason);
return false;
}
if (OriginsFromDestination(destinationId, metadata)) // prevent replicating back to source
{
reason = string.Format("Will not replicate document '{0}' to '{1}' because the destination server is the same server it originated from", key, destinationId);
Log.Debug(reason);
return false;
}
switch (ReplicationOptionsBehavior)
{
case TransitiveReplicationOptions.None:
var value = metadata.Value<string>(Constants.RavenReplicationSource);
if (value != null && (value != CurrentDatabaseId))
{
reason = string.Format("Will not replicate document '{0}' to '{1}' because it was not created on the current server, and TransitiveReplicationOptions = none", key, destinationId);
Log.Debug(reason);
return false;
}
break;
}
reason = string.Format("Will replicate '{0}' to '{1}'", key, destinationId);
Log.Debug(reason);
return true;
}