public static bool CompareRavenJArrayData(this ICollection <DocumentsChanges> docChanges, RavenJArray selfArray, RavenJArray otherArray, string fieldArrName) { IEnumerable <RavenJToken> differences = selfArray.Length < otherArray.Length ? otherArray.Except(selfArray, RavenJTokenEqualityComparer.Default) : selfArray.Except(otherArray, RavenJTokenEqualityComparer.Default); if (!differences.Any()) { return(true); } foreach (var dif in differences) { var changes = new DocumentsChanges { FieldName = fieldArrName }; if (selfArray.Length < otherArray.Length) { changes.Change = DocumentsChanges.ChangeType.ArrayValueRemoved; changes.FieldOldValue = dif.ToString(); changes.FieldOldType = dif.Type.ToString(); } if (selfArray.Length > otherArray.Length) { changes.Change = DocumentsChanges.ChangeType.ArrayValueAdded; changes.FieldNewValue = dif.ToString(); changes.FieldNewType = dif.Type.ToString(); } docChanges.Add(changes); } return(false); }
public static async Task<RavenJToken> LoadAsync(JsonTextReaderAsync reader) { if (reader.TokenType == JsonToken.None) { if (!await reader.ReadAsync()) throw new Exception("Error reading RavenJObject from JsonReader."); } if (reader.TokenType != JsonToken.StartObject) throw new Exception( "Error reading RavenJObject from JsonReader. Current JsonReader item is not an object: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); if (await reader.ReadAsync() == false) throw new Exception("Unexpected end of json object"); string propName = null; var o = new RavenJObject(); do { switch (reader.TokenType) { case JsonToken.Comment: // ignore comments break; case JsonToken.PropertyName: propName = reader.Value.ToString(); break; case JsonToken.EndObject: return o; case JsonToken.StartObject: if (!string.IsNullOrEmpty(propName)) { var val = await RavenJObject.LoadAsync(reader); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; case JsonToken.StartArray: if (!string.IsNullOrEmpty(propName)) { var val = await RavenJArray.LoadAsync(reader); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; default: if (!string.IsNullOrEmpty(propName)) { var val = RavenJValue.Load(reader); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; } } while (await reader.ReadAsync()); throw new Exception("Error reading RavenJObject from JsonReader."); }
/// <summary> /// Loads an <see cref="RavenJObject"/> from a <see cref="JsonReader"/>. /// </summary> /// <param name="reader">A <see cref="JsonReader"/> that will be read for the content of the <see cref="RavenJObject"/>.</param> /// <returns>A <see cref="RavenJObject"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns> public new static RavenJObject Load(JsonReader reader) { if (reader.TokenType == JsonToken.None) { if (!reader.Read()) { throw new Exception("Error reading RavenJObject from JsonReader."); } } if (reader.TokenType != JsonToken.StartObject) { throw new Exception( "Error reading RavenJObject from JsonReader. Current JsonReader item is not an object: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } if (reader.Read() == false) { throw new Exception("Unexpected end of json object"); } string propName = null; var o = new RavenJObject(); do { switch (reader.TokenType) { case JsonToken.Comment: // ignore comments break; case JsonToken.PropertyName: propName = reader.Value.ToString(); if (String.Equals(propName, String.Empty)) { throw new InvalidDataException("Deserializing Json object with empty string as property name is not supported."); } break; case JsonToken.EndObject: return(o); case JsonToken.StartObject: if (!string.IsNullOrEmpty(propName)) { var val = RavenJObject.Load(reader); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; case JsonToken.StartArray: if (!string.IsNullOrEmpty(propName)) { var val = RavenJArray.Load(reader); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; default: if (!string.IsNullOrEmpty(propName)) { var val = RavenJValue.Load(reader); o[propName] = val; // TODO: Assert when o.Properties.ContainsKey and its value != val propName = null; } else { throw new InvalidOperationException("The JsonReader should not be on a token of type {0}." .FormatWith(CultureInfo.InvariantCulture, reader.TokenType)); } break; } } while (reader.Read()); throw new Exception("Error reading RavenJObject from JsonReader."); }