begin application build overhaul

This commit is contained in:
Nathan
2025-12-17 15:34:34 -07:00
parent 5cc6060323
commit 610cdb62a8
23 changed files with 2379 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using UnifiedFarmLauncher.Models;
using UnifiedFarmLauncher.Services;
namespace UnifiedFarmLauncher.ViewModels
{
public class MainWindowViewModel : ViewModelBase
{
private readonly ConfigService _configService;
private WorkerConfig? _selectedWorker;
private string _statusText = "Ready";
private string _selectedWorkerType = "All";
public MainWindowViewModel()
{
_configService = new ConfigService();
Workers = new ObservableCollection<WorkerConfig>();
LoadWorkers();
}
public ObservableCollection<WorkerConfig> Workers { get; }
public WorkerConfig? SelectedWorker
{
get => _selectedWorker;
set
{
if (SetAndRaise(ref _selectedWorker, value))
{
UpdateStatusText();
}
}
}
public string StatusText
{
get => _statusText;
set => SetAndRaise(ref _statusText, value);
}
public string SelectedWorkerType
{
get => _selectedWorkerType;
set
{
if (SetAndRaise(ref _selectedWorkerType, value))
{
LoadWorkers();
}
}
}
public void LoadWorkers()
{
var config = _configService.Load();
Workers.Clear();
var workers = config.Workers;
if (SelectedWorkerType != "All")
{
workers = workers.Where(w =>
{
if (SelectedWorkerType == "SheepIt")
return w.WorkerTypes.SheepIt != null;
if (SelectedWorkerType == "Flamenco")
return w.WorkerTypes.Flamenco != null;
return true;
}).ToList();
}
foreach (var worker in workers)
{
Workers.Add(worker);
}
UpdateStatusText();
}
private void UpdateStatusText()
{
if (SelectedWorker == null)
{
StatusText = $"Total workers: {Workers.Count}";
}
else
{
StatusText = $"Selected: {SelectedWorker.Name} ({SelectedWorker.Ssh.Host}:{SelectedWorker.Ssh.Port})";
}
}
public void RefreshWorkers()
{
LoadWorkers();
}
}
}

View File

@@ -0,0 +1,26 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace UnifiedFarmLauncher.ViewModels
{
public class ViewModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
protected bool SetAndRaise<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (Equals(field, value))
return false;
field = value;
OnPropertyChanged(propertyName);
return true;
}
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -0,0 +1,204 @@
using System.Collections.ObjectModel;
using System.Linq;
using UnifiedFarmLauncher.Models;
using UnifiedFarmLauncher.Services;
namespace UnifiedFarmLauncher.ViewModels
{
public class WorkerEditViewModel : ViewModelBase
{
private readonly ConfigService _configService;
private readonly bool _isNew;
private int _id;
private string _name = string.Empty;
private bool _enabled = true;
private string _sshHost = string.Empty;
private int _sshPort = 22;
private string _sshArgs = string.Empty;
private string _sheepItGpu = "OPTIX_0";
private string _sheepItUsername = string.Empty;
private string _sheepItRenderKey = string.Empty;
private string _flamencoWorkerPath = string.Empty;
private bool _hasSheepIt;
private bool _hasFlamenco;
public WorkerEditViewModel(ConfigService configService, WorkerConfig? worker = null)
{
_configService = configService;
_isNew = worker == null;
NetworkDrives = new ObservableCollection<string>();
NetworkPaths = new ObservableCollection<string>();
if (worker != null)
{
LoadWorker(worker);
}
else
{
_id = _configService.GetNextWorkerId();
}
}
public int Id
{
get => _id;
set => SetAndRaise(ref _id, value);
}
public string Name
{
get => _name;
set => SetAndRaise(ref _name, value);
}
public bool Enabled
{
get => _enabled;
set => SetAndRaise(ref _enabled, value);
}
public string SshHost
{
get => _sshHost;
set => SetAndRaise(ref _sshHost, value);
}
public int SshPort
{
get => _sshPort;
set => SetAndRaise(ref _sshPort, value);
}
public string SshArgs
{
get => _sshArgs;
set => SetAndRaise(ref _sshArgs, value);
}
public bool HasSheepIt
{
get => _hasSheepIt;
set => SetAndRaise(ref _hasSheepIt, value);
}
public bool HasFlamenco
{
get => _hasFlamenco;
set => SetAndRaise(ref _hasFlamenco, value);
}
public string SheepItGpu
{
get => _sheepItGpu;
set => SetAndRaise(ref _sheepItGpu, value);
}
public string SheepItUsername
{
get => _sheepItUsername;
set => SetAndRaise(ref _sheepItUsername, value);
}
public string SheepItRenderKey
{
get => _sheepItRenderKey;
set => SetAndRaise(ref _sheepItRenderKey, value);
}
public string FlamencoWorkerPath
{
get => _flamencoWorkerPath;
set => SetAndRaise(ref _flamencoWorkerPath, value);
}
public ObservableCollection<string> NetworkDrives { get; }
public ObservableCollection<string> NetworkPaths { get; }
private void LoadWorker(WorkerConfig worker)
{
Id = worker.Id;
Name = worker.Name;
Enabled = worker.Enabled;
SshHost = worker.Ssh.Host;
SshPort = worker.Ssh.Port;
SshArgs = worker.Ssh.Args;
if (worker.WorkerTypes.SheepIt != null)
{
HasSheepIt = true;
SheepItGpu = worker.WorkerTypes.SheepIt.Gpu;
SheepItUsername = worker.WorkerTypes.SheepIt.Username;
SheepItRenderKey = worker.WorkerTypes.SheepIt.RenderKey;
}
if (worker.WorkerTypes.Flamenco != null)
{
HasFlamenco = true;
FlamencoWorkerPath = worker.WorkerTypes.Flamenco.WorkerPath;
NetworkDrives.Clear();
foreach (var drive in worker.WorkerTypes.Flamenco.NetworkDrives)
{
NetworkDrives.Add(drive);
}
NetworkPaths.Clear();
foreach (var path in worker.WorkerTypes.Flamenco.NetworkPaths)
{
NetworkPaths.Add(path);
}
}
}
public WorkerConfig ToWorkerConfig()
{
var worker = new WorkerConfig
{
Id = Id,
Name = Name,
Enabled = Enabled,
Ssh = new SshConfig
{
Host = SshHost,
Port = SshPort,
Args = SshArgs
},
WorkerTypes = new WorkerTypeConfig()
};
if (HasSheepIt)
{
worker.WorkerTypes.SheepIt = new SheepItConfig
{
Gpu = SheepItGpu,
Username = SheepItUsername,
RenderKey = SheepItRenderKey
};
}
if (HasFlamenco)
{
worker.WorkerTypes.Flamenco = new FlamencoConfig
{
WorkerPath = FlamencoWorkerPath,
NetworkDrives = NetworkDrives.ToList(),
NetworkPaths = NetworkPaths.ToList()
};
}
return worker;
}
public void Save()
{
var worker = ToWorkerConfig();
if (_isNew)
{
_configService.AddWorker(worker);
}
else
{
_configService.UpdateWorker(worker);
}
}
}
}