private void BuildCollection(IFileViewModel fileViewModel, JsonArray jsonArray, Schema schema, List<string> path, CancellationToken? token) { foreach (object obj in jsonArray) { path.Add("[0]"); SchemaObject schemaObject = schema.GetSchemaObject(path); if (schemaObject == null) continue; if (schemaObject.AutoCompleteTargetKey != null) { string prefix = schemaObject.Prefix; AddParameters(ref prefix, fileViewModel); Add(schemaObject.AutoCompleteTargetKey, obj.ToString(), prefix, fileViewModel); } JsonNode node = obj as JsonNode; if (node != null) BuildCollection(fileViewModel, node, schema, path, token); JsonArray array = obj as JsonArray; if (array != null) BuildCollection(fileViewModel, array, schema, path, token); path.RemoveAt(path.Count - 1); } }
private void BuildCollection(IFileViewModel fileViewModel, JsonNode jsonNode, Schema schema, List<string> path, CancellationToken? token) { if (token.HasValue && token.Value.IsCancellationRequested) return; foreach (JsonElement jsonElement in jsonNode) { path.Add(jsonElement.Key); SchemaObject schemaObject = schema.GetSchemaObject(path); if (schemaObject != null) { if (schemaObject.AutoCompleteTargetKey != null) { string prefix = schemaObject.Prefix; AddParameters(ref prefix, fileViewModel); if (jsonElement.Value is JsonNode) AddRange(schemaObject.AutoCompleteTargetKey, ((JsonNode)jsonElement.Value).Keys, prefix, fileViewModel); else Add(schemaObject.AutoCompleteTargetKey, jsonElement.Value.ToString(), prefix,fileViewModel); } JsonNode node = jsonElement.Value as JsonNode; if (node != null) BuildCollection(fileViewModel, node, schema, path, token); else { JsonArray array = jsonElement.Value as JsonArray; if (array != null) BuildCollection(fileViewModel, array, schema, path, token); } } path.RemoveAt(path.Count - 1); } }