File tree Expand file tree Collapse file tree 3 files changed +38
-11
lines changed
Extensions.Configuration.GitRepository Expand file tree Collapse file tree 3 files changed +38
-11
lines changed Original file line number Diff line number Diff line change 1+ using Microsoft . Extensions . Primitives ;
2+
13var builder = WebApplication . CreateBuilder ( args ) ;
24builder . Services . AddControllers ( ) ;
35builder . Services . AddOpenApi ( ) ;
46builder . Configuration . AddUserSecrets ( "personal_access_tokens" ) ;
57builder . Configuration . AddGitRepository ( cfg => cfg . WithGitLab ( )
6- . WithHostUrl ( "https://git.uixe.net/" )
7- . WithRepositoryPath ( "uixe/stdlanedevctlsvr" )
8+ . WithRepositoryPath ( "IoTSharp/gitlabcfg" )
89 . WithAuthenticationToken ( builder . Configuration . GetValue < string > ( "personal_access_tokens" ) )
9- . WithFileName ( $ "{ Environment . GetEnvironmentVariable ( "UIXEID" ) } / appsettings. { builder . Environment . EnvironmentName } .json")
10+ . WithFileName ( $ "appsettings.json")
1011 . WithCache ( $ "{ builder . Environment . ContentRootPath } { System . IO . Path . DirectorySeparatorChar } appsettings.{ builder . Environment . EnvironmentName } .json")
1112 ) ;
1213
1819 app . MapOpenApi ( ) ;
1920}
2021Console . WriteLine ( $ "abc={ app . Configuration . GetValue < string > ( "abc" ) } ") ;
21- app . UseAuthorization ( ) ;
22+
23+ ChangeToken . OnChange ( ( ) => app . Configuration . GetReloadToken ( ) , ( ) =>
24+ {
25+ Console . WriteLine ( $ "abc={ app . Configuration . GetValue < string > ( "abc" ) } ") ;
26+ var settings = app . Configuration . Get < AppSettings > ( ) ;
27+ foreach ( var item in settings ? . Menus )
28+ {
29+ Console . WriteLine ( $ "Menu={ item } ") ;
30+ }
31+ } ) ;
32+ app . UseAuthorization ( ) ;
2233app . MapControllers ( ) ;
23- app . Run ( ) ;
34+ app . Run ( ) ;
35+
36+ public class AppSettings
37+ {
38+ public List < string > Menus { get ; set ; } = new List < string > ( ) ;
39+
40+ }
Original file line number Diff line number Diff line change 55 "Microsoft.AspNetCore" : " Warning"
66 }
77 },
8- "abc" : 12223467 ,
9- "sdfsd" : " asdfsadfasd"
8+ "sdfsd" : " asdfsadfasd" ,
9+ "abc" : 1232323223 ,
10+ "Menus" : [
11+ " App" ,
12+ " abc" ,
13+ " fdsfsdfsd" ,
14+ " sadfsdfsd12" ,
15+ " sdfasdfasds"
16+ ]
1017}
Original file line number Diff line number Diff line change @@ -64,10 +64,9 @@ private void SyncGitRepoFile()
6464 {
6565 _jsonData = ReadCache ( ) ;
6666 }
67- ReadGitRepo ( ref _jsonData ) ;
68- if ( _jsonData != null )
67+ bool result = ReadGitRepo ( ref _jsonData ) ;
68+ if ( _jsonData != null && result )
6969 {
70-
7170 Data = JsonConfigurationFileParser . Parse ( _jsonData ) ;
7271 OnReload ( ) ;
7372 }
@@ -84,8 +83,9 @@ private void SyncGitRepoFile()
8483 }
8584 }
8685
87- private void ReadGitRepo ( ref JsonDocument _jsonData )
86+ private bool ReadGitRepo ( ref JsonDocument _jsonData )
8887 {
88+ bool result = false ;
8989 try
9090 {
9191 if ( __gitRepo . FileExists ( _options . FileName ) )
@@ -97,6 +97,7 @@ private void ReadGitRepo( ref JsonDocument _jsonData)
9797 if ( _jsonData != null )
9898 {
9999 SaveCache ( fileContent ) ;
100+ result = true ;
100101 }
101102 }
102103 else
@@ -109,6 +110,7 @@ private void ReadGitRepo( ref JsonDocument _jsonData)
109110 string _json = _jn . ToJsonString ( new JsonSerializerOptions ( ) { WriteIndented = true } ) ;
110111 SaveCache ( _json ) ;
111112 _jsonData = JsonDocument . Parse ( _json ) ;
113+ result = true ;
112114
113115 }
114116 }
@@ -126,6 +128,7 @@ private void ReadGitRepo( ref JsonDocument _jsonData)
126128 Console . WriteLine ( ex1 . ToString ( ) ) ;
127129
128130 }
131+ return result ;
129132 }
130133
131134 private JsonDocument ReadCache ( )
You can’t perform that action at this time.
0 commit comments