Adicionado custom parser para faturas onde não existe período de leitura.
Faturas sem data de leitura são classificadas como erro e salva na pasta de erros.
This commit is contained in:
parent
d16a799ebc
commit
52a32b9279
34
Download Faturas/DefaultDateTimeConverter.cs
Normal file
34
Download Faturas/DefaultDateTimeConverter.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Download_Faturas
|
||||
{
|
||||
public class DefaultDateTimeConverter : JsonConverter<DateTime>
|
||||
{
|
||||
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
string? str = reader.GetString();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
|
||||
if (DateTime.TryParse(str, out var date))
|
||||
{
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStringValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,10 @@
|
||||
<Platforms>AnyCPU</Platforms>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Class1.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\.editorconfig" Link=".editorconfig" />
|
||||
</ItemGroup>
|
||||
@ -25,11 +29,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="DataSet1.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>DataSet1.xsd</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
@ -44,11 +43,4 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="DataSet1.xsd">
|
||||
<Generator>MSDataSetGenerator</Generator>
|
||||
<LastGenOutput>DataSet1.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@ -85,8 +85,13 @@
|
||||
this.faturaParsed.TryGetProperty("json", out a);
|
||||
}
|
||||
|
||||
// var val = a.ToString().Contains("\"measured\": [");
|
||||
Rootobject parsedResult = JsonSerializer.Deserialize<Rootobject>(a)!;
|
||||
|
||||
if (parsedResult.dates.reading.periodUntil == DateTime.MinValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
dadosTusd.Mes = int.Parse(parsedResult.dates.reading.periodUntil.AddDays(-15).ToString("yMM"));
|
||||
|
||||
string uc = new Regex("^0+").Replace(parsedResult.locationNumber, string.Empty).Replace("/", string.Empty).Replace("-", string.Empty).Replace(".", string.Empty);
|
||||
|
||||
@ -88,8 +88,10 @@
|
||||
|
||||
public class Reading
|
||||
{
|
||||
[JsonConverter(typeof(DefaultDateTimeConverter))]
|
||||
public DateTime periodFrom { get; set; }
|
||||
|
||||
[JsonConverter(typeof(DefaultDateTimeConverter))]
|
||||
public DateTime periodUntil { get; set; }
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user