File tree 3 files changed +38
-11
lines changed
Extensions.Configuration.GitRepository
3 files changed +38
-11
lines changed Original file line number Diff line number Diff line change
1
+ using Microsoft . Extensions . Primitives ;
2
+
1
3
var builder = WebApplication . CreateBuilder ( args ) ;
2
4
builder . Services . AddControllers ( ) ;
3
5
builder . Services . AddOpenApi ( ) ;
4
6
builder . Configuration . AddUserSecrets ( "personal_access_tokens" ) ;
5
7
builder . Configuration . AddGitRepository ( cfg => cfg . WithGitLab ( )
6
- . WithHostUrl ( "https://git.uixe.net/" )
7
- . WithRepositoryPath ( "uixe/stdlanedevctlsvr" )
8
+ . WithRepositoryPath ( "IoTSharp/gitlabcfg" )
8
9
. WithAuthenticationToken ( builder . Configuration . GetValue < string > ( "personal_access_tokens" ) )
9
- . WithFileName ( $ "{ Environment . GetEnvironmentVariable ( "UIXEID" ) } / appsettings. { builder . Environment . EnvironmentName } .json")
10
+ . WithFileName ( $ "appsettings.json")
10
11
. WithCache ( $ "{ builder . Environment . ContentRootPath } { System . IO . Path . DirectorySeparatorChar } appsettings.{ builder . Environment . EnvironmentName } .json")
11
12
) ;
12
13
18
19
app . MapOpenApi ( ) ;
19
20
}
20
21
Console . 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 ( ) ;
22
33
app . 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 5
5
"Microsoft.AspNetCore" : " Warning"
6
6
}
7
7
},
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
+ ]
10
17
}
Original file line number Diff line number Diff line change @@ -64,10 +64,9 @@ private void SyncGitRepoFile()
64
64
{
65
65
_jsonData = ReadCache ( ) ;
66
66
}
67
- ReadGitRepo ( ref _jsonData ) ;
68
- if ( _jsonData != null )
67
+ bool result = ReadGitRepo ( ref _jsonData ) ;
68
+ if ( _jsonData != null && result )
69
69
{
70
-
71
70
Data = JsonConfigurationFileParser . Parse ( _jsonData ) ;
72
71
OnReload ( ) ;
73
72
}
@@ -84,8 +83,9 @@ private void SyncGitRepoFile()
84
83
}
85
84
}
86
85
87
- private void ReadGitRepo ( ref JsonDocument _jsonData )
86
+ private bool ReadGitRepo ( ref JsonDocument _jsonData )
88
87
{
88
+ bool result = false ;
89
89
try
90
90
{
91
91
if ( __gitRepo . FileExists ( _options . FileName ) )
@@ -97,6 +97,7 @@ private void ReadGitRepo( ref JsonDocument _jsonData)
97
97
if ( _jsonData != null )
98
98
{
99
99
SaveCache ( fileContent ) ;
100
+ result = true ;
100
101
}
101
102
}
102
103
else
@@ -109,6 +110,7 @@ private void ReadGitRepo( ref JsonDocument _jsonData)
109
110
string _json = _jn . ToJsonString ( new JsonSerializerOptions ( ) { WriteIndented = true } ) ;
110
111
SaveCache ( _json ) ;
111
112
_jsonData = JsonDocument . Parse ( _json ) ;
113
+ result = true ;
112
114
113
115
}
114
116
}
@@ -126,6 +128,7 @@ private void ReadGitRepo( ref JsonDocument _jsonData)
126
128
Console . WriteLine ( ex1 . ToString ( ) ) ;
127
129
128
130
}
131
+ return result ;
129
132
}
130
133
131
134
private JsonDocument ReadCache ( )
You can’t perform that action at this time.
0 commit comments