Skip to content

Commit

Permalink
Implement GUI as well as general code improvements and structural cha…
Browse files Browse the repository at this point in the history
…nges (#22)
  • Loading branch information
sudokoko committed Jul 9, 2023
1 parent 359b099 commit c3f4215
Show file tree
Hide file tree
Showing 32 changed files with 588 additions and 164 deletions.
44 changes: 33 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ jobs:
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

- name: Run QDNET Scan
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json

build:
name: Build and Upload Artifacts
runs-on: ubuntu-latest
Expand All @@ -36,30 +41,47 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Restore Dependencies
run: dotnet restore

- name: Get Commit Hash
id: hash
run: echo "hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Restore dependencies
run: dotnet restore

- name: Publish for Windows x64
run: dotnet publish -c Release -r win-x64 --self-contained
- name: Publish for Linux x64
run: dotnet publish -c Release -r linux-x64 --self-contained
- name: Publish CLI for Windows x64
run: dotnet publish -c Release -r win-x64 --self-contained PLRPC
- name: Publish CLI for Linux x64
run: dotnet publish -c Release -r linux-x64 --self-contained PLRPC
- name: Publish GUI for Windows x64
run: dotnet publish -c Release -r win-x64 --self-contained PLRPC.GUI.Windows
- name: Publish GUI for Linux x64
run: dotnet publish -c Release -r linux-x64 --self-contained PLRPC.GUI.Linux

- name: Upload Windows x64 build
- name: Upload Windows x64 CLI build
uses: actions/[email protected]
with:
name: PLRPC Windows x64 [${{ steps.hash.outputs.hash }}]
name: PLRPC CLI Windows x64 [${{ steps.hash.outputs.hash }}]
path: "/home/runner/work/PLRPC/PLRPC/PLRPC/bin/Release/net7.0/win-x64/publish/"
if-no-files-found: error
retention-days: 3
- name: Upload Linux x64 build
- name: Upload Linux x64 CLI build
uses: actions/[email protected]
with:
name: PLRPC Linux x64 [${{ steps.hash.outputs.hash }}]
name: PLRPC CLI Linux x64 [${{ steps.hash.outputs.hash }}]
path: "/home/runner/work/PLRPC/PLRPC/PLRPC/bin/Release/net7.0/linux-x64/publish/"
if-no-files-found: error
retention-days: 3
- name: Upload Windows x64 GUI build
uses: actions/[email protected]
with:
name: PLRPC GUI Windows x64 [${{ steps.hash.outputs.hash }}]
path: "/home/runner/work/PLRPC/PLRPC/PLRPC.GUI.Windows/bin/Release/net7.0-windows/win-x64/publish/"
if-no-files-found: error
retention-days: 3
- name: Upload Linux x64 GUI build
uses: actions/[email protected]
with:
name: PLRPC GUI Linux x64 [${{ steps.hash.outputs.hash }}]
path: "/home/runner/work/PLRPC/PLRPC/PLRPC.GUI.Linux/bin/Release/net7.0/linux-x64/publish/"
if-no-files-found: error
retention-days: 3
25 changes: 25 additions & 0 deletions PLRPC.GUI.Linux/PLRPC.GUI.Linux.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>LBPUnion.PLRPC.GUI</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<SelfContained>true</SelfContained>
<TargetFramework>net7.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Eto.Platform.Gtk" Version="2.7.5"/>
<ProjectReference Include="..\PLRPC.GUI\PLRPC.GUI.csproj"/>
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions PLRPC.GUI.Linux/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace LBPUnion.PLRPC.GUI;

public static class Program
{
[STAThread]
public static void Main()
{
Gui.Initialize();
}
}
30 changes: 30 additions & 0 deletions PLRPC.GUI.Windows/PLRPC.GUI.Windows.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>LBPUnion.PLRPC.GUI</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<SelfContained>true</SelfContained>
<TargetFramework>net7.0-windows</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

<PropertyGroup>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Eto.Platform.Windows" Version="2.7.5"/>
<ProjectReference Include="..\PLRPC.GUI\PLRPC.GUI.csproj"/>
</ItemGroup>

<ItemGroup>
<KnownFrameworkReference Update="Microsoft.WindowsDesktop.App.WindowsForms" IsWindowsOnly="false"/>
<KnownFrameworkReference Update="Microsoft.WindowsDesktop.App" IsWindowsOnly="false"/>
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions PLRPC.GUI.Windows/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace LBPUnion.PLRPC.GUI;

public static class Program
{
[STAThread]
public static void Main()
{
Gui.Initialize();
}
}
170 changes: 170 additions & 0 deletions PLRPC.GUI/Forms/MainForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
using System.Text;
using Eto.Drawing;
using Eto.Forms;
using LBPUnion.PLRPC.Helpers;
using LBPUnion.PLRPC.Types.Logging;
using Serilog;

namespace LBPUnion.PLRPC.GUI.Forms;

public class MainForm : Form
{
private static readonly TextBox username;
private static readonly TextBox serverUrl;
private static readonly TextBox applicationId;

public MainForm()
{
this.Title = "PLRPC";
this.ClientSize = new Size(400, -1);
this.Resizable = false;

this.Content = this.tableLayout;

Log.Logger = Program.Logger;
}

private static readonly GroupBox configurationEntries = new()
{
Text = Strings.MainForm.Configuration,
Content = new TableLayout
{
Padding = new Padding(3, 3, 3, 3),
Spacing = new Size(3, 3),
Rows =
{
new TableRow(new List<TableCell>
{
new(new Label
{
Text = Strings.MainForm.Username,
}),
new(username = new TextBox()),
}),
new TableRow(new List<TableCell>
{
new(new Label
{
Text = Strings.MainForm.ServerUrl,
}),
new(serverUrl = new TextBox
{
Text = "https://lighthouse.lbpunion.com/",
Enabled = false,
}),
}),
new TableRow(new List<TableCell>
{
new(new Label
{
Text = Strings.MainForm.ApplicationId,
}),
new(applicationId = new TextBox
{
Text = "1060973475151495288",
Enabled = false,
}),
}),
},
},
};

private static readonly Button connectButton = new(InitializeClientHandler)
{
Text = Strings.MainForm.Connect,
};

private static readonly Button unlockDefaultsButton = new(UnlockDefaultsHandler)
{
Text = Strings.MainForm.UnlockDefaults,
};

private readonly TableLayout tableLayout = new()
{
Padding = new Padding(10, 10, 10, 10),
Spacing = new Size(5, 5),
Rows =
{
new TableRow(configurationEntries),
new TableRow(connectButton),
new TableRow(unlockDefaultsButton),
},
};

private static async void InitializeClientHandler(object sender, EventArgs eventArgs)
{
List<TextBox> arguments = new()
{
serverUrl,
username,
applicationId,
};

switch (arguments)
{
case not null when arguments.Any(a => string.IsNullOrWhiteSpace(a.Text)):
{
MessageBox.Show(Strings.MainForm.BlankFieldsError, MessageBoxButtons.OK, MessageBoxType.Error);
return;
}
case not null when !ValidationHelper.IsValidUsername(username.Text):
{
MessageBox.Show(Strings.MainForm.InvalidUsernameError, MessageBoxButtons.OK, MessageBoxType.Error);
return;
}
case not null when !ValidationHelper.IsValidUrl(serverUrl.Text):
{
MessageBox.Show(Strings.MainForm.InvalidUrlError, MessageBoxButtons.OK, MessageBoxType.Error);
return;
}
}

try
{
// Text changes
connectButton.Text = Strings.MainForm.Connected;

// Button states
connectButton.Enabled = false;
unlockDefaultsButton.Enabled = false;

// Field states
serverUrl.Enabled = false;
username.Enabled = false;
applicationId.Enabled = false;

await Program.InitializeLighthouseClient(serverUrl.Text.Trim('/'), username.Text, applicationId.Text);
}
catch (Exception exception)
{
StringBuilder exceptionBuilder = new();

exceptionBuilder.AppendLine($"{Strings.MainForm.InitializationError}\n");
exceptionBuilder.AppendLine($"{exception.Message}\n");
exceptionBuilder.AppendLine($"{exception.Source}");

Log.Error(exception, "{@Area}: Failed to initialize the client",
LogArea.LighthouseClient);

MessageBox.Show(exceptionBuilder.ToString(), MessageBoxButtons.OK, MessageBoxType.Error);
}
}

private static void UnlockDefaultsHandler(object sender, EventArgs eventArgs)
{
// Text changes
unlockDefaultsButton.Text = Strings.MainForm.UnlockedDefaults;

// Button states
unlockDefaultsButton.Enabled = false;

// Field states
serverUrl.Enabled = true;
applicationId.Enabled = true;

MessageBox.Show(Strings.MainForm.UnlockedDefaultsWarning,
"Warning",
MessageBoxButtons.OK,
MessageBoxType.Warning);
}
}
12 changes: 12 additions & 0 deletions PLRPC.GUI/Gui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Eto.Forms;
using LBPUnion.PLRPC.GUI.Forms;

namespace LBPUnion.PLRPC.GUI;

public static class Gui
{
public static void Initialize()
{
new Application().Run(new MainForm());
}
}
27 changes: 27 additions & 0 deletions PLRPC.GUI/PLRPC.GUI.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<SelfContained>true</SelfContained>
<TargetFramework>net7.0</TargetFramework>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>

<PropertyGroup>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
</PropertyGroup>

<PropertyGroup>
<RootNamespace>LBPUnion.PLRPC.GUI</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<SelfContained>true</SelfContained>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Serilog" Version="3.0.1"/>
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0"/>
<PackageReference Include="Eto.Forms" Version="2.7.5"/>
<ProjectReference Include="..\PLRPC\PLRPC.csproj"/>
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions PLRPC.GUI/Strings/MainForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace LBPUnion.PLRPC.GUI.Strings;

public static class MainForm
{
public const string Configuration = "Configuration";
public const string Username = "Username";
public const string ServerUrl = "Server URL";
public const string ApplicationId = "Application ID";
public const string Connect = "Connect";
public const string Connected = "Connected";
public const string UnlockDefaults = "Unlock Defaults";
public const string UnlockedDefaults = "Unlocked Defaults";
public const string BlankFieldsError = "Please fill in all fields and try again.";
public const string InitializationError = "An error occurred while initializing the PLRPC client.";
public const string InvalidUrlError = "The URL specified is in an invalid format. Please try again.";
public const string InvalidUsernameError = "The username specified is invalid. Please try again.";
public const string UnlockedDefaultsWarning = "You have just unlocked defaults. Support will not be provided whilst using modified defaults. Continue at your own risk.";
}
Loading

0 comments on commit c3f4215

Please sign in to comment.