Skip to content

Commit

Permalink
added global only flag for PersistentVariableService
Browse files Browse the repository at this point in the history
- related to #27
  • Loading branch information
fbarresi committed Mar 3, 2023
1 parent 68f4c02 commit 5cf8c20
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
14 changes: 13 additions & 1 deletion TwinCatAdsTool.Gui/ViewModels/BackupViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class BackupViewModel : ViewModelBase
private readonly Subject<JObject> variableSubject = new Subject<JObject>();
private string backupText;
private ObservableAsPropertyHelper<string> currentTaskHelper;
private bool globalOnly;

public BackupViewModel(IClientService clientService, IPersistentVariableService persistentVariableService)
{
Expand All @@ -41,6 +42,17 @@ public string BackupText
}
}

public bool GlobalOnly
{
get => globalOnly;
set
{
if (value == globalOnly) return;
globalOnly = value;
raisePropertyChanged();
}
}

public ReactiveCommand<Unit, Unit> Read { get; set; }
public ReactiveCommand<Unit, Unit> Save { get; set; }

Expand Down Expand Up @@ -69,7 +81,7 @@ private async Task<Unit> ReadVariables()
{
var persistentVariables = await persistentVariableService.ReadGlobalPersistentVariables(
clientService.Client,
clientService.TreeViewSymbols);
clientService.TreeViewSymbols, globalOnly);
variableSubject.OnNext(persistentVariables);
Logger.Debug(Resources.ReadPersistentVariables);

Expand Down
14 changes: 13 additions & 1 deletion TwinCatAdsTool.Gui/ViewModels/CompareViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class CompareViewModel : ViewModelBase
private IEnumerable<ListBoxItem> rightBoxText;
private string sourceLeft;
private string sourceRight;
private bool globalOnly = true;

public CompareViewModel(IClientService clientService, IPersistentVariableService persistentVariableService)
{
Expand Down Expand Up @@ -269,9 +270,20 @@ private Task LoadJsonRight()
return Task.FromResult(Unit.Default);
}

public bool GlobalOnly
{
get => globalOnly;
set
{
if (value == globalOnly) return;
globalOnly = value;
raisePropertyChanged();
}
}

private async Task<JObject> ReadVariables()
{
var persistentVariables = await persistentVariableService.ReadGlobalPersistentVariables(clientService.Client, clientService.TreeViewSymbols);
var persistentVariables = await persistentVariableService.ReadGlobalPersistentVariables(clientService.Client, clientService.TreeViewSymbols, globalOnly);

Logger.Debug(Resources.ReadPersistentVariables);
return persistentVariables;
Expand Down
2 changes: 2 additions & 0 deletions TwinCatAdsTool.Gui/Views/BackupView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
>
</Button>

<CheckBox Margin="16" IsChecked="{Binding GlobalOnly}">global only</CheckBox>

<Label Margin="24,16,0,16" Content="{Binding CurrentTask}"/>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace TwinCatAdsTool.Interfaces.Services
{
public interface IPersistentVariableService
{
Task<JObject> ReadGlobalPersistentVariables(AdsClient client, IInstanceCollection<ISymbol> symbols);
Task<JObject> ReadGlobalPersistentVariables(AdsClient client, IInstanceCollection<ISymbol> symbols,
bool globalOnly);
IObservable<string> CurrentTask { get; }
}
}
6 changes: 4 additions & 2 deletions TwinCatAdsTool.Logic/Services/PersistentVariableService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ public class PersistentVariableService : IPersistentVariableService
{
private readonly ILog logger =LoggerFactory.GetLogger();
private readonly Subject<string> currentTaskSubject = new Subject<string>();
public async Task<JObject> ReadGlobalPersistentVariables(AdsClient client, IInstanceCollection<ISymbol> symbols)
public async Task<JObject> ReadGlobalPersistentVariables(AdsClient client, IInstanceCollection<ISymbol> symbols,
bool globalOnly)
{
var jobj = new JObject();
try
{
if (client.IsConnected)
{
var iterator = new SymbolIterator(symbols,
s => s.IsPersistent && s.InstancePath.Split('.').Length >= 2 &&
s => s.IsPersistent &&
(globalOnly ? s.InstancePath.Split('.').Length == 2 : s.InstancePath.Split('.').Length >= 2) &&
!s.InstancePath.Contains("["))
;

Expand Down

0 comments on commit 5cf8c20

Please sign in to comment.