This commit is contained in:
2020-02-25 22:39:40 +01:00
commit de3da55bac
16 changed files with 436 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Remove="**\*.glade" />
<EmbeddedResource Include="**\*.glade">
<LogicalName>%(Filename)%(Extension)</LogicalName>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="GtkSharp" Version="3.22.25.*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EstusShots.Shared\EstusShots.Shared.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,70 @@
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using EstusShots.Shared.Models;
using Gtk;
using UI = Gtk.Builder.ObjectAttribute;
namespace EstusShots.Gtk
{
class MainWindow : Window
{
private const string ApiUrl = "http://localhost:5000/api/";
[UI] private TreeView _seasonsView = null;
[UI] private Button _loadButton = null;
[UI] private Label _infoLabel = null;
public MainWindow() : this(new Builder("MainWindow.glade")) { }
private MainWindow(Builder builder) : base(builder.GetObject("MainWindow").Handle)
{
builder.Autoconnect(this);
DeleteEvent += Window_DeleteEvent;
_loadButton.Clicked += _loadButton_Clicked;
}
private void Window_DeleteEvent(object sender, DeleteEventArgs a)
{
Application.Quit();
}
private void _loadButton_Clicked(object sender, EventArgs a)
{
var season = new Season()
{
Game = "Test Game",
Start = DateTime.Now
};
var content = new StringContent(JsonSerializer.Serialize(season), Encoding.UTF8, "application/json");
var client = new HttpClient();
try
{
var response = client.PostAsync(ApiUrl + "seasons", content).Result;
if (response.Headers.Location == null)
{
_infoLabel.Text = $"Error while creating Season: {response.ReasonPhrase}";
return;
}
var data = client.GetAsync(response.Headers.Location).Result;
var jsonData = data.Content.ReadAsStringAsync().Result;
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
};
var s = JsonSerializer.Deserialize<Season>(jsonData, options);
_infoLabel.Text = $"Created new Season: {s.Game} ({s.SeasonId})";
}
catch (Exception e)
{
_infoLabel.Text = $"Exception Occured: {e.Message}";
Console.WriteLine(e.Message);
}
}
}
}

View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.18"/>
<object class="GtkWindow" id="MainWindow">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Example Window</property>
<property name="default_width">480</property>
<property name="default_height">240</property>
<child>
<placeholder/>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="_infoLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTreeView" id="_seasonsView">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="_loadButton">
<property name="label" translatable="yes">Load Seasons</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
</interface>

23
EstusShots.Gtk/Program.cs Normal file
View File

@@ -0,0 +1,23 @@
using System;
using Gtk;
namespace EstusShots.Gtk
{
class Program
{
[STAThread]
public static void Main(string[] args)
{
Application.Init();
var app = new Application("EstusShots.Gtk", GLib.ApplicationFlags.None);
app.Register(GLib.Cancellable.Current);
var win = new MainWindow();
app.AddWindow(win);
win.Show();
Application.Run();
}
}
}