Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions xChanger.Api/Brokers/Sheets/ISheetBroker.ExternalPersonPetInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - -
// Copyright (c) Coalition of Good-Hearted Engineers
// Free to Use for Precise File Conversion
//- - - - - - - - - - - - - - - - - - - - - - - - - -

namespace xChanger.Api.Brokers.Sheets
{
public partial interface ISheetBroker
{
ValueTask UploadExternalPersonPetsFileAsync(IFormFile file);
}
}
14 changes: 14 additions & 0 deletions xChanger.Api/Brokers/Sheets/ISheetBroker.ExternalPersonPets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - -
// Copyright (c) Coalition of Good-Hearted Engineers
// Free to Use for Precise File Conversion
//- - - - - - - - - - - - - - - - - - - - - - - - - -

using xChanger.Api.Models.Foundations.ExternalPersons;

namespace xChanger.Api.Brokers.Sheets
{
public partial interface ISheetBroker
{
ValueTask<List<ExternalPerson>> ReadAllExternalPersonPetsAsync();
}
}
18 changes: 18 additions & 0 deletions xChanger.Api/Brokers/Sheets/ISheetBroker.PersonXML.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - -
// Copyright (c) Coalition of Good-Hearted Engineers
// Free to Use for Precise File Conversion
//- - - - - - - - - - - - - - - - - - - - - - - - - -

using xChanger.Api.Models.Foundations.Persons;

namespace xChanger.Api.Brokers.Sheets
{
public partial interface ISheetBroker
{
ValueTask SavePeopleWithPetsToXmlFile(
IEnumerable<Person> peopleWithPets,
string filePath);

ValueTask<MemoryStream> RetrievePeopleWithPetsXmlFile(string filePath);
}
}
10 changes: 10 additions & 0 deletions xChanger.Api/Brokers/Sheets/ISheetBroker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - -
// Copyright (c) Coalition of Good-Hearted Engineers
// Free to Use for Precise File Conversion
//- - - - - - - - - - - - - - - - - - - - - - - - - -

namespace xChanger.Api.Brokers.Sheets
{
public partial interface ISheetBroker
{ }
}
20 changes: 20 additions & 0 deletions xChanger.Api/Brokers/Sheets/SheetBroker.ExternalPersonPetInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - -
// Copyright (c) Coalition of Good-Hearted Engineers
// Free to Use for Precise File Conversion
//- - - - - - - - - - - - - - - - - - - - - - - - - -

namespace xChanger.Api.Brokers.Sheets
{
public partial class SheetBroker
{
public async ValueTask UploadExternalPersonPetsFileAsync(IFormFile file)
{
string filePath = GetSheetLocationWithName();

using (var fileStream = new FileStream(filePath, FileMode.Create))
{
await file.CopyToAsync(fileStream);
}
}
}
}
51 changes: 51 additions & 0 deletions xChanger.Api/Brokers/Sheets/SheetBroker.ExternalPersonPets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - -
// Copyright (c) Coalition of Good-Hearted Engineers
// Free to Use for Precise File Conversion
//- - - - - - - - - - - - - - - - - - - - - - - - - -

using OfficeOpenXml;
using xChanger.Api.Models.Foundations.ExternalPersons;

