11using System ;
2+ using System . Collections . Generic ;
23using System . IO ;
34
45using Synapse . Core . Utilities ;
@@ -18,14 +19,81 @@ public SynapseNodeConfig()
1819 public static readonly string CurrentPath = $ "{ Path . GetDirectoryName ( typeof ( SynapseNodeConfig ) . Assembly . Location ) } ";
1920 public static readonly string FileName = $ "{ Path . GetDirectoryName ( typeof ( SynapseNodeConfig ) . Assembly . Location ) } \\ Synapse.Node.config.yaml";
2021
21- public int MaxServerThreads { get ; set ; } = 10 ;
22+
23+ public string ServiceName { get ; set ; } = "Synapse.Node" ;
24+ internal bool HasServiceName { get { return ! string . IsNullOrWhiteSpace ( ServiceName ) ; } }
25+
26+ public string ServiceDisplayName { get ; set ; } = "Synapse Node" ;
27+ internal bool HasServiceDisplayName { get { return ! string . IsNullOrWhiteSpace ( ServiceDisplayName ) ; } }
28+
29+ public int MaxServerThreads { get ; set ; } = 0 ;
30+ internal string MaxServerThreadsString { get ; set ; } = "0" ;
31+ internal bool TestSetMaxServerThreadsString
32+ {
33+ get
34+ {
35+ int threads = MaxServerThreads ;
36+ bool ok = int . TryParse ( MaxServerThreadsString , out threads ) ;
37+ if ( ok )
38+ MaxServerThreads = threads ;
39+ return ok ;
40+ }
41+ }
42+
2243 public string AuditLogRootPath { get ; set ; } = @".\Logs" ;
44+ internal bool HasAuditLogRootPath { get { return ! string . IsNullOrWhiteSpace ( AuditLogRootPath ) ; } }
45+
2346 public string ServiceLogRootPath { get ; set ; } = @".\Logs" ;
47+ internal bool HasServiceLogRootPath { get { return ! string . IsNullOrWhiteSpace ( ServiceLogRootPath ) ; } }
48+
2449 public string Log4NetConversionPattern { get ; set ; } = "%d{ISO8601}|%-5p|(%t)|%m%n" ;
50+ internal bool HasLog4NetConversionPattern { get { return ! string . IsNullOrWhiteSpace ( Log4NetConversionPattern ) ; } }
51+
2552 public bool SerializeResultPlan { get ; set ; } = true ;
53+ internal string SerializeResultPlanString { get ; set ; } = "true" ;
54+ internal bool TestSetSerializeResultPlanString
55+ {
56+ get
57+ {
58+ bool v = SerializeResultPlan ;
59+ bool ok = bool . TryParse ( SerializeResultPlanString , out v ) ;
60+ if ( ok )
61+ SerializeResultPlan = v ;
62+ return ok ;
63+ }
64+ }
65+
2666 public bool ValidatePlanSignature { get ; set ; } = true ;
67+ internal string ValidatePlanSignatureString { get ; set ; } = "true" ;
68+ internal bool TestSetValidatePlanSignatureString
69+ {
70+ get
71+ {
72+ bool v = ValidatePlanSignature ;
73+ bool ok = bool . TryParse ( ValidatePlanSignatureString , out v ) ;
74+ if ( ok )
75+ ValidatePlanSignature = v ;
76+ return ok ;
77+ }
78+ }
79+
2780 public string ControllerServiceUrl { get ; set ; } = "http://localhost:8008/synapse/execute" ;
28- public string WebApiPort { get ; set ; } = "8000" ;
81+ internal bool HasControllerServiceUrl { get { return ! string . IsNullOrWhiteSpace ( ControllerServiceUrl ) ; } }
82+
83+ public int WebApiPort { get ; set ; } = 8000 ;
84+ internal string WebApiPortString { get ; set ; } = "8000" ;
85+ internal bool TestSetWebApiPortString
86+ {
87+ get
88+ {
89+ int port = WebApiPort ;
90+ bool ok = int . TryParse ( WebApiPortString , out port ) ;
91+ if ( ok )
92+ WebApiPort = port ;
93+ return ok ;
94+ }
95+ }
96+
2997
3098 public string GetResolvedAuditLogRootPath ( )
3199 {
@@ -86,5 +154,105 @@ public static SynapseNodeConfig Deserialze()
86154
87155 return YamlHelpers . DeserializeFile < SynapseNodeConfig > ( FileName ) ;
88156 }
157+
158+ public static Dictionary < string , string > GetConfigDefaultValues ( )
159+ {
160+ Dictionary < string , string > values = new Dictionary < string , string > ( ) ;
161+
162+ SynapseNodeConfig c = new SynapseNodeConfig ( ) ;
163+ values [ nameof ( c . ServiceName ) ] = c . ServiceName ;
164+ values [ nameof ( c . ServiceDisplayName ) ] = c . ServiceDisplayName ;
165+ values [ nameof ( c . MaxServerThreads ) ] = c . MaxServerThreads . ToString ( ) ;
166+ values [ nameof ( c . AuditLogRootPath ) ] = c . AuditLogRootPath ;
167+ values [ nameof ( c . ServiceLogRootPath ) ] = c . ServiceLogRootPath ;
168+ values [ nameof ( c . Log4NetConversionPattern ) ] = c . Log4NetConversionPattern ;
169+ values [ nameof ( c . SerializeResultPlan ) ] = c . SerializeResultPlan . ToString ( ) ;
170+ values [ nameof ( c . ValidatePlanSignature ) ] = c . ValidatePlanSignature . ToString ( ) ;
171+ values [ nameof ( c . ControllerServiceUrl ) ] = c . ControllerServiceUrl ;
172+ values [ nameof ( c . WebApiPort ) ] = c . WebApiPort . ToString ( ) ;
173+
174+ return values ;
175+ }
176+
177+ public static SynapseNodeConfig Configure ( Dictionary < string , string > values )
178+ {
179+ SynapseNodeConfig c = new SynapseNodeConfig ( ) ;
180+
181+ if ( values . ContainsKey ( nameof ( c . ServiceName ) . ToLower ( ) ) )
182+ c . ServiceName = values [ nameof ( c . ServiceName ) . ToLower ( ) ] ;
183+
184+ if ( values . ContainsKey ( nameof ( c . ServiceDisplayName ) . ToLower ( ) ) )
185+ c . ServiceDisplayName = values [ nameof ( c . ServiceDisplayName ) . ToLower ( ) ] ;
186+
187+ if ( values . ContainsKey ( nameof ( c . MaxServerThreads ) . ToLower ( ) ) )
188+ c . MaxServerThreadsString = values [ nameof ( c . MaxServerThreads ) . ToLower ( ) ] ;
189+
190+ if ( values . ContainsKey ( nameof ( c . AuditLogRootPath ) . ToLower ( ) ) )
191+ c . AuditLogRootPath = values [ nameof ( c . AuditLogRootPath ) . ToLower ( ) ] ;
192+
193+ if ( values . ContainsKey ( nameof ( c . ServiceLogRootPath ) . ToLower ( ) ) )
194+ c . ServiceLogRootPath = values [ nameof ( c . ServiceLogRootPath ) . ToLower ( ) ] ;
195+
196+ if ( values . ContainsKey ( nameof ( c . Log4NetConversionPattern ) . ToLower ( ) ) )
197+ c . Log4NetConversionPattern = values [ nameof ( c . Log4NetConversionPattern ) . ToLower ( ) ] ;
198+
199+ if ( values . ContainsKey ( nameof ( c . SerializeResultPlan ) . ToLower ( ) ) )
200+ c . SerializeResultPlanString = values [ nameof ( c . SerializeResultPlan ) . ToLower ( ) ] ;
201+
202+ if ( values . ContainsKey ( nameof ( c . ValidatePlanSignature ) . ToLower ( ) ) )
203+ c . ValidatePlanSignatureString = values [ nameof ( c . ValidatePlanSignature ) . ToLower ( ) ] ;
204+
205+ if ( values . ContainsKey ( nameof ( c . ControllerServiceUrl ) . ToLower ( ) ) )
206+ c . ControllerServiceUrl = values [ nameof ( c . ControllerServiceUrl ) . ToLower ( ) ] ;
207+
208+ if ( values . ContainsKey ( nameof ( c . WebApiPort ) . ToLower ( ) ) )
209+ c . WebApiPortString = values [ nameof ( c . WebApiPort ) . ToLower ( ) ] ;
210+
211+ return Configure ( c ) ;
212+ }
213+
214+ public static SynapseNodeConfig Configure ( SynapseNodeConfig value )
215+ {
216+ //initialize with defaults
217+ SynapseNodeConfig config = new SynapseNodeConfig ( ) ;
218+ //ovrride defaults with file values
219+ if ( File . Exists ( FileName ) )
220+ config = YamlHelpers . DeserializeFile < SynapseNodeConfig > ( FileName ) ;
221+
222+ //configure with anything provided
223+ if ( value . HasServiceName && ! ( value . ServiceName == config . ServiceName ) )
224+ config . ServiceName = value . ServiceName ;
225+
226+ if ( value . HasServiceDisplayName && ! ( value . ServiceDisplayName == config . ServiceDisplayName ) )
227+ config . ServiceDisplayName = value . ServiceDisplayName ;
228+
229+ if ( value . TestSetMaxServerThreadsString && ! ( value . MaxServerThreads == config . MaxServerThreads ) )
230+ config . MaxServerThreads = value . MaxServerThreads ;
231+
232+ if ( value . HasAuditLogRootPath && ! ( value . AuditLogRootPath == config . AuditLogRootPath ) )
233+ config . AuditLogRootPath = value . AuditLogRootPath ;
234+
235+ if ( value . HasServiceLogRootPath && ! ( value . ServiceLogRootPath == config . ServiceLogRootPath ) )
236+ config . ServiceLogRootPath = value . ServiceLogRootPath ;
237+
238+ if ( value . HasLog4NetConversionPattern && ! ( value . Log4NetConversionPattern == config . Log4NetConversionPattern ) )
239+ config . Log4NetConversionPattern = value . Log4NetConversionPattern ;
240+
241+ if ( value . TestSetSerializeResultPlanString && ! ( value . SerializeResultPlan == config . SerializeResultPlan ) )
242+ config . SerializeResultPlan = value . SerializeResultPlan ;
243+
244+ if ( value . TestSetValidatePlanSignatureString && ! ( value . ValidatePlanSignature == config . ValidatePlanSignature ) )
245+ config . ValidatePlanSignature = value . ValidatePlanSignature ;
246+
247+ if ( value . HasControllerServiceUrl && ! ( value . ControllerServiceUrl == config . ControllerServiceUrl ) )
248+ config . ControllerServiceUrl = value . ControllerServiceUrl ;
249+
250+ if ( value . TestSetWebApiPortString && ! ( value . WebApiPort == config . WebApiPort ) )
251+ config . WebApiPort = value . WebApiPort ;
252+
253+ config . Serialize ( ) ;
254+
255+ return config ;
256+ }
89257 }
90258}
0 commit comments