First commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
**/bin/
|
||||
**/obj/
|
||||
**/.vscode/
|
||||
24
Feladat1/Feladat1.csproj
Normal file
24
Feladat1/Feladat1.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GirCore.Adw-1" Version="0.6.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.9" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="UI/MainWindow/MainWindow.ui.xml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../Logic/Logic.csproj" />
|
||||
<ProjectReference Include="../Repository/Repository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
30
Feladat1/Program.cs
Normal file
30
Feladat1/Program.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Feladat1.UI.MainWindow;
|
||||
using Logic;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Repository;
|
||||
|
||||
namespace Feladat1;
|
||||
|
||||
class Program
|
||||
{
|
||||
static int Main()
|
||||
{
|
||||
var application = Adw.Application.New("org.piper.feladat1", Gio.ApplicationFlags.FlagsNone);
|
||||
application.OnActivate += (sender, args) =>
|
||||
{
|
||||
var window = new MainWindow().Window;
|
||||
window.Application = (Adw.Application)sender;
|
||||
window.Show();
|
||||
};
|
||||
|
||||
return application.RunWithSynchronizationContext(null);
|
||||
}
|
||||
|
||||
private static ServiceProvider SetupServices()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<IRepository, JsonRepository>();
|
||||
services.AddSingleton<IUserService, UserService>();
|
||||
return services.BuildServiceProvider();
|
||||
}
|
||||
}
|
||||
85
Feladat1/UI/MainWindow/MainWindow.cs
Normal file
85
Feladat1/UI/MainWindow/MainWindow.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using Adw;
|
||||
using Logic;
|
||||
|
||||
namespace Feladat1.UI.MainWindow;
|
||||
|
||||
public class MainWindow
|
||||
{
|
||||
private IUserService userService;
|
||||
private const string windowId = "main_window";
|
||||
|
||||
public Window Window;
|
||||
|
||||
private Gtk.Button saveBtn;
|
||||
private const string saveBtnId = "save_btn";
|
||||
|
||||
private EntryRow emailField;
|
||||
private const string emailFieldId = "email";
|
||||
|
||||
private EntryRow userNameField;
|
||||
private const string userNameFieldId = "username";
|
||||
|
||||
private PasswordEntryRow passwordField;
|
||||
private const string passwordFieldId = "password";
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
var builder = new Gtk.Builder("Feladat1.UI.MainWindow.MainWindow.ui.xml");
|
||||
|
||||
Window = builder.GetObject(windowId) as Window;
|
||||
if (Window == null)
|
||||
{
|
||||
throw new Exception("Failed to load embedded resource MainWindow.ui.xml");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
saveBtn = builder.GetObject(saveBtnId) as Gtk.Button;
|
||||
if (saveBtn == null)
|
||||
{
|
||||
throw new NullReferenceException(saveBtnId);
|
||||
}
|
||||
saveBtn.OnClicked += (sender, args) => Save();
|
||||
|
||||
emailField = builder.GetObject(emailFieldId) as EntryRow;
|
||||
if (emailField == null)
|
||||
{
|
||||
throw new NullReferenceException(emailFieldId);
|
||||
}
|
||||
|
||||
userNameField = builder.GetObject(userNameFieldId) as EntryRow;
|
||||
if (userNameField == null)
|
||||
{
|
||||
throw new NullReferenceException(userNameFieldId);
|
||||
}
|
||||
|
||||
passwordField = builder.GetObject(passwordFieldId) as PasswordEntryRow;
|
||||
if (passwordField == null)
|
||||
{
|
||||
throw new NullReferenceException(passwordFieldId);
|
||||
}
|
||||
}
|
||||
catch (NullReferenceException e)
|
||||
{
|
||||
Console.WriteLine($"Failed to load UI element with ID: {e.Message}");
|
||||
Window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private bool ValidateFields()
|
||||
{
|
||||
if (userNameField.Text_ != null && emailField.Text_ != null && passwordField.Text_ != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
if (ValidateFields())
|
||||
{
|
||||
userService.Create(userNameField.GetText(), emailField.GetText(), passwordField.GetText());
|
||||
}
|
||||
}
|
||||
}
|
||||
83
Feladat1/UI/MainWindow/MainWindow.ui.xml
Normal file
83
Feladat1/UI/MainWindow/MainWindow.ui.xml
Normal file
@@ -0,0 +1,83 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="AdwWindow" id="main_window">
|
||||
<property name="width-request">300</property>
|
||||
<property name="height-request">300</property>
|
||||
<property name="default-width">500</property>
|
||||
<property name="default-height">600</property>
|
||||
<property name="content">
|
||||
<object class="AdwToolbarView">
|
||||
<child type="top">
|
||||
<object class="AdwHeaderBar" id="header_bar">
|
||||
<property name="title-widget">
|
||||
<object class="AdwViewSwitcher">
|
||||
<property name="stack">stack</property>
|
||||
<property name="policy">wide</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<property name="content">
|
||||
<object class="AdwViewStack" id="stack">
|
||||
<property name="enable-transitions">True</property>
|
||||
<child>
|
||||
<object class="AdwViewStackPage">
|
||||
<property name="name">save</property>
|
||||
<property name="title">Save</property>
|
||||
<property name="child">
|
||||
<object class="AdwPreferencesPage">
|
||||
<child>
|
||||
<object class="AdwPreferencesGroup">
|
||||
<child>
|
||||
<object class="AdwEntryRow" id="email">
|
||||
<property name="title">Email</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwEntryRow" id="username">
|
||||
<property name="title">Felhasználónév</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwPasswordEntryRow" id="password">
|
||||
<property name="title">Jelszó</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="save_btn">
|
||||
<style>
|
||||
<class name="suggested-action" />
|
||||
</style>
|
||||
<property name="label">Exportálás</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="halign">center</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="AdwViewStackPage">
|
||||
<property name="name">load</property>
|
||||
<property name="title">Load</property>
|
||||
<property name="child">
|
||||
<object class="AdwStatusPage">
|
||||
<property name="title">Load</property>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
<child type="bottom">
|
||||
<object class="AdwViewSwitcherBar" id="switcher_bar">
|
||||
<property name="stack">stack</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</interface>
|
||||
9
Logic/IUserService.cs
Normal file
9
Logic/IUserService.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Models;
|
||||
|
||||
namespace Logic;
|
||||
|
||||
public interface IUserService
|
||||
{
|
||||
public void Create(string username, string email, string password);
|
||||
public User? Read();
|
||||
}
|
||||
13
Logic/Logic.csproj
Normal file
13
Logic/Logic.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../Repository/Repository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
18
Logic/UserService.cs
Normal file
18
Logic/UserService.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Models;
|
||||
using Repository;
|
||||
|
||||
namespace Logic;
|
||||
|
||||
public class UserService : IUserService
|
||||
{
|
||||
private IRepository repository;
|
||||
public User? Read()
|
||||
{
|
||||
return repository.Read();
|
||||
}
|
||||
|
||||
public void Create(string username, string email, string password)
|
||||
{
|
||||
repository.Write(new User(username, email, password));
|
||||
}
|
||||
}
|
||||
9
Models/Models.csproj
Normal file
9
Models/Models.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
20
Models/User.cs
Normal file
20
Models/User.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace Models;
|
||||
|
||||
public class User
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string Email { get; }
|
||||
|
||||
private string password;
|
||||
public string Password
|
||||
{
|
||||
set => password = value;
|
||||
}
|
||||
|
||||
public User(string username, string email, string password)
|
||||
{
|
||||
Username = username;
|
||||
Email = email;
|
||||
Password = password;
|
||||
}
|
||||
}
|
||||
40
PiperFeladat.sln
Normal file
40
PiperFeladat.sln
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31903.59
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Feladat1", "Feladat1\Feladat1.csproj", "{F143EA5A-C9F3-4838-9805-ECC8D176DADF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logic", "Logic\Logic.csproj", "{F83A4E28-94CB-4E8D-ADE7-396B3A893115}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Repository", "Repository\Repository.csproj", "{42A51F92-4197-4070-BF2C-0036B636A71D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Models", "Models\Models.csproj", "{21C21D56-FD79-43F3-BAF3-BFB82CD323FD}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{F143EA5A-C9F3-4838-9805-ECC8D176DADF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F143EA5A-C9F3-4838-9805-ECC8D176DADF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F143EA5A-C9F3-4838-9805-ECC8D176DADF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F143EA5A-C9F3-4838-9805-ECC8D176DADF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F83A4E28-94CB-4E8D-ADE7-396B3A893115}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F83A4E28-94CB-4E8D-ADE7-396B3A893115}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F83A4E28-94CB-4E8D-ADE7-396B3A893115}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F83A4E28-94CB-4E8D-ADE7-396B3A893115}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{42A51F92-4197-4070-BF2C-0036B636A71D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{42A51F92-4197-4070-BF2C-0036B636A71D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{42A51F92-4197-4070-BF2C-0036B636A71D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{42A51F92-4197-4070-BF2C-0036B636A71D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{21C21D56-FD79-43F3-BAF3-BFB82CD323FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{21C21D56-FD79-43F3-BAF3-BFB82CD323FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{21C21D56-FD79-43F3-BAF3-BFB82CD323FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{21C21D56-FD79-43F3-BAF3-BFB82CD323FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
9
Repository/IRepository.cs
Normal file
9
Repository/IRepository.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Models;
|
||||
|
||||
namespace Repository;
|
||||
|
||||
public interface IRepository
|
||||
{
|
||||
public User? Read();
|
||||
public void Write(User item);
|
||||
}
|
||||
61
Repository/JsonRepository.cs
Normal file
61
Repository/JsonRepository.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System.Text.Json;
|
||||
using Models;
|
||||
|
||||
namespace Repository;
|
||||
|
||||
public class JsonRepository : IRepository
|
||||
{
|
||||
private const string _fileName = "data.json";
|
||||
|
||||
public User? Read()
|
||||
{
|
||||
if (File.Exists(_fileName))
|
||||
{
|
||||
try
|
||||
{
|
||||
string json = File.ReadAllText(_fileName);
|
||||
return JsonSerializer.Deserialize<User>(json) ?? new User("fallback", "fallback", "fallback");
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
WriteToStdErr($"JSON error: {e.Message}");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
WriteToStdErr($"File I/O error: {e.Message}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
WriteToStdErr($"Unexpected error: {e.Message}");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Write(User item)
|
||||
{
|
||||
try
|
||||
{
|
||||
string json = JsonSerializer.Serialize(item);
|
||||
File.WriteAllText(_fileName, json);
|
||||
}
|
||||
catch (JsonException e)
|
||||
{
|
||||
WriteToStdErr($"JSON error: {e.Message}");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
WriteToStdErr($"File I/O error: {e.Message}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
WriteToStdErr($"Unexpected error: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteToStdErr(string message)
|
||||
{
|
||||
using var sw = new StreamWriter(Console.OpenStandardError());
|
||||
sw.WriteLine(message);
|
||||
}
|
||||
}
|
||||
13
Repository/Repository.csproj
Normal file
13
Repository/Repository.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../Models/Models.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user