Implementing console commands

This commit is contained in:
Eugene ;) 2020-07-29 01:31:32 +02:00
parent cd7ebf6cce
commit 31f5a79b52
11 changed files with 163 additions and 54 deletions

View File

@ -17,14 +17,6 @@
@if (IsAnyFileSelected)
{
<div class="field is-grouped">
<div class="control">
<div class="button is-small is-rounded neoBtnSmallPlain">
<div class="field">
<input @onchange="OnDraftModeSwitch" id="switchRoundedOutlinedWarning" type="checkbox" name="switchRoundedOutlinedWarning" class="switch is-rounded is-outlined is-danger" checked="@IsDraftMode">
<label for="switchRoundedOutlinedWarning">Draft mode @DraftMode</label>
</div>
</div>
</div>
<div class="control is-expanded borderRBig neomorphXSmall has-icons-left has-text-centered">
<span>@SelectedFile.Name</span>
</div>
@ -91,20 +83,27 @@
<div class="editorActions">
@if (IsAnyFileSelected)
{
<div class="buttons is-centered">
<button @onclick="OnUndoChanges" class="button is-rounded neoBtnSmall is-small has-icon-left noBottomMargin"><span class="icon is-left has-text-dark"><i class="mdi mdi-undo-variant"></i></span> <span>Undo changes</span></button>
@if (HasTesting && !IsDraftMode)
{
<button @onclick="OnTest" class="button is-rounded neoBtnSmall is-small has-icon-left noBottomMargin"><span class="icon is-left has-text-danger"><i class="mdi mdi-alert"></i></span> <span>Test</span></button>
}
@if (IsDraftMode)
{
<button @onclick="OnSaveDraft" class="button is-rounded neoBtnSmall is-small has-icon-left noBottomMargin"><span class="icon is-left has-text-light"><i class="mdi mdi-content-save"></i></span> <span>@(string.IsNullOrEmpty(SelectedFile.DraftBody) ? "Create" : "Save") draft</span></button>
}
else
{
<button @onclick="OnSave" class="button is-rounded neoBtnSmall is-small has-icon-left noBottomMargin"><span class="icon is-left has-text-success"><i class="mdi mdi-content-save-all"></i></span> <span>Save</span></button>
}
<div class="level">
<div class="level-left">
<div class="level-item">
<div class="button is-rounded is-small noStyle isNoFinger">
<div class="field">
<input @onchange="OnDraftModeSwitch" id="switchRoundedOutlinedWarning" type="checkbox" name="switchRoundedOutlinedWarning" class="switch is-rounded is-outlined is-danger" checked="@IsDraftMode">
<label for="switchRoundedOutlinedWarning">Draft mode @DraftMode</label>
</div>
</div>
</div>
</div>
<div class="level-right">
<div class="level-item">
<div class="buttons">
<button @onclick="OnUndoChanges" class="button is-rounded neoBtnSmall is-small has-icon-left noBottomMargin"><span class="icon is-left has-text-dark"><i class="mdi mdi-undo-variant"></i></span> <span>Undo changes</span></button>
<button @onclick="OnTest" class="button is-rounded neoBtnSmall is-small has-icon-left noBottomMargin @(HasTesting && !IsDraftMode ? null : "is-hidden")"><span class="icon is-left has-text-danger"><i class="mdi mdi-alert"></i></span> <span>Test</span></button>
<button @onclick="OnSaveDraft" class="button is-rounded neoBtnSmall is-small has-icon-left noBottomMargin @(IsDraftMode ? null : "is-hidden")"><span class="icon is-left has-text-light"><i class="mdi mdi-content-save"></i></span> <span>@(string.IsNullOrEmpty(SelectedFile.DraftBody) ? "Create" : "Save") draft</span></button>
<button @onclick="OnSave" class="button is-rounded neoBtnSmall is-small has-icon-left noBottomMargin @(IsDraftMode ? "is-hidden" : null)"><span class="icon is-left has-text-success"><i class="mdi mdi-content-save-all"></i></span> <span>Save</span></button>
</div>
</div>
</div>
</div>
}
else

View File

@ -86,6 +86,8 @@ namespace Seenginx.Components
DraftMode = IsDraftMode ? "on" : "off";
if (IsDraftMode)
await JsRuntime.InvokeVoidAsync("UpdateEditor", SelectedFile.DraftBody ?? SelectedFile.Body);
else
await JsRuntime.InvokeVoidAsync("UpdateEditor", SelectedFile.Body);
}
protected async Task OnFileClick(MouseEventArgs e, CFile file)

