commit c58ce200e04aab3e0267e0f05931e7157d919d67 Author: Creeper Lv Date: Thu May 28 02:54:17 2026 +1000 Initial Commit. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f6adf54 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.vs/ +.vscode/ +bin/ +obj/ diff --git a/Client/SNote.Android/Application.cs b/Client/SNote.Android/Application.cs new file mode 100644 index 0000000..94174f6 --- /dev/null +++ b/Client/SNote.Android/Application.cs @@ -0,0 +1,21 @@ +using Android.App; +using Android.Runtime; +using Avalonia; +using Avalonia.Android; + +namespace SNote.Android +{ + [Application] + public class Application : AvaloniaAndroidApplication + { + protected Application(nint javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) + { + } + + protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) + { + return base.CustomizeAppBuilder(builder) + .WithInterFont(); + } + } +} diff --git a/Client/SNote.Android/Icon.png b/Client/SNote.Android/Icon.png new file mode 100644 index 0000000..3c39845 Binary files /dev/null and b/Client/SNote.Android/Icon.png differ diff --git a/Client/SNote.Android/MainActivity.cs b/Client/SNote.Android/MainActivity.cs new file mode 100644 index 0000000..b93aa42 --- /dev/null +++ b/Client/SNote.Android/MainActivity.cs @@ -0,0 +1,16 @@ +using Android.App; +using Android.Content.PM; +using Avalonia; +using Avalonia.Android; + +namespace SNote.Android; + +[Activity( + Label = "SNote.Android", + Theme = "@style/MyTheme.NoActionBar", + Icon = "@drawable/icon", + MainLauncher = true, + ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.ScreenSize | ConfigChanges.UiMode)] +public class MainActivity : AvaloniaMainActivity +{ +} diff --git a/Client/SNote.Android/Properties/AndroidManifest.xml b/Client/SNote.Android/Properties/AndroidManifest.xml new file mode 100644 index 0000000..d9fdf5e --- /dev/null +++ b/Client/SNote.Android/Properties/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/Client/SNote.Android/Resources/AboutResources.txt b/Client/SNote.Android/Resources/AboutResources.txt new file mode 100644 index 0000000..c2bca97 --- /dev/null +++ b/Client/SNote.Android/Resources/AboutResources.txt @@ -0,0 +1,44 @@ +Images, layout descriptions, binary blobs and string dictionaries can be included +in your application as resource files. Various Android APIs are designed to +operate on the resource IDs instead of dealing with images, strings or binary blobs +directly. + +For example, a sample Android app that contains a user interface layout (main.axml), +an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) +would keep its resources in the "Resources" directory of the application: + +Resources/ + drawable/ + icon.png + + layout/ + main.axml + + values/ + strings.xml + +In order to get the build system to recognize Android resources, set the build action to +"AndroidResource". The native Android APIs do not operate directly with filenames, but +instead operate on resource IDs. When you compile an Android application that uses resources, +the build system will package the resources for distribution and generate a class called "R" +(this is an Android convention) that contains the tokens for each one of the resources +included. For example, for the above Resources layout, this is what the R class would expose: + +public class R { + public class drawable { + public const int icon = 0x123; + } + + public class layout { + public const int main = 0x456; + } + + public class strings { + public const int first_string = 0xabc; + public const int second_string = 0xbcd; + } +} + +You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main +to reference the layout/main.axml file, or R.strings.first_string to reference the first +string in the dictionary file values/strings.xml. \ No newline at end of file diff --git a/Client/SNote.Android/Resources/drawable-night-v31/avalonia_anim.xml b/Client/SNote.Android/Resources/drawable-night-v31/avalonia_anim.xml new file mode 100644 index 0000000..dde4b5a --- /dev/null +++ b/Client/SNote.Android/Resources/drawable-night-v31/avalonia_anim.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Client/SNote.Android/Resources/drawable-v31/avalonia_anim.xml b/Client/SNote.Android/Resources/drawable-v31/avalonia_anim.xml new file mode 100644 index 0000000..94f27d9 --- /dev/null +++ b/Client/SNote.Android/Resources/drawable-v31/avalonia_anim.xml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Client/SNote.Android/Resources/drawable/splash_screen.xml b/Client/SNote.Android/Resources/drawable/splash_screen.xml new file mode 100644 index 0000000..2e920b4 --- /dev/null +++ b/Client/SNote.Android/Resources/drawable/splash_screen.xml @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/Client/SNote.Android/Resources/values-night/colors.xml b/Client/SNote.Android/Resources/values-night/colors.xml new file mode 100644 index 0000000..3d47b6f --- /dev/null +++ b/Client/SNote.Android/Resources/values-night/colors.xml @@ -0,0 +1,4 @@ + + + #212121 + diff --git a/Client/SNote.Android/Resources/values-v31/styles.xml b/Client/SNote.Android/Resources/values-v31/styles.xml new file mode 100644 index 0000000..d5ecec4 --- /dev/null +++ b/Client/SNote.Android/Resources/values-v31/styles.xml @@ -0,0 +1,21 @@ + + + + + + + + diff --git a/Client/SNote.Android/Resources/values/colors.xml b/Client/SNote.Android/Resources/values/colors.xml new file mode 100644 index 0000000..59279d5 --- /dev/null +++ b/Client/SNote.Android/Resources/values/colors.xml @@ -0,0 +1,4 @@ + + + #FFFFFF + diff --git a/Client/SNote.Android/Resources/values/styles.xml b/Client/SNote.Android/Resources/values/styles.xml new file mode 100644 index 0000000..6e534de --- /dev/null +++ b/Client/SNote.Android/Resources/values/styles.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/Client/SNote.Android/SNote.Android.csproj b/Client/SNote.Android/SNote.Android.csproj new file mode 100644 index 0000000..f1f6a61 --- /dev/null +++ b/Client/SNote.Android/SNote.Android.csproj @@ -0,0 +1,28 @@ + + + Exe + net10.0-android + 23 + enable + com.CompanyName.SNote + 1 + 1.0 + apk + false + + + + + Resources\drawable\Icon.png + + + + + + + + + + + + diff --git a/Client/SNote.Browser/Program.cs b/Client/SNote.Browser/Program.cs new file mode 100644 index 0000000..5f1df6f --- /dev/null +++ b/Client/SNote.Browser/Program.cs @@ -0,0 +1,18 @@ +using System.Runtime.Versioning; +using System.Threading.Tasks; +using Avalonia; +using Avalonia.Browser; +using SNote; + +internal sealed partial class Program +{ + private static Task Main(string[] args) => BuildAvaloniaApp() + .WithInterFont() +#if DEBUG + .WithDeveloperTools() +#endif + .StartBrowserAppAsync("out"); + + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure(); +} \ No newline at end of file diff --git a/Client/SNote.Browser/Properties/AssemblyInfo.cs b/Client/SNote.Browser/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fb78795 --- /dev/null +++ b/Client/SNote.Browser/Properties/AssemblyInfo.cs @@ -0,0 +1 @@ +[assembly:System.Runtime.Versioning.SupportedOSPlatform("browser")] diff --git a/Client/SNote.Browser/Properties/launchSettings.json b/Client/SNote.Browser/Properties/launchSettings.json new file mode 100644 index 0000000..d21d382 --- /dev/null +++ b/Client/SNote.Browser/Properties/launchSettings.json @@ -0,0 +1,13 @@ +{ + "profiles": { + "SNote.Browser": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:7169;http://localhost:5235", + "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}" + } + } +} diff --git a/Client/SNote.Browser/SNote.Browser.csproj b/Client/SNote.Browser/SNote.Browser.csproj new file mode 100644 index 0000000..7be7cce --- /dev/null +++ b/Client/SNote.Browser/SNote.Browser.csproj @@ -0,0 +1,16 @@ + + + net10.0-browser + Exe + true + enable + + + + + + + + + + diff --git a/Client/SNote.Browser/runtimeconfig.template.json b/Client/SNote.Browser/runtimeconfig.template.json new file mode 100644 index 0000000..b96a943 --- /dev/null +++ b/Client/SNote.Browser/runtimeconfig.template.json @@ -0,0 +1,10 @@ +{ + "wasmHostProperties": { + "perHostConfig": [ + { + "name": "browser", + "host": "browser" + } + ] + } +} \ No newline at end of file diff --git a/Client/SNote.Browser/wwwroot/app.css b/Client/SNote.Browser/wwwroot/app.css new file mode 100644 index 0000000..1d6f754 --- /dev/null +++ b/Client/SNote.Browser/wwwroot/app.css @@ -0,0 +1,58 @@ +/* HTML styles for the splash screen */ +.avalonia-splash { + position: absolute; + height: 100%; + width: 100%; + background: white; + font-family: 'Outfit', sans-serif; + justify-content: center; + align-items: center; + display: flex; + pointer-events: none; +} + +/* Light theme styles */ +@media (prefers-color-scheme: light) { + .avalonia-splash { + background: white; + } + + .avalonia-splash h2 { + color: #1b2a4e; + } + + .avalonia-splash a { + color: #0D6EFD; + } +} + +@media (prefers-color-scheme: dark) { + .avalonia-splash { + background: #1b2a4e; + } + + .avalonia-splash h2 { + color: white; + } + + .avalonia-splash a { + color: white; + } +} + +.avalonia-splash h2 { + font-weight: 400; + font-size: 1.5rem; +} + +.avalonia-splash a { + text-decoration: none; + font-size: 2.5rem; + display: block; +} + +.avalonia-splash.splash-close { + transition: opacity 200ms, display 200ms; + display: none; + opacity: 0; +} diff --git a/Client/SNote.Browser/wwwroot/favicon.ico b/Client/SNote.Browser/wwwroot/favicon.ico new file mode 100644 index 0000000..f7da8bb Binary files /dev/null and b/Client/SNote.Browser/wwwroot/favicon.ico differ diff --git a/Client/SNote.Browser/wwwroot/index.html b/Client/SNote.Browser/wwwroot/index.html new file mode 100644 index 0000000..df63d6d --- /dev/null +++ b/Client/SNote.Browser/wwwroot/index.html @@ -0,0 +1,36 @@ + + + + + SNote.Browser + + + + + + +
+
+

