private static string ReplaceData(NamedContentData data, string text) { return(ContentDataPlaceholder.Replace(text, match => { var captures = match.Groups[2].Captures; var path = new string[captures.Count]; for (var i = 0; i < path.Length; i++) { path[i] = captures[i].Value; } if (!data.TryGetValue(path[0], out var field)) { return Undefined; } if (!field.TryGetValue(path[1], out var value)) { return Undefined; } for (var j = 2; j < path.Length; j++) { if (value is JObject obj && obj.TryGetValue(path[j], out value)) { continue; } if (value is JArray arr && int.TryParse(path[j], out var idx) && idx >= 0 && idx < arr.Count) { value = arr[idx]; }
private static string FormatReferenceFields(this NamedContentData data, Schema schema, string partitionKey, string separator) { Guard.NotNull(schema, nameof(schema)); var sb = new StringBuilder(); void AddValue(object value) { if (sb.Length > 0) { sb.Append(separator); } sb.Append(value); } var referenceFields = schema.ReferenceFields(); foreach (var referenceField in referenceFields) { if (data.TryGetValue(referenceField.Name, out var fieldData) && fieldData != null) { if (fieldData.TryGetValue(partitionKey, out var value)) { AddValue(value); } else if (fieldData.TryGetValue(InvariantPartitioning.Key, out var value2)) { AddValue(value2); } } } return(sb.ToString()); }
private static void AddReferencedIds(NamedContentData source, HashSet <DomainId> result, int referencesPerField, IField field) { if (source.TryGetValue(field.Name, out var fieldData) && fieldData != null) { foreach (var partitionValue in fieldData) { ReferencesExtractor.Extract(field, partitionValue.Value, result, referencesPerField); } } }
private static void AddReferencedIds(NamedContentData source, IField field, ReferencesExtractor extractor) { if (source.TryGetValue(field.Name, out var fieldData) && fieldData != null) { foreach (var partitionValue in fieldData) { extractor.SetValue(partitionValue.Value); field.Accept(extractor); } } }
public static void AddReferencedIds(this NamedContentData source, IField field, HashSet <DomainId> result, int referencesPerField = int.MaxValue) { Guard.NotNull(field, nameof(field)); Guard.NotNull(result, nameof(result)); if (source.TryGetValue(field.Name, out var fieldData) && fieldData != null) { foreach (var partitionValue in fieldData) { ReferencesExtractor.Extract(field, partitionValue.Value, result, referencesPerField); } } }
public static IEnumerable <Guid> GetReferencedIds(this NamedContentData source, IField field, Ids strategy = Ids.All) { Guard.NotNull(field); if (source.TryGetValue(field.Name, out var fieldData) && fieldData != null) { foreach (var partitionValue in fieldData) { var ids = field.GetReferencedIds(partitionValue.Value, strategy); foreach (var id in ids) { yield return(id); } } } }
private static string FormatReferenceFields(this NamedContentData data, Schema schema, string partition, string separator) { Guard.NotNull(schema, nameof(schema)); var sb = new StringBuilder(); void AddValue(object value) { if (sb.Length > 0) { sb.Append(separator); } sb.Append(value); } var referenceFields = schema.Fields.Where(x => x.RawProperties.IsReferenceField); if (!referenceFields.Any()) { referenceFields = schema.Fields.Take(1); } foreach (var referenceField in referenceFields) { if (data.TryGetValue(referenceField.Name, out var fieldData)) { if (fieldData.TryGetValue(partition, out var value)) { AddValue(value); } else if (fieldData.TryGetValue(InvariantPartitioning.Key, out var value2)) { AddValue(value2); } } } return(sb.ToString()); }
private static ClrValue TryGetValue(IRootField field, NamedContentData data) { var value = JsonValue.Null; if (data.TryGetValue(field.Name, out var fieldValue)) { if (fieldValue.TryGetValue(InvariantPartitioning.Key, out var temp) && temp != null) { value = temp; } } switch (field.RawProperties) { case BooleanFieldProperties _ when value is JsonBoolean boolean: return(boolean.Value); case BooleanFieldProperties _ when value is JsonNull: return(ClrValue.Null); case NumberFieldProperties _ when value is JsonNumber number: return(number.Value); case NumberFieldProperties _ when value is JsonNull: return(ClrValue.Null); case StringFieldProperties _ when value is JsonString @string: return(@string.Value); case StringFieldProperties _ when value is JsonNull: return(ClrValue.Null); case ReferencesFieldProperties _ when value is JsonArray array && array.FirstOrDefault() is JsonString @string: return(@string.Value); } return(null); }