-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9fb559
commit 96db827
Showing
73 changed files
with
11,732 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
**/.classpath | ||
**/.dockerignore | ||
**/.env | ||
**/.git | ||
**/.gitignore | ||
**/.project | ||
**/.settings | ||
**/.toolstarget | ||
**/.vs | ||
**/.vscode | ||
**/*.*proj.user | ||
**/*.dbmdl | ||
**/*.jfm | ||
**/azds.yaml | ||
**/bin | ||
**/charts | ||
**/docker-compose* | ||
**/Dockerfile* | ||
**/node_modules | ||
**/npm-debug.log | ||
**/obj | ||
**/secrets.dev.yaml | ||
**/values.dev.yaml | ||
LICENSE | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Validador.API.Models; | ||
|
||
namespace Validador.API.Controllers | ||
{ | ||
[ApiController] | ||
[Route("[controller]")] | ||
public class ValidadorController : ControllerBase | ||
{ | ||
[HttpPost] | ||
public IActionResult Validate([FromForm] ValidadorModel model) | ||
{ | ||
var validador = Application.Factory.Create(model.CollectionName); | ||
var errorList =validador.ValidateSchema(model.XmlText); | ||
if (errorList.Count > 0) | ||
{ | ||
return BadRequest(errorList); | ||
} | ||
return Ok(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. | ||
|
||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base | ||
WORKDIR /app | ||
EXPOSE 80 | ||
EXPOSE 443 | ||
|
||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build | ||
WORKDIR /src | ||
COPY ["Validador.API/Validador.API.csproj", "Validador.API/"] | ||
RUN dotnet restore "Validador.API/Validador.API.csproj" | ||
COPY . . | ||
WORKDIR "/src/Validador.API" | ||
RUN dotnet build "Validador.API.csproj" -c Release -o /app/build | ||
|
||
FROM build AS publish | ||
RUN dotnet publish "Validador.API.csproj" -c Release -o /app/publish | ||
|
||
FROM base AS final | ||
WORKDIR /app | ||
COPY --from=publish /app/publish . | ||
ENTRYPOINT ["dotnet", "Validador.API.dll"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Validador.API.Models | ||
{ | ||
public class ValidadorModel | ||
{ | ||
[Required] | ||
public string CollectionName { get; set; } | ||
[Required] | ||
public string XmlText { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
|
||
builder.Services.AddControllers(); | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.UseAuthorization(); | ||
|
||
app.MapControllers(); | ||
|
||
app.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:17700", | ||
"sslPort": 44325 | ||
} | ||
}, | ||
"profiles": { | ||
"Validador.API": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:7077;http://localhost:5077", | ||
"dotnetRunMessages": true | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"Docker": { | ||
"commandName": "Docker", | ||
"launchBrowser": true, | ||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", | ||
"publishAllPorts": true, | ||
"useSSL": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<UserSecretsId>b19b3e5b-3f96-4c84-a094-a766d2305d1f</UserSecretsId> | ||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Validador\Validador.Application.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Validador.Application | ||
{ | ||
public class Abrasf : Collection | ||
{ | ||
public Abrasf() | ||
{ | ||
CollectionName = "Abrasf"; | ||
} | ||
|
||
public override void SetSchemas() | ||
{ | ||
Schema.Add(null, Path.Combine(SchemaDirectoryPath, "nfse_v2-03 2016.xsd")); | ||
Schema.Add(null, Path.Combine(SchemaDirectoryPath, "xmldsig-core-schema20020212.xsd")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Xml; | ||
|
||
namespace Validador.Application | ||
{ | ||
public class Betha : Collection | ||
{ | ||
public Betha() | ||
{ | ||
CollectionName = "Betha"; | ||
} | ||
|
||
public override void SetSchemas() | ||
{ | ||
Schema.Add(null, Path.Combine(SchemaDirectoryPath, "nfse_v01.xsd")); | ||
XmlReader reader = XmlReader.Create(Path.Combine(SchemaDirectoryPath, "xmldsig-core-schema_v01.xsd")); | ||
Schema.Add(null, reader); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Reflection; | ||
using System.Xml; | ||
using System.Xml.Linq; | ||
using System.Xml.Schema; | ||
|
||
namespace Validador.Application | ||
{ | ||
public abstract class Collection | ||
{ | ||
private static readonly string DirectoryPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); | ||
public string CollectionName { get; set; } | ||
public XmlSchemaSet Schema { get; set; } | ||
public string SchemaDirectoryPath | ||
{ | ||
get | ||
{ | ||
return Path.Combine(DirectoryPath, "Schemas", this.CollectionName); | ||
} | ||
} | ||
|
||
public Collection() | ||
{ | ||
Schema = new XmlSchemaSet(); | ||
CollectionName = "Abrasf"; | ||
} | ||
|
||
private readonly List<string> ValidationErrors = new(); | ||
|
||
public List<string> ValidateSchema(string xmlString) | ||
{ | ||
SetSchemas(); | ||
XmlReader reader = XmlReader.Create(new StringReader(xmlString)); | ||
XDocument document = XDocument.Load(reader); | ||
document.Validate(Schema, ValidationEventHandler); | ||
return ValidationErrors; | ||
} | ||
|
||
private void ValidationEventHandler(object sender, ValidationEventArgs e) | ||
{ | ||
ValidationErrors.Add(e.Message); | ||
} | ||
|
||
public abstract void SetSchemas(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
| ||
namespace Validador.Application | ||
{ | ||
public enum ECollections | ||
{ | ||
Abrasf, | ||
Ginfes, | ||
Betha | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Validador.Application | ||
{ | ||
public class Ginfes : Collection | ||
{ | ||
public Ginfes() | ||
{ | ||
CollectionName = "Ginfes"; | ||
} | ||
|
||
public override void SetSchemas() | ||
{ | ||
Schema.Add(null, Path.Combine(SchemaDirectoryPath, "tipos_v03.xsd")); | ||
Schema.Add(null, Path.Combine(SchemaDirectoryPath, "cabecalho_v03.xsd")); | ||
Schema.Add(null, Path.Combine(SchemaDirectoryPath, "servico_enviar_lote_rps_envio_v03.xsd")); | ||
Schema.Add(null, Path.Combine(SchemaDirectoryPath, "servico_consultar_situacao_lote_rps_envio_v03.xsd")); | ||
Schema.Add(null, Path.Combine(SchemaDirectoryPath, "xmldsig-core-schema20020212_v03.xsd")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Validador.Application | ||
{ | ||
public static class Factory | ||
{ | ||
public static Collection Create(ECollections collection) | ||
{ | ||
return Create(collection.ToString()); | ||
} | ||
|
||
public static Collection Create(string collection) | ||
{ | ||
switch (collection) | ||
{ | ||
default: | ||
return new Abrasf(); | ||
case "Ginfes": | ||
return new Ginfes(); | ||
case "Betha": | ||
return new Betha(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.