private static MetadataJson Validate([NotNull] IReadOnlyFileSystem rootFs) { using var fileStream = rootFs.FileOpen("metadata.json"); using var reader = new StreamReader(fileStream); using var jsonReader = new JsonTextReader(reader); var serializer = new JsonSerializer(); var metadata = serializer.Deserialize <MetadataJson>(jsonReader); if (!HasContinuousDigitPlaceholders(metadata.Structure.Volume)) { throw new InvalidDataException("Volume path cannot have separated digits"); } if (!HasContinuousDigitPlaceholders(metadata.Structure.Chapter)) { throw new InvalidDataException("Chapter path cannot have separated digits"); } if (!HasContinuousDigitPlaceholders(metadata.Structure.Page)) { throw new InvalidDataException("Page path cannot have separated digits"); } var matcher = new Regex(@"^.*?\{volume}.*?\{chapter}.*?\{page}.*?$"); foreach (var p in new[] { metadata.Structure.Raw, metadata.Structure.Translated, metadata.Structure.Save, metadata.Structure.Capture }) { if (!matcher.IsMatch(p)) { throw new InvalidDataException("The {volume} placeholder must be before {chapter} placeholder, which must be before {page} placeholder"); } } return(metadata); }
public TextReader FileOpen(string path) { return(new StreamReader(readOnlyFileSystem.FileOpen(path))); }