chore: release v2.4
- Add theme system (Dark/Light palettes, ModernTheme, ThemeManager) - Add InputDialog, Spinner common view - Add DuplicatesCsvExportService - Refresh views, dialogs, and view models across tabs - Update localization strings (en/fr) - Tweak services (transfer, permissions, search, user access, ownership elevation, bulk operations) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using SharepointToolbox.Core.Models;
|
||||
using SharepointToolbox.Localization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
@@ -10,12 +11,18 @@ namespace SharepointToolbox.Services.Export;
|
||||
/// </summary>
|
||||
public class StorageCsvExportService
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds a single-section CSV: header row plus one row per
|
||||
/// <see cref="StorageNode"/> with library, site, file count, total size
|
||||
/// (MB), version size (MB), and last-modified date.
|
||||
/// </summary>
|
||||
public string BuildCsv(IReadOnlyList<StorageNode> nodes)
|
||||
{
|
||||
var T = TranslationSource.Instance;
|
||||
var sb = new StringBuilder();
|
||||
|
||||
// Header
|
||||
sb.AppendLine("Library,Site,Files,Total Size (MB),Version Size (MB),Last Modified");
|
||||
sb.AppendLine($"{T["report.col.library"]},{T["report.col.site"]},{T["report.stat.files"]},{T["report.col.total_size_mb"]},{T["report.col.version_size_mb"]},{T["report.col.last_modified"]}");
|
||||
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
@@ -33,10 +40,11 @@ public class StorageCsvExportService
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>Writes the library-level CSV to <paramref name="filePath"/> with UTF-8 BOM.</summary>
|
||||
public async Task WriteAsync(IReadOnlyList<StorageNode> nodes, string filePath, CancellationToken ct)
|
||||
{
|
||||
var csv = BuildCsv(nodes);
|
||||
await File.WriteAllTextAsync(filePath, csv, new UTF8Encoding(encoderShouldEmitUTF8Identifier: true), ct);
|
||||
await ExportFileWriter.WriteCsvAsync(filePath, csv, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -44,10 +52,11 @@ public class StorageCsvExportService
|
||||
/// </summary>
|
||||
public string BuildCsv(IReadOnlyList<StorageNode> nodes, IReadOnlyList<FileTypeMetric> fileTypeMetrics)
|
||||
{
|
||||
var T = TranslationSource.Instance;
|
||||
var sb = new StringBuilder();
|
||||
|
||||
// Library details
|
||||
sb.AppendLine("Library,Site,Files,Total Size (MB),Version Size (MB),Last Modified");
|
||||
sb.AppendLine($"{T["report.col.library"]},{T["report.col.site"]},{T["report.stat.files"]},{T["report.col.total_size_mb"]},{T["report.col.version_size_mb"]},{T["report.col.last_modified"]}");
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
sb.AppendLine(string.Join(",",
|
||||
@@ -65,10 +74,10 @@ public class StorageCsvExportService
|
||||
if (fileTypeMetrics.Count > 0)
|
||||
{
|
||||
sb.AppendLine();
|
||||
sb.AppendLine("File Type,Size (MB),File Count");
|
||||
sb.AppendLine($"{T["report.col.file_type"]},{T["report.col.size_mb"]},{T["report.col.file_count"]}");
|
||||
foreach (var m in fileTypeMetrics)
|
||||
{
|
||||
string label = string.IsNullOrEmpty(m.Extension) ? "(no extension)" : m.Extension;
|
||||
string label = string.IsNullOrEmpty(m.Extension) ? T["report.text.no_extension"] : m.Extension;
|
||||
sb.AppendLine(string.Join(",", Csv(label), FormatMb(m.TotalSizeBytes), m.FileCount.ToString()));
|
||||
}
|
||||
}
|
||||
@@ -76,10 +85,55 @@ public class StorageCsvExportService
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>Writes the two-section CSV (libraries + file-type breakdown) with UTF-8 BOM.</summary>
|
||||
public async Task WriteAsync(IReadOnlyList<StorageNode> nodes, IReadOnlyList<FileTypeMetric> fileTypeMetrics, string filePath, CancellationToken ct)
|
||||
{
|
||||
var csv = BuildCsv(nodes, fileTypeMetrics);
|
||||
await File.WriteAllTextAsync(filePath, csv, new UTF8Encoding(encoderShouldEmitUTF8Identifier: true), ct);
|
||||
await ExportFileWriter.WriteCsvAsync(filePath, csv, ct);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes storage metrics with optional per-site partitioning.
|
||||
/// Single → one file. BySite → one file per SiteTitle. File-type metrics
|
||||
/// are replicated across all partitions because the tenant-level scan
|
||||
/// does not retain per-site breakdowns.
|
||||
/// </summary>
|
||||
public Task WriteAsync(
|
||||
IReadOnlyList<StorageNode> nodes,
|
||||
IReadOnlyList<FileTypeMetric> fileTypeMetrics,
|
||||
string basePath,
|
||||
ReportSplitMode splitMode,
|
||||
CancellationToken ct)
|
||||
=> ReportSplitHelper.WritePartitionedAsync(
|
||||
nodes, basePath, splitMode,
|
||||
PartitionBySite,
|
||||
(part, path, c) => WriteAsync(part, fileTypeMetrics, path, c),
|
||||
ct);
|
||||
|
||||
/// <summary>
|
||||
/// Splits the flat StorageNode list into per-site slices while preserving
|
||||
/// the DFS hierarchy (each root library followed by its indented descendants).
|
||||
/// Siblings sharing a SiteTitle roll up into the same partition.
|
||||
/// </summary>
|
||||
internal static IEnumerable<(string Label, IReadOnlyList<StorageNode> Partition)> PartitionBySite(
|
||||
IReadOnlyList<StorageNode> nodes)
|
||||
{
|
||||
var buckets = new Dictionary<string, List<StorageNode>>(StringComparer.OrdinalIgnoreCase);
|
||||
string currentSite = string.Empty;
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
if (node.IndentLevel == 0)
|
||||
currentSite = string.IsNullOrWhiteSpace(node.SiteTitle)
|
||||
? ReportSplitHelper.DeriveSiteLabel(node.Url)
|
||||
: node.SiteTitle;
|
||||
if (!buckets.TryGetValue(currentSite, out var list))
|
||||
{
|
||||
list = new List<StorageNode>();
|
||||
buckets[currentSite] = list;
|
||||
}
|
||||
list.Add(node);
|
||||
}
|
||||
return buckets.Select(kv => (kv.Key, (IReadOnlyList<StorageNode>)kv.Value));
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
@@ -87,12 +141,6 @@ public class StorageCsvExportService
|
||||
private static string FormatMb(long bytes)
|
||||
=> (bytes / (1024.0 * 1024.0)).ToString("F2");
|
||||
|
||||
/// <summary>RFC 4180 CSV field quoting.</summary>
|
||||
private static string Csv(string value)
|
||||
{
|
||||
if (string.IsNullOrEmpty(value)) return string.Empty;
|
||||
if (value.Contains(',') || value.Contains('"') || value.Contains('\n'))
|
||||
return $"\"{value.Replace("\"", "\"\"")}\"";
|
||||
return value;
|
||||
}
|
||||
/// <summary>RFC 4180 CSV field quoting with formula-injection guard.</summary>
|
||||
private static string Csv(string value) => CsvSanitizer.EscapeMinimal(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user