Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
KleversonCruz committed May 23, 2022
1 parent d9fb559 commit 96db827
Show file tree
Hide file tree
Showing 73 changed files with 11,732 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
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
22 changes: 22 additions & 0 deletions Validador.API/Controllers/ValidadorController.cs
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();
}
}
}
22 changes: 22 additions & 0 deletions Validador.API/Dockerfile
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"]
12 changes: 12 additions & 0 deletions Validador.API/Models/ValidadorModel.cs
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; }
}
}
25 changes: 25 additions & 0 deletions Validador.API/Program.cs
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();
38 changes: 38 additions & 0 deletions Validador.API/Properties/launchSettings.json
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
}
}
}
20 changes: 20 additions & 0 deletions Validador.API/Validador.API.csproj
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>
8 changes: 8 additions & 0 deletions Validador.API/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions Validador.API/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
16 changes: 16 additions & 0 deletions Validador/Collections/Abrasf.cs
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"));
}
}
}
19 changes: 19 additions & 0 deletions Validador/Collections/Betha.cs
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);
}
}
}
45 changes: 45 additions & 0 deletions Validador/Collections/Collection.cs
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();
}
}
10 changes: 10 additions & 0 deletions Validador/Collections/ECollections.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace Validador.Application
{
public enum ECollections
{
Abrasf,
Ginfes,
Betha
}
}
19 changes: 19 additions & 0 deletions Validador/Collections/Ginfes.cs
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"));
}
}
}
23 changes: 23 additions & 0 deletions Validador/Factory.cs
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();
}
}
}
}
Loading

0 comments on commit 96db827

Please sign in to comment.