|
@@ -1,8 +1,10 @@
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
+using EEMSClientCore;
|
|
using EEMSUIClient.Models;
|
|
using EEMSUIClient.Models;
|
|
using EEMSUIClient.Services;
|
|
using EEMSUIClient.Services;
|
|
using GeneralData;
|
|
using GeneralData;
|
|
|
|
+using Microsoft.Win32;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
@@ -13,8 +15,9 @@ public partial class MainWindowViewModel : ObservableObject
|
|
{
|
|
{
|
|
private readonly IClientService _clientService;
|
|
private readonly IClientService _clientService;
|
|
|
|
|
|
- private readonly string _ipAddressFilePath = $"{Environment.CurrentDirectory}/IpAddressInformation.json";
|
|
|
|
- private readonly string _deviceInfoFilePath = $"{Environment.CurrentDirectory}/DeviceInformation.json";
|
|
|
|
|
|
+ private readonly string _settingsFolder = $"{Environment.CurrentDirectory}/Settings";
|
|
|
|
+ private readonly string _ipAddressFileName = "IpAddressInformation.json";
|
|
|
|
+ private readonly string _deviceInfoFileName = "DeviceInformation.json";
|
|
private bool _isInitialized = false;
|
|
private bool _isInitialized = false;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
@@ -31,6 +34,12 @@ public partial class MainWindowViewModel : ObservableObject
|
|
private bool _isConnected;
|
|
private bool _isConnected;
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
|
|
+ private string _selectedRecipeDict=string.Empty;
|
|
|
|
+
|
|
|
|
+ [ObservableProperty]
|
|
|
|
+ private string _selectedConfigDict = string.Empty;
|
|
|
|
+
|
|
|
|
+ [ObservableProperty]
|
|
private string[] _deviceModels = Enum.GetNames(typeof(DeviceModel));
|
|
private string[] _deviceModels = Enum.GetNames(typeof(DeviceModel));
|
|
|
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
@@ -60,13 +69,43 @@ public partial class MainWindowViewModel : ObservableObject
|
|
public MainWindowViewModel(IClientService clientService)
|
|
public MainWindowViewModel(IClientService clientService)
|
|
{
|
|
{
|
|
_clientService = clientService;
|
|
_clientService = clientService;
|
|
- InitializeIpAddress();
|
|
|
|
- InitializeDeviceInfo();
|
|
|
|
|
|
+
|
|
|
|
+ Initialize();
|
|
}
|
|
}
|
|
|
|
|
|
public bool IsNotConnected => !IsConnected;
|
|
public bool IsNotConnected => !IsConnected;
|
|
|
|
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
|
|
+ private void SelectRecipe()
|
|
|
|
+ {
|
|
|
|
+ var dialog = new OpenFolderDialog()
|
|
|
|
+ {
|
|
|
|
+ Title = "Select Folder"
|
|
|
|
+ };
|
|
|
|
+ if (dialog.ShowDialog() == true)
|
|
|
|
+ {
|
|
|
|
+ SelectedRecipeDict = dialog.FolderName;
|
|
|
|
+ var service = (IClientBaseProvider)_clientService;
|
|
|
|
+ service.RecipePath = SelectedRecipeDict;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [RelayCommand]
|
|
|
|
+ private void SelectConfig()
|
|
|
|
+ {
|
|
|
|
+ var dialog = new OpenFolderDialog()
|
|
|
|
+ {
|
|
|
|
+ Title = "Select Folder"
|
|
|
|
+ };
|
|
|
|
+ if (dialog.ShowDialog() == true)
|
|
|
|
+ {
|
|
|
|
+ SelectedConfigDict = dialog.FolderName;
|
|
|
|
+ var service = (IClientBaseProvider)_clientService;
|
|
|
|
+ service.ConfigPath = SelectedConfigDict;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ [RelayCommand]
|
|
private void Connect()
|
|
private void Connect()
|
|
{
|
|
{
|
|
if (string.IsNullOrWhiteSpace(IpAddress) || string.IsNullOrWhiteSpace(Port) || string.IsNullOrWhiteSpace(HubName))
|
|
if (string.IsNullOrWhiteSpace(IpAddress) || string.IsNullOrWhiteSpace(Port) || string.IsNullOrWhiteSpace(HubName))
|
|
@@ -91,8 +130,9 @@ public partial class MainWindowViewModel : ObservableObject
|
|
Port=int.Parse(Port),
|
|
Port=int.Parse(Port),
|
|
HubName=HubName,
|
|
HubName=HubName,
|
|
};
|
|
};
|
|
|
|
+
|
|
string jsonString = JsonSerializer.Serialize(addressInfo);
|
|
string jsonString = JsonSerializer.Serialize(addressInfo);
|
|
- File.WriteAllText(_ipAddressFilePath, jsonString);
|
|
|
|
|
|
+ File.WriteAllText(Path.Combine(_settingsFolder, _ipAddressFileName), jsonString);
|
|
}
|
|
}
|
|
|
|
|
|
[RelayCommand]
|
|
[RelayCommand]
|
|
@@ -134,7 +174,7 @@ public partial class MainWindowViewModel : ObservableObject
|
|
MessageBox.Show("设备注册成功。");
|
|
MessageBox.Show("设备注册成功。");
|
|
|
|
|
|
var jsonString = JsonSerializer.Serialize(deviceInfo);
|
|
var jsonString = JsonSerializer.Serialize(deviceInfo);
|
|
- File.WriteAllText(_deviceInfoFilePath, jsonString);
|
|
|
|
|
|
+ File.WriteAllText(Path.Combine(_settingsFolder, _deviceInfoFileName), jsonString);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
@@ -142,53 +182,44 @@ public partial class MainWindowViewModel : ObservableObject
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void InitializeIpAddress()
|
|
|
|
|
|
+ private void Initialize()
|
|
{
|
|
{
|
|
- if (!Path.Exists(_ipAddressFilePath))
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- string jsonFromFile = File.ReadAllText(_ipAddressFilePath);
|
|
|
|
- var deserializedAddressInfo = JsonSerializer.Deserialize<AddressInfo>(jsonFromFile);
|
|
|
|
- if (deserializedAddressInfo is null)
|
|
|
|
|
|
+ if (!Directory.Exists(_settingsFolder))
|
|
{
|
|
{
|
|
- return;
|
|
|
|
|
|
+ Directory.CreateDirectory(_settingsFolder);
|
|
}
|
|
}
|
|
|
|
|
|
- IpAddress = deserializedAddressInfo.Ip;
|
|
|
|
- Port = deserializedAddressInfo.Port.ToString();
|
|
|
|
- HubName = deserializedAddressInfo.HubName;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void InitializeDeviceInfo()
|
|
|
|
- {
|
|
|
|
- if (!Path.Exists(_deviceInfoFilePath))
|
|
|
|
|
|
+ var ipAddressFilePath = Path.Combine(_settingsFolder, _ipAddressFileName);
|
|
|
|
+ if (Path.Exists(ipAddressFilePath))
|
|
{
|
|
{
|
|
- return;
|
|
|
|
|
|
+ string jsonFromFile = File.ReadAllText(ipAddressFilePath);
|
|
|
|
+ var deserializedAddressInfo = JsonSerializer.Deserialize<AddressInfo>(jsonFromFile);
|
|
|
|
+ if (deserializedAddressInfo is not null)
|
|
|
|
+ {
|
|
|
|
+ IpAddress = deserializedAddressInfo.Ip;
|
|
|
|
+ Port = deserializedAddressInfo.Port.ToString();
|
|
|
|
+ HubName = deserializedAddressInfo.HubName;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- string jsonFromFile = File.ReadAllText(_deviceInfoFilePath);
|
|
|
|
- var deserializedDeviceInfo = JsonSerializer.Deserialize<Models.DeviceInfo>(jsonFromFile);
|
|
|
|
- if (deserializedDeviceInfo is null)
|
|
|
|
|
|
+ var deviceInfoFilePath = Path.Combine(_settingsFolder, _deviceInfoFileName);
|
|
|
|
+ if (Path.Exists(deviceInfoFilePath))
|
|
{
|
|
{
|
|
- return;
|
|
|
|
|
|
+ string jsonFromFile = File.ReadAllText(deviceInfoFilePath);
|
|
|
|
+ var deserializedDeviceInfo = JsonSerializer.Deserialize<DeviceInfo>(jsonFromFile);
|
|
|
|
+ if (deserializedDeviceInfo is not null)
|
|
|
|
+ {
|
|
|
|
+ DeviceModelIndex = (int)deserializedDeviceInfo.DeviceModel!;
|
|
|
|
+ DeviceModel = deserializedDeviceInfo.DeviceModel.ToString() ?? string.Empty;
|
|
|
|
+ DeviceSubModel = deserializedDeviceInfo.DeviceSubModel ?? string.Empty;
|
|
|
|
+ DeviceName = deserializedDeviceInfo.DeviceName ?? string.Empty;
|
|
|
|
+ Position = deserializedDeviceInfo.Position ?? string.Empty;
|
|
|
|
+ SoftwareVersion = deserializedDeviceInfo.SoftwareVersion ?? string.Empty;
|
|
|
|
+ GuidStr = deserializedDeviceInfo.Guid.ToString() ?? string.Empty;
|
|
|
|
+ DBConnectionString = deserializedDeviceInfo.DBConnectionString ?? string.Empty;
|
|
|
|
+
|
|
|
|
+ _isInitialized = true;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
-
|
|
|
|
- DeviceModelIndex = (int)deserializedDeviceInfo.DeviceModel!;
|
|
|
|
- DeviceModel = deserializedDeviceInfo.DeviceModel.ToString() ?? string.Empty;
|
|
|
|
- DeviceSubModel = deserializedDeviceInfo.DeviceSubModel ?? string.Empty;
|
|
|
|
- DeviceName = deserializedDeviceInfo.DeviceName ?? string.Empty;
|
|
|
|
- Position = deserializedDeviceInfo.Position ?? string.Empty;
|
|
|
|
- SoftwareVersion = deserializedDeviceInfo.SoftwareVersion ?? string.Empty;
|
|
|
|
- GuidStr = deserializedDeviceInfo.Guid.ToString() ?? string.Empty;
|
|
|
|
- DBConnectionString = deserializedDeviceInfo.DBConnectionString ?? string.Empty;
|
|
|
|
-
|
|
|
|
- _isInitialized = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void OnRequestFileReceived(object? sender, (Guid guid, ServiceBase.FileType fileType) e)
|
|
|
|
- {
|
|
|
|
- //log
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|