commit de3da55bacc9424b81957164583dfc5cabea65e3 Author: luxick Date: Tue Feb 25 22:39:40 2020 +0100 Initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d5fd0f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +.blob +.idea/ \ No newline at end of file diff --git a/EstusShots.Gtk/EstusShots.Gtk.csproj b/EstusShots.Gtk/EstusShots.Gtk.csproj new file mode 100644 index 0000000..82d6bad --- /dev/null +++ b/EstusShots.Gtk/EstusShots.Gtk.csproj @@ -0,0 +1,23 @@ + + + + WinExe + netcoreapp3.1 + + + + + + %(Filename)%(Extension) + + + + + + + + + + + + diff --git a/EstusShots.Gtk/MainWindow.cs b/EstusShots.Gtk/MainWindow.cs new file mode 100644 index 0000000..78df622 --- /dev/null +++ b/EstusShots.Gtk/MainWindow.cs @@ -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(jsonData, options); + _infoLabel.Text = $"Created new Season: {s.Game} ({s.SeasonId})"; + } + catch (Exception e) + { + _infoLabel.Text = $"Exception Occured: {e.Message}"; + Console.WriteLine(e.Message); + } + } + } +} \ No newline at end of file diff --git a/EstusShots.Gtk/MainWindow.glade b/EstusShots.Gtk/MainWindow.glade new file mode 100644 index 0000000..b7ec637 --- /dev/null +++ b/EstusShots.Gtk/MainWindow.glade @@ -0,0 +1,59 @@ + + + + + + False + Example Window + 480 + 240 + + + + + + True + False + vertical + + + True + False + + + False + True + 0 + + + + + True + True + + + + + + True + True + 1 + + + + + Load Seasons + True + True + True + + + False + True + 2 + + + + + + diff --git a/EstusShots.Gtk/Program.cs b/EstusShots.Gtk/Program.cs new file mode 100644 index 0000000..600cc43 --- /dev/null +++ b/EstusShots.Gtk/Program.cs @@ -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(); + } + } +} \ No newline at end of file diff --git a/EstusShots.Server/Controllers/SeasonsController.cs b/EstusShots.Server/Controllers/SeasonsController.cs new file mode 100644 index 0000000..9786ec3 --- /dev/null +++ b/EstusShots.Server/Controllers/SeasonsController.cs @@ -0,0 +1,36 @@ +using System; +using System.Threading.Tasks; +using EstusShots.Server.Services; +using EstusShots.Shared.Models; +using Microsoft.AspNetCore.Mvc; + +namespace EstusShots.Server.Controllers +{ + [ApiController] + [Route("/api/[controller]")] + public class SeasonsController : ControllerBase + { + private readonly EstusShotsContext _context; + + public SeasonsController(EstusShotsContext context) + { + _context = context; + } + + [HttpGet("{id}")] + public async Task> GetSeason(Guid id) + { + var season = await _context.Seasons.FindAsync(id); + if (season == null) return NotFound(); + return season; + } + + [HttpPost] + public async Task> CreateSeason(Season season) + { + _context.Seasons.Add(season); + await _context.SaveChangesAsync(); + return CreatedAtAction(nameof(GetSeason), new {id = season.SeasonId}, season); + } + } +} \ No newline at end of file diff --git a/EstusShots.Server/EstusShots.Server.csproj b/EstusShots.Server/EstusShots.Server.csproj new file mode 100644 index 0000000..96f98dd --- /dev/null +++ b/EstusShots.Server/EstusShots.Server.csproj @@ -0,0 +1,25 @@ + + + + netcoreapp3.1 + enable + + + + NU1605;CS8618 + + + + NU1605;CS8618 + + + + + + + + + + + + diff --git a/EstusShots.Server/Program.cs b/EstusShots.Server/Program.cs new file mode 100644 index 0000000..e25fef7 --- /dev/null +++ b/EstusShots.Server/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace EstusShots.Server +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); }); + } +} \ No newline at end of file diff --git a/EstusShots.Server/Properties/launchSettings.json b/EstusShots.Server/Properties/launchSettings.json new file mode 100644 index 0000000..7509c02 --- /dev/null +++ b/EstusShots.Server/Properties/launchSettings.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:26850", + "sslPort": 44318 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "weatherforecast", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "EstusShots.Server": { + "commandName": "Project", + "launchBrowser": false, + "launchUrl": "", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/EstusShots.Server/Services/EstusShotsContext.cs b/EstusShots.Server/Services/EstusShotsContext.cs new file mode 100644 index 0000000..636094f --- /dev/null +++ b/EstusShots.Server/Services/EstusShotsContext.cs @@ -0,0 +1,14 @@ +using EstusShots.Shared.Models; +using Microsoft.EntityFrameworkCore; + +namespace EstusShots.Server.Services +{ + public class EstusShotsContext : DbContext + { + public EstusShotsContext(DbContextOptions options) : base(options) + { + } + + public DbSet Seasons { get; set; } = default!; + } +} \ No newline at end of file diff --git a/EstusShots.Server/Startup.cs b/EstusShots.Server/Startup.cs new file mode 100644 index 0000000..4d7c0f1 --- /dev/null +++ b/EstusShots.Server/Startup.cs @@ -0,0 +1,47 @@ +using EstusShots.Server.Services; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace EstusShots.Server +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddDbContext( + opt => opt.UseInMemoryDatabase("debug.db")); + services.AddControllers(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + if (!env.IsDevelopment()) + { + app.UseHttpsRedirection(); + } + + app.UseRouting(); + app.UseAuthorization(); + + app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); + } + } +} \ No newline at end of file diff --git a/EstusShots.Server/appsettings.Development.json b/EstusShots.Server/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/EstusShots.Server/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/EstusShots.Server/appsettings.json b/EstusShots.Server/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/EstusShots.Server/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/EstusShots.Shared/EstusShots.Shared.csproj b/EstusShots.Shared/EstusShots.Shared.csproj new file mode 100644 index 0000000..adf3d2b --- /dev/null +++ b/EstusShots.Shared/EstusShots.Shared.csproj @@ -0,0 +1,16 @@ + + + + netcoreapp3.1 + enable + + + + NU1605;CS8618 + + + + NU1605;CS8618 + + + diff --git a/EstusShots.Shared/Models/Season.cs b/EstusShots.Shared/Models/Season.cs new file mode 100644 index 0000000..3a3dda7 --- /dev/null +++ b/EstusShots.Shared/Models/Season.cs @@ -0,0 +1,18 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace EstusShots.Shared.Models +{ + public class Season + { + public Guid SeasonId { get; set; } + + [MaxLength(50)] public string Game { get; set; } = default!; + + public string? Description { get; set; } + + public DateTime Start { get; set; } + + public DateTime? End { get; set; } + } +} \ No newline at end of file diff --git a/EstusShots.sln b/EstusShots.sln new file mode 100644 index 0000000..fd2ab21 --- /dev/null +++ b/EstusShots.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EstusShots.Server", "EstusShots.Server\EstusShots.Server.csproj", "{E5D0D7FB-5F7C-43E8-88F5-15DD60104AE9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EstusShots.Shared", "EstusShots.Shared\EstusShots.Shared.csproj", "{1E26150D-ADFE-41ED-9896-941B486E8777}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EstusShots.Gtk", "EstusShots.Gtk\EstusShots.Gtk.csproj", "{165F3B5C-9802-46C5-BCE2-F40C42819045}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E5D0D7FB-5F7C-43E8-88F5-15DD60104AE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E5D0D7FB-5F7C-43E8-88F5-15DD60104AE9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E5D0D7FB-5F7C-43E8-88F5-15DD60104AE9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E5D0D7FB-5F7C-43E8-88F5-15DD60104AE9}.Release|Any CPU.Build.0 = Release|Any CPU + {1E26150D-ADFE-41ED-9896-941B486E8777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E26150D-ADFE-41ED-9896-941B486E8777}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E26150D-ADFE-41ED-9896-941B486E8777}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E26150D-ADFE-41ED-9896-941B486E8777}.Release|Any CPU.Build.0 = Release|Any CPU + {165F3B5C-9802-46C5-BCE2-F40C42819045}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {165F3B5C-9802-46C5-BCE2-F40C42819045}.Debug|Any CPU.Build.0 = Debug|Any CPU + {165F3B5C-9802-46C5-BCE2-F40C42819045}.Release|Any CPU.ActiveCfg = Release|Any CPU + {165F3B5C-9802-46C5-BCE2-F40C42819045}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal