本文整理汇总了C#中RavenJArray类的典型用法代码示例。如果您正苦于以下问题:C# RavenJArray类的具体用法?C# RavenJArray怎么用?C# RavenJArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RavenJArray类属于命名空间,在下文中一共展示了RavenJArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例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: RecordActionForDebug
protected void RecordActionForDebug(string actionName, string documentKey, RavenJObject documentData, RavenJObject documentMetadata)
{
if (debugMode == false)
return;
var actions = DebugActions[actionName] as RavenJArray;
switch (actionName)
{
case "LoadDocument":
case "DeleteDocument":
if (actions == null)
DebugActions[actionName] = actions = new RavenJArray();
actions.Add(documentKey);
break;
case "PutDocument":
if (actions == null)
DebugActions[actionName] = actions = new RavenJArray();
actions.Add(new RavenJObject
{
{ "Key", documentKey },
{ "Data", documentData },
{ "Metadata", documentMetadata }
});
break;
default:
throw new NotSupportedException("Cannot record action: " + actionName);
}
}
示例4: AddCascadeDeleteReference
/// <summary>
/// Adds the cascade delete reference.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="entity">The entity.</param>
/// <param name="documentKeys">The document keys.</param>
public static void AddCascadeDeleteReference(this IAdvancedDocumentSessionOperations session, object entity, params string[] documentKeys)
{
var metadata = session.GetMetadataFor(entity);
if(metadata == null)
{
throw new InvalidOperationException("The entity must be tracked in the session before calling this method.");
}
if(documentKeys.Length == 0)
{
throw new ArgumentException("At least one document key must be specified.");
}
const string metadataKey = "Raven-Cascade-Delete-Documents";
RavenJToken token;
if(!metadata.TryGetValue(metadataKey, out token))
{
token = new RavenJArray();
}
var list = (RavenJArray)token;
foreach(var documentKey in documentKeys.Where(key => !list.Contains(key)))
{
list.Add(documentKey);
}
metadata[metadataKey] = list;
}
示例5: Respond
public override void Respond(IHttpContext context)
{
RavenJArray itemsToLoad;
if(context.Request.HttpMethod == "POST")
itemsToLoad = context.ReadJsonArray();
else
itemsToLoad = new RavenJArray(context.Request.QueryString.GetValues("id"));
var result = new MultiLoadResult();
var loadedIds = new HashSet<string>();
var includes = context.Request.QueryString.GetValues("include") ?? new string[0];
var transactionInformation = GetRequestTransaction(context);
var includedEtags = new List<byte>();
Database.TransactionalStorage.Batch(actions =>
{
foreach (RavenJToken item in itemsToLoad)
{
var value = item.Value<string>();
if(loadedIds.Add(value)==false)
continue;
var documentByKey = Database.Get(value, transactionInformation);
if (documentByKey == null)
continue;
result.Results.Add(documentByKey.ToJson());
if (documentByKey.Etag != null)
{
includedEtags.AddRange(documentByKey.Etag.Value.ToByteArray());
}
includedEtags.Add((documentByKey.NonAuthoritativeInformation ?? false) ? (byte)0 : (byte)1);
}
var addIncludesCommand = new AddIncludesCommand(Database, transactionInformation, (etag, includedDoc) =>
{
includedEtags.AddRange(etag.ToByteArray());
result.Includes.Add(includedDoc);
}, includes, loadedIds);
foreach (var item in result.Results.Where(item => item != null))
{
addIncludesCommand.Execute(item);
}
});
Guid computedEtag;
using (var md5 = MD5.Create())
{
var computeHash = md5.ComputeHash(includedEtags.ToArray());
computedEtag = new Guid(computeHash);
}
if (context.MatchEtag(computedEtag))
{
context.SetStatusToNotModified();
return;
}
context.WriteETag(computedEtag);
context.WriteJson(result);
}
示例6: 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);
}
}
示例7: ReplicationTopologyDiscoverer
public ReplicationTopologyDiscoverer(DocumentDatabase database, RavenJArray @from, int ttl, ILog log)
{
this.database = database;
this.ttl = ttl;
this.log = log;
[email protected] = @from;
requestFactory = new HttpRavenRequestFactory();
}
示例8: Initialize
private void Initialize()
{
if (mappedTypes != null)
return;
lock (padlock)
{
if (mappedTypes != null)
return;
var collectionData = new CollectionData();
var jsonDoc = store.DatabaseCommands.Get(collectionNamesDocId);
if (jsonDoc != null)
{
var collectionNames = jsonDoc.DataAsJson["Collections"] as RavenJArray;
foreach (RavenJValue value in collectionNames)
{
collectionData.Collections.Add(value.Value as string);
}
}
if (timeoutsEnabled)
{
MapTypeToCollectionName(typeof(TimeoutPersisters.RavenDB.TimeoutData), collectionData);
}
if (sagasEnabled)
{
foreach (var sagaType in types.Where(IsSagaEntity))
{
MapTypeToCollectionName(sagaType, collectionData);
}
}
if (collectionData.Changed)
{
var newDoc = new RavenJObject();
var list = new RavenJArray();
foreach (var name in collectionData.Collections)
{
list.Add(new RavenJValue(name));
}
newDoc["EndpointName"] = this.endpointName;
newDoc["EndpointName"] = this.endpointName;
newDoc["Collections"] = list;
var metadata = new RavenJObject();
store.DatabaseCommands.Put(collectionNamesDocId, null, newDoc, metadata);
}
// Completes initialization
this.mappedTypes = collectionData.Mappings;
}
}
示例9: TryHandleArrayValue
private bool TryHandleArrayValue(int index, Dictionary<string, object> result, KeyValuePair<string, RavenJToken> prop)
{
var arrays = new List<RavenJArray>
{
(RavenJArray)prop.Value
};
for (var i = 0; i < docs.Length; i++)
{
if (i == index)
continue;
RavenJToken token;
if (docs[i].TryGetValue(prop.Key, out token) && token.Type != JTokenType.Array)
return false;
if (token == null)
continue;
if (token.IsSnapshot)
token = token.CreateSnapshot();
arrays.Add((RavenJArray)token);
}
var mergedArray = new RavenJArray();
while (arrays.Count > 0)
{
var set = new HashSet<RavenJToken>(RavenJTokenEqualityComparer.Default);
for (var i = 0; i < arrays.Count; i++)
{
if (arrays[i].Length == 0)
{
arrays.RemoveAt(i);
i -= 1;
continue;
}
set.Add(arrays[i][0]);
arrays[i].RemoveAt(0);
}
foreach (var ravenJToken in set)
{
mergedArray.Add(ravenJToken);
}
}
if (RavenJTokenEqualityComparer.Default.Equals(mergedArray, prop.Value))
{
result.Add(prop.Key, mergedArray);
return true;
}
result.Add(prop.Key, new ArrayWithWarning(mergedArray));
return true;
}
示例10: PerformBulkOperation
private RavenJArray PerformBulkOperation(string index, IndexQuery indexQuery, bool allowStale, Func<string, TransactionInformation, object> batchOperation)
{
var array = new RavenJArray();
var bulkIndexQuery = new IndexQuery
{
Query = indexQuery.Query,
Start = indexQuery.Start,
Cutoff = indexQuery.Cutoff,
WaitForNonStaleResultsAsOfNow = indexQuery.WaitForNonStaleResultsAsOfNow,
PageSize = int.MaxValue,
FieldsToFetch = new[] { Constants.DocumentIdFieldName },
SortedFields = indexQuery.SortedFields,
HighlighterPreTags = indexQuery.HighlighterPreTags,
HighlighterPostTags = indexQuery.HighlighterPostTags,
HighlightedFields = indexQuery.HighlightedFields,
SortHints = indexQuery.SortHints
};
bool stale;
var queryResults = database.Queries.QueryDocumentIds(index, bulkIndexQuery, tokenSource, out stale);
if (stale && allowStale == false)
{
throw new InvalidOperationException(
"Bulk operation cancelled because the index is stale and allowStale is false");
}
var token = tokenSource.Token;
const int batchSize = 1024;
using (var enumerator = queryResults.GetEnumerator())
{
while (true)
{
if (timeout != null)
timeout.Delay();
var batchCount = 0;
token.ThrowIfCancellationRequested();
database.TransactionalStorage.Batch(actions =>
{
while (batchCount < batchSize && enumerator.MoveNext())
{
batchCount++;
var result = batchOperation(enumerator.Current, transactionInformation);
array.Add(RavenJObject.FromObject(result));
}
});
if (batchCount < batchSize) break;
}
}
return array;
}
示例11: OnPut
public override void OnPut(string key, Stream data, RavenJObject metadata)
{
using (Database.DisableAllTriggersForCurrentThread())
{
metadata.Remove(Constants.RavenReplicationConflict);// you can't put conflicts
var oldVersion = Database.Attachments.GetStatic(key);
if (oldVersion == null)
return;
if (oldVersion.Metadata[Constants.RavenReplicationConflict] == null)
return;
var history = new RavenJArray(ReplicationData.GetHistory(metadata));
metadata[Constants.RavenReplicationHistory] = history;
var ravenJTokenEqualityComparer = new RavenJTokenEqualityComparer();
// this is a conflict document, holding document keys in the
// values of the properties
var conflictData = oldVersion.Data().ToJObject();
var conflicts = conflictData.Value<RavenJArray>("Conflicts");
if (conflicts == null)
return;
foreach (var prop in conflicts)
{
var id = prop.Value<string>();
Attachment attachment = Database.Attachments.GetStatic(id);
if(attachment == null)
continue;
Database.Attachments.DeleteStatic(id, null);
// add the conflict history to the mix, so we make sure that we mark that we resolved the conflict
var conflictHistory = new RavenJArray(ReplicationData.GetHistory(attachment.Metadata));
conflictHistory.Add(new RavenJObject
{
{Constants.RavenReplicationVersion, attachment.Metadata[Constants.RavenReplicationVersion]},
{Constants.RavenReplicationSource, attachment.Metadata[Constants.RavenReplicationSource]}
});
foreach (var item in conflictHistory)
{
if (history.Any(x => ravenJTokenEqualityComparer.Equals(x, item)))
continue;
history.Add(item);
}
}
}
}
示例12: Execute
public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
{
int count = 0;
foreach (var commentsForPosts in rows.Partition(Constants.BatchSize))
{
var cmds = new List<ICommandData>();
foreach (var commentsForPost in commentsForPosts.GroupBy(row => row["PostId"]))
{
var comments = new RavenJArray();
foreach (var row in commentsForPost)
{
comments.Add(new RavenJObject
{
{"Score", new RavenJValue(row["Score"])},
{"CreationDate", new RavenJValue(row["CreationDate"])},
{"Text", new RavenJValue(row["Text"])},
{"UserId", new RavenJValue(row["UserId"])}
});
}
cmds.Add(new PatchCommandData
{
Key = "posts/" + commentsForPost.Key,
Patches = new[]
{
new PatchRequest
{
Name = "Comments",
Type = PatchCommandType.Set,
Value = comments
},
}
});
}
count++;
WriteCommandsTo("Comments #" + count.ToString("00000") + ".json", cmds);
}
yield break;
}
示例13: OnPut
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation)
{
using (Database.DisableAllTriggersForCurrentThread())
{
metadata.Remove(Constants.RavenReplicationConflict);// you can't put conflicts
var oldVersion = Database.Get(key, transactionInformation);
if (oldVersion == null)
return;
if (oldVersion.Metadata[Constants.RavenReplicationConflict] == null)
return;
RavenJArray history = new RavenJArray(ReplicationData.GetHistory(metadata));
metadata[Constants.RavenReplicationHistory] = history;
var ravenJTokenEqualityComparer = new RavenJTokenEqualityComparer();
// 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;
foreach (var prop in conflicts)
{
RavenJObject deletedMetadata;
Database.Delete(prop.Value<string>(), null, transactionInformation, out deletedMetadata);
// add the conflict history to the mix, so we make sure that we mark that we resolved the conflict
var conflictHistory = new RavenJArray(ReplicationData.GetHistory(deletedMetadata));
conflictHistory.Add(new RavenJObject
{
{Constants.RavenReplicationVersion, deletedMetadata[Constants.RavenReplicationVersion]},
{Constants.RavenReplicationSource, deletedMetadata[Constants.RavenReplicationSource]}
});
foreach (var item in conflictHistory)
{
if(history.Any(x=>ravenJTokenEqualityComparer.Equals(x, item)))
continue;
history.Add(item);
}
}
}
}
示例14: WriteJsonArray
private static void WriteJsonArray(RavenJArray array, StringWriter sw, int margin, int indent = 0)
{
sw.WriteLine('[');
indent += 1;
var isFirstItem = true;
foreach (var token in array.Values())
{
if (isFirstItem)
isFirstItem = false;
else
sw.WriteLine(',');
Indent(sw, indent);
WriteValue(token, sw, margin, indent);
}
sw.WriteLine();
indent -= 1;
Indent(sw, indent);
sw.Write(']');
}
示例15: PerformBulkOperation
private RavenJArray PerformBulkOperation(string index, IndexQuery indexQuery, bool allowStale, Func<string, TransactionInformation, object> batchOperation)
{
var array = new RavenJArray();
var bulkIndexQuery = new IndexQuery
{
Query = indexQuery.Query,
Start = indexQuery.Start,
Cutoff = indexQuery.Cutoff,
PageSize = int.MaxValue,
FieldsToFetch = new[] { Constants.DocumentIdFieldName },
SortedFields = indexQuery.SortedFields
};
bool stale;
var queryResults = database.QueryDocumentIds(index, bulkIndexQuery, out stale);
if (stale && allowStale == false)
{
throw new InvalidOperationException(
"Bulk operation cancelled because the index is stale and allowStale is false");
}
const int batchSize = 1024;
using (var enumerator = queryResults.GetEnumerator())
{
while (true)
{
var batchCount = 0;
database.TransactionalStorage.Batch(actions =>
{
while (batchCount < batchSize && enumerator.MoveNext())
{
batchCount++;
var result = batchOperation(enumerator.Current, transactionInformation);
array.Add(RavenJObject.FromObject(result, JsonExtensions.CreateDefaultJsonSerializer()));
}
});
if (batchCount < batchSize) break;
}
}
return array;
}