private Transactionfile LoadEntity(JObject payload, FileModel file) { Transactionfile result = new Transactionfile(); JsonSerializer serializer = new JsonSerializer() { }; var reader = new JTokenReader(payload); var converter = new ConvertEntities <ReferentialEntity>(this._parent, this._parent.Diagnostic, file); serializer.Converters.Add(converter); var model = (Entities <ReferentialEntity>)serializer.Deserialize(reader, typeof(Entities <ReferentialEntity>)); if (converter.Exception != null) { throw converter.Exception; } //if (model.HasChangedOnLoading) // model.Save(file.FullPath, Formatting.Indented, converter); var items = this._parent.CollectContentOfFile <ReferentialEntity>(file).ToList(); foreach (var item in model) { try { if (!string.IsNullOrEmpty(item.Name)) { this._parent.Add(item); var p = items.RemoveWhere(c => c.Name == item.Name); if (p.Count == 0) { result.Added.Add(item); } else { result.Updated.Add(item); } } } catch (System.Exception e) { _parent.Diagnostic.Append( new DiagnositcMessage() { Severity = SeverityEnum.Error, File = file.FullPath, Exception = e, Text = $"Failed to adding entity {item.Name}" } ); } } foreach (var item in items) { this._parent.RemoveReferential(item); result.Deleted.Add(item); } return(result); }
public void Dispose() { _reader = null; }
internal LicensesReader(JToken json) { _json = json; _reader = new JTokenReader(_json); }
internal PresetReader(JToken json) { _json = json; _reader = new JTokenReader(_json); }
public void YahooFinance() { JObject o = new JObject( new JProperty("Test1", new DateTime(2000, 10, 15, 5, 5, 5, DateTimeKind.Utc)), new JProperty("Test2", new DateTimeOffset(2000, 10, 15, 5, 5, 5, new TimeSpan(11, 11, 0))), new JProperty("Test3", "Test3Value"), new JProperty("Test4", null) ); using (JTokenReader jsonReader = new JTokenReader(o)) { IJsonLineInfo lineInfo = jsonReader; jsonReader.Read(); Assert.AreEqual(JsonToken.StartObject, jsonReader.TokenType); Assert.AreEqual(false, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType); Assert.AreEqual("Test1", jsonReader.Value); Assert.AreEqual(false, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(JsonToken.Date, jsonReader.TokenType); Assert.AreEqual(new DateTime(2000, 10, 15, 5, 5, 5, DateTimeKind.Utc), jsonReader.Value); Assert.AreEqual(false, lineInfo.HasLineInfo()); Assert.AreEqual(0, lineInfo.LinePosition); Assert.AreEqual(0, lineInfo.LineNumber); jsonReader.Read(); Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType); Assert.AreEqual("Test2", jsonReader.Value); jsonReader.Read(); Assert.AreEqual(JsonToken.Date, jsonReader.TokenType); Assert.AreEqual(new DateTimeOffset(2000, 10, 15, 5, 5, 5, new TimeSpan(11, 11, 0)), jsonReader.Value); jsonReader.Read(); Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType); Assert.AreEqual("Test3", jsonReader.Value); jsonReader.Read(); Assert.AreEqual(JsonToken.String, jsonReader.TokenType); Assert.AreEqual("Test3Value", jsonReader.Value); jsonReader.Read(); Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType); Assert.AreEqual("Test4", jsonReader.Value); jsonReader.Read(); Assert.AreEqual(JsonToken.Null, jsonReader.TokenType); Assert.AreEqual(null, jsonReader.Value); Assert.IsTrue(jsonReader.Read()); Assert.AreEqual(JsonToken.EndObject, jsonReader.TokenType); Assert.IsFalse(jsonReader.Read()); Assert.AreEqual(JsonToken.None, jsonReader.TokenType); } using (JsonReader jsonReader = new JTokenReader(o.Property("Test2"))) { Assert.IsTrue(jsonReader.Read()); Assert.AreEqual(JsonToken.PropertyName, jsonReader.TokenType); Assert.AreEqual("Test2", jsonReader.Value); Assert.IsTrue(jsonReader.Read()); Assert.AreEqual(JsonToken.Date, jsonReader.TokenType); Assert.AreEqual(new DateTimeOffset(2000, 10, 15, 5, 5, 5, new TimeSpan(11, 11, 0)), jsonReader.Value); Assert.IsFalse(jsonReader.Read()); Assert.AreEqual(JsonToken.None, jsonReader.TokenType); } }
public void ReadLineInfo() { string input = @"{ CPU: 'Intel', Drives: [ 'DVD read/writer', ""500 gigabyte hard drive"" ] }"; StringReader sr = new StringReader(input); JObject o = JObject.Parse(input); using (JTokenReader jsonReader = new JTokenReader(o)) { IJsonLineInfo lineInfo = jsonReader; Assert.AreEqual(jsonReader.TokenType, JsonToken.None); Assert.AreEqual(0, lineInfo.LineNumber); Assert.AreEqual(0, lineInfo.LinePosition); Assert.AreEqual(false, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.StartObject); Assert.AreEqual(1, lineInfo.LineNumber); Assert.AreEqual(1, lineInfo.LinePosition); Assert.AreEqual(true, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName); Assert.AreEqual(jsonReader.Value, "CPU"); Assert.AreEqual(2, lineInfo.LineNumber); Assert.AreEqual(7, lineInfo.LinePosition); Assert.AreEqual(true, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.String); Assert.AreEqual(jsonReader.Value, "Intel"); Assert.AreEqual(2, lineInfo.LineNumber); Assert.AreEqual(15, lineInfo.LinePosition); Assert.AreEqual(true, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.PropertyName); Assert.AreEqual(jsonReader.Value, "Drives"); Assert.AreEqual(3, lineInfo.LineNumber); Assert.AreEqual(10, lineInfo.LinePosition); Assert.AreEqual(true, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.StartArray); Assert.AreEqual(3, lineInfo.LineNumber); Assert.AreEqual(12, lineInfo.LinePosition); Assert.AreEqual(true, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.String); Assert.AreEqual(jsonReader.Value, "DVD read/writer"); Assert.AreEqual(4, lineInfo.LineNumber); Assert.AreEqual(22, lineInfo.LinePosition); Assert.AreEqual(true, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.String); Assert.AreEqual(jsonReader.Value, "500 gigabyte hard drive"); Assert.AreEqual(5, lineInfo.LineNumber); Assert.AreEqual(30, lineInfo.LinePosition); Assert.AreEqual(true, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.EndArray); Assert.AreEqual(0, lineInfo.LineNumber); Assert.AreEqual(0, lineInfo.LinePosition); Assert.AreEqual(false, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.EndObject); Assert.AreEqual(0, lineInfo.LineNumber); Assert.AreEqual(0, lineInfo.LinePosition); Assert.AreEqual(false, lineInfo.HasLineInfo()); jsonReader.Read(); Assert.AreEqual(jsonReader.TokenType, JsonToken.None); } }