Update diagnostics NTFS ensure actions
This commit is contained in:
@@ -584,7 +584,7 @@ namespace LiamWorkflowDiagnostics
|
||||
|
||||
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}");
|
||||
@@ -617,35 +617,21 @@ namespace LiamWorkflowDiagnostics
|
||||
|
||||
await ExecuteProviderActionAsync("NTFS Folder Create", async () =>
|
||||
{
|
||||
var result = await Task.Run(() => LiamWorkflowRuntime.CreateDataAreaAsync(
|
||||
provider,
|
||||
folderPath,
|
||||
parentPath,
|
||||
null,
|
||||
ownerSids,
|
||||
readerSids,
|
||||
writerSids));
|
||||
var result = await RunWithWorkflowWhatIfAsync(provider, () => Task.Run(() => LiamWorkflowRuntime.CreateDataAreaAsync(
|
||||
provider,
|
||||
folderPath,
|
||||
parentPath,
|
||||
null,
|
||||
ownerSids,
|
||||
readerSids,
|
||||
writerSids)));
|
||||
|
||||
return new
|
||||
{
|
||||
result.Success,
|
||||
ResultToken = MapResultToken(result.ResultToken)
|
||||
};
|
||||
}, () =>
|
||||
{
|
||||
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
|
||||
});
|
||||
});
|
||||
}, actionHandlesWhatIf: true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -667,35 +653,21 @@ namespace LiamWorkflowDiagnostics
|
||||
|
||||
await ExecuteProviderActionAsync("NTFS Ensure Groups / ACLs", async () =>
|
||||
{
|
||||
var result = await Task.Run(() => LiamWorkflowRuntime.EnsureNtfsPermissionGroupsAsync(
|
||||
provider,
|
||||
folderPath,
|
||||
null,
|
||||
ownerSids,
|
||||
readerSids,
|
||||
writerSids,
|
||||
ensureTraverse));
|
||||
var result = await RunWithWorkflowWhatIfAsync(provider, () => Task.Run(() => LiamWorkflowRuntime.EnsureNtfsPermissionGroupsAsync(
|
||||
provider,
|
||||
folderPath,
|
||||
null,
|
||||
ownerSids,
|
||||
readerSids,
|
||||
writerSids,
|
||||
ensureTraverse)));
|
||||
|
||||
return new
|
||||
{
|
||||
result.Success,
|
||||
ResultToken = MapResultToken(result.ResultToken)
|
||||
};
|
||||
}, () =>
|
||||
{
|
||||
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
|
||||
});
|
||||
});
|
||||
}, actionHandlesWhatIf: true);
|
||||
}
|
||||
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)
|
||||
{
|
||||
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)
|
||||
throw new ArgumentNullException(nameof(action));
|
||||
@@ -959,11 +959,11 @@ namespace LiamWorkflowDiagnostics
|
||||
try
|
||||
{
|
||||
SaveSettings();
|
||||
var runInWhatIfMode = IsWhatIfEnabled && whatIfAction != null;
|
||||
var runInWhatIfMode = IsWhatIfEnabled && (whatIfAction != null || actionHandlesWhatIf);
|
||||
AppendLog(runInWhatIfMode
|
||||
? $"{actionName} im WhatIf-Modus gestartet. Schreibende Aenderungen werden nur simuliert."
|
||||
: $"{actionName} gestartet.");
|
||||
var result = runInWhatIfMode
|
||||
var result = runInWhatIfMode && whatIfAction != null
|
||||
? await Task.Run(whatIfAction)
|
||||
: await action();
|
||||
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)
|
||||
{
|
||||
success = false;
|
||||
|
||||
Reference in New Issue
Block a user