View File

@ -87,7 +87,7 @@ namespace Seenginx.Pages
var validationResult = await NginxService.ValidateForRenameFileAsync(ConfigFiles, SelectedFile, result.Data.ToString());
if (!validationResult.AllOk)
{
var popupAwait = Modal.Show<GenericPopup>(string.Empty, new ModalParameters().Setup(PopupType.Ok, validationResult.ErrorMessage));
var popupAwait = Modal.Show<GenericPopup>(string.Empty, new ModalParameters().Setup(PopupType.Ok, validationResult.ErrorMessage));
await popupAwait.Result;
return;
}
@ -95,7 +95,7 @@ namespace Seenginx.Pages
var renameResult = await NginxService.RenameFileAsync(SelectedFile, $"{result.Data}.conf");
if (!renameResult.AllOk)
{
var popupAwait = Modal.Show<GenericPopup>(string.Empty, new ModalParameters().Setup(PopupType.Ok, renameResult.ErrorMessage));
var popupAwait = Modal.Show<GenericPopup>(string.Empty, new ModalParameters().Setup(PopupType.Ok, renameResult.ErrorMessage));
await popupAwait.Result;
return;
}
@ -124,13 +124,13 @@ namespace Seenginx.Pages
public async Task SaveDraftFileAsync()
{
var validationResult = await NginxService.ValidateForSaveDraftFileAsync(SelectedFile);
//var validationResult = await NginxService.ValidateForSaveDraftFileAsync(SelectedFile);
if (!validationResult.AllOk)
{
await Modal.Show<GenericPopup>(string.Empty, new ModalParameters().Setup(PopupType.Ok, validationResult.ErrorMessage)).Result;
return;
}
//if (!validationResult.AllOk)
//{
// await Modal.Show<GenericPopup>(string.Empty, new ModalParameters().Setup(PopupType.Ok, validationResult.ErrorMessage)).Result;
// return;
//}
var saveDraftResult = await NginxService.SaveDraftFileAsync(SelectedFile);
@ -143,7 +143,14 @@ namespace Seenginx.Pages
public async Task TestConfiguration()
{
var testResult = await NginxService.TestFileAsync(SelectedFile);
if (!testResult.AllOk)
{
await Modal.Show<GenericPopup>(string.Empty, new ModalParameters().Setup(PopupType.Ok, $"{testResult.ErrorMessage}, ex [{testResult.Exception.Message}]")).Result;
return;
}
await Modal.Show<GenericPopup>(string.Empty, new ModalParameters().Setup(PopupType.Ok, testResult.Data)).Result;
}
public async Task DeleteFile()

View File

@ -101,3 +101,14 @@ html {
.switch[type="checkbox"] + label {
font-size: inherit
}
.switch[type="checkbox"].is-rounded + label::before,
.switch[type="checkbox"].is-rounded + label::before {
box-shadow: inset -3px -3px 6px rgba($light-shadow, .5), inset 3px 3px 6px rgba($dark-shadow, .5);
border: none
}
.button.noStyle {
border: none;
background: transparent;
}

View File

@ -32,6 +32,10 @@
&Finger {
cursor: pointer
}
&NoFinger {
cursor: none
}
}
.neomorph {
@ -105,6 +109,12 @@
transform: scale(1.1);
}
&InsetPlain {
box-shadow: inset 3px 3px 6px rgba($dark-shadow, .5), inset -3px -3px 6px rgba($light-shadow, .5);
background: none !important;
border: none !important;
}
&Plain {
box-shadow: -3px -3px 6px rgba($light-shadow, .5), 3px 3px 6px rgba($dark-shadow, .5);
background: none !important;

View File

@ -0,0 +1,39 @@
using Seenginx.Models;
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace Seenginx.Services
{
public class CommandService
{
public async Task<Result<string>> RunCommandAsync(string command)
{
var runResult = new Result<string>();
try
{
var output = string.Empty;
var cmd = new ProcessStartInfo("CMD.exe", $"/C {command}");
cmd.UseShellExecute = false;
cmd.RedirectStandardInput = true;
cmd.RedirectStandardOutput = true;
cmd.CreateNoWindow = true;
if (Environment.OSVersion.Platform.ToString().StartsWith("Win"))
cmd.WorkingDirectory = @"C:\Program Files\nginx";
using (var process = Process.Start(cmd))
using (var reader = process.StandardOutput)
output = reader.ReadToEnd();
runResult.SetData(output);
return runResult;
}
catch (Exception ex)
{
return runResult.Invalidate($"Error at running the command '{command}'", ex);
}
}
}
}

View File

@ -3,6 +3,7 @@ using Seenginx.Models;
using Seenginx.Services.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.AccessControl;
@ -15,9 +16,12 @@ namespace Seenginx.Services
{
private readonly ConfigPaths ConfigPaths;
public NginxService(ConfigPaths configPaths)
private readonly CommandService CommandService;
public NginxService(ConfigPaths configPaths, CommandService commandService)
{
ConfigPaths = configPaths;
CommandService = commandService;
}
public async Task<IEnumerable<ConfigFile>> GetFilesAsync()
@ -250,7 +254,7 @@ namespace Seenginx.Services
{
var draftPathName = $"{configFile.FullPath}.draft";
if (File.Exists(draftPathName))
if (!File.Exists(draftPathName))
return validationResult.Invalidate($"File '{draftPathName}' not found.");
return validationResult;
@ -290,7 +294,7 @@ namespace Seenginx.Services
if (File.Exists(selectedConfigFile.FullPath))
if (!File.Exists(selectedConfigFile.FullPath))
return renameResult.Invalidate($"Original file '{selectedConfigFile.FullPath}' not found.");
var newPathName = Path.Combine(ConfigPaths.NginxPath, selectedConfigFile.Folder, $"{newName}.conf");
@ -327,10 +331,30 @@ namespace Seenginx.Services
public async Task<Result<string>> TestFileAsync(ConfigFile configFile)
{
await Task.Run(() => { });
var result = new Result<string>();
result.SetData("Uhu");
return result;
var command1 = string.Empty;
var command2 = string.Empty;
var runResult = new Result<string>();
var originalPathName = Path.Combine(ConfigPaths.NginxPath, configFile.Folder, $"{configFile.Name}.conf");
switch (Environment.OSVersion.Platform)
{
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.Win32NT:
case PlatformID.WinCE:
//command1 = @$"cd ""C:\Program Files\nginx""";
command2 = @$"nginx.exe -c ""{originalPathName}"" -t";
break;
case PlatformID.Unix:
command1 = "";
break;
case PlatformID.Xbox:
case PlatformID.MacOSX:
return runResult.Invalidate($"Invalid platform '{Environment.OSVersion.Platform}'");
}
runResult = await CommandService.RunCommandAsync(/*command1,*/ command2);
return runResult;
}
//public async Task<Result> DeleteFileAsync(ConfigFile configFile)

View File

@ -23,86 +23,86 @@
</div>
<div class="level-right">
<div class="level-item">
<Blazorise.Bulma.Button Clicked="Ok" Class="is-rounded neoBtnSmall is-small has-text-dark">
<button @onclick="Ok" class="button is-rounded neoBtnSmall is-small has-text-dark">
<span class="icon is-small has-text-success">
<i class="mdi mdi-check"></i>
</span>
<span>Ok</span>
</Blazorise.Bulma.Button>
</button>
</div>
</div>
break;
case PopupType.OkCancel:
<div class="level-left">
<div class="level-item">
<Blazorise.Bulma.Button Clicked="Cancel" Class="is-rounded neoBtnSmall is-small has-text-dark">
<button @onclick="Cancel" class="button is-rounded neoBtnSmall is-small has-text-dark">
<span class="icon is-small">
<i class="mdi mdi-close"></i>
</span>
<span>Cancel</span>
</Blazorise.Bulma.Button>
</button>
</div>
</div>
<div class="level-right">
<div class="level-item">
<Blazorise.Bulma.Button Clicked="Ok" Class="is-rounded neoBtnSmall is-small has-text-dark" Type="ButtonType.Submit">
<button @onclick="Ok" class="button is-rounded neoBtnSmall is-small has-text-dark">
<span class="icon is-small has-text-success">
<i class="mdi mdi-check"></i>
</span>
<span>Ok</span>
</Blazorise.Bulma.Button>
</button>
</div>
</div>
break;
case PopupType.YesNo:
<div class="level-left">
<div class="level-item">
<Blazorise.Bulma.Button Clicked="No" Class="is-rounded neoBtnSmall is-small has-text-dark">
<button @onclick="No" class="button is-rounded neoBtnSmall is-small has-text-dark">
<span class="icon is-small has-text-danger">
<i class="mdi mdi-close"></i>
</span>
<span>No</span>
</Blazorise.Bulma.Button>
</button>
</div>
</div>
<div class="level-right">
<div class="level-item">
<Blazorise.Bulma.Button Clicked="Yes" Class="is-rounded neoBtnSmall is-small has-text-dark" Type="ButtonType.Submit">
<button @onclick="Yes" class="button is-rounded neoBtnSmall is-small has-text-dark">
<span class="icon is-small has-text-success">
<i class="mdi mdi-check"></i>
</span>
<span>Yes</span>
</Blazorise.Bulma.Button>
</button>
</div>
</div>
break;
case PopupType.YesNoCancel:
<div class="level-left">
<div class="level-item">
<Blazorise.Bulma.Button Clicked="Cancel" Class="is-rounded neoBtnSmall is-small has-text-dark">
<button @onclick="Cancel" class="button is-rounded neoBtnSmall is-small has-text-dark">
<span class="icon is-small">
<i class="mdi mdi-close"></i>
</span>
<span>Cancel</span>
</Blazorise.Bulma.Button>
</button>
</div>
</div>
<div class="level-right">
<div class="level-item">
<Blazorise.Bulma.Button Clicked="No" Class="is-rounded neoBtnSmall is-small has-text-dark">
<button @onclick="No" class="button is-rounded neoBtnSmall is-small has-text-dark">
<span class="icon is-small has-text-danger">
<i class="mdi mdi-close"></i>
</span>
<span>No</span>
</Blazorise.Bulma.Button>
</button>
</div>
<div class="level-item">
<Blazorise.Bulma.Button Clicked="Yes" Class="is-rounded neoBtnSmall is-small has-text-dark" Type="ButtonType.Submit">
<button @onclick="Yes" class="button is-rounded neoBtnSmall is-small has-text-dark">
<span class="icon is-small has-text-success">
<i class="mdi mdi-check"></i>
</span>
<span>Yes</span>
</Blazorise.Bulma.Button>
</button>
</div>
</div>
break;

View File

@ -38,6 +38,7 @@ namespace Seenginx
configPaths.SystemDPath = @"C:\systemd\system\";
services.AddSingleton(configPaths);
services.AddTransient<CommandService>();
services.AddTransient<IDmesgService, DmesgService>();
services.AddTransient<INginxService, NginxService>();
services.AddTransient<ISystemDService, SystemDService>();

View File

@ -59,6 +59,9 @@ html {
.isFinger {
cursor: pointer; }
.isNoFinger {
cursor: none; }
.neomorph {
/*box-shadow: 0px 0px 4px 4px rgba($background, 1), -8px -8px 16px rgba($light-shadow, 1), 8px 8px 16px rgba($dark-shadow, 1);*/
box-shadow: -8px -8px 16px rgba(251, 238, 208, 0.5), 8px 8px 16px rgba(241, 185, 65, 0.5); }
@ -106,6 +109,10 @@ html {
background: none !important;
border: none !important;
transform: scale(1.1); }
.neoBtnSmallInsetPlain {
box-shadow: inset 3px 3px 6px rgba(241, 185, 65, 0.5), inset -3px -3px 6px rgba(251, 238, 208, 0.5);
background: none !important;
border: none !important; }
.neoBtnSmallPlain {
box-shadow: -3px -3px 6px rgba(251, 238, 208, 0.5), 3px 3px 6px rgba(241, 185, 65, 0.5);
background: none !important;
@ -235,6 +242,15 @@ html {
.switch[type="checkbox"] + label {
font-size: inherit; }
.switch[type="checkbox"].is-rounded + label::before,
.switch[type="checkbox"].is-rounded + label::before {
box-shadow: inset -3px -3px 6px rgba(251, 238, 208, 0.5), inset 3px 3px 6px rgba(241, 185, 65, 0.5);
border: none; }
.button.noStyle {
border: none;
background: transparent; }
.main {
display: flex;
flex-wrap: nowrap;

File diff suppressed because one or more lines are too long