+ Powered by + + + + + + + + + + + + + + +

+
+
+ + + + diff --git a/Client/SNote.Browser/wwwroot/main.js b/Client/SNote.Browser/wwwroot/main.js new file mode 100644 index 0000000..bf1555e --- /dev/null +++ b/Client/SNote.Browser/wwwroot/main.js @@ -0,0 +1,13 @@ +import { dotnet } from './_framework/dotnet.js' + +const is_browser = typeof window != "undefined"; +if (!is_browser) throw new Error(`Expected to be running in a browser`); + +const dotnetRuntime = await dotnet + .withDiagnosticTracing(false) + .withApplicationArgumentsFromQuery() + .create(); + +const config = dotnetRuntime.getConfig(); + +await dotnetRuntime.runMain(config.mainAssemblyName, [globalThis.location.href]); diff --git a/Client/SNote.Desktop/Program.cs b/Client/SNote.Desktop/Program.cs new file mode 100644 index 0000000..5b1353d --- /dev/null +++ b/Client/SNote.Desktop/Program.cs @@ -0,0 +1,24 @@ +using System; +using Avalonia; + +namespace SNote.Desktop; + +sealed class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() +#if DEBUG + .WithDeveloperTools() +#endif + .WithInterFont() + .LogToTrace(); +} diff --git a/Client/SNote.Desktop/SNote.Desktop.csproj b/Client/SNote.Desktop/SNote.Desktop.csproj new file mode 100644 index 0000000..6bbd48d --- /dev/null +++ b/Client/SNote.Desktop/SNote.Desktop.csproj @@ -0,0 +1,25 @@ + + + WinExe + + net10.0 + enable + + + + app.manifest + + + + + + None + All + + + + + + + diff --git a/Client/SNote.Desktop/app.manifest b/Client/SNote.Desktop/app.manifest new file mode 100644 index 0000000..ce384f6 --- /dev/null +++ b/Client/SNote.Desktop/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/Client/SNote.iOS/AppDelegate.cs b/Client/SNote.iOS/AppDelegate.cs new file mode 100644 index 0000000..0e8bd8d --- /dev/null +++ b/Client/SNote.iOS/AppDelegate.cs @@ -0,0 +1,23 @@ +using Foundation; +using UIKit; +using Avalonia; +using Avalonia.Controls; +using Avalonia.iOS; +using Avalonia.Media; + +namespace SNote.iOS; + +// The UIApplicationDelegate for the application. This class is responsible for launching the +// User Interface of the application, as well as listening (and optionally responding) to +// application events from iOS. +[Register("AppDelegate")] +#pragma warning disable CA1711 // Identifiers should not have incorrect suffix +public partial class AppDelegate : AvaloniaAppDelegate +#pragma warning restore CA1711 // Identifiers should not have incorrect suffix +{ + protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) + { + return base.CustomizeAppBuilder(builder) + .WithInterFont(); + } +} diff --git a/Client/SNote.iOS/Entitlements.plist b/Client/SNote.iOS/Entitlements.plist new file mode 100644 index 0000000..0c67376 --- /dev/null +++ b/Client/SNote.iOS/Entitlements.plist @@ -0,0 +1,5 @@ + + + + + diff --git a/Client/SNote.iOS/Info.plist b/Client/SNote.iOS/Info.plist new file mode 100644 index 0000000..3dcebf0 --- /dev/null +++ b/Client/SNote.iOS/Info.plist @@ -0,0 +1,43 @@ + + + + + CFBundleDisplayName + SNote + CFBundleIdentifier + companyName.SNote + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1.0 + LSRequiresIPhoneOS + + MinimumOSVersion + 13.0 + UIDeviceFamily + + 1 + 2 + + UILaunchStoryboardName + LaunchScreen + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/Client/SNote.iOS/Main.cs b/Client/SNote.iOS/Main.cs new file mode 100644 index 0000000..41af4b1 --- /dev/null +++ b/Client/SNote.iOS/Main.cs @@ -0,0 +1,14 @@ +using UIKit; + +namespace SNote.iOS; + +public class Application +{ + // This is the main entry point of the application. + static void Main(string[] args) + { + // if you want to use a different Application Delegate class from "AppDelegate" + // you can specify it here. + UIApplication.Main(args, null, typeof(AppDelegate)); + } +} diff --git a/Client/SNote.iOS/Resources/LaunchScreen.xib b/Client/SNote.iOS/Resources/LaunchScreen.xib new file mode 100644 index 0000000..f86e157 --- /dev/null +++ b/Client/SNote.iOS/Resources/LaunchScreen.xib @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Client/SNote.iOS/SNote.iOS.csproj b/Client/SNote.iOS/SNote.iOS.csproj new file mode 100644 index 0000000..b2c4eff --- /dev/null +++ b/Client/SNote.iOS/SNote.iOS.csproj @@ -0,0 +1,16 @@ + + + Exe + net10.0-ios + 13.0 + enable + + + + + + + + + + diff --git a/Client/SNote/App.axaml b/Client/SNote/App.axaml new file mode 100644 index 0000000..6f122c5 --- /dev/null +++ b/Client/SNote/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Client/SNote/App.axaml.cs b/Client/SNote/App.axaml.cs new file mode 100644 index 0000000..c86d13c --- /dev/null +++ b/Client/SNote/App.axaml.cs @@ -0,0 +1,42 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core; +using Avalonia.Data.Core.Plugins; +using System.Linq; +using Avalonia.Markup.Xaml; +using SNote.ViewModels; +using SNote.Views; + +namespace SNote; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow + { + DataContext = new MainViewModel() + }; + } + else if (ApplicationLifetime is IActivityApplicationLifetime singleViewFactoryApplicationLifetime) + { + singleViewFactoryApplicationLifetime.MainViewFactory = () => new MainView { DataContext = new MainViewModel() }; + } + else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform) + { + singleViewPlatform.MainView = new MainView + { + DataContext = new MainViewModel() + }; + } + + base.OnFrameworkInitializationCompleted(); + } +} \ No newline at end of file diff --git a/Client/SNote/Assets/avalonia-logo.ico b/Client/SNote/Assets/avalonia-logo.ico new file mode 100644 index 0000000..f7da8bb Binary files /dev/null and b/Client/SNote/Assets/avalonia-logo.ico differ diff --git a/Client/SNote/SNote.csproj b/Client/SNote/SNote.csproj new file mode 100644 index 0000000..8a03b5e --- /dev/null +++ b/Client/SNote/SNote.csproj @@ -0,0 +1,23 @@ + + + net10.0 + enable + latest + true + + + + + + + + + + + + None + All + + + + diff --git a/Client/SNote/ViewLocator.cs b/Client/SNote/ViewLocator.cs new file mode 100644 index 0000000..1f512d2 --- /dev/null +++ b/Client/SNote/ViewLocator.cs @@ -0,0 +1,37 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using SNote.ViewModels; + +namespace SNote; + +/// +/// Given a view model, returns the corresponding view if possible. +/// +[RequiresUnreferencedCode( + "Default implementation of ViewLocator involves reflection which may be trimmed away.", + Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")] +public class ViewLocator : IDataTemplate +{ + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) + { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } +} \ No newline at end of file diff --git a/Client/SNote/ViewModels/MainViewModel.cs b/Client/SNote/ViewModels/MainViewModel.cs new file mode 100644 index 0000000..5a83dcb --- /dev/null +++ b/Client/SNote/ViewModels/MainViewModel.cs @@ -0,0 +1,9 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace SNote.ViewModels; + +public partial class MainViewModel : ViewModelBase +{ + [ObservableProperty] + private string _greeting = "Welcome to Avalonia!"; +} diff --git a/Client/SNote/ViewModels/ViewModelBase.cs b/Client/SNote/ViewModels/ViewModelBase.cs new file mode 100644 index 0000000..2513953 --- /dev/null +++ b/Client/SNote/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace SNote.ViewModels; + +public abstract class ViewModelBase : ObservableObject +{ +} diff --git a/Client/SNote/Views/MainView.axaml b/Client/SNote/Views/MainView.axaml new file mode 100644 index 0000000..1aa423e --- /dev/null +++ b/Client/SNote/Views/MainView.axaml @@ -0,0 +1,16 @@ + + + + + + + + diff --git a/Client/SNote/Views/MainView.axaml.cs b/Client/SNote/Views/MainView.axaml.cs new file mode 100644 index 0000000..13c233b --- /dev/null +++ b/Client/SNote/Views/MainView.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace SNote.Views; + +public partial class MainView : UserControl +{ + public MainView() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/Client/SNote/Views/MainWindow.axaml b/Client/SNote/Views/MainWindow.axaml new file mode 100644 index 0000000..883bfed --- /dev/null +++ b/Client/SNote/Views/MainWindow.axaml @@ -0,0 +1,12 @@ + + + diff --git a/Client/SNote/Views/MainWindow.axaml.cs b/Client/SNote/Views/MainWindow.axaml.cs new file mode 100644 index 0000000..5a53608 --- /dev/null +++ b/Client/SNote/Views/MainWindow.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace SNote.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..c283293 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,23 @@ + + + + true + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..0982f7d --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# Simple Note + +This project is a structured note-taking software-server. + +# Client + +Client it self can also do note-taking locally without setup server. + +The client is written in C# using avalonia to achieve cross-platform. + +Target platforms: + +- Windows +- Linux +- macOS +- Android +- Web (WASM) + +# Server + +Server is also written in C# using ASP.Net Core Web API. + +Server is a distributed server structure. A server can set a destination server to sync content from and to target server. And server can broadcast data changes to other servers connected to it. + +The server utilizes RESTful API style: Only serve API services via HTTP requests. + +The server provides a multi-user service, every user has its own notebook. A user can share their notes/folders to anyone. + +For database, it can be configured as the server is a ASP.Net Core Web API application, and by default, it uses SQLite. + +# Underlying + +Each node (folder/note) have its own UUID and all its children are assigned via UUID, which allows symbollic linking a folder to another folder. + +Each node also have ACLs, controlls who can assess those nodes, (their owner always have full control). + +Permissions are: +- View +- Edit +- Delete +- Rename + +To setup a server network, every server should share a private-public certificate, if a server want to join (or connect to) another server, it must have the same private-public certificate. diff --git a/SNote.slnx b/SNote.slnx new file mode 100644 index 0000000..3c6fbbf --- /dev/null +++ b/SNote.slnx @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/Server/Program.cs b/Server/Program.cs new file mode 100644 index 0000000..4cd8643 --- /dev/null +++ b/Server/Program.cs @@ -0,0 +1,56 @@ +using System.Text.Json.Serialization; +using Microsoft.AspNetCore.Http.HttpResults; + +namespace SNote.Server; + +public class Program +{ + public static void Main(string[] args) + { + var builder = WebApplication.CreateSlimBuilder(args); + + builder.Services.ConfigureHttpJsonOptions(options => + { + options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default); + }); + + // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi + builder.Services.AddOpenApi(); + + var app = builder.Build(); + + if (app.Environment.IsDevelopment()) + { + app.MapOpenApi(); + } + + Todo[] sampleTodos = + [ + new(1, "Walk the dog"), + new(2, "Do the dishes", DateOnly.FromDateTime(DateTime.Now)), + new(3, "Do the laundry", DateOnly.FromDateTime(DateTime.Now.AddDays(1))), + new(4, "Clean the bathroom"), + new(5, "Clean the car", DateOnly.FromDateTime(DateTime.Now.AddDays(2))) + ]; + + var todosApi = app.MapGroup("/todos"); + todosApi.MapGet("/", () => sampleTodos) + .WithName("GetTodos"); + + todosApi.MapGet("/{id}", Results, NotFound> (int id) => + sampleTodos.FirstOrDefault(a => a.Id == id) is { } todo + ? TypedResults.Ok(todo) + : TypedResults.NotFound()) + .WithName("GetTodoById"); + + app.Run(); + } +} + +public record Todo(int Id, string? Title, DateOnly? DueBy = null, bool IsComplete = false); + +[JsonSerializable(typeof(Todo[]))] +internal partial class AppJsonSerializerContext : JsonSerializerContext +{ + +} diff --git a/Server/Properties/launchSettings.json b/Server/Properties/launchSettings.json new file mode 100644 index 0000000..f1c3d42 --- /dev/null +++ b/Server/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "todos", + "applicationUrl": "http://localhost:5202", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Server/SNote.Server.csproj b/Server/SNote.Server.csproj new file mode 100644 index 0000000..418c7d7 --- /dev/null +++ b/Server/SNote.Server.csproj @@ -0,0 +1,15 @@ + + + + net10.0 + enable + enable + true + true + + + + + + + diff --git a/Server/SNote.Server.http b/Server/SNote.Server.http new file mode 100644 index 0000000..c1f9b9a --- /dev/null +++ b/Server/SNote.Server.http @@ -0,0 +1,11 @@ +@SNote.Server_HostAddress = http://localhost:5202 + +GET {{SNote.Server_HostAddress}}/todos/ +Accept: application/json + +### + +GET {{SNote.Server_HostAddress}}/todos/1 +Accept: application/json + +### diff --git a/Server/appsettings.Development.json b/Server/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Server/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Server/appsettings.json b/Server/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Server/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}