Files
Nebula-Auth/NebulaAuth/ViewModel/MainVM_MAAC.cs
T
Давид Чернопятов 9016f96b6a Prepared for 1.5.3 Release.
- Code clean-ups
- Added "Copy File" support in mafile context menu
- Added hotkeys support to "Copy Login" and "Copy File" commands
- Added experimental feature "Ignore Patch Tuesday errors"
- Added MAAC batch control
- Added SessionID client-side generation in MafileSerializer to support mafiles without SessionID (especially from SDA)
- SplashScreen.png was slightly enhanced
2024-10-28 00:14:44 +02:00

177 lines
4.9 KiB
C#

using System.Collections.Generic;
using System.Linq;
using CommunityToolkit.Mvvm.Input;
using NebulaAuth.Core;
using NebulaAuth.Model;
using NebulaAuth.Model.Entities;
using NebulaAuth.Model.MAAC;
namespace NebulaAuth.ViewModel;
public partial class MainVM //MAAC
{
public bool MaacDisplay
{
get => _maacDisplay;
set
{
if (SetProperty(ref _maacDisplay, value))
{
SwitchMAACDisplay(value);
}
}
}
private bool _maacDisplay;
public bool MarketTimerEnabled
{
get => SelectedMafile?.LinkedClient?.AutoConfirmMarket ?? false;
set => SetMarketTimer(value);
}
public bool TradeTimerEnabled
{
get => SelectedMafile?.LinkedClient?.AutoConfirmTrades ?? false;
set => SetTradeTimer(value);
}
public int TimerCheckSeconds
{
get => Settings.Instance.TimerSeconds;
set => SetTimer(value);
}
private void SetMarketTimer(bool value)
{
var selectedMafile = SelectedMafile;
if (selectedMafile == null) return;
if (value && selectedMafile.LinkedClient == null)
{
MultiAccountAutoConfirmer.TryAddToConfirm(selectedMafile);
}
if (!value && selectedMafile is { LinkedClient.AutoConfirmTrades: false })
{
MultiAccountAutoConfirmer.RemoveFromConfirm(selectedMafile);
}
if (selectedMafile.LinkedClient != null)
{
selectedMafile.LinkedClient.AutoConfirmMarket = value;
}
}
private void SetTradeTimer(bool value)
{
var selectedMafile = SelectedMafile;
if (selectedMafile == null) return;
if (value && selectedMafile.LinkedClient == null)
{
MultiAccountAutoConfirmer.TryAddToConfirm(selectedMafile);
}
if (!value && selectedMafile is { LinkedClient.AutoConfirmMarket: false })
{
MultiAccountAutoConfirmer.RemoveFromConfirm(selectedMafile);
}
if (selectedMafile.LinkedClient != null)
{
selectedMafile.LinkedClient.AutoConfirmTrades = value;
}
}
private void SetTimer(int value)
{
var timerCheckSeconds = Settings.TimerSeconds;
if (timerCheckSeconds == value) return;
if (timerCheckSeconds < 10)
{
timerCheckSeconds = 10; //Guard
}
if (value < 10)
{
value = timerCheckSeconds;
SnackbarController.SendSnackbar(GetLocalization("TimerTooFast"));
}
Settings.TimerSeconds = value;
OnPropertyChanged(nameof(TimerCheckSeconds));
if (timerCheckSeconds != TimerCheckSeconds)
SnackbarController.SendSnackbar(GetLocalization("TimerChanged"));
}
[RelayCommand]
private void SwitchMAAC(bool market)
{
var maf = SelectedMafile;
if (maf == null) return;
SwitchMAACOn([maf], market);
}
[RelayCommand]
private void SwitchMAACOnGroup(bool market)
{
var group = SelectedGroup;
if(group == null) return;
var mafilesInGroup = MaFiles.Where(m => group.Equals(m.Group));
SwitchMAACOn(mafilesInGroup, market);
}
[RelayCommand]
private void SwitchMAACOnAll(bool market)
{
SwitchMAACOn(MaFiles, market);
}
private void SwitchMAACOn(IEnumerable<Mafile> mafiles, bool market)
{
mafiles = mafiles.ToArray();
var turnOn = mafiles.All(m => m.LinkedClient == null || GetCurrentMode(m.LinkedClient) == false);
if (turnOn)
{
foreach (var mafile in mafiles)
{
MultiAccountAutoConfirmer.TryAddToConfirm(mafile);
SetCurrentMode(mafile.LinkedClient, turnOn);
}
}
else
{
foreach (var mafile in mafiles)
{
SetCurrentMode(mafile.LinkedClient, turnOn);
if(PretendsToRemove(mafile))
MultiAccountAutoConfirmer.RemoveFromConfirm(mafile);
}
}
return;
bool PretendsToRemove(Mafile mafile) => mafile.LinkedClient is {AutoConfirmMarket: false, AutoConfirmTrades: false};
bool GetCurrentMode(PortableMaClient linkedClient) => market ? linkedClient.AutoConfirmMarket : linkedClient.AutoConfirmTrades;
void SetCurrentMode(PortableMaClient? linkedClient, bool value)
{
if (linkedClient == null) return;
if (market)
{
linkedClient.AutoConfirmMarket = value;
}
else
{
linkedClient.AutoConfirmTrades = value;
}
}
}
private void SwitchMAACDisplay(bool newValue)
{
if (newValue)
{
MaFiles = MultiAccountAutoConfirmer.Clients;
}
else
{
PerformQuery();
}
}
}