Merge branch 'main' of https://git.azuze.fr/kawa/Sharepoint-Toolbox
This commit is contained in:
@@ -8,6 +8,7 @@ using Microsoft.Win32;
|
||||
using SharepointToolbox.Core.Models;
|
||||
using SharepointToolbox.Localization;
|
||||
using SharepointToolbox.Services;
|
||||
using SharepointToolbox.Services.Export;
|
||||
|
||||
namespace SharepointToolbox.ViewModels.Tabs;
|
||||
|
||||
@@ -15,6 +16,8 @@ public partial class VersionCleanupViewModel : FeatureViewModelBase
|
||||
{
|
||||
private readonly IVersionCleanupService _versionService;
|
||||
private readonly ISessionManager _sessionManager;
|
||||
private readonly VersionCleanupHtmlExportService _htmlExportService;
|
||||
private readonly IBrandingService _brandingService;
|
||||
private readonly ILogger<FeatureViewModelBase> _logger;
|
||||
private TenantProfile? _currentProfile;
|
||||
|
||||
@@ -50,20 +53,26 @@ public partial class VersionCleanupViewModel : FeatureViewModelBase
|
||||
public IAsyncRelayCommand SelectLibrariesCommand { get; }
|
||||
public IRelayCommand ClearLibrariesCommand { get; }
|
||||
public IAsyncRelayCommand ExportCsvCommand { get; }
|
||||
public IAsyncRelayCommand ExportHtmlCommand { get; }
|
||||
|
||||
public VersionCleanupViewModel(
|
||||
IVersionCleanupService versionService,
|
||||
ISessionManager sessionManager,
|
||||
VersionCleanupHtmlExportService htmlExportService,
|
||||
IBrandingService brandingService,
|
||||
ILogger<FeatureViewModelBase> logger)
|
||||
: base(logger)
|
||||
{
|
||||
_versionService = versionService;
|
||||
_sessionManager = sessionManager;
|
||||
_htmlExportService = htmlExportService;
|
||||
_brandingService = brandingService;
|
||||
_logger = logger;
|
||||
|
||||
SelectLibrariesCommand = new AsyncRelayCommand(SelectLibrariesAsync, CanPickLibraries);
|
||||
ClearLibrariesCommand = new RelayCommand(ClearLibraries);
|
||||
ExportCsvCommand = new AsyncRelayCommand(ExportCsvAsync, () => Results.Count > 0);
|
||||
ExportHtmlCommand = new AsyncRelayCommand(ExportHtmlAsync, () => Results.Count > 0);
|
||||
|
||||
SelectedLibraries.CollectionChanged += (_, _) => UpdateSelectedLibrariesLabel();
|
||||
Results.CollectionChanged += (_, _) =>
|
||||
@@ -73,6 +82,7 @@ public partial class VersionCleanupViewModel : FeatureViewModelBase
|
||||
OnPropertyChanged(nameof(TotalVersionsDeleted));
|
||||
OnPropertyChanged(nameof(TotalFilesAffected));
|
||||
ExportCsvCommand.NotifyCanExecuteChanged();
|
||||
ExportHtmlCommand.NotifyCanExecuteChanged();
|
||||
};
|
||||
UpdateSelectedLibrariesLabel();
|
||||
}
|
||||
@@ -212,8 +222,7 @@ public partial class VersionCleanupViewModel : FeatureViewModelBase
|
||||
r.BytesFreed,
|
||||
Csv(r.Error ?? string.Empty)));
|
||||
}
|
||||
try { Process.Start(new ProcessStartInfo(dialog.FileName) { UseShellExecute = true }); }
|
||||
catch { }
|
||||
OpenFile(dialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -222,6 +231,39 @@ public partial class VersionCleanupViewModel : FeatureViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ExportHtmlAsync()
|
||||
{
|
||||
if (Results.Count == 0) return;
|
||||
var dialog = new SaveFileDialog
|
||||
{
|
||||
Title = "Export version cleanup results to HTML",
|
||||
Filter = "HTML files (*.html)|*.html|All files (*.*)|*.*",
|
||||
DefaultExt = "html",
|
||||
FileName = "version_cleanup",
|
||||
};
|
||||
if (dialog.ShowDialog() != true) return;
|
||||
try
|
||||
{
|
||||
var mspLogo = await _brandingService.GetMspLogoAsync();
|
||||
var clientLogo = _currentProfile?.ClientLogo;
|
||||
var branding = new ReportBranding(mspLogo, clientLogo);
|
||||
|
||||
await _htmlExportService.WriteAsync(Results, dialog.FileName, CancellationToken.None, branding);
|
||||
OpenFile(dialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StatusMessage = $"Export failed: {ex.Message}";
|
||||
_logger.LogError(ex, "Version cleanup HTML export failed.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void OpenFile(string filePath)
|
||||
{
|
||||
try { Process.Start(new ProcessStartInfo(filePath) { UseShellExecute = true }); }
|
||||
catch { }
|
||||
}
|
||||
|
||||
private static string Csv(string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) return string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user