本文整理汇总了C#中RavenJArray.RemoveAt方法的典型用法代码示例。如果您正苦于以下问题:C# RavenJArray.RemoveAt方法的具体用法?C# RavenJArray.RemoveAt怎么用?C# RavenJArray.RemoveAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RavenJArray
的用法示例。
在下文中一共展示了RavenJArray.RemoveAt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPut
public override void OnPut(string key, Stream data, RavenJObject metadata)
{
if (key.StartsWith("Raven/")) // we don't deal with system attachment
return;
using (Database.DisableAllTriggersForCurrentThread())
{
var attachmentMetadata = GetAttachmentMetadata(key);
if (attachmentMetadata != null)
{
RavenJArray history = new RavenJArray(metadata.Value<RavenJArray>(Constants.RavenReplicationHistory));
metadata[Constants.RavenReplicationHistory] = history;
if (attachmentMetadata.ContainsKey(Constants.RavenReplicationVersion) &&
attachmentMetadata.ContainsKey(Constants.RavenReplicationSource))
{
history.Add(new RavenJObject
{
{Constants.RavenReplicationVersion, attachmentMetadata[Constants.RavenReplicationVersion]},
{Constants.RavenReplicationSource, attachmentMetadata[Constants.RavenReplicationSource]}
});
}
if (history.Length > Constants.ChangeHistoryLength)
{
history.RemoveAt(0);
}
}
metadata[Constants.RavenReplicationVersion] = RavenJToken.FromObject(HiLo.NextId());
metadata[Constants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id);
}
}
示例2: OnPut
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
if (key.StartsWith("Raven/", StringComparison.OrdinalIgnoreCase) && // we don't deal with system documents
key.StartsWith("Raven/Hilo/", StringComparison.OrdinalIgnoreCase) == false) // except for hilos
return;
using (Database.DisableAllTriggersForCurrentThread())
{
var documentMetadata = GetDocumentMetadata(key);
if (documentMetadata != null)
{
RavenJArray history = new RavenJArray(ReplicationData.GetHistory(documentMetadata));
metadata[Constants.RavenReplicationHistory] = history;
if (documentMetadata.ContainsKey(Constants.RavenReplicationVersion) &&
documentMetadata.ContainsKey(Constants.RavenReplicationSource))
{
history.Add(new RavenJObject
{
{Constants.RavenReplicationVersion, documentMetadata[Constants.RavenReplicationVersion]},
{Constants.RavenReplicationSource, documentMetadata[Constants.RavenReplicationSource]}
});
}
while (history.Length > Constants.ChangeHistoryLength)
{
history.RemoveAt(0);
}
}
metadata[Constants.RavenReplicationVersion] = RavenJToken.FromObject(HiLo.NextId());
metadata[Constants.RavenReplicationSource] = RavenJToken.FromObject(Database.TransactionalStorage.Id);
}
}
示例3: OnPut
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
using (Database.DisableAllTriggersForCurrentThread())
{
if (metadata.Remove(Constants.RavenReplicationConflictSkipResolution))
{
if (key.IndexOf("/conflicts/", StringComparison.OrdinalIgnoreCase) == -1)
{
metadata["@Http-Status-Code"] = 409;
metadata["@Http-Status-Description"] = "Conflict";
}
return;
}
metadata.Remove(Constants.RavenReplicationConflict);// you can't put conflicts
var oldVersion = Database.Documents.Get(key, transactionInformation);
if (oldVersion == null)
return;
if (oldVersion.Metadata[Constants.RavenReplicationConflict] == null)
return;
var history = new RavenJArray();
metadata[Constants.RavenReplicationHistory] = history;
// this is a conflict document, holding document keys in the
// values of the properties
var conflicts = oldVersion.DataAsJson.Value<RavenJArray>("Conflicts");
if(conflicts == null)
return;
var list = new List<RavenJArray>
{
new RavenJArray(ReplicationData.GetHistory(metadata)) // first item to interleave
};
foreach (var prop in conflicts)
{
RavenJObject deletedMetadata;
Database.Documents.Delete(prop.Value<string>(), null, transactionInformation, out deletedMetadata);
if (deletedMetadata != null)
{
var conflictHistory = new RavenJArray(ReplicationData.GetHistory(deletedMetadata));
conflictHistory.Add(new RavenJObject
{
{Constants.RavenReplicationVersion, deletedMetadata[Constants.RavenReplicationVersion]},
{Constants.RavenReplicationSource, deletedMetadata[Constants.RavenReplicationSource]}
});
list.Add(conflictHistory);
}
}
int index = 0;
bool added = true;
while (added) // interleave the history from all conflicts
{
added = false;
foreach (var deletedMetadata in list)
{
// add the conflict history to the mix, so we make sure that we mark that we resolved the conflict
if (index < deletedMetadata.Length)
{
history.Add(deletedMetadata[index]);
added = true;
}
}
index++;
}
while (history.Length > Constants.ChangeHistoryLength)
{
history.RemoveAt(0);
}
}
}
示例4: RemoveValue
private void RemoveValue(PatchRequest patchCmd, string propName, RavenJToken token)
{
EnsurePreviousValueMatchCurrentValue(patchCmd, token);
if (token == null)
{
token = new RavenJArray();
document[propName] = token;
}
var array = GetArray(token, propName);
array = new RavenJArray(array);
document[propName] = array;
var position = patchCmd.Position;
var value = patchCmd.Value;
if (position == null && (value == null || value.Type == JTokenType.Null))
throw new InvalidOperationException("Cannot remove value from '" + propName +
"' because position element does not exists or not an integer and no value was present");
if (position != null && value != null && value.Type != JTokenType.Null)
throw new InvalidOperationException("Cannot remove value from '" + propName +
"' because both a position and a value are set");
if (position != null && (position.Value < 0 || position.Value >= array.Length))
throw new IndexOutOfRangeException("Cannot remove value from '" + propName +
"' because position element is out of bounds");
if (value != null && value.Type != JTokenType.Null)
{
foreach (var ravenJToken in array.Where(x => RavenJToken.DeepEquals(x, value)).ToList())
{
array.Remove(ravenJToken);
}
return;
}
if (position != null)
array.RemoveAt(position.Value);
}