| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 3 | | using ValidateLib.Metadata.Descriptors.Interfaces; |
| | 4 | | using ValidateLib.Metadata.Parsers; |
| | 5 | | using ValidateLib.Metadata.Properties; |
| | 6 | | using ValidateLib.Metadata.Properties.AtomicProperties; |
| | 7 | | using ValidateLib.Metadata.PropertyParsers; |
| | 8 | | using ValidateLib.Metadata.PropertyParsers.DescriptorNS; |
| | 9 | | using ValidateLib.Metadata.PropertyParsers.DIalect; |
| | 10 | |
|
| | 11 | | namespace ValidateLib.Metadata.Descriptors |
| | 12 | | { |
| | 13 | | public class DialectDescriptor : Descriptor, INormalize, Interfaces.IParsable<DialectDescriptor>, ITypable |
| | 14 | | { |
| 1 | 15 | | public AtomicPropertyString? commentPrefix { get; set; } = null; |
| 1 | 16 | | public AtomicPropertyString? delimiter { get; set; } = new AtomicPropertyString(",") { IsDefault = true }; |
| 1 | 17 | | public AtomicPropertyBoolean? doubleQuote { get; set; } = new AtomicPropertyBoolean(true) { IsDefault = true }; |
| 1 | 18 | | public AtomicPropertyString? encoding { get; set; } = new AtomicPropertyString("utf-8") { IsDefault = true }; |
| 1 | 19 | | public AtomicPropertyBoolean? header { get; set; } = new AtomicPropertyBoolean(true) { IsDefault = true }; |
| 1 | 20 | | public AtomicPropertyInteger? headerRowCount { get; set; } = new AtomicPropertyInteger(1) { IsDefault = true }; |
| 1 | 21 | | public AtomicPropertyArray<string>? lineTerminators { get; set; } = new AtomicPropertyArray<string>(new List<str |
| 1 | 22 | | public AtomicPropertyString? quoteChar { get; set; } = new AtomicPropertyString("\"") { IsDefault = true }; |
| 1 | 23 | | public AtomicPropertyBoolean? skipBlankRows { get; set; } = new AtomicPropertyBoolean(false) { IsDefault = true |
| 1 | 24 | | public AtomicPropertyBoolean? skipInitialSpace { get; set; } = new AtomicPropertyBoolean(false) { IsDefault = tr |
| 1 | 25 | | public AtomicPropertyInteger? skipColumns { get; set; } = new AtomicPropertyInteger(0) { IsDefault = true }; |
| 1 | 26 | | public AtomicPropertyInteger? skipRows { get; set; } = new AtomicPropertyInteger(0) { IsDefault = true }; |
| 1 | 27 | | public AtomicPropertyString? trim { get; set; } = new AtomicPropertyString("true") { IsDefault = true }; |
| 0 | 28 | | public string? referenceUrl { get; set; } |
| | 29 | |
|
| 1 | 30 | | new public static string getTypeForTypeProperty() => "Dialect"; |
| | 31 | |
|
| | 32 | | public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null) |
| | 33 | | { |
| 1 | 34 | | List<Warning> errors = new List<Warning>(); |
| 1 | 35 | | if (token.Type != JTokenType.Object) return errors; |
| 1 | 36 | | foreach (JProperty jProperty in token) |
| | 37 | | { |
| 1 | 38 | | var results = NormalizeProperty(jProperty, context); |
| 1 | 39 | | MergeTwoList(errors, results); |
| | 40 | | } |
| 1 | 41 | | return errors; |
| | 42 | | } |
| | 43 | |
|
| | 44 | | new static public List<Warning> NormalizeProperty(JProperty property, Context context) |
| | 45 | | { |
| 1 | 46 | | List<Warning> errors = new List<Warning>(); |
| 1 | 47 | | if (CommonProperty.IsCommonProperty(property.Name)) return CommonProperty.Normalize(property.Value, context, |
| 1 | 48 | | switch (property.Name) |
| | 49 | | { |
| | 50 | | case "commentPrefix": |
| | 51 | | case "delimiter": |
| | 52 | | case "doubleQuote": |
| | 53 | | case "encoding": |
| | 54 | | case "header": |
| | 55 | | case "headerRowCount": |
| | 56 | | case "lineTerminators": |
| | 57 | | case "quoteChar": |
| | 58 | | case "skipBlankRows": |
| | 59 | | case "skipInitialSpace": |
| | 60 | | case "skipColumns": |
| | 61 | | case "skipRows": |
| | 62 | | case "trim": |
| 1 | 63 | | return errors; |
| | 64 | | default: |
| 1 | 65 | | return Descriptor.NormalizeProperty(property, context); |
| | 66 | | } |
| | 67 | | } |
| | 68 | |
|
| | 69 | | new public IPropertyParserBase? GetPropertyParser(JProperty property, List<Warning> warnings) |
| | 70 | | { |
| 1 | 71 | | switch (property.Name) |
| | 72 | | { |
| | 73 | | case "commentPrefix": |
| 1 | 74 | | return new CommentPrefixPropertyParser(warnings, this); |
| | 75 | | case "delimiter": |
| 1 | 76 | | return new DelimiterPropertyParser(warnings, this); |
| | 77 | | case "doubleQuote": |
| 1 | 78 | | return new DoubleQuotePropertyParser(warnings, this); |
| | 79 | | case "encoding": |
| 1 | 80 | | return new EncodingPropertyParser(warnings, this); |
| | 81 | | case "header": |
| 1 | 82 | | return new HeaderPropertyParser(warnings, this); |
| | 83 | | case "headerRowCount": |
| 1 | 84 | | return new HeaderRowCountPropertyParser(warnings, this); |
| | 85 | | case "lineTerminators": |
| 1 | 86 | | return new LineTerminatorsPropertyParser(warnings, this); |
| | 87 | | case "quoteChar": |
| 1 | 88 | | return new QuoteCharPropertyParser(warnings, this); |
| | 89 | | case "skipBlankRows": |
| 1 | 90 | | return new SkipBlankRowsPropertyParser(warnings, this); |
| | 91 | | case "skipInitialSpace": |
| 1 | 92 | | return new SkipInitialSpacePropertyParser(warnings, this); |
| | 93 | | case "skipColumns": |
| 1 | 94 | | return new SkipColumnsPropertyParser(warnings, this); |
| | 95 | | case "skipRows": |
| 1 | 96 | | return new SkipRowsPropertyParser(warnings, this); |
| | 97 | | case "trim": |
| 1 | 98 | | return new TrimPropertyParser(warnings, this); |
| | 99 | | case "@type": |
| 1 | 100 | | return new TypePropertyParser<DialectDescriptor>(warnings, this); |
| | 101 | | default: |
| 1 | 102 | | return ((Descriptor)this).GetPropertyParser(property, warnings); |
| | 103 | | } |
| | 104 | | } |
| | 105 | |
|
| 0 | 106 | | public static IParser<DialectDescriptor> GetParser(List<Warning> warnings, DialectDescriptor? descriptor = null) |
| | 107 | |
|
| | 108 | |
|
| | 109 | | } |
| | 110 | | } |