Skip to content

Commit

Permalink
Update vault ui on change
Browse files Browse the repository at this point in the history
  • Loading branch information
Triky313 committed Apr 20, 2022
1 parent 2f2225c commit 2f9de3f
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/StatisticsAnalysisTool/Network/Manager/VaultController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ public class VaultController
private VaultInfo _currentVaultInfo;
private readonly List<DiscoveredItem> _discoveredItems = new();
private readonly List<ItemContainerObject> _vaultContainer = new();
private ObservableCollection<Vault> _vaults = new();
private ObservableCollection<Vault> _vault = new();

private ObservableCollection<Vault> Vaults
{
get => _vault;
set
{
_vault = value;
OnVaultsChange?.Invoke();
}
}

public VaultController(TrackingController trackingController, MainWindowViewModel mainWindowViewModel)
{
Expand Down Expand Up @@ -94,11 +104,11 @@ private void ParseVault()
return;
}

var removableVaultInfo = _vaults.FirstOrDefault(x => x.Location == _currentVaultInfo.Location);
var removableVaultInfo = Vaults.FirstOrDefault(x => x.Location == _currentVaultInfo.Location);

if (removableVaultInfo != null)
{
_vaults.Remove(removableVaultInfo);
Vaults.Remove(removableVaultInfo);
}

var vault = new Vault()
Expand All @@ -124,7 +134,7 @@ private void ParseVault()
vault.VaultContainer.Add(vaultContainer);
}

_vaults.Add(vault);
Vaults.Add(vault);
OnVaultsChange?.Invoke();
}
catch (Exception e)
Expand Down Expand Up @@ -177,7 +187,7 @@ private void UpdateUi()
Application.Current.Dispatcher.Invoke(() =>
{
var unknownVaultSelection = new Vault() { Location = "UNKNOWN" };
var list = _vaults.ToList();
var list = Vaults.ToList();
list.Insert(0, unknownVaultSelection);

_mainWindowViewModel.VaultBindings.Vaults = list;
Expand All @@ -199,19 +209,19 @@ public void LoadFromFile()
{
var localFileString = File.ReadAllText(localFilePath, Encoding.UTF8);
var vaults = JsonSerializer.Deserialize<List<Vault>>(localFileString) ?? new List<Vault>();
_vaults = new ObservableCollection<Vault>(vaults);
Vaults = new ObservableCollection<Vault>(vaults);
return;
}
catch (Exception e)
{
ConsoleManager.WriteLineForError(MethodBase.GetCurrentMethod()?.DeclaringType, e);
Log.Error(MethodBase.GetCurrentMethod()?.DeclaringType, e);
_vaults = new ObservableCollection<Vault>();
Vaults = new ObservableCollection<Vault>();
return;
}
}

_vaults = new ObservableCollection<Vault>();
Vaults = new ObservableCollection<Vault>();
}

public void SaveInFile()
Expand All @@ -220,7 +230,7 @@ public void SaveInFile()

try
{
var fileString = JsonSerializer.Serialize(_vaults);
var fileString = JsonSerializer.Serialize(Vaults);
File.WriteAllText(localFilePath, fileString, Encoding.UTF8);
}
catch (Exception e)
Expand Down

0 comments on commit 2f9de3f

Please sign in to comment.