本文整理汇总了C#中RavenJObject.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# RavenJObject.ContainsKey方法的具体用法?C# RavenJObject.ContainsKey怎么用?C# RavenJObject.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RavenJObject
的用法示例。
在下文中一共展示了RavenJObject.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPut
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
VersioningConfiguration versioningConfiguration;
if (metadata.ContainsKey(Constants.RavenCreateVersion))
{
metadata.__ExternalState[Constants.RavenCreateVersion] = metadata[Constants.RavenCreateVersion];
metadata.Remove(Constants.RavenCreateVersion);
}
if (metadata.ContainsKey(Constants.RavenIgnoreVersioning))
{
metadata.__ExternalState[Constants.RavenIgnoreVersioning] = metadata[Constants.RavenIgnoreVersioning];
metadata.Remove(Constants.RavenIgnoreVersioning);
return;
}
if (TryGetVersioningConfiguration(key, metadata, out versioningConfiguration) == false)
return;
var revision = GetNextRevisionNumber(key);
using (Database.DisableAllTriggersForCurrentThread())
{
RemoveOldRevisions(key, revision, versioningConfiguration, transactionInformation);
}
metadata.__ExternalState["Next-Revision"] = revision;
metadata.__ExternalState["Parent-Revision"] = metadata.Value<string>(VersioningUtil.RavenDocumentRevision);
metadata[VersioningUtil.RavenDocumentRevisionStatus] = RavenJToken.FromObject("Current");
metadata[VersioningUtil.RavenDocumentRevision] = RavenJToken.FromObject(revision);
}
示例2: 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");
}
示例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: OnPut
public override void OnPut(string name, RavenJObject headers)
{
if (headers.ContainsKey(Constants.RavenCreateVersion))
{
headers.__ExternalState[Constants.RavenCreateVersion] = headers[Constants.RavenCreateVersion];
headers.Remove(Constants.RavenCreateVersion);
}
FileSystem.Storage.Batch(accessor =>
{
VersioningConfiguration versioningConfiguration;
if (TryGetVersioningConfiguration(name, headers, accessor, out versioningConfiguration) == false)
return;
var revision = GetNextRevisionNumber(name, accessor);
using (FileSystem.DisableAllTriggersForCurrentThread())
{
RemoveOldRevisions(name, revision, versioningConfiguration);
}
headers.__ExternalState["Next-Revision"] = revision;
headers.__ExternalState["Parent-Revision"] = headers.Value<string>(VersioningUtil.RavenFileRevision);
headers[VersioningUtil.RavenFileRevisionStatus] = RavenJToken.FromObject("Current");
headers[VersioningUtil.RavenFileRevision] = RavenJToken.FromObject(revision);
});
}
示例5: 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;
}
示例6: DetermineWork
public SynchronizationWorkItem DetermineWork(string file, RavenJObject localMetadata, RavenJObject destinationMetadata, string localServerUrl, out NoSyncReason reason)
{
reason = NoSyncReason.Unknown;
if (localMetadata == null)
{
reason = NoSyncReason.SourceFileNotExist;
return null;
}
if (destinationMetadata != null && destinationMetadata[SynchronizationConstants.RavenSynchronizationConflict] != null && destinationMetadata[SynchronizationConstants.RavenSynchronizationConflictResolution] == null)
{
reason = NoSyncReason.DestinationFileConflicted;
return null;
}
if (localMetadata[SynchronizationConstants.RavenSynchronizationConflict] != null)
{
reason = NoSyncReason.SourceFileConflicted;
return null;
}
if (localMetadata[SynchronizationConstants.RavenDeleteMarker] != null)
{
if (localMetadata.ContainsKey(SynchronizationConstants.RavenRenameFile))
{
var rename = localMetadata.Value<string>(SynchronizationConstants.RavenRenameFile);
if (destinationMetadata != null)
return new RenameWorkItem(file, rename, localServerUrl, storage);
return new ContentUpdateWorkItem(rename, localServerUrl, storage, sigGenerator);
// we have a rename tombstone but file does not exists on destination
}
return new DeleteWorkItem(file, localServerUrl, storage);
}
if (destinationMetadata != null && Historian.IsDirectChildOfCurrent(localMetadata, destinationMetadata))
{
reason = NoSyncReason.ContainedInDestinationHistory;
return null;
}
// file exists on dest and has the same content
if (destinationMetadata != null && localMetadata.Value<string>("Content-MD5") == destinationMetadata.Value<string>("Content-MD5"))
{
// check metadata to detect if any synchronization is needed
if (localMetadata.Keys.Except(new[] { Constants.MetadataEtagField, Constants.RavenLastModified, Constants.LastModified })
.Any(key => !destinationMetadata.ContainsKey(key) || localMetadata[key] != destinationMetadata[key]))
{
return new MetadataUpdateWorkItem(file, localServerUrl, destinationMetadata, storage);
}
reason = NoSyncReason.SameContentAndMetadata;
return null; // the same content and metadata - no need to synchronize
}
return new ContentUpdateWorkItem(file, localServerUrl, storage, sigGenerator);
}
示例7: OnPut
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
if (!metadata.ContainsKey("IsRoutable") || !metadata.Value<bool>("IsRoutable")) {
return;
}
RavenJToken parentIdToken;
RavenJToken slugToken;
if (document.TryGetValue("ParentId", out parentIdToken) && document.TryGetValue("Slug", out slugToken)) {
var parentId = parentIdToken.Value<string>();
var slug = slugToken.Value<string>();
string parentPath = null;
if (!String.IsNullOrEmpty(parentId)) {
var parent = Database.Get(parentId, transactionInformation);
parentPath = parent.DataAsJson["Path"].Value<string>();
}
if (String.IsNullOrEmpty(parentPath)) {
document["Path"] = slug;
} else {
document["Path"] = parentPath + "/" + slug;
}
}
base.OnPut(key, document, metadata, transactionInformation);
}
示例8: AssertLocalFileExistsAndIsNotConflicted
protected void AssertLocalFileExistsAndIsNotConflicted(RavenJObject sourceMetadata)
{
if (sourceMetadata == null)
throw new SynchronizationException(string.Format("File {0} does not exist", FileName));
if (sourceMetadata.ContainsKey(SynchronizationConstants.RavenSynchronizationConflict))
throw new SynchronizationException(string.Format("File {0} is conflicted", FileName));
}
示例9: AllowRead
public override ReadVetoResult AllowRead(string key, RavenJObject metadata, ReadOperation operation, TransactionInformation transactionInformation)
{
if (operation != ReadOperation.Index)
return ReadVetoResult.Allowed;
if (metadata.ContainsKey("Deleted") == false)
return ReadVetoResult.Allowed;
return ReadVetoResult.Ignore;
}
示例10: CreateCommand
public static ICommandData CreateCommand(RavenJObject jsonCommand, TransactionInformation transactionInformation)
{
var key = jsonCommand["Key"].Value<string>();
switch (jsonCommand.Value<string>("Method"))
{
case "PUT":
var putCommand = new PutCommandData
{
Key = key,
Etag = GetEtagFromCommand(jsonCommand),
Document = jsonCommand["Document"] as RavenJObject,
Metadata = jsonCommand["Metadata"] as RavenJObject,
TransactionInformation = transactionInformation
};
ValidateMetadataKeys(putCommand.Metadata);
return putCommand;
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(),
SkipPatchIfEtagMismatch = jsonCommand.ContainsKey("SkipPatchIfEtagMismatch") && jsonCommand.Value<bool>("SkipPatchIfEtagMismatch")
};
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.");
}
}
示例11: DeserializeHistory
public static List<HistoryItem> DeserializeHistory(RavenJObject metadata)
{
var history = new List<HistoryItem>();
if (metadata.ContainsKey(SynchronizationConstants.RavenSynchronizationHistory))
{
var array = (RavenJArray) metadata[SynchronizationConstants.RavenSynchronizationHistory];
var items = array.Values<RavenJObject>().Select(x => JsonExtensions.JsonDeserialization<HistoryItem>(x));
return new List<HistoryItem>(items);
}
return history;
}
示例12: InitializeMetadata
public void InitializeMetadata(string name, RavenJObject metadata)
{
if (metadata.ContainsKey(Constants.RavenCreateVersion))
{
metadata.__ExternalState[Constants.RavenCreateVersion] = metadata[Constants.RavenCreateVersion];
metadata.Remove(Constants.RavenCreateVersion);
}
if (metadata.ContainsKey(Constants.RavenIgnoreVersioning))
{
metadata.__ExternalState[Constants.RavenIgnoreVersioning] = metadata[Constants.RavenIgnoreVersioning];
metadata.Remove(Constants.RavenIgnoreVersioning);
return;
}
fileSystem.Storage.Batch(accessor =>
{
FileVersioningConfiguration versioningConfiguration;
if (TryGetVersioningConfiguration(name, metadata, accessor, out versioningConfiguration) == false)
return;
long revision;
if (metadata.__ExternalState.ContainsKey("Synchronization-Next-Revision"))
revision = (long) metadata.__ExternalState["Synchronization-Next-Revision"];
else
revision = GetNextRevisionNumber(name, accessor);
RemoveOldRevisions(name, revision, versioningConfiguration);
metadata.__ExternalState["Next-Revision"] = revision;
metadata.__ExternalState["Parent-Revision"] = metadata.Value<string>(VersioningUtil.RavenFileRevision);
metadata[VersioningUtil.RavenFileRevisionStatus] = RavenJToken.FromObject("Current");
metadata[VersioningUtil.RavenFileRevision] = RavenJToken.FromObject(revision);
});
}
示例13: 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;
}
示例14: AfterPut
public override void AfterPut(string key, RavenJObject document, RavenJObject metadata, Etag etag, TransactionInformation transactionInformation)
{
if (!metadata.__ExternalState.ContainsKey(RavenDocumentRevision))
return;
using (Database.DisableAllTriggersForCurrentThread())
{
var revisionMetadata = new RavenJObject(metadata);
revisionMetadata[RavenDocumentRevisionStatus] = RavenJToken.FromObject("Historical");
revisionMetadata.Remove(RavenDocumentRevision);
if (revisionMetadata.ContainsKey(RavenDocumentEnsureUniqueConstraints))
revisionMetadata.Remove(RavenDocumentEnsureUniqueConstraints);
var revisionCopy = new RavenJObject(document);
var revisionkey = key + RevisionSegment + metadata.__ExternalState[RavenDocumentRevision];
Database.Documents.Put(revisionkey, null, revisionCopy, revisionMetadata, transactionInformation);
}
}
示例15: AfterPut
public override void AfterPut(string key, RavenJObject document, RavenJObject metadata, Guid etag, TransactionInformation transactionInformation)
{
// leave raven system docs alone
if (key.StartsWith("Raven/"))
return;
// when there's already a Created date written, this is not the original insert
if (metadata.ContainsKey("Created"))
return;
// get the timestamp set for the last-modified date
var timestamp = metadata.Value<DateTime>(Constants.LastModified);
// copy the metadata and add the timestamp
var newMetadata = (RavenJObject)metadata.CreateSnapshot();
newMetadata.Add("Created", timestamp);
// update the metadata in the document
using (Database.DisableAllTriggersForCurrentThread())
Database.PutDocumentMetadata(key, newMetadata);
}