Add export of NuGet package asset versions to csv file

This commit is contained in:
Florian Hopfner 2024-01-29 18:57:52 +01:00
Родитель 0b228c2b2d
Коммит d5a082879c
1 изменённых файлов: 45 добавлений и 1 удалений

Просмотреть файл

@ -21,6 +21,7 @@ using Xceed.Words.NET;
using static LCS.NativeMethods;
using System.Globalization;
using LCS.AssetLibrary;
using AutoMapper;
namespace LCS.Forms
{
@ -2556,7 +2557,50 @@ namespace LCS.Forms
private void nuGetPackagesToolStripMenuItem_Click(object sender, EventArgs e)
{
_httpClientHelper.GetSharedAssetList(AssetFileType.NuGetPackage);
var assets = _httpClientHelper.GetSharedAssetList(AssetFileType.NuGetPackage);
// for each asset in 50 latest assets
// get the asset versions
// compile all versions into one list that includes the asset name
// sort the list by asset name and version
var assetVersionsForExportList = new List<AssetVersionForExport>();
var config = new MapperConfiguration(cfg => cfg.CreateMap<AssetVersion, AssetVersionForExport>());
var mapper = config.CreateMapper();
assets
.Take(2)
.ToList()
.ForEach(asset =>
{
var assetVersions = _httpClientHelper.GetSharedAssetVersionList(asset.ParentAssetId);
assetVersionsForExportList.AddRange(assetVersions
.Select(assetVersion => mapper.Map<AssetVersionForExport>(assetVersion))
.Select(assetVersionForExport =>
{
assetVersionForExport.AssetName = asset.Name;
return assetVersionForExport;
}));
});
SaveFileDialog saveFile = new()
{
FileName = "D365FO NuGet Packages.csv",
Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*"
};
if (saveFile.ShowDialog() == DialogResult.OK)
{
try
{
using StreamWriter sw = new(saveFile.FileName, false, Encoding.Unicode);
var csv = new CsvWriter(sw, CultureInfo.CurrentCulture);
csv.WriteRecords(assetVersionsForExportList);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}