namespace xChanger.Api.Brokers.Sheets
{
public partial class SheetBroker
{
public async ValueTask<List<ExternalPerson>> ReadAllExternalPersonPetsAsync()
{
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;

Check warning on line 15 in xChanger.Api/Brokers/Sheets/SheetBroker.ExternalPersonPets.cs

View workflow job for this annotation

GitHub Actions / Build

'LicenseContext' is obsolete: 'Used in versions prior to EPPlus 8. Will be removed in coming versions.'

Check warning on line 15 in xChanger.Api/Brokers/Sheets/SheetBroker.ExternalPersonPets.cs

View workflow job for this annotation

GitHub Actions / Build

'ExcelPackage.LicenseContext' is obsolete: 'Please use the static 'ExcelPackage.License' property to set the required license information from EPPlus 8 and later versions. For more info see http://epplussoftware.com/developers/licensenotsetexception.'
var externalPersons = new List<ExternalPerson>();
using var sheetBroker = new SheetBroker(this.configuration);
FileInfo file = sheetBroker.GetFileInfo();
int row = 2, column = 1;

using var excelPackage =
new ExcelPackage(file);

ExcelWorksheet workSheet =
excelPackage.Workbook.Worksheets[PositionID: 0];

await excelPackage.LoadAsync(file);

while (!IsTrailingFinalRow(row, column, workSheet))
{
ExternalPerson externalPerson = new ExternalPerson();

externalPerson.PersonName = workSheet.Cells[row, column].Value.ToString();

Check warning on line 33 in xChanger.Api/Brokers/Sheets/SheetBroker.ExternalPersonPets.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference assignment.
externalPerson.Age = int.Parse(workSheet.Cells[row, column + 1].Value.ToString());

Check warning on line 34 in xChanger.Api/Brokers/Sheets/SheetBroker.ExternalPersonPets.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.
externalPerson.PetOne = workSheet.Cells[row, column + 2].Value.ToString();

Check warning on line 35 in xChanger.Api/Brokers/Sheets/SheetBroker.ExternalPersonPets.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference assignment.
externalPerson.PetOneType = workSheet.Cells[row, column + 3].Value.ToString();
externalPerson.PetTwo = workSheet.Cells[row, column + 4].Value.ToString();
externalPerson.PetTwoType = workSheet.Cells[row, column + 5].Value.ToString();
externalPerson.PetThree = workSheet.Cells[row, column + 6].Value.ToString();
externalPerson.PetThreeType = workSheet.Cells[row, column + 7].Value.ToString();
externalPersons.Add(externalPerson);
row++;
}

return externalPersons;

static bool IsTrailingFinalRow(int row, int column, ExcelWorksheet workSheet) =>
String.IsNullOrEmpty(workSheet.Cells[row, column].Value?.ToString());
}
}
}
28 changes: 28 additions & 0 deletions xChanger.Api/Brokers/Sheets/SheetBroker.PersonXML.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - -
// Copyright (c) Coalition of Good-Hearted Engineers
// Free to Use for Precise File Conversion
//- - - - - - - - - - - - - - - - - - - - - - - - - -

using System.Xml.Serialization;
using xChanger.Api.Models.Foundations.Persons;

namespace xChanger.Api.Brokers.Sheets
{
public partial class SheetBroker
{
public async ValueTask SavePeopleWithPetsToXmlFile(
IEnumerable<Person> peopleWithPets,
string filePath)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Person>));
await using FileStream fileStream = new FileStream(filePath, FileMode.Create);
xmlSerializer.Serialize(fileStream, peopleWithPets);
}

public async ValueTask<MemoryStream> RetrievePeopleWithPetsXmlFile(string filePath)
{
byte[] fileBytes = await File.ReadAllBytesAsync(filePath);
return new MemoryStream(fileBytes);
}
}
}
23 changes: 23 additions & 0 deletions xChanger.Api/Brokers/Sheets/SheetBroker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//- - - - - - - - - - - - - - - - - - - - - - - - - -
// Copyright (c) Coalition of Good-Hearted Engineers
// Free to Use for Precise File Conversion
//- - - - - - - - - - - - - - - - - - - - - - - - - -

namespace xChanger.Api.Brokers.Sheets
{
public partial class SheetBroker : ISheetBroker, IDisposable
{
private readonly IConfiguration configuration;

public SheetBroker(IConfiguration configuration) =>
this.configuration = configuration;

public void Dispose() { }

private string GetSheetLocationWithName() =>
this.configuration.GetConnectionString("SheetConnection");

Check warning on line 18 in xChanger.Api/Brokers/Sheets/SheetBroker.cs

View workflow job for this annotation

GitHub Actions / Build

Possible null reference return.

private FileInfo GetFileInfo() =>
new FileInfo(fileName: GetSheetLocationWithName());
}
}
1 change: 1 addition & 0 deletions xChanger.Api/xChanger.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="EFxceptions" Version="0.4.5" />
<PackageReference Include="EPPlus" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.18">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Loading