Update diagnostics NTFS ensure actions
This commit is contained in:
@@ -283,6 +283,7 @@
|
|||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<TextBlock Text="Folder Path" Grid.Row="0" Grid.Column="0" Margin="0,0,8,8" VerticalAlignment="Center"/>
|
<TextBlock Text="Folder Path" Grid.Row="0" Grid.Column="0" Margin="0,0,8,8" VerticalAlignment="Center"/>
|
||||||
@@ -299,7 +300,8 @@
|
|||||||
|
|
||||||
<CheckBox x:Name="NtfsEnsureTraverseCheckBox" Grid.Row="4" Grid.Column="1" Margin="0,0,0,8" Content="Ensure traverse groups and ACLs on parent path"/>
|
<CheckBox x:Name="NtfsEnsureTraverseCheckBox" Grid.Row="4" Grid.Column="1" Margin="0,0,0,8" Content="Ensure traverse groups and ACLs on parent path"/>
|
||||||
|
|
||||||
<Button x:Name="ExecuteNtfsEnsureButton" Grid.Row="5" Grid.Column="1" Width="220" HorizontalAlignment="Right" Content="Ensure Missing Groups / ACLs" Click="ExecuteNtfsEnsureButton_Click"/>
|
<Button x:Name="ExecuteNtfsEnsureButton" Grid.Row="5" Grid.Column="1" Width="220" HorizontalAlignment="Right" Margin="0,0,0,8" Content="Ensure Missing Groups / ACLs" Click="ExecuteNtfsEnsureButton_Click"/>
|
||||||
|
<Button x:Name="ExecuteNtfsTraverseOnlyButton" Grid.Row="6" Grid.Column="1" Width="220" HorizontalAlignment="Right" Content="Ensure Traverse Only" Click="ExecuteNtfsTraverseOnlyButton_Click"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
</TabControl>
|
</TabControl>
|
||||||
|
|||||||
@@ -584,7 +584,7 @@ namespace LiamWorkflowDiagnostics
|
|||||||
|
|
||||||
if (runWhatIf && result.AutomaticEnsurePreview != null && result.AutomaticEnsurePreview.Count > 0)
|
if (runWhatIf && result.AutomaticEnsurePreview != null && result.AutomaticEnsurePreview.Count > 0)
|
||||||
{
|
{
|
||||||
AppendLog($"EnsureNtfsPermissionGroups wurde nur simuliert fuer {result.AutomaticEnsurePreview.Count} Ordner. Details stehen im Result-JSON.", LogLevels.Warning);
|
AppendLog($"Automatisches NTFS-Ensure wurde nur simuliert fuer {result.AutomaticEnsurePreview.Count} DataAreas. Details stehen im Result-JSON.", LogLevels.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
AppendLog($"DataAreas erhalten: {result.DataAreas.Count}");
|
AppendLog($"DataAreas erhalten: {result.DataAreas.Count}");
|
||||||
@@ -617,35 +617,21 @@ namespace LiamWorkflowDiagnostics
|
|||||||
|
|
||||||
await ExecuteProviderActionAsync("NTFS Folder Create", async () =>
|
await ExecuteProviderActionAsync("NTFS Folder Create", async () =>
|
||||||
{
|
{
|
||||||
var result = await Task.Run(() => LiamWorkflowRuntime.CreateDataAreaAsync(
|
var result = await RunWithWorkflowWhatIfAsync(provider, () => Task.Run(() => LiamWorkflowRuntime.CreateDataAreaAsync(
|
||||||
provider,
|
provider,
|
||||||
folderPath,
|
folderPath,
|
||||||
parentPath,
|
parentPath,
|
||||||
null,
|
null,
|
||||||
ownerSids,
|
ownerSids,
|
||||||
readerSids,
|
readerSids,
|
||||||
writerSids));
|
writerSids)));
|
||||||
|
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
result.Success,
|
result.Success,
|
||||||
ResultToken = MapResultToken(result.ResultToken)
|
ResultToken = MapResultToken(result.ResultToken)
|
||||||
};
|
};
|
||||||
}, () =>
|
}, actionHandlesWhatIf: true);
|
||||||
{
|
|
||||||
return CreateWhatIfResult(
|
|
||||||
"NTFS Folder Create",
|
|
||||||
"Wuerde einen Ordner anlegen und fehlende Gruppen sowie ACLs sicherstellen. Es wurden keine Aenderungen ausgefuehrt.",
|
|
||||||
new
|
|
||||||
{
|
|
||||||
ProviderRootPath = provider.RootPath,
|
|
||||||
NewFolderPath = folderPath,
|
|
||||||
ParentFolderPath = parentPath,
|
|
||||||
OwnerSids = ownerSids,
|
|
||||||
ReaderSids = readerSids,
|
|
||||||
WriterSids = writerSids
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -667,35 +653,21 @@ namespace LiamWorkflowDiagnostics
|
|||||||
|
|
||||||
await ExecuteProviderActionAsync("NTFS Ensure Groups / ACLs", async () =>
|
await ExecuteProviderActionAsync("NTFS Ensure Groups / ACLs", async () =>
|
||||||
{
|
{
|
||||||
var result = await Task.Run(() => LiamWorkflowRuntime.EnsureNtfsPermissionGroupsAsync(
|
var result = await RunWithWorkflowWhatIfAsync(provider, () => Task.Run(() => LiamWorkflowRuntime.EnsureNtfsPermissionGroupsAsync(
|
||||||
provider,
|
provider,
|
||||||
folderPath,
|
folderPath,
|
||||||
null,
|
null,
|
||||||
ownerSids,
|
ownerSids,
|
||||||
readerSids,
|
readerSids,
|
||||||
writerSids,
|
writerSids,
|
||||||
ensureTraverse));
|
ensureTraverse)));
|
||||||
|
|
||||||
return new
|
return new
|
||||||
{
|
{
|
||||||
result.Success,
|
result.Success,
|
||||||
ResultToken = MapResultToken(result.ResultToken)
|
ResultToken = MapResultToken(result.ResultToken)
|
||||||
};
|
};
|
||||||
}, () =>
|
}, actionHandlesWhatIf: true);
|
||||||
{
|
|
||||||
return CreateWhatIfResult(
|
|
||||||
"NTFS Ensure Groups / ACLs",
|
|
||||||
"Wuerde fehlende NTFS-Berechtigungsgruppen und ACLs additiv sicherstellen. Es wurden keine Aenderungen ausgefuehrt.",
|
|
||||||
new
|
|
||||||
{
|
|
||||||
ProviderRootPath = provider.RootPath,
|
|
||||||
FolderPath = folderPath,
|
|
||||||
OwnerSids = ownerSids,
|
|
||||||
ReaderSids = readerSids,
|
|
||||||
WriterSids = writerSids,
|
|
||||||
EnsureTraverseGroups = ensureTraverse
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -704,6 +676,34 @@ namespace LiamWorkflowDiagnostics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void ExecuteNtfsTraverseOnlyButton_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var provider = EnsureInitializedProvider<cLiamProviderNtfs>("NTFS");
|
||||||
|
var folderPath = GetRequiredText(NtfsEnsureFolderPathTextBox.Text, "Folder Path");
|
||||||
|
|
||||||
|
await ExecuteProviderActionAsync("NTFS Ensure Traverse Only", async () =>
|
||||||
|
{
|
||||||
|
var token = await Task.Run(() => provider.EnsureTraverseGroupsAsync(
|
||||||
|
folderPath,
|
||||||
|
null,
|
||||||
|
IsWhatIfEnabled));
|
||||||
|
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
Success = token != null && token.resultErrorId == 0,
|
||||||
|
ResultToken = MapResultToken(token)
|
||||||
|
};
|
||||||
|
}, actionHandlesWhatIf: true);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
AppendLog($"NTFS Ensure Traverse Only fehlgeschlagen: {ex.Message}", LogLevels.Error);
|
||||||
|
MessageBox.Show(this, ex.ToString(), "NTFS Ensure Traverse Only", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async void ExecuteAdCreateButton_Click(object sender, RoutedEventArgs e)
|
private async void ExecuteAdCreateButton_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -950,7 +950,7 @@ namespace LiamWorkflowDiagnostics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ExecuteProviderActionAsync(string actionName, Func<Task<object>> action, Func<object> whatIfAction = null)
|
private async Task ExecuteProviderActionAsync(string actionName, Func<Task<object>> action, Func<object> whatIfAction = null, bool actionHandlesWhatIf = false)
|
||||||
{
|
{
|
||||||
if (action == null)
|
if (action == null)
|
||||||
throw new ArgumentNullException(nameof(action));
|
throw new ArgumentNullException(nameof(action));
|
||||||
@@ -959,11 +959,11 @@ namespace LiamWorkflowDiagnostics
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
SaveSettings();
|
SaveSettings();
|
||||||
var runInWhatIfMode = IsWhatIfEnabled && whatIfAction != null;
|
var runInWhatIfMode = IsWhatIfEnabled && (whatIfAction != null || actionHandlesWhatIf);
|
||||||
AppendLog(runInWhatIfMode
|
AppendLog(runInWhatIfMode
|
||||||
? $"{actionName} im WhatIf-Modus gestartet. Schreibende Aenderungen werden nur simuliert."
|
? $"{actionName} im WhatIf-Modus gestartet. Schreibende Aenderungen werden nur simuliert."
|
||||||
: $"{actionName} gestartet.");
|
: $"{actionName} gestartet.");
|
||||||
var result = runInWhatIfMode
|
var result = runInWhatIfMode && whatIfAction != null
|
||||||
? await Task.Run(whatIfAction)
|
? await Task.Run(whatIfAction)
|
||||||
: await action();
|
: await action();
|
||||||
ResultTextBox.Text = JsonConvert.SerializeObject(result, Formatting.Indented);
|
ResultTextBox.Text = JsonConvert.SerializeObject(result, Formatting.Indented);
|
||||||
@@ -985,6 +985,39 @@ namespace LiamWorkflowDiagnostics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<TResult> RunWithWorkflowWhatIfAsync<TResult>(cLiamProviderBase provider, Func<Task<TResult>> action)
|
||||||
|
{
|
||||||
|
if (provider == null)
|
||||||
|
throw new ArgumentNullException(nameof(provider));
|
||||||
|
if (action == null)
|
||||||
|
throw new ArgumentNullException(nameof(action));
|
||||||
|
|
||||||
|
if (!IsWhatIfEnabled)
|
||||||
|
return await action();
|
||||||
|
|
||||||
|
var additionalConfiguration = provider.AdditionalConfiguration;
|
||||||
|
if (additionalConfiguration == null)
|
||||||
|
{
|
||||||
|
additionalConfiguration = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
provider.AdditionalConfiguration = additionalConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hadWhatIf = additionalConfiguration.TryGetValue("WhatIf", out var previousWhatIf);
|
||||||
|
additionalConfiguration["WhatIf"] = "1";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await action();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (hadWhatIf)
|
||||||
|
additionalConfiguration["WhatIf"] = previousWhatIf;
|
||||||
|
else
|
||||||
|
additionalConfiguration.Remove("WhatIf");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetSuccessFlag(object instance, out bool success)
|
private bool TryGetSuccessFlag(object instance, out bool success)
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user