| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
-
- using ServiceBase;
- namespace EEMSCenterUI.ViewModels;
- internal partial class MainWindowViewModel : ObservableObject, IEEMSBaseServerProvider
- {
- public MainWindowViewModel()
- {
- this.Server = new()
- {
- IP = "127.0.0.1",
- Port = 50054
- };
- }
- private IClientProvider? _clientProvider;
- [ObservableProperty]
- private ServiceEndpoint _Server;
- [ObservableProperty]
- private string? _GUID;
- [RelayCommand]
- private void StartService()
- {
- EEMSBaseServer baseServer = new();
- if (!baseServer.Initialize(this, out _clientProvider) || _clientProvider is null)
- {
- MessageBox.Show("Service Start Failed");
- return;
- }
- Task.Factory.StartNew(async () =>
- {
- if (!await baseServer.StartServiceAsync(this.Server.IP!, this.Server.Port))
- MessageBox.Show("Service Start Failed");
- }, TaskCreationOptions.LongRunning);
- }
- [RelayCommand]
- private void RequestFile()
- {
- Guid.TryParse(this.GUID, out Guid guid);
- this._clientProvider?.RequestFile(guid, FileType.Config);
- }
- void IEEMSBaseServerProvider.Started()
- {
- Task.Factory.StartNew(() =>
- {
- MessageBox.Show($"Service Started {this.Server.IP}:{this.Server.Port}");
- });
- }
- void IEEMSBaseServerProvider.OnConnected(string ip, ushort port, ServiceHub serviceHub)
- {
- ServiceEndpoint serviceEndpoint = new()
- {
- IP = ip,
- Port = port,
- Hub = serviceHub
- };
- App.Current.Dispatcher?.Invoke(() =>
- {
- Clients[$"{ip}{port}{serviceHub}"] = serviceEndpoint;
- });
- }
- public void OnDisConnected(string ip, ushort port, ServiceHub serviceHub)
- {
- App.Current.Dispatcher?.Invoke(() =>
- {
- Clients.TryRemove($"{ip}{port}{serviceHub}", out _);
- });
- }
- [ObservableProperty]
- ObservableDictionary<string, ServiceEndpoint> _Clients = [];
- }
- public partial class ServiceEndpoint : ObservableObject
- {
- [ObservableProperty]
- private string? _IP;
- [ObservableProperty]
- private ushort _Port;
- [ObservableProperty]
- private ServiceHub _Hub;
- }
|