((inputPath, outputPath, debug) =>
+ {
+ if(debug)
+ Log.Logger.Debug("Debug is on");
+
+
+ if (inputPath == null)
+ throw new ArgumentNullException(nameof(inputPath));
+
+ if(outputPath == null)
+ throw new ArgumentNullException(nameof(outputPath));
+
+
+ ConvertToBlazor(inputPath,outputPath);
+
+ });
+
+ // Parse the incoming args and invoke the handler
+ return await rootCommand.InvokeAsync(args);
+
}
+
+
+ public static void ConvertToBlazor(string inputPath, string outputPath)
+ {
+
+ BlazorPage blazorPage= new BlazorPage("TestApp", outputPath);
+ blazorPage.CreatePage();
+
+ File.Delete(Path.Combine(inputPath, "index.html"));
+
+ Directory.CreateDirectory(Path.Combine(outputPath, "wwwroot", "nicepage"));
+ Directory.CreateDirectory(Path.Combine(outputPath, "wwwroot", "nicepage", "css"));
+ Directory.CreateDirectory(Path.Combine(outputPath, "wwwroot", "nicepage", "js"));
+
+ File.Move(Path.Combine(inputPath, "nicepage.css"), Path.Combine(outputPath, "wwwroot", "nicepage", "css", "nicepage.css"));
+ File.Move(Path.Combine(inputPath, "nicepage.js"), Path.Combine(outputPath, "wwwroot", "nicepage", "js", "nicepage.js"));
+ File.Move(Path.Combine(inputPath, "jquery.js"), Path.Combine(outputPath, "wwwroot", "nicepage", "js", "jquery.js"));
+
+ Directory.Move(Path.Combine(inputPath, "images"), Path.Combine(outputPath, "wwwroot", "nicepage", "images"));
+
+
+ Directory.CreateDirectory(Path.Combine(outputPath, "Pages", "nicepage"));
+
+ var files = Directory.GetFiles(inputPath).ToList();
+
+
+ foreach (var file in files)
+ {
+
+ string str = File.ReadAllText(file);
+ str = str.Replace("images/","nicepage/images/");
+ File.WriteAllText(file, str);
+
+ int i = files.IndexOf(file);
+ FileInfo fileInfo = new FileInfo(file);
+ string fileContont = File.ReadAllText(file);
+
+ if(fileInfo.Extension == ".html")
+ {
+ HtmlDocument doc = new HtmlDocument();
+ doc.Load(file);
+
+ var body = doc.DocumentNode.SelectSingleNode("//body");
+ var header = doc.DocumentNode.SelectSingleNode("//header");
+ var head = doc.DocumentNode.SelectSingleNode("//head");
+ if (i == 1)
+ {
+ StringBuilder sb = new StringBuilder();
+ StringBuilder bodyClasses = new StringBuilder();
+ foreach (var classes in body.GetClasses())
+ {
+ bodyClasses.Append($"{classes} ");
+ }
+
+ sb.AppendLine("@inherits LayoutComponentBase");
+ sb.AppendLine($"");
+ sb.Append(header.OuterHtml);
+ sb.AppendLine("@Body");
+ sb.AppendLine("
");
+
+
+ File.WriteAllText (Path.Combine(outputPath, "Shared", "MainLayout.razor"), sb.ToString());
+
+ var content = File.ReadAllLines(Path.Combine(outputPath, "Pages", "_Layout.cshtml")).ToList();
+ content.Insert(12, "");
+ File.WriteAllLines(Path.Combine(outputPath, "Pages", "_Layout.cshtml"), content);
+ }
+
+ body.SelectSingleNode("//header").Remove();
+
+ StringBuilder fText = new StringBuilder();
+
+ fText.AppendLine("@page " + '"' + "/" + Path.GetFileName(file).Replace(".html","") + '"');
+ fText.AppendLine(body.InnerHtml);
+
+ File.WriteAllText(file, fText.ToString());
+
+ var fileName = Path.GetFileName(file);
+ var newFileName = fileName.Replace(".html", ".razor");
+
+ File.Move(file, Path.Combine(outputPath, "Pages", "nicepage", newFileName));
+ }
+ else if (fileInfo.Extension == ".css")
+ {
+ var fileName = Path.GetFileName(file);
+ var newFileName = fileName.Replace(".css", ".razor.css");
+
+ File.Move(file, Path.Combine(outputPath, "Pages", "nicepage", newFileName));
+ }
+
+
+
+
+ }
+
+
+ }
+
}
}
\ No newline at end of file
diff --git a/NTOB/appsettings.json b/NTOB/appsettings.json
index 29091fa..764bc0d 100644
--- a/NTOB/appsettings.json
+++ b/NTOB/appsettings.json
@@ -1,3 +1,23 @@
{
-
+ "Serilog": {
+ "MinimumLevel": "Debug",
+ "WriteTo": [
+ {
+ "Name": "Console",
+ "Args": {
+ "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console",
+ "outputTemplate": "===> {Timestamp:HH:mm:ss.fff zzz} [{Level:w3}] {Message:lj}{NewLine}{Exception}"
+ }
+
+ },
+ {
+ "Name": "File",
+ "Args": {
+ "path": "C:\\Users\\elias\\OneDrive\\Dokumente\\NTOB\\log\\NTOB.log",
+ "rollingInterval": "Day",
+ "outputTemplate": "===> {Timestamp:HH:mm:ss.fff zzz} [{Level:w3}] {Message:lj}{NewLine}{Exception}"
+ }
+ }
+ ]
+ }
}
\ No newline at end of file
diff --git a/NTOB/logic/BlazorPage.cs b/NTOB/logic/BlazorPage.cs
index 002322d..0b8d9b4 100644
--- a/NTOB/logic/BlazorPage.cs
+++ b/NTOB/logic/BlazorPage.cs
@@ -1,7 +1,61 @@
-namespace NTOB.logic
+using System;
+using System.Diagnostics;
+using System.Threading.Tasks;
+
+namespace NTOB.logic
{
public class BlazorPage
{
+ public string Title { get; set; }
+ public string Path { get; set; }
+
+
+ public BlazorPage(string title, string path)
+ {
+ Title = title;
+ Path = path;
+ }
+
+ public void CreatePage(bool https = false, AuthType authType = AuthType.Individual, bool debug = false)
+ {
+
+
+ string command = "dotnet new blazorserver" +
+ " -o " + '"' +Path + '"' +
+ " -n " + Title +
+ (https ? " " : " --no-https ") +
+ "-au " + authType.ToString();
+
+
+ Process cmd = new Process();
+ cmd.StartInfo.FileName = "cmd.exe";
+ cmd.StartInfo.RedirectStandardInput = true;
+ cmd.StartInfo.RedirectStandardOutput = true;
+ cmd.StartInfo.CreateNoWindow = true;
+ cmd.StartInfo.UseShellExecute = false;
+ cmd.Start();
+
+ cmd.StandardInput.WriteLine(command);
+ cmd.StandardInput.Flush();
+ cmd.StandardInput.Close();
+ cmd.WaitForExit();
+ if (debug)
+ {
+ Console.WriteLine(cmd.StandardOutput.ReadToEnd());
+ }
+
+
+ }
+ }
+
+ public enum AuthType
+ {
+ None,
+ Individual,
+ IndividualB2C,
+ SingleOrg,
+ MultiOrg,
+ Windows
}
}
\ No newline at end of file