Skip to content

Commit

Permalink
Merge pull request #88 from FH-Inway/shared-asset-library
Browse files Browse the repository at this point in the history
Export list of NuGet packages from shared asset library and fix export of user list issue
  • Loading branch information
FH-Inway authored Feb 25, 2024
2 parents 702db98 + 7e7a9c7 commit 3be7396
Show file tree
Hide file tree
Showing 12 changed files with 4,028 additions and 1,592 deletions.
3 changes: 2 additions & 1 deletion 2LCS/2LCS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<LangVersion>8.0</LangVersion>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>
Expand Down Expand Up @@ -82,6 +82,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="CsvHelper">
<Version>30.0.1</Version>
</PackageReference>
Expand Down
229 changes: 229 additions & 0 deletions 2LCS/AssetLibrary/AssetLibrarySearch.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 92 additions & 0 deletions 2LCS/AssetLibrary/AssetLibrarySearch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using AutoMapper;
using CsvHelper;
using LCS.JsonObjects;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LCS.AssetLibrary;

public partial class AssetLibrarySearch : Form
{
private HttpClientHelper _httpClientHelper;

internal AssetLibrarySearch(HttpClientHelper httpClientHelper)
{
InitializeComponent();
_httpClientHelper = httpClientHelper;
}

private void AssetLibrarySearch_Load(object sender, EventArgs e)
{
assetsCreatedAfter.Value = DateTime.Now.AddMonths(-6);
assetsCreatedBefore.Value = DateTime.Now;
}

private void search_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;

var assets = _httpClientHelper.GetSharedAssetList(AssetFileType.NuGetPackage);

var assetVersionsForExportList = new List<AssetVersionForExport>();

var config = new MapperConfiguration(
cfg => cfg.CreateMap<AssetVersion, AssetVersionForExport>());
var mapper = config.CreateMapper();

// linear with progress, only assets in date range
assetExportProgress.Maximum = assets.Count;
assetExportProgress.Value = 0;
foreach (var asset in assets)
{
assetExportProgress.Value++;
assetExportProgressNumberOfMax.Text = $"{assetExportProgress.Value} of {assetExportProgress.Maximum}";
assetExportProgressAssetName.Text = asset.Name;
var assetVersions = _httpClientHelper.GetSharedAssetVersionList(asset.ParentAssetId)
.Where(assetVersion => assetVersion.CreatedDate >= assetsCreatedAfter.Value
&& assetVersion.CreatedDate <= assetsCreatedBefore.Value);
if (assetVersions.Any() == false)
{
break;
}
assetVersionsForExportList.AddRange(assetVersions
.Select(assetVersion =>
{
var fileDescription = assetVersion.FileDescription.Split('\n').Last();
assetVersion.ApplicationOrPlatformVersion = fileDescription;
return mapper.Map<AssetVersionForExport>(assetVersion);
}));
; }

Cursor.Current = Cursors.Default;
assetExportProgress.Value = 0;
assetExportProgressNumberOfMax.Text = string.Empty;
assetExportProgressAssetName.Text = string.Empty;

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);
}
}
}
}
Loading

0 comments on commit 3be7396

Please sign in to comment.