1- // Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2-
3- using PostSharp . Engineering . BuildTools . Build ;
4- using System ;
5- using System . Collections . Generic ;
6- using System . IO ;
7- using System . Linq ;
8-
9- namespace PostSharp . Engineering . BuildTools . Utilities ;
10-
11- internal static class EmbeddedResourceHelper
12- {
13- public static void ExtractScript ( BuildContext context , string fileName , string targetDirectory )
14- {
15- var product = context . Product ;
16- var replacements = new Dictionary < string , string > ( ) ;
17- replacements . Add ( "<ENG_PATH>" , product . EngineeringDirectory ) ;
18- replacements . Add ( "<ENVIRONMENT_VARIABLES>" , string . Join ( "," , EnvironmentVariableNames . All . OrderBy ( x => x ) ) ) ;
19- replacements . Add ( "<PRODUCT_NAME>" , product . ProductNameWithoutDot ) ;
20-
21- ExtractResource ( context , fileName , targetDirectory , replacements ) ;
22- }
23-
24- public static void ExtractResource (
25- BuildContext context ,
26- string fileName ,
27- string targetDirectory ,
28- IReadOnlyDictionary < string , string > ? replacements = null )
29- {
30- var targetPath = Path . Combine ( context . RepoDirectory , targetDirectory , fileName ) ;
31-
32- using var resource = typeof ( EmbeddedResourceHelper ) . Assembly . GetManifestResourceStream ( $ "PostSharp.Engineering.BuildTools.Resources.{ fileName } " )
33- ?? throw new InvalidOperationException ( $ "Cannot find the resource { fileName } ." ) ;
34-
35- using var reader = new StreamReader ( resource ) ;
36- var text = reader . ReadToEnd ( ) ;
37-
38- if ( replacements != null )
39- {
40- foreach ( var replacement in replacements )
41- {
42- text = text . Replace ( replacement . Key , replacement . Value , StringComparison . Ordinal ) ;
43- }
44- }
45-
46- TextFileHelper . WriteIfDifferent ( targetPath , text , context ) ;
47- }
1+ // Copyright (c) SharpCrafters s.r.o. See the LICENSE.md file in the root directory of this repository root for details.
2+
3+ using PostSharp . Engineering . BuildTools . Build ;
4+ using System ;
5+ using System . Collections . Generic ;
6+ using System . IO ;
7+ using System . Linq ;
8+
9+ namespace PostSharp . Engineering . BuildTools . Utilities ;
10+
11+ internal static class EmbeddedResourceHelper
12+ {
13+ public static void ExtractScript ( BuildContext context , string fileName , string targetDirectory )
14+ {
15+ var product = context . Product ;
16+ var replacements = new Dictionary < string , string > ( ) ;
17+ replacements . Add ( "<ENG_PATH>" , product . EngineeringDirectory ) ;
18+ replacements . Add ( "<ENVIRONMENT_VARIABLES>" , string . Join ( "," , EnvironmentVariableNames . All . OrderBy ( x => x ) ) ) ;
19+ replacements . Add ( "<PRODUCT_NAME>" , product . ProductNameWithoutDot ) ;
20+ replacements . Add ( "<DEFAULT_MEMORY_GB>" , ( product . DockerSpec ? . Memory ?? 8 ) . ToString ( System . Globalization . CultureInfo . InvariantCulture ) ) ;
21+
22+ ExtractResource ( context , fileName , targetDirectory , replacements ) ;
23+ }
24+
25+ public static void ExtractResource (
26+ BuildContext context ,
27+ string fileName ,
28+ string targetDirectory ,
29+ IReadOnlyDictionary < string , string > ? replacements = null )
30+ {
31+ var targetPath = Path . Combine ( context . RepoDirectory , targetDirectory , fileName ) ;
32+
33+ using var resource = typeof ( EmbeddedResourceHelper ) . Assembly . GetManifestResourceStream ( $ "PostSharp.Engineering.BuildTools.Resources.{ fileName } " )
34+ ?? throw new InvalidOperationException ( $ "Cannot find the resource { fileName } ." ) ;
35+
36+ using var reader = new StreamReader ( resource ) ;
37+ var text = reader . ReadToEnd ( ) ;
38+
39+ if ( replacements != null )
40+ {
41+ foreach ( var replacement in replacements )
42+ {
43+ text = text . Replace ( replacement . Key , replacement . Value , StringComparison . Ordinal ) ;
44+ }
45+ }
46+
47+ TextFileHelper . WriteIfDifferent ( targetPath , text , context ) ;
48+ }
4849}
0 commit comments