Knocks/BackEnd/Knoks.Sandbox/Program.cs

99 lines
3.2 KiB
C#

using System;
using Microsoft.Extensions.CommandLineUtils;
using RazorLight;
using System.IO;
using Microsoft.Extensions.Logging;
using System.Globalization;
using System.Text;
using Knoks.CryptoExchanges;
namespace Knoks.Sandbox
{
public class Program
{
private static ILoggerFactory LoggerFactory = new LoggerFactory()
.AddConsole()
.AddDebug();
public static void Main(string[] args)
{
var app = new CommandLineApplication();
app.Name = "dotnet run";
app.OnExecute(() =>
{
Console.WriteLine("LDI Sandbox.");
return 0;
});
app.Command("sm", command =>
{
command.Description = "State machine example.";
command.OnExecute(() =>
{
LoanRequestStateMachine.Test();
return 0;
});
});
app.Command("test", command =>
{
command.Description = "State machine example.";
command.OnExecute(() =>
{
CultureInfo ci;
RegionInfo ri;
StringBuilder sb = new StringBuilder();
foreach (var name in new[] { "en", "en-US", "ru", "uk", "hi", "he" })
{
ci = null;
ri = null;
ci = new CultureInfo(name);
if (!ci.IsNeutralCulture)
ri = new RegionInfo(name);
sb.AppendLine($"{ci.EnglishName},{ci.NativeName},{ci.DisplayName}");
}
return 0;
});
});
app.Command("exchanges", command =>
{
command.Description = "Start CryptoExchanges request.";
command.OnExecute(() =>
{
var exchanges = new CryptoExchangeManager();
exchanges.StartExchangesRequest();
Console.ReadLine();
exchanges.StopExchangesRequest().Wait();
return 0;
});
});
app.Command("be", command =>
{
command.Description = "Build email with RazorLigr library.";
command.OnExecute(() =>
{
//https://github.com/mailgun/transactional-email-templates
//https://docs.microsoft.com/en-us/aspnet/core/mvc/views/layout
//https://github.com/toddams/RazorLight
var engine = new EngineFactory().ForFileSystem(Path.Combine(Directory.GetCurrentDirectory(), "Templates", "Email"));
var result = engine.CompileRenderAsync("welcome.cshtml", new { BrandName = "Knoks Inc.", Text = "Kuku 123", Layout = "./NewFolder/_Layout.cshtml" });
return 0;
});
});
app.HelpOption("-?|-h|--help");
Environment.Exit(app.Execute(args.Length == 0 ? new[] { "-?" } : args));
}
}
}