create desktop from jykov
This commit is contained in:
parent
fca90f53eb
commit
380963926e
15
Presence.Desktop/App.axaml
Normal file
15
Presence.Desktop/App.axaml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<Application xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
x:Class="Presence.Desktop.App"
|
||||||
|
xmlns:local="using:Presence.Desktop"
|
||||||
|
RequestedThemeVariant="Default">
|
||||||
|
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
|
||||||
|
|
||||||
|
<Application.DataTemplates>
|
||||||
|
<local:ViewLocator/>
|
||||||
|
</Application.DataTemplates>
|
||||||
|
|
||||||
|
<Application.Styles>
|
||||||
|
<FluentTheme />
|
||||||
|
</Application.Styles>
|
||||||
|
</Application>
|
37
Presence.Desktop/App.axaml.cs
Normal file
37
Presence.Desktop/App.axaml.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Presence.Desktop.DI;
|
||||||
|
using Presence.Desktop.ViewModels;
|
||||||
|
using Presence.Desktop.Views;
|
||||||
|
|
||||||
|
namespace Presence.Desktop
|
||||||
|
{
|
||||||
|
public partial class App : Application
|
||||||
|
{
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
AvaloniaXamlLoader.Load(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnFrameworkInitializationCompleted()
|
||||||
|
{
|
||||||
|
var serviceCollection = new ServiceCollection();
|
||||||
|
serviceCollection.AddCommonService();
|
||||||
|
var services = serviceCollection.BuildServiceProvider();
|
||||||
|
var mainViewModel = services.GetRequiredService<MainWindowViewModel>();
|
||||||
|
|
||||||
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
|
{
|
||||||
|
desktop.MainWindow = new MainWindow
|
||||||
|
{
|
||||||
|
DataContext = mainViewModel,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
base.OnFrameworkInitializationCompleted();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
BIN
Presence.Desktop/Assets/avalonia-logo.ico
Normal file
BIN
Presence.Desktop/Assets/avalonia-logo.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 172 KiB |
27
Presence.Desktop/DI/ServiceColletionExtensions.cs
Normal file
27
Presence.Desktop/DI/ServiceColletionExtensions.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using Demo.Data.RemoteData.RemoteDataBase;
|
||||||
|
using Demo.Data.Repository;
|
||||||
|
using Demo.Domain.UseCase;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Presence.Desktop.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Presence.Desktop.DI
|
||||||
|
{
|
||||||
|
public static class ServiceColletionExtensions
|
||||||
|
{
|
||||||
|
public static void AddCommonService(this IServiceCollection collection) {
|
||||||
|
collection
|
||||||
|
.AddDbContext<RemoteDatabaseContext>()
|
||||||
|
.AddSingleton<IGroupRepository, SQLGroupRepositoryImpl>()
|
||||||
|
.AddSingleton<IUserRepository, SQLUserRepositoryImpl>()
|
||||||
|
.AddTransient<IGroupUseCase, GroupUseCase>()
|
||||||
|
.AddTransient<IUserUseCase, UserUseCase>()
|
||||||
|
.AddTransient<MainWindowViewModel>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
Presence.Desktop/Models/GroupPresenter.cs
Normal file
17
Presence.Desktop/Models/GroupPresenter.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using ReactiveUI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Presence.Desktop.Models
|
||||||
|
{
|
||||||
|
public class GroupPresenter
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public IEnumerable<UserPresenter>? users { get; set; } = null;
|
||||||
|
}
|
||||||
|
}
|
15
Presence.Desktop/Models/UserPresenter.cs
Normal file
15
Presence.Desktop/Models/UserPresenter.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Presence.Desktop.Models
|
||||||
|
{
|
||||||
|
public class UserPresenter
|
||||||
|
{
|
||||||
|
public Guid Guid { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public GroupPresenter Group { get; set; }
|
||||||
|
}
|
||||||
|
}
|
34
Presence.Desktop/Presence.Desktop.csproj
Normal file
34
Presence.Desktop/Presence.Desktop.csproj
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||||
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
|
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Models\" />
|
||||||
|
<AvaloniaResource Include="Assets\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Avalonia" Version="11.2.1" />
|
||||||
|
<PackageReference Include="Avalonia.Desktop" Version="11.2.1" />
|
||||||
|
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.1" />
|
||||||
|
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1" />
|
||||||
|
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.1" />
|
||||||
|
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
|
||||||
|
<PackageReference Include="Avalonia.Diagnostics" Version="11.2.1">
|
||||||
|
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||||
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\data\data.csproj" />
|
||||||
|
<ProjectReference Include="..\domain\domain.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
24
Presence.Desktop/Program.cs
Normal file
24
Presence.Desktop/Program.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.ReactiveUI;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Presence.Desktop
|
||||||
|
{
|
||||||
|
internal 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<App>()
|
||||||
|
.UsePlatformDetect()
|
||||||
|
.WithInterFont()
|
||||||
|
.LogToTrace()
|
||||||
|
.UseReactiveUI();
|
||||||
|
}
|
||||||
|
}
|
32
Presence.Desktop/ViewLocator.cs
Normal file
32
Presence.Desktop/ViewLocator.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Controls.Templates;
|
||||||
|
using Presence.Desktop.ViewModels;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Presence.Desktop
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
72
Presence.Desktop/ViewModels/MainWindowViewModel.cs
Normal file
72
Presence.Desktop/ViewModels/MainWindowViewModel.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using Demo.Domain.UseCase;
|
||||||
|
using DynamicData;
|
||||||
|
using DynamicData.Binding;
|
||||||
|
using Presence.Desktop.Models;
|
||||||
|
using ReactiveUI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reactive.Linq;
|
||||||
|
using Tmds.DBus.Protocol;
|
||||||
|
|
||||||
|
namespace Presence.Desktop.ViewModels
|
||||||
|
{
|
||||||
|
public class MainWindowViewModel : ViewModelBase
|
||||||
|
{
|
||||||
|
private readonly IGroupUseCase _groupService;
|
||||||
|
private List<GroupPresenter> groupPresentersDataSource = new List<GroupPresenter>();
|
||||||
|
private ObservableCollection<GroupPresenter> _groups;
|
||||||
|
public ObservableCollection<GroupPresenter> Groups => _groups;
|
||||||
|
|
||||||
|
public GroupPresenter? SelectedGroupItem {
|
||||||
|
get => _selectedGroupItem;
|
||||||
|
set => this.RaiseAndSetIfChanged(ref _selectedGroupItem, value); }
|
||||||
|
|
||||||
|
private GroupPresenter? _selectedGroupItem;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public ObservableCollection<UserPresenter> Users { get => _users;}
|
||||||
|
public ObservableCollection<UserPresenter> _users;
|
||||||
|
public MainWindowViewModel(IGroupUseCase groupUseCase)
|
||||||
|
{
|
||||||
|
_groupService = groupUseCase;
|
||||||
|
|
||||||
|
foreach (var item in _groupService.GetAllGroupsWithUsers())
|
||||||
|
{
|
||||||
|
GroupPresenter groupPresenter = new GroupPresenter
|
||||||
|
{
|
||||||
|
Id = item.ID,
|
||||||
|
Name = item.Name,
|
||||||
|
users = item.Users?.Select(user => new UserPresenter
|
||||||
|
{
|
||||||
|
Name = user.FIO,
|
||||||
|
Guid = user.Guid,
|
||||||
|
Group = new GroupPresenter { Id = item.ID, Name = item.Name }
|
||||||
|
}
|
||||||
|
).ToList()
|
||||||
|
};
|
||||||
|
groupPresentersDataSource.Add(groupPresenter);
|
||||||
|
}
|
||||||
|
_groups = new ObservableCollection<GroupPresenter>(groupPresentersDataSource);
|
||||||
|
|
||||||
|
_users = new ObservableCollection<UserPresenter>();
|
||||||
|
|
||||||
|
this.WhenAnyValue(vm => vm.SelectedGroupItem)
|
||||||
|
.Subscribe(_ => SetUsers());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetUsers()
|
||||||
|
{
|
||||||
|
if(SelectedGroupItem == null) return;
|
||||||
|
if (SelectedGroupItem.users == null) return;
|
||||||
|
Users.Clear();
|
||||||
|
foreach (var item in SelectedGroupItem.users)
|
||||||
|
{
|
||||||
|
Users.Add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
Presence.Desktop/ViewModels/ViewModelBase.cs
Normal file
8
Presence.Desktop/ViewModels/ViewModelBase.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using ReactiveUI;
|
||||||
|
|
||||||
|
namespace Presence.Desktop.ViewModels
|
||||||
|
{
|
||||||
|
public class ViewModelBase : ReactiveObject
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
47
Presence.Desktop/Views/MainWindow.axaml
Normal file
47
Presence.Desktop/Views/MainWindow.axaml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<Window xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:vm="using:Presence.Desktop.ViewModels"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
|
x:Class="Presence.Desktop.Views.MainWindow"
|
||||||
|
x:DataType="vm:MainWindowViewModel"
|
||||||
|
Icon="/Assets/avalonia-logo.ico"
|
||||||
|
Title="Presence.Desktop">
|
||||||
|
|
||||||
|
<Design.DataContext>
|
||||||
|
<vm:MainWindowViewModel/>
|
||||||
|
</Design.DataContext>
|
||||||
|
<DockPanel Background="Azure">
|
||||||
|
<StackPanel DockPanel.Dock="Bottom">
|
||||||
|
<TextBlock Text="List ↑" HorizontalAlignment="Center"/>
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel
|
||||||
|
Spacing="10"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
DockPanel.Dock="Top"
|
||||||
|
Orientation="Horizontal">
|
||||||
|
<TextBlock Text="Combobox ->"/>
|
||||||
|
<ComboBox ItemsSource="{Binding Groups}" SelectedValue="{Binding SelectedGroupItem}">
|
||||||
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<TextBlock Text="{Binding Name}"/>
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
|
<ComboBox/>
|
||||||
|
<ComboBox/>
|
||||||
|
</StackPanel>
|
||||||
|
<Border>
|
||||||
|
<ListBox Background="Bisque" ItemsSource="{Binding Users}">
|
||||||
|
<ListBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock Text="{Binding Name}" />
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</ListBox.ItemTemplate>
|
||||||
|
</ListBox>
|
||||||
|
</Border>
|
||||||
|
</DockPanel>
|
||||||
|
</Window>
|
12
Presence.Desktop/Views/MainWindow.axaml.cs
Normal file
12
Presence.Desktop/Views/MainWindow.axaml.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using Avalonia.Controls;
|
||||||
|
|
||||||
|
namespace Presence.Desktop.Views
|
||||||
|
{
|
||||||
|
public partial class MainWindow : Window
|
||||||
|
{
|
||||||
|
public MainWindow()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
Presence.Desktop/app.manifest
Normal file
18
Presence.Desktop/app.manifest
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<!-- This manifest is used on Windows only.
|
||||||
|
Don't remove it as it might cause problems with window transparency and embedded controls.
|
||||||
|
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
|
||||||
|
<assemblyIdentity version="1.0.0.0" name="Presence.Desktop.Desktop"/>
|
||||||
|
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
|
<application>
|
||||||
|
<!-- A list of the Windows versions that this application has been tested on
|
||||||
|
and is designed to work with. Uncomment the appropriate elements
|
||||||
|
and Windows will automatically select the most compatible environment. -->
|
||||||
|
|
||||||
|
<!-- Windows 10 -->
|
||||||
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||||
|
</application>
|
||||||
|
</compatibility>
|
||||||
|
</assembly>
|
@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "data", "data\data.csproj",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "presence_api", "presence_api\presence_api.csproj", "{F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "presence_api", "presence_api\presence_api.csproj", "{F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Presence.Desktop", "Presence.Desktop\Presence.Desktop.csproj", "{7B4467D9-1176-4C11-8940-7D0559ED6593}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -42,5 +44,9 @@ Global
|
|||||||
{F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}.Release|Any CPU.Build.0 = Release|Any CPU
|
{F7B9C650-020B-45AE-AB31-4C6DC1C1D4CE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7B4467D9-1176-4C11-8940-7D0559ED6593}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7B4467D9-1176-4C11-8940-7D0559ED6593}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7B4467D9-1176-4C11-8940-7D0559ED6593}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7B4467D9-1176-4C11-8940-7D0559ED6593}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
Loading…
Reference in New Issue
Block a user