private void ProcessObject(JObject obj) { Item item = null; try { item = Item.From(currentRecord, obj, currentConf); } catch (ArgumentException e) { // FIXME PatchFormatException.ThrowWhenInvalidToken(obj, currentConf, e); } var id = item?.Id ?? throw new Exception("Unreachable!"); if (current.ContainsKey(id)) { var existed = current[id]; Logger.Warn($"Conflict between " + $"Item1@({existed.Source})" + " & " + $"Item2@({item.Source})\n" + "Item1 will be overriden/merged."); existed.Merge(item); } else { current.Add(id, item); } }
private void ProcessArray(JArray array) { foreach (var token in array) { if (token.Type != JTokenType.Object) { PatchFormatException.ThrowWhenInvalidToken(token, currentConf); } // Checked token type above ProcessObject(token.Value <JObject>()); } }
private void UpdateState(FileInfo conf) { currentConf = conf; var name = Path.GetFileNameWithoutExtension(conf.Name); try { currentRecord = ConfClassRecordStore.ByName(name); } catch (KeyNotFoundException e) { PatchFormatException.ThrowWhenRecordNotFound(e, conf); } current = items.GetOrAdd(currentRecord, new Dictionary <int, Item>()); }
public void Process(FileInfo conf) { UpdateState(conf); JArray array = null; using (var reader = new JsonTextReader(currentConf.OpenText())) { try { array = JArray.Load(reader, new JsonLoadSettings { LineInfoHandling = LineInfoHandling.Load }); } catch (JsonReaderException e) { PatchFormatException.ThrowWhenJsonReaderException(e); } } Logger.Assert(array != null, "Array must not be null since it whether be assigned or an exception has been thrown."); ProcessArray(array); }