Начал более менее создание десктоп приложения

This commit is contained in:
Hukuta committed 2026-11-03 22:42:07 +09:00
1 parent fa0925808c
commit 05358eb179
17 files changed
+237 -1

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
<Application x:Class="CartriX.Service.Wpf.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CartriX.Service.Wpf"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
+14
View File
@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;
namespace CartriX.Service.Wpf
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
+10
View File
@@ -0,0 +1,10 @@
using System.Windows;
[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
+13
View File
@@ -0,0 +1,13 @@
<Window x:Class="CartriX.Service.Wpf.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:CartriX.Service.Wpf"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Name="textStatus"/>
<Button Content="Кнопка" Click="Button_Click"/>
</StackPanel>
</Window>
+57
View File
@@ -0,0 +1,57 @@
using System.IO;
using System.IO.Pipes;
using System.Net.Http;
using System.Text;
using System.Windows;
namespace CartriX.Service.Wpf
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void CheckServiceStatus()
{
const string PipeName = "CartriX.Service";
try
{
// Создаем клиента для подключения к локальной трубе "." означает локальный ПК
using var pipeClient = new NamedPipeClientStream(".", PipeName, PipeDirection.In, PipeOptions.Asynchronous);
// Пытаемся подключиться с таймаутом в 1 секунду (чтобы интерфейс не зависал, если служба выключена)
await pipeClient.ConnectAsync(1000);
// Читаем ответ от службы
using var reader = new StreamReader(pipeClient, Encoding.UTF8);
string response = await reader.ReadToEndAsync();
if (!string.IsNullOrEmpty(response))
{
// Успешно получили данные
textStatus.Text = $"Служба онлайн\nДанные: {response}";
// Здесь можно распарсить JSON через JsonSerializer.Deserialize(...)
}
}
catch (TimeoutException)
{
// Не смогли подключиться за 1 секунду — служба скорее всего остановлена
textStatus.Text = "Служба не отвечает (Таймаут)";
}
catch (Exception ex)
{
// Другие ошибки (например, службы вообще нет в системе)
textStatus.Text = "Служба отключена";
}
}
private void Button_Click(object sender, RoutedEventArgs e) => CheckServiceStatus();
}
}