11using CSharpOpenBMCLAPI . Modules ;
22using Newtonsoft . Json ;
3- using TeraIO . Runnable ;
43using YamlDotNet . Serialization ;
54using AppContext = CSharpOpenBMCLAPI . Modules . AppContext ;
65
76namespace CSharpOpenBMCLAPI
87{
9- internal class Program : RunnableBase
8+ internal class Program
109 {
11- public Program ( ) : base ( ) { }
10+ public Program ( ) : base ( )
11+ {
12+ }
1213
1314 static void Main ( string [ ] args )
1415 {
1516 Logger . Instance . LogSystem ( $ "Starting CSharp-OpenBMCLAPI v{ AppContext . Config . clusterVersion } ") ;
1617 Logger . Instance . LogSystem ( "高性能、低メモリ占有!" ) ;
1718 Logger . Instance . LogSystem ( $ "运行时环境:{ Utils . GetRuntime ( ) } ") ;
18- Program program = new Program ( ) ;
19- program . Start ( ) ;
20- program . WaitForStop ( ) ;
21- }
2219
23- protected Config GetConfig ( )
24- {
25- const string configFileName = "config.yml" ;
26- string configPath = Path . Combine ( AppContext . Config . clusterWorkingDirectory , configFileName ) ;
27- if ( ! File . Exists ( configPath ) )
28- {
29- Config config = new Config ( ) ;
30- Serializer serializer = new Serializer ( ) ;
31- File . WriteAllText ( configPath , serializer . Serialize ( config ) ) ;
32- return config ;
33- }
34- else
35- {
36- string file = File . ReadAllText ( configPath ) ;
37- Deserializer deserializer = new Deserializer ( ) ;
38- Config ? config = deserializer . Deserialize < Config > ( file ) ;
39- Config result ;
40- if ( config != null )
41- {
42- result = config ;
43- }
44- else
45- {
46- result = new Config ( ) ;
47- }
48- Serializer serializer = new Serializer ( ) ;
49- File . WriteAllText ( configPath , serializer . Serialize ( config ) ) ;
50- return result ;
51- }
52- }
53-
54- protected override int Run ( string [ ] args )
55- {
5620 try
5721 {
5822 Directory . CreateDirectory ( AppContext . Config . clusterWorkingDirectory ) ;
@@ -61,14 +25,15 @@ protected override int Run(string[] args)
6125 string bsonFilePath = Path . Combine ( AppContext . Config . clusterWorkingDirectory , bsonFile ) ;
6226 AppContext . Config = GetConfig ( ) ;
6327
64- int returns = 0 ;
65-
6628 const string environment = "working/.env.json" ;
6729
68- if ( ! File . Exists ( environment ) ) throw new FileNotFoundException ( $ "请在程序目录下新建 { environment } 文件,然后填入 \" ClusterId\" 和 \" ClusterSecret\" 以启动集群!") ;
30+ if ( ! File . Exists ( environment ) )
31+ throw new FileNotFoundException (
32+ $ "请在程序目录下新建 { environment } 文件,然后填入 \" ClusterId\" 和 \" ClusterSecret\" 以启动集群!") ;
6933
7034 // 从 .env.json 读取密钥然后 FetchToken
71- ClusterInfo info = JsonConvert . DeserializeObject < ClusterInfo > ( File . ReadAllTextAsync ( environment ) . Result ) ;
35+ ClusterInfo info =
36+ JsonConvert . DeserializeObject < ClusterInfo > ( File . ReadAllTextAsync ( environment ) . Result ) ;
7237 AppContext requiredData = new ( info ) ;
7338 Logger . Instance . LogSystem ( $ "Cluster id: { info . clusterId } ") ;
7439 TokenManager token = new TokenManager ( info ) ;
@@ -86,14 +51,35 @@ protected override int Run(string[] args)
8651 } ;
8752
8853 cluster . Start ( ) ;
89- return returns ;
9054 }
9155 catch ( Exception ex )
9256 {
9357 Console . WriteLine ( ex . ExceptionToDetail ( ) ) ;
9458 Console . ReadKey ( ) ;
95- return - 1 ;
59+ }
60+ }
61+
62+ private static Config GetConfig ( )
63+ {
64+ const string configFileName = "config.yml" ;
65+ string configPath = Path . Combine ( AppContext . Config . clusterWorkingDirectory , configFileName ) ;
66+ if ( ! File . Exists ( configPath ) )
67+ {
68+ Config config = new Config ( ) ;
69+ Serializer serializer = new Serializer ( ) ;
70+ File . WriteAllText ( configPath , serializer . Serialize ( config ) ) ;
71+ return config ;
72+ }
73+ else
74+ {
75+ string file = File . ReadAllText ( configPath ) ;
76+ Deserializer deserializer = new Deserializer ( ) ;
77+ Config config = deserializer . Deserialize < Config > ( file ) ;
78+ var result = config ;
79+ Serializer serializer = new Serializer ( ) ;
80+ File . WriteAllText ( configPath , serializer . Serialize ( config ) ) ;
81+ return result ;
9682 }
9783 }
9884 }
99- }
85+ }
0 commit comments