Skip to content

Commit dd71e21

Browse files
authored
Fix parsing platform tag from CloudSmith package (#309)
***NO_CI***
1 parent d1ecdb3 commit dd71e21

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

nanoFirmwareFlasher.Library/CloudSmithPackageDetails.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using System;
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
25
using System.Collections.Generic;
36
using System.Linq;
47
using System.Text;
@@ -20,5 +23,10 @@ public class CloudSmithPackageDetail
2023
/// Package version.
2124
/// </summary>
2225
public string Version { get; set; }
26+
27+
/// <summary>
28+
/// Platform code
29+
/// </summary>
30+
public string Platform { get; set; }
2331
}
2432
}

nanoFirmwareFlasher.Library/FirmwareArchiveManager.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public async Task<ExitCodes> DownloadFirmwareFromRepository(
187187
{
188188
IsPreview = preview,
189189
Name = remoteTarget.Name,
190-
Platform = platform.ToString(),
190+
Platform = remoteTarget.Platform ?? platform?.ToString(),
191191
Version = remoteTarget.Version,
192192
};
193193
File.WriteAllText(
@@ -209,11 +209,6 @@ public async Task<ExitCodes> DownloadFirmwareFromRepository(
209209
/// </summary>
210210
private sealed class PersistedPackageInformation : CloudSmithPackageDetail
211211
{
212-
/// <summary>
213-
/// Platform code
214-
/// </summary>
215-
public string Platform { get; set; }
216-
217212
/// <summary>
218213
/// Indicates whether this is a preview
219214
/// </summary>

nanoFirmwareFlasher.Library/FirmwarePackage.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public abstract class FirmwarePackage : IDisposable
3838
".nanoFramework",
3939
"fw_cache");
4040
private static readonly AsyncLocal<string> s_locationPathBase = new();
41+
private static readonly HashSet<string> s_supportedPlatforms = new HashSet<string>(Enum.GetNames(typeof(SupportedPlatform)), StringComparer.OrdinalIgnoreCase);
4142

4243
/// <summary>
4344
/// Path with the base location for firmware packages.
@@ -197,11 +198,32 @@ public static List<CloudSmithPackageDetail> GetTargetList(
197198
return targetPackages;
198199
}
199200

200-
targetPackages = JsonConvert.DeserializeObject<List<CloudSmithPackageDetail>>(responseBody);
201-
201+
List<CloudSmithPackageDetailJson> deserializedPackages = JsonConvert.DeserializeObject<List<CloudSmithPackageDetailJson>>(responseBody);
202+
targetPackages.AddRange(from p in deserializedPackages
203+
select new CloudSmithPackageDetail()
204+
{
205+
Name = p.Name,
206+
Version = p.Version,
207+
Platform = p.Tags?.Info is null
208+
? null
209+
: (from t in p.Tags.Info
210+
where s_supportedPlatforms.Contains(t)
211+
select t).FirstOrDefault(),
212+
});
202213
return targetPackages;
203214
}
204215

216+
private sealed class CloudSmithPackageDetailJson : CloudSmithPackageDetail
217+
{
218+
public CloudSmithPackageDetailTagsJson Tags { get; set; }
219+
220+
public sealed class CloudSmithPackageDetailTagsJson
221+
{
222+
public List<string> Info { get; set; }
223+
}
224+
}
225+
226+
205227
/// <summary>
206228
/// Download the firmware zip, extract this zip file, and get the firmware parts
207229
/// </summary>

0 commit comments

Comments
 (0)