Skip to content

Commit

Permalink
fix: added null check for DownloadsCount, e.g. made the counter nulla…
Browse files Browse the repository at this point in the history
…ble, this closes #137
  • Loading branch information
iadonkey committed Aug 2, 2024
1 parent 0d136ed commit 783adbe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion TwinpackShared/Models/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public CatalogItemGetResponse(CatalogItemGetResponse obj)
public string DisplayName { get; set; }

[JsonPropertyName("downloads")]
public int Downloads { get; set; }
public int? Downloads { get; set; }
[JsonPropertyName("created")]
public string Created { get; set; }
[JsonPropertyName("modified")]
Expand Down
20 changes: 10 additions & 10 deletions TwinpackShared/Protocol/Nuget/NugetServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ public virtual async Task<Tuple<IEnumerable<CatalogItemGetResponse>, bool>> GetC
PackageId = null,
Name = x.Identity.Id,
DistributorName = x.Authors,
// Description = x.Description, Beckhoff's descriptions are meh
Description = x.Description,
IconUrl = x.IconUrl?.ToString() ?? IconUrl,
RuntimeLicense = 1,
DisplayName = x.Identity.Id,
Downloads = (int)x.DownloadCount,
Created = x.Published?.ToString(),
Modified = x.Published?.ToString()
Downloads = x.DownloadCount.HasValue && x.DownloadCount.Value > 0 ? ((int?)x.DownloadCount.Value) : null,
Created = x.Published?.ToString() ?? "Unknown",
Modified = x.Published?.ToString() ?? "Unknown"
}).ToList(),
results.Any());
}
Expand Down Expand Up @@ -165,7 +165,7 @@ public async Task<Tuple<IEnumerable<PackageVersionGetResponse>, bool>> GetPackag
Title = EvaluateTitle(x),
DistributorName = x.Authors,
DisplayName = x.Identity.Id,
// Description = x.Description,
Description = x.Description,
Entitlement = null,
ProjectUrl = x.ProjectUrl?.ToString(),
IconUrl = x.IconUrl?.ToString() ?? IconUrl,
Expand Down Expand Up @@ -328,10 +328,10 @@ public virtual async Task<PackageVersionGetResponse> GetPackageVersionAsync(PlcL
IPackageSearchMetadata x = library.Version == null ? packages.FirstOrDefault() : packages.FirstOrDefault(p => p.Identity.Version.Version.ToString() == library.Version);

if (x == null)
throw new Exceptions.LibraryNotFoundException(library.Name, library.Version, $"Package {library.Name} (version: {library.Version}, distributor: {library.DistributorName}) not found!");
throw new Exceptions.LibraryNotFoundException(library.Name, library.Version, $"Package {library.Name} {library.Version} (distributor: {library.DistributorName}) not found!");

if (!x.Tags?.ToLower().Contains("library") == true && !x.Tags?.ToLower().Contains("plc-library") == true)
throw new Exceptions.LibraryFileInvalidException($"Package {library.Name} (version: {library.Version}, distributor: {library.DistributorName}) does not have a 'plc-library' or 'library' tag!");
throw new Exceptions.LibraryFileInvalidException($"Package {library.Name} {library.Version} (distributor: {library.DistributorName}) does not have a 'plc-library' or 'library' tag!");

var dependencyPackages = x.DependencySets?.SelectMany(p => p.Packages).ToList() ?? new List<PackageDependency>();
List<PackageVersionGetResponse> dependencies = new List<PackageVersionGetResponse>();
Expand Down Expand Up @@ -359,7 +359,7 @@ public virtual async Task<PackageVersionGetResponse> GetPackageVersionAsync(PlcL
Title = EvaluateTitle(dependency),
DistributorName = x.Authors,
DisplayName = dependency.Identity.Id,
// Description = dependency.Description,
Description = dependency.Description,
Entitlement = null,
ProjectUrl = dependency.ProjectUrl?.ToString(),
IconUrl = dependency.IconUrl?.ToString() ?? IconUrl,
Expand Down Expand Up @@ -393,7 +393,7 @@ public virtual async Task<PackageVersionGetResponse> GetPackageVersionAsync(PlcL
Title = EvaluateTitle(x),
DistributorName = x.Authors,
DisplayName = x.Identity.Id,
// Description = x.Description,
Description = x.Description,
Entitlement = null,
ProjectUrl = x.ProjectUrl?.ToString(),
IconUrl = x.IconUrl?.ToString() ?? IconUrl,
Expand Down Expand Up @@ -445,7 +445,7 @@ public async Task<PackageGetResponse> GetPackageAsync(string distributorName, st
Title = EvaluateTitle(x),
DistributorName = x.Authors,
DisplayName = x.Identity.Id,
// Description = x.Description,
Description = x.Description,
Entitlement = null,
ProjectUrl = x.ProjectUrl?.ToString(),
IconUrl = x.IconUrl?.ToString() ?? IconUrl,
Expand Down
7 changes: 6 additions & 1 deletion TwinpackVsixShared/Dialogs/CatalogWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@
<fa:ImageAwesome Margin="0 0 0 0" Foreground="{DynamicResource {x:Static platform:EnvironmentColors.ToolboxContentTextBrushKey}}" Icon="IdCard" Height="14" d:Visibility="Visible" Visibility="{Binding HasRuntimeLicense, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<Run Text="{Binding DisplayName}" FontWeight="SemiBold" FontSize="16"/>
<Run Text="by"/>
<Run Text="{Binding DistributorName}"/><Run Text=","/>
<Run Text="{Binding DistributorName}"/>
</TextBlock>
<TextBlock VerticalAlignment="Bottom"
d:Visibility="Visible"
Visibility="{Binding Downloads, Converter={StaticResource NullToVisibilityConverter}}">
<Run Text=","/>
<Run Text="{Binding Downloads}" d:Text="10" FontWeight="DemiBold"/>
<Run Text="downloads"/>
</TextBlock>
Expand Down

0 comments on commit 783adbe

Please sign in to comment.