Skip to content

Commit b9b1546

Browse files
authored
Fixing icons project (#2516)
* Fixing icons project * Fixing warnings * Fixing NRE warnings
1 parent 5f22a5d commit b9b1546

File tree

5 files changed

+63
-62
lines changed

5 files changed

+63
-62
lines changed

MaterialDesignToolkit.Full.sln

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
3232
Directory.Build.props = Directory.Build.props
3333
Directory.packages.props = Directory.packages.props
3434
global.json = global.json
35-
.github\workflows\icon_update.yml = .github\workflows\icon_update.yml
3635
MaterialDesignColors.nuspec = MaterialDesignColors.nuspec
3736
MaterialDesignThemes.MahApps.nuspec = MaterialDesignThemes.MahApps.nuspec
3837
MaterialDesignThemes.nuspec = MaterialDesignThemes.nuspec
39-
.github\workflows\nightly_release.yml = .github\workflows\nightly_release.yml
40-
.github\workflows\pr_verification.yml = .github\workflows\pr_verification.yml
4138
README.md = README.md
42-
.github\workflows\release.yml = .github\workflows\release.yml
4339
EndProjectSection
4440
EndProject
4541
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialDesignThemes.UITests", "MaterialDesignThemes.UITests\MaterialDesignThemes.UITests.csproj", "{594D2254-3623-4088-A8BD-D74B6E96DE9F}"
@@ -51,6 +47,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{9E303A4A
5147
EndProject
5248
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "mdresgen", "mdresgen\mdresgen.csproj", "{59CE50AC-D176-4CC0-B465-26F66054A15E}"
5349
EndProject
50+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{18401177-A30E-4330-8F6B-101DF876CE99}"
51+
ProjectSection(SolutionItems) = preProject
52+
.github\workflows\icon_update.yml = .github\workflows\icon_update.yml
53+
.github\workflows\nightly_release.yml = .github\workflows\nightly_release.yml
54+
.github\workflows\pr_verification.yml = .github\workflows\pr_verification.yml
55+
.github\workflows\release.yml = .github\workflows\release.yml
56+
EndProjectSection
57+
EndProject
5458
Global
5559
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5660
Debug|Any CPU = Debug|Any CPU
@@ -215,6 +219,7 @@ Global
215219
{CF0A27A8-EF82-44E5-B673-ECCC150C48ED} = {D34BE232-DE51-43C1-ABDC-B69003BB50FF}
216220
{803954E5-3A35-4D8B-95A7-F6E9B63EC0DF} = {D34BE232-DE51-43C1-ABDC-B69003BB50FF}
217221
{59CE50AC-D176-4CC0-B465-26F66054A15E} = {9E303A4A-3712-44B9-91EE-830FDC087795}
222+
{18401177-A30E-4330-8F6B-101DF876CE99} = {55087897-5F09-45CA-8E12-12B36B45F262}
218223
EndGlobalSection
219224
GlobalSection(ExtensibilityGlobals) = postSolution
220225
SolutionGuid = {730B2F9E-74AE-46CE-9E61-89AA5C6D5DD3}

mdresgen/IconThing.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.IO;
44
using System.Linq;
55
using System.Net;
6+
using System.Net.Http;
7+
using System.Threading.Tasks;
68
using Humanizer;
79
using Microsoft.CodeAnalysis;
810
using Microsoft.CodeAnalysis.CSharp;
@@ -14,11 +16,13 @@ namespace mdresgen
1416
{
1517
static class IconThing
1618
{
17-
public static void Run()
19+
private static HttpClient Client { get; } = new();
20+
21+
public static async Task RunAsync()
1822
{
1923
Console.WriteLine("Downloading icon data...");
2024

21-
var nameDataPairs = GetIcons(GetSourceData()).ToList();
25+
var nameDataPairs = GetIcons(await GetSourceDataAsync()).ToList();
2226
Console.WriteLine("Items: " + nameDataPairs.Count);
2327

2428
//var nameDataPairs = GetNameDataPairs("TEST").ToList();
@@ -50,31 +54,22 @@ private static void Write(string content, string filePath)
5054
Console.WriteLine($"WARNING: Failed to find '{filePath}'");
5155
}
5256

53-
private static string GetSourceData()
57+
private static async Task<string> GetSourceDataAsync()
5458
{
55-
var webClient = new WebClient();
56-
57-
webClient.Credentials = CredentialCache.DefaultCredentials;
58-
if (webClient.Proxy != null)
59-
webClient.Proxy.Credentials = CredentialCache.DefaultCredentials;
60-
61-
var iconData =
62-
webClient.DownloadString(
59+
return await Client.GetStringAsync(
6360
"https://materialdesignicons.com/api/package/38EF63D0-4744-11E4-B3CF-842B2B6CFE1B");
64-
65-
return iconData;
6661
}
6762

6863
private static IEnumerable<Icon> GetIcons(string sourceData)
6964
{
7065
var jObject = JObject.Parse(sourceData);
7166
var icons = new[] { new Icon("None", string.Empty, new List<string>()) } //Add None value always to Enum at first place
7267
.Concat(
73-
jObject["icons"].Select(t => new Icon(
68+
jObject["icons"]?.Select(t => new Icon(
7469
t["name"]?.ToString().Underscore().Pascalize() ?? throw new Exception("Failed to find name"),
7570
t["data"]?.ToString() ?? throw new Exception("Failed to find data"),
76-
t["aliases"]?.ToObject<IEnumerable<string>>().Select(x => x.Underscore().Pascalize()).ToList()
77-
?? throw new Exception("Failed to find aliases")))
71+
t["aliases"]?.ToObject<IEnumerable<string>>()?.Select(x => x.Underscore().Pascalize()).ToList()
72+
?? throw new Exception("Failed to find aliases"))) ?? throw new Exception("failed to find icons")
7873
);
7974

8075
var iconsByName = new Dictionary<string, Icon>(StringComparer.OrdinalIgnoreCase);

mdresgen/MdPaletteJson.json

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
11
{
2-
shades: ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900", "A100", "A200", "A400", "A700"],
3-
palettes: [
2+
"shades": ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900", "A100", "A200", "A400", "A700"],
3+
"palettes": [
44
{
55
"name": "Red",
66
"hexes": [ "#FFEBEE", "#FFCDD2", "#EF9A9A", "#E57373", "#EF5350", "#F44336", "#E53935", "#D32F2F", "#C62828", "#B71C1C", "#FF8A80", "#FF5252", "#FF1744", "#D50000" ]
77
},
88
{
9-
name: "Pink",
10-
hexes: [ "#FCE4EC", "#F8BBD0", "#F48FB1", "#F06292", "#EC407A", "#E91E63", "#D81B60", "#C2185B", "#AD1457", "#880E4F", "#FF80AB", "#FF4081", "#F50057", "#C51162" ]
9+
"name": "Pink",
10+
"hexes": [ "#FCE4EC", "#F8BBD0", "#F48FB1", "#F06292", "#EC407A", "#E91E63", "#D81B60", "#C2185B", "#AD1457", "#880E4F", "#FF80AB", "#FF4081", "#F50057", "#C51162" ]
1111
},
1212
{
13-
name: "Purple",
14-
hexes: [ "#F3E5F5", "#E1BEE7", "#CE93D8", "#BA68C8", "#AB47BC", "#9C27B0", "#8E24AA", "#7B1FA2", "#6A1B9A", "#4A148C", "#EA80FC", "#E040FB", "#D500F9", "#AA00FF" ]
13+
"name": "Purple",
14+
"hexes": [ "#F3E5F5", "#E1BEE7", "#CE93D8", "#BA68C8", "#AB47BC", "#9C27B0", "#8E24AA", "#7B1FA2", "#6A1B9A", "#4A148C", "#EA80FC", "#E040FB", "#D500F9", "#AA00FF" ]
1515
},
1616
{
17-
name: "Deep Purple",
18-
hexes: [ "#EDE7F6", "#D1C4E9", "#B39DDB", "#9575CD", "#7E57C2", "#673AB7", "#5E35B1", "#512DA8", "#4527A0", "#311B92", "#B388FF", "#7C4DFF", "#651FFF", "#6200EA" ]
17+
"name": "Deep Purple",
18+
"hexes": [ "#EDE7F6", "#D1C4E9", "#B39DDB", "#9575CD", "#7E57C2", "#673AB7", "#5E35B1", "#512DA8", "#4527A0", "#311B92", "#B388FF", "#7C4DFF", "#651FFF", "#6200EA" ]
1919
},
2020
{
21-
name: "Indigo",
22-
hexes: [ "#E8EAF6", "#C5CAE9", "#9FA8DA", "#7986CB", "#5C6BC0", "#3F51B5", "#3949AB", "#303F9F", "#283593", "#1A237E", "#8C9EFF", "#536DFE", "#3D5AFE", "#304FFE" ]
21+
"name": "Indigo",
22+
"hexes": [ "#E8EAF6", "#C5CAE9", "#9FA8DA", "#7986CB", "#5C6BC0", "#3F51B5", "#3949AB", "#303F9F", "#283593", "#1A237E", "#8C9EFF", "#536DFE", "#3D5AFE", "#304FFE" ]
2323
},
2424
{
25-
name: "Blue",
26-
hexes: [ "#E3F2FD", "#BBDEFB", "#90CAF9", "#64B5F6", "#42A5F5", "#2196F3", "#1E88E5", "#1976D2", "#1565C0", "#0D47A1", "#82B1FF", "#448AFF", "#2979FF", "#2962FF" ]
25+
"name": "Blue",
26+
"hexes": [ "#E3F2FD", "#BBDEFB", "#90CAF9", "#64B5F6", "#42A5F5", "#2196F3", "#1E88E5", "#1976D2", "#1565C0", "#0D47A1", "#82B1FF", "#448AFF", "#2979FF", "#2962FF" ]
2727
},
2828
{
29-
name: "Light Blue",
30-
hexes: [ "#E1F5FE", "#B3E5FC", "#81D4FA", "#4FC3F7", "#29B6F6", "#03A9F4", "#039BE5", "#0288D1", "#0277BD", "#01579B", "#80D8FF", "#40C4FF", "#00B0FF", "#0091EA" ]
29+
"name": "Light Blue",
30+
"hexes": [ "#E1F5FE", "#B3E5FC", "#81D4FA", "#4FC3F7", "#29B6F6", "#03A9F4", "#039BE5", "#0288D1", "#0277BD", "#01579B", "#80D8FF", "#40C4FF", "#00B0FF", "#0091EA" ]
3131
},
3232
{
33-
name: "Cyan",
34-
hexes: [ "#E0F7FA", "#B2EBF2", "#80DEEA", "#4DD0E1", "#26C6DA", "#00BCD4", "#00ACC1", "#0097A7", "#00838F", "#006064", "#84FFFF", "#18FFFF", "#00E5FF", "#00B8D4" ]
33+
"name": "Cyan",
34+
"hexes": [ "#E0F7FA", "#B2EBF2", "#80DEEA", "#4DD0E1", "#26C6DA", "#00BCD4", "#00ACC1", "#0097A7", "#00838F", "#006064", "#84FFFF", "#18FFFF", "#00E5FF", "#00B8D4" ]
3535
},
3636
{
37-
name: "Teal",
38-
hexes: [ "#E0F2F1", "#B2DFDB", "#80CBC4", "#4DB6AC", "#26A69A", "#009688", "#00897B", "#00796B", "#00695C", "#004D40", "#A7FFEB", "#64FFDA", "#1DE9B6", "#00BFA5" ]
37+
"name": "Teal",
38+
"hexes": [ "#E0F2F1", "#B2DFDB", "#80CBC4", "#4DB6AC", "#26A69A", "#009688", "#00897B", "#00796B", "#00695C", "#004D40", "#A7FFEB", "#64FFDA", "#1DE9B6", "#00BFA5" ]
3939
},
4040
{
41-
name: "Green",
42-
hexes: [ "#E8F5E9", "#C8E6C9", "#A5D6A7", "#81C784", "#66BB6A", "#4CAF50", "#43A047", "#388E3C", "#2E7D32", "#1B5E20", "#B9F6CA", "#69F0AE", "#00E676", "#00C853" ]
41+
"name": "Green",
42+
"hexes": [ "#E8F5E9", "#C8E6C9", "#A5D6A7", "#81C784", "#66BB6A", "#4CAF50", "#43A047", "#388E3C", "#2E7D32", "#1B5E20", "#B9F6CA", "#69F0AE", "#00E676", "#00C853" ]
4343
},
4444
{
45-
name: "Light Green",
46-
hexes: [ "#F1F8E9", "#DCEDC8", "#C5E1A5", "#AED581", "#9CCC65", "#8BC34A", "#7CB342", "#689F38", "#558B2F", "#33691E", "#CCFF90", "#B2FF59", "#76FF03", "#64DD17" ]
45+
"name": "Light Green",
46+
"hexes": [ "#F1F8E9", "#DCEDC8", "#C5E1A5", "#AED581", "#9CCC65", "#8BC34A", "#7CB342", "#689F38", "#558B2F", "#33691E", "#CCFF90", "#B2FF59", "#76FF03", "#64DD17" ]
4747
},
4848
{
49-
name: "Lime",
50-
hexes: [ "#F9FBE7", "#F0F4C3", "#E6EE9C", "#DCE775", "#D4E157", "#CDDC39", "#C0CA33", "#AFB42B", "#9E9D24", "#827717", "#F4FF81", "#EEFF41", "#C6FF00", "#AEEA00" ]
49+
"name": "Lime",
50+
"hexes": [ "#F9FBE7", "#F0F4C3", "#E6EE9C", "#DCE775", "#D4E157", "#CDDC39", "#C0CA33", "#AFB42B", "#9E9D24", "#827717", "#F4FF81", "#EEFF41", "#C6FF00", "#AEEA00" ]
5151
},
5252
{
53-
name: "Yellow",
54-
hexes: [ "#FFFDE7", "#FFF9C4", "#FFF59D", "#FFF176", "#FFEE58", "#FFEB3B", "#FDD835", "#FBC02D", "#F9A825", "#F57F17", "#FFFF8D", "#FFFF00", "#FFEA00", "#FFD600" ]
53+
"name": "Yellow",
54+
"hexes": [ "#FFFDE7", "#FFF9C4", "#FFF59D", "#FFF176", "#FFEE58", "#FFEB3B", "#FDD835", "#FBC02D", "#F9A825", "#F57F17", "#FFFF8D", "#FFFF00", "#FFEA00", "#FFD600" ]
5555
},
5656
{
57-
name: "Amber",
58-
hexes: [ "#FFF8E1", "#FFECB3", "#FFE082", "#FFD54F", "#FFCA28", "#FFC107", "#FFB300", "#FFA000", "#FF8F00", "#FF6F00", "#FFE57F", "#FFD740", "#FFC400", "#FFAB00" ]
57+
"name": "Amber",
58+
"hexes": [ "#FFF8E1", "#FFECB3", "#FFE082", "#FFD54F", "#FFCA28", "#FFC107", "#FFB300", "#FFA000", "#FF8F00", "#FF6F00", "#FFE57F", "#FFD740", "#FFC400", "#FFAB00" ]
5959
},
6060
{
61-
name: "Orange",
62-
hexes: [ "#FFF3E0", "#FFE0B2", "#FFCC80", "#FFB74D", "#FFA726", "#FF9800", "#FB8C00", "#F57C00", "#EF6C00", "#E65100", "#FFD180", "#FFAB40", "#FF9100", "#FF6D00" ]
61+
"name": "Orange",
62+
"hexes": [ "#FFF3E0", "#FFE0B2", "#FFCC80", "#FFB74D", "#FFA726", "#FF9800", "#FB8C00", "#F57C00", "#EF6C00", "#E65100", "#FFD180", "#FFAB40", "#FF9100", "#FF6D00" ]
6363
},
6464
{
65-
name: "Deep Orange",
66-
hexes: [ "#FBE9E7", "#FFCCBC", "#FFAB91", "#FF8A65", "#FF7043", "#FF5722", "#F4511E", "#E64A19", "#D84315", "#BF360C", "#FF9E80", "#FF6E40", "#FF3D00", "#DD2C00" ]
65+
"name": "Deep Orange",
66+
"hexes": [ "#FBE9E7", "#FFCCBC", "#FFAB91", "#FF8A65", "#FF7043", "#FF5722", "#F4511E", "#E64A19", "#D84315", "#BF360C", "#FF9E80", "#FF6E40", "#FF3D00", "#DD2C00" ]
6767
},
6868
{
69-
name: "Brown",
70-
hexes: [ "#EFEBE9", "#D7CCC8", "#BCAAA4", "#A1887F", "#8D6E63", "#795548", "#6D4C41", "#5D4037", "#4E342E", "#3E2723" ]
69+
"name": "Brown",
70+
"hexes": [ "#EFEBE9", "#D7CCC8", "#BCAAA4", "#A1887F", "#8D6E63", "#795548", "#6D4C41", "#5D4037", "#4E342E", "#3E2723" ]
7171
},
7272
{
73-
name: "Grey",
74-
hexes: [ "#FAFAFA", "#F5F5F5", "#EEEEEE", "#E0E0E0", "#BDBDBD", "#9E9E9E", "#757575", "#616161", "#424242", "#212121" ]
73+
"name": "Grey",
74+
"hexes": [ "#FAFAFA", "#F5F5F5", "#EEEEEE", "#E0E0E0", "#BDBDBD", "#9E9E9E", "#757575", "#616161", "#424242", "#212121" ]
7575
},
7676
{
77-
name: "Blue Grey",
78-
hexes: [ "#ECEFF1", "#CFD8DC", "#B0BEC5", "#90A4AE", "#78909C", "#607D8B", "#546E7A", "#455A64", "#37474F", "#263238" ]
77+
"name": "Blue Grey",
78+
"hexes": [ "#ECEFF1", "#CFD8DC", "#B0BEC5", "#90A4AE", "#78909C", "#607D8B", "#546E7A", "#455A64", "#37474F", "#263238" ]
7979
}
8080
]
8181
}

mdresgen/Program.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Text;
7+
using System.Threading.Tasks;
78
using System.Xml.Linq;
89
using Newtonsoft.Json;
910
using Newtonsoft.Json.Linq;
@@ -41,7 +42,7 @@ class Program
4142
{"color dark-when-small", Color.Black}
4243
};
4344

44-
static void Main(string[] args)
45+
static async Task Main(string[] args)
4546
{
4647
var xDocument = XDocument.Load(BaseSnippetLocation);
4748
var xmlRoot = xDocument.Root ??
@@ -68,7 +69,7 @@ static void Main(string[] args)
6869
else if (args.Contains("old"))
6970
GenerateOldXaml(xmlRoot);
7071
else if (args.Contains("icons"))
71-
IconThing.Run();
72+
await IconThing.RunAsync();
7273
else
7374
GenerateXaml(xmlRoot);
7475

@@ -80,7 +81,7 @@ static void Main(string[] args)
8081

8182
private static void GenerateClasses(MdPalette palettes)
8283
{
83-
foreach(var palette in palettes.palettes ?? Enumerable.Empty<MdPalette.palette>())
84+
foreach (var palette in palettes.palettes ?? Enumerable.Empty<MdPalette.palette>())
8485
{
8586
var sb = new StringBuilder();
8687

mdresgen/mdresgen.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net6</TargetFramework>
55
</PropertyGroup>
66
<ItemGroup>
77
<Content Include="MdPaletteJson.json">

0 commit comments

Comments
 (0)