@@ -25,10 +25,10 @@ internal static class NanoFrameworkGenerator
25
25
{
26
26
private const int AlignPad = 35 ;
27
27
28
- static internal string MscorlibVersion = "" ;
29
- static internal string MscorlibNuGetVersion = "" ;
30
- static internal string MathVersion = "" ;
31
- static internal string MathNuGetVersion = "" ;
28
+ internal static string MscorlibVersion = "" ;
29
+ internal static string MscorlibNuGetVersion = "" ;
30
+ internal static string MathVersion = "" ;
31
+ internal static string MathNuGetVersion = "" ;
32
32
33
33
/// <summary>
34
34
/// These projects require inclusion of Math NuGet package.
@@ -43,7 +43,7 @@ internal static class NanoFrameworkGenerator
43
43
} ;
44
44
45
45
/// <summary>
46
- /// Create the root folder NanoFramewok
46
+ /// Create the root folder NanoFramework
47
47
/// Create all the quantities unit and quantities file
48
48
/// Create all individual nanoFramework projects
49
49
/// Create common package file
@@ -55,42 +55,35 @@ internal static class NanoFrameworkGenerator
55
55
public static void Generate ( string rootDir , Quantity [ ] quantities , bool updateNanoFrameworkDependencies )
56
56
{
57
57
// get latest version of .NET nanoFramework mscorlib
58
- NuGet . Common . ILogger logger = NullLogger . Instance ;
59
- CancellationToken cancellationToken = CancellationToken . None ;
58
+ ILogger logger = NullLogger . Instance ;
59
+ var ct = CancellationToken . None ;
60
60
61
- SourceCacheContext cache = new SourceCacheContext ( ) ;
61
+ SourceCacheContext cache = new ( ) ;
62
62
SourceRepository repository = Repository . Factory . GetCoreV3 ( "https://api.nuget.org/v3/index.json" ) ;
63
- FindPackageByIdResource resource = repository . GetResourceAsync < FindPackageByIdResource > ( ) . Result ;
63
+ FindPackageByIdResource resource = repository . GetResourceAsync < FindPackageByIdResource > ( ct ) . Result ;
64
64
65
65
var outputDir = Path . Combine ( rootDir , "UnitsNet.NanoFramework" , "GeneratedCode" ) ;
66
- var outputQuantitites = Path . Combine ( outputDir , "Quantities" ) ;
66
+ var outputQuantities = Path . Combine ( outputDir , "Quantities" ) ;
67
67
var outputUnits = Path . Combine ( outputDir , "Units" ) ;
68
68
var outputProperties = Path . Combine ( outputDir , "Properties" ) ;
69
69
// Ensure output directories exist
70
70
71
- Directory . CreateDirectory ( outputQuantitites ) ;
71
+ Directory . CreateDirectory ( outputQuantities ) ;
72
72
Directory . CreateDirectory ( outputUnits ) ;
73
73
Directory . CreateDirectory ( outputProperties ) ;
74
74
75
- Log . Information ( $ "Directory NanoFramework creation(OK)") ;
76
-
77
75
var lengthNuspecFile = Path . Combine ( outputDir , "Length" , "UnitsNet.NanoFramework.Length.nuspec" ) ;
78
76
var projectVersion = ParseVersion ( File . ReadAllText ( lengthNuspecFile ) ,
79
77
new Regex ( @"<version>(?<version>[\d\.]+)</version>" , RegexOptions . IgnoreCase ) ,
80
78
"projectVersion" ) ;
81
79
82
80
SetDependencyVersions ( resource , cache , logger , ct , updateNanoFrameworkDependencies , outputDir ) ;
83
- GenerateProperties ( Path . Combine ( outputProperties , "AssemblyInfo.cs" ) , projectVersion ) ;
84
- Log . Information ( "Property(OK)" ) ;
85
81
86
82
int numberQuantity = 0 ;
87
83
foreach ( var quantity in quantities )
88
84
{
89
- Log . Information ( $ "Creating .NET nanoFramework project for { quantity . Name } ") ;
90
-
91
85
var projectPath = Path . Combine ( outputDir , quantity . Name ) ;
92
86
Directory . CreateDirectory ( projectPath ) ;
93
- var sb = new StringBuilder ( $ "{ quantity . Name } :". PadRight ( AlignPad ) ) ;
94
87
95
88
GeneratePackageConfig ( projectPath , quantity . Name ) ;
96
89
@@ -100,9 +93,9 @@ public static void Generate(string rootDir, Quantity[] quantities, bool updateNa
100
93
MscorlibNuGetVersion ,
101
94
MathNuGetVersion ) ;
102
95
103
- GenerateUnitType ( sb , quantity , Path . Combine ( outputUnits , $ "{ quantity . Name } Unit.g.cs") ) ;
104
- GenerateQuantity ( sb , quantity , Path . Combine ( outputQuantitites , $ "{ quantity . Name } .g.cs") ) ;
105
- GenerateProject ( sb , quantity , Path . Combine ( projectPath , $ "{ quantity . Name } .nfproj") ) ;
96
+ GenerateUnitType ( quantity , Path . Combine ( outputUnits , $ "{ quantity . Name } Unit.g.cs") ) ;
97
+ GenerateQuantity ( quantity , Path . Combine ( outputQuantities , $ "{ quantity . Name } .g.cs") ) ;
98
+ GenerateProject ( quantity , Path . Combine ( projectPath , $ "{ quantity . Name } .nfproj") ) ;
106
99
107
100
// Convert decimal based units to floats; decimals are not supported by nanoFramework
108
101
if ( quantity . BaseType == "decimal" )
@@ -119,12 +112,18 @@ public static void Generate(string rootDir, Quantity[] quantities, bool updateNa
119
112
new FileInfo ( $ "{ outputDir } \\ Quantities\\ { quantity . Name } .g.cs") . EditFile ( replacements ) ;
120
113
}
121
114
115
+ Log . Information ( "✅ {Quantity} (nanoFramework)" , quantity . Name ) ;
122
116
numberQuantity ++ ;
123
117
}
118
+ Log . Information ( "" ) ;
124
119
120
+ GenerateProperties ( Path . Combine ( outputProperties , "AssemblyInfo.cs" ) , projectVersion ) ;
125
121
GenerateSolution ( quantities , outputDir ) ;
126
- Log . Information ( "UnitsNet.nanoFramework.sln generated" ) ;
127
- Log . Information ( $ "Count of generated projects: { numberQuantity } ") ;
122
+
123
+ var unitCount = quantities . SelectMany ( q => q . Units ) . Count ( ) ;
124
+ Log . Information ( "" ) ;
125
+ Log . Information ( "Total of {UnitCount} units and {QuantityCount} quantities (nanoFramework)" , unitCount , quantities . Length ) ;
126
+ Log . Information ( "" ) ;
128
127
}
129
128
130
129
private static void SetDependencyVersions ( FindPackageByIdResource resource , SourceCacheContext cache , ILogger logger ,
@@ -229,16 +228,16 @@ private static void GenerateProperties(string filePath, string version)
229
228
{
230
229
var content = new PropertyGenerator ( version ) . Generate ( ) ;
231
230
File . WriteAllText ( filePath , content ) ;
231
+ Log . Information ( "✅ AssemblyInfo.cs (nanoFramework)" ) ;
232
232
}
233
233
234
- private static void GenerateUnitType ( StringBuilder sb , Quantity quantity , string filePath )
234
+ private static void GenerateUnitType ( Quantity quantity , string filePath )
235
235
{
236
236
var content = new UnitTypeGenerator ( quantity ) . Generate ( ) ;
237
237
File . WriteAllText ( filePath , content ) ;
238
- sb . Append ( "unit(OK) " ) ;
239
238
}
240
239
241
- private static void GenerateQuantity ( StringBuilder sb , Quantity quantity , string filePath )
240
+ private static void GenerateQuantity ( Quantity quantity , string filePath )
242
241
{
243
242
var content = new QuantityGenerator ( quantity ) . Generate ( ) ;
244
243
// Replace any Math.PI by the real number 3.1415926535897931
@@ -248,44 +247,42 @@ private static void GenerateQuantity(StringBuilder sb, Quantity quantity, string
248
247
// Replace Math.Pow(2.54e-2, 4) by 0.0000004162314256
249
248
content = content . Replace ( "Math.Pow(2.54e-2, 4)" , "0.0000004162314256" ) ;
250
249
File . WriteAllText ( filePath , content ) ;
251
- sb . Append ( "quantity(OK) " ) ;
252
250
}
253
251
254
- private static void GenerateProject ( StringBuilder sb , Quantity quantity , string filePath )
252
+ private static void GenerateProject ( Quantity quantity , string filePath )
255
253
{
256
254
var content = new ProjectGenerator ( quantity ) . Generate ( ) ;
257
255
File . WriteAllText ( filePath , content ) ;
258
- sb . Append ( "project(OK) " ) ;
259
256
}
260
257
261
258
private static void GenerateSolution ( Quantity [ ] quantities , string outputDir )
262
259
{
263
260
var content = new SolutionGenerator ( quantities ) . Generate ( ) ;
264
-
265
261
var filePath = Path . Combine ( outputDir , "UnitsNet.nanoFramework.sln" ) ;
266
262
267
263
File . WriteAllText ( filePath , content ) ;
264
+ Log . Information ( "✅ UnitsNet.nanoFramework.sln (nanoFramework)" ) ;
268
265
}
269
266
270
267
private static string GeneratePackageConfigFile ( string quantityName )
271
268
{
272
- MyTextWriter Writer = new MyTextWriter ( ) ;
269
+ MyTextWriter writer = new ( ) ;
273
270
274
- Writer . WL ( $@ "
271
+ writer . WL ( $@ "
275
272
<?xml version=""1.0"" encoding=""utf-8""?>
276
273
<packages>
277
274
<package id=""nanoFramework.CoreLibrary"" version=""{ MscorlibNuGetVersion } "" targetFramework=""netnanoframework10"" />" ) ;
278
275
279
276
280
277
if ( NanoFrameworkGenerator . ProjectsRequiringMath . Contains ( quantityName ) )
281
278
{
282
- Writer . WL ( $@ "
279
+ writer . WL ( $@ "
283
280
<package id=""nanoFramework.System.Math"" version=""{ MathNuGetVersion } "" targetFramework=""netnanoframework10"" />" ) ;
284
281
}
285
282
286
- Writer . WL ( $@ "</packages>") ;
283
+ writer . WL ( $@ "</packages>") ;
287
284
288
- return Writer . ToString ( ) ;
285
+ return writer . ToString ( ) ;
289
286
}
290
287
}
291
288
}
0 commit comments