Skip to content

Commit

Permalink
Renamed consoleapp to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
josdeweger authored and josdeweger committed Jan 6, 2019
1 parent 0347ca6 commit e321766
Show file tree
Hide file tree
Showing 22 changed files with 313 additions and 307 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace SheetToObjects.ConsoleApp
{
public class AppSettings
{
public string ApiKey { get; set; }
public string SheetId { get; set; }
}
}
namespace SheetToObjects.Examples
{
public class AppSettings
{
public string ApiKey { get; set; }
public string SheetId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.IO;
using SheetToObjects.ConsoleApp.Models;
using SheetToObjects.Core;
using SheetToObjects.Examples.Models;
using SheetToObjects.Lib;
using IProvideSheet = SheetToObjects.Adapters.Csv.IProvideSheet;

namespace SheetToObjects.ConsoleApp
namespace SheetToObjects.Examples
{
public class CsvAppWithValidationErrors
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System.IO;
using SheetToObjects.ConsoleApp.Models;
using SheetToObjects.Core;
using SheetToObjects.Examples.Models;
using SheetToObjects.Lib;
using IProvideSheet = SheetToObjects.Adapters.Csv.IProvideSheet;

namespace SheetToObjects.ConsoleApp
namespace SheetToObjects.Examples
{
public class CsvAppWithoutValidationErrors
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
using System;
using SheetToObjects.Adapters.MicrosoftExcel;
using SheetToObjects.ConsoleApp.Models;
using SheetToObjects.Core;
using SheetToObjects.Lib;

namespace SheetToObjects.ConsoleApp
{
public class ExcelApp
{
private readonly IProvideSheet _sheetProvider;
private readonly IMapSheetToObjects _sheetMapper;

public ExcelApp(
IProvideSheet sheetProvider,
IMapSheetToObjects sheetMapper)
{
_sheetProvider = sheetProvider;
_sheetMapper = sheetMapper;
}

public void Run()
{
var result = Timer.TimeFunc(() =>
{
var excelRange = new ExcelRange(new ExcelCell("A", 1), new ExcelCell("U", 9995));
var sheet = _sheetProvider.GetFromPath(@"./Files/Sample - Superstore.xlsx", "orders", excelRange);
return _sheetMapper.Map<Superstore>(sheet);
});

foreach (var error in result.Item1.ValidationErrors)
{
Console.WriteLine($"Column: {error.ColumnName} | Row: {error.RowIndex} | Message: {error.ErrorMessage}");
}
Console.WriteLine($"Mapped {result.Item1.ParsedModels.Count} models in {result.Item2.ToString()} " +
$"with {result.Item1.ValidationErrors.Count} validation errors");
Console.WriteLine("===============================================================");
}
}
using System;
using SheetToObjects.Adapters.MicrosoftExcel;
using SheetToObjects.Core;
using SheetToObjects.Examples.Models;
using SheetToObjects.Lib;

namespace SheetToObjects.Examples
{
public class ExcelApp
{
private readonly IProvideSheet _sheetProvider;
private readonly IMapSheetToObjects _sheetMapper;

public ExcelApp(
IProvideSheet sheetProvider,
IMapSheetToObjects sheetMapper)
{
_sheetProvider = sheetProvider;
_sheetMapper = sheetMapper;
}

public void Run()
{
var result = Timer.TimeFunc(() =>
{
var excelRange = new ExcelRange(new ExcelCell("A", 1), new ExcelCell("U", 9995));
var sheet = _sheetProvider.GetFromPath(@"./Files/Sample - Superstore.xlsx", "orders", excelRange);
return _sheetMapper.Map<Superstore>(sheet);
});

foreach (var error in result.Item1.ValidationErrors)
{
Console.WriteLine($"Column: {error.ColumnName} | Row: {error.RowIndex} | Message: {error.ErrorMessage}");
}
Console.WriteLine($"Mapped {result.Item1.ParsedModels.Count} models in {result.Item2.ToString()} " +
$"with {result.Item1.ValidationErrors.Count} validation errors");
Console.WriteLine("===============================================================");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using SheetToObjects.Adapters.GoogleSheets;
using SheetToObjects.ConsoleApp.Models;
using SheetToObjects.Core;
using SheetToObjects.Lib;

namespace SheetToObjects.ConsoleApp
{
public class GoogleSheetsApp
{
private readonly AppSettings _appSettings;
private readonly IProvideSheet _sheetProvider;
private readonly IMapSheetToObjects _sheetMapper;

public GoogleSheetsApp(
IOptions<AppSettings> appSettings,
IProvideSheet sheetProvider,
IMapSheetToObjects sheetMapper)
{
_appSettings = appSettings.Value;
_sheetProvider = sheetProvider;
_sheetMapper = sheetMapper;
}

public async Task Run()
{
var result = await Timer.TimeFuncAsync(async () =>
{
var sheet = await _sheetProvider.GetAsync(
_appSettings.SheetId,
"'Herstructurering Filters Data'!A1:H9",
_appSettings.ApiKey);
return _sheetMapper.Map<EpicTracking>(sheet);
});

foreach (var error in result.Item1.ValidationErrors)
{
Console.WriteLine($"Column: {error.ColumnName} | Row: {error.RowIndex} | Message: {error.ErrorMessage}");
}
Console.WriteLine($"Mapped {result.Item1.ParsedModels.Count} models in {result.Item2.ToString()} " +
$"with {result.Item1.ValidationErrors.Count} validation errors");
Console.WriteLine("===============================================================");
}
}
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using SheetToObjects.Adapters.GoogleSheets;
using SheetToObjects.Core;
using SheetToObjects.Examples.Models;
using SheetToObjects.Lib;

namespace SheetToObjects.Examples
{
public class GoogleSheetsApp
{
private readonly AppSettings _appSettings;
private readonly IProvideSheet _sheetProvider;
private readonly IMapSheetToObjects _sheetMapper;

public GoogleSheetsApp(
IOptions<AppSettings> appSettings,
IProvideSheet sheetProvider,
IMapSheetToObjects sheetMapper)
{
_appSettings = appSettings.Value;
_sheetProvider = sheetProvider;
_sheetMapper = sheetMapper;
}

public async Task Run()
{
var result = await Timer.TimeFuncAsync(async () =>
{
var sheet = await _sheetProvider.GetAsync(
_appSettings.SheetId,
"'Herstructurering Filters Data'!A1:H9",
_appSettings.ApiKey);
return _sheetMapper.Map<EpicTracking>(sheet);
});

foreach (var error in result.Item1.ValidationErrors)
{
Console.WriteLine($"Column: {error.ColumnName} | Row: {error.RowIndex} | Message: {error.ErrorMessage}");
}
Console.WriteLine($"Mapped {result.Item1.ParsedModels.Count} models in {result.Item2.ToString()} " +
$"with {result.Item1.ValidationErrors.Count} validation errors");
Console.WriteLine("===============================================================");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SheetToObjects.ConsoleApp.Models
namespace SheetToObjects.Examples.Models
{
public class EpicTracking
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using SheetToObjects.Lib.AttributesConfiguration.MappingTypeAttributes;
using SheetToObjects.Lib.AttributesConfiguration.RuleAttributes;

namespace SheetToObjects.ConsoleApp.Models
namespace SheetToObjects.Examples.Models
{

[SheetToObjectAttributeConfig(true)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;

namespace SheetToObjects.ConsoleApp.Models
namespace SheetToObjects.Examples.Models
{
public class Superstore
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;

namespace SheetToObjects.ConsoleApp
{
internal class Program
{
private static ServiceProvider _services;

private static void Main()
{
_services = new ServiceCollection().ConfigureServices().BuildServiceProvider();

RunGoogleSheetsExampleAsync().GetAwaiter().GetResult();
RunProtectedGoogleSheetsExampleAsync().GetAwaiter().GetResult();
RunExcelExample();
RunCsvWithValidationErrorsExample();
RunCsvWithoutValidationErrorsExample();

Console.ReadLine();
}

private static async Task RunGoogleSheetsExampleAsync()
{
Console.WriteLine("===============================================================");
Console.WriteLine("Running Google Sheets example");

await _services.GetService<GoogleSheetsApp>().Run();
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;

namespace SheetToObjects.Examples
{
internal class Program
{
private static ServiceProvider _services;

private static void Main()
{
_services = new ServiceCollection().ConfigureServices().BuildServiceProvider();

RunGoogleSheetsExampleAsync().GetAwaiter().GetResult();
RunProtectedGoogleSheetsExampleAsync().GetAwaiter().GetResult();
RunExcelExample();
RunCsvWithValidationErrorsExample();
RunCsvWithoutValidationErrorsExample();

Console.ReadLine();
}

private static async Task RunGoogleSheetsExampleAsync()
{
Console.WriteLine("===============================================================");
Console.WriteLine("Running Google Sheets example");

await _services.GetService<GoogleSheetsApp>().Run();
}

private static async Task RunProtectedGoogleSheetsExampleAsync()
{
Console.WriteLine("===============================================================");
{
Console.WriteLine("===============================================================");
Console.WriteLine("Running Protected Google Sheets example");

await _services.GetService<ProtectedGoogleSheetsApp>().Run();
}

private static void RunExcelExample()
{
Console.WriteLine("===============================================================");
Console.WriteLine("Running Excel example");

_services.GetService<ExcelApp>().Run();
}

private static void RunCsvWithValidationErrorsExample()
{
Console.WriteLine("===============================================================");
Console.WriteLine("Running CSV with validation errors example");

_services.GetService<CsvAppWithValidationErrors>().Run();
}

private static void RunCsvWithoutValidationErrorsExample()
{
Console.WriteLine("===============================================================");
Console.WriteLine("Running CSV without validation errors example");

_services.GetService<CsvAppWithoutValidationErrors>().Run();
}
}
}
}

private static void RunExcelExample()
{
Console.WriteLine("===============================================================");
Console.WriteLine("Running Excel example");

_services.GetService<ExcelApp>().Run();
}

private static void RunCsvWithValidationErrorsExample()
{
Console.WriteLine("===============================================================");
Console.WriteLine("Running CSV with validation errors example");

_services.GetService<CsvAppWithValidationErrors>().Run();
}

private static void RunCsvWithoutValidationErrorsExample()
{
Console.WriteLine("===============================================================");
Console.WriteLine("Running CSV without validation errors example");

_services.GetService<CsvAppWithoutValidationErrors>().Run();
}
}
}
Loading

0 comments on commit e321766

Please sign in to comment.