@@ -25,7 +25,7 @@ public class Program
2525 public static Dictionary < string , IFileJob > Jobs = new Dictionary < string , IFileJob > ( ) ;
2626 public static void Main ( string [ ] args )
2727 {
28- ConfigureLogger ( args . FirstOrDefault ( ) ) ;
28+ ConfigureLogger ( args ? . FirstOrDefault ( ) ) ;
2929 log = LoggerFactory . CreateLogger ( "FileSyncAppMain" ) ;
3030 if ( null != args && args . Length > 0 )
3131 {
@@ -50,6 +50,7 @@ static void RunProgram()
5050 ContractResolver = new IgnorePropertyResolver ( new string [ ] { "Logger" } ) ,
5151 TypeNameHandling = TypeNameHandling . Auto ,
5252 } ;
53+
5354 if ( ! File . Exists ( "config.json" ) )
5455 {
5556 log . LogInformation ( "Config file {A} not found, creating a new one" , "config.json" ) ;
@@ -96,20 +97,32 @@ static void RunProgram()
9697 var json = JsonConvert . SerializeObject ( jobOptions , Formatting . Indented , jsonSettings ) ;
9798 File . WriteAllText ( "config.json" , json ) ;
9899 }
100+
99101 log . LogInformation ( "reading config file {A}" , "config.json" ) ;
100- var readJobOptions = JsonConvert . DeserializeObject < Dictionary < string , IFileJobOptions > > ( File . ReadAllText ( "config.json" ) , jsonSettings ) ;
101- //List<IFileJob> Jobs = new List<IFileJob>();
102+ Dictionary < string , IFileJobOptions > readJobOptions = new Dictionary < string , IFileJobOptions > ( ) ;
103+ try
104+ {
105+ readJobOptions = JsonConvert . DeserializeObject < Dictionary < string , IFileJobOptions > > ( File . ReadAllText ( "config.json" ) , jsonSettings ) ;
106+ }
107+ catch ( Exception exc )
108+ {
109+ log . LogCritical ( exc , "exception reading config file {A}" , "config.json" ) ;
110+ return ;
111+ }
102112
103113 foreach ( var jobOption in readJobOptions )
104114 {
105-
106115 jobOption . Value . Logger = LoggerFactory . CreateLogger ( jobOption . Key ) ;
107116 Jobs . Add ( jobOption . Key , FileSyncJob . CreateJob ( jobOption . Value ) ) ;
108117 }
109118 JobsReady ? . Invoke ( null , EventArgs . Empty ) ;
119+ Dictionary < IFileJob , bool > jobsDone = new Dictionary < IFileJob , bool > ( ) ;
110120 foreach ( var job in Jobs )
111121 {
122+ jobsDone . Add ( job . Value , false ) ;
123+ job . Value . JobFinished += ( s , e ) => { jobsDone [ ( IFileJob ) s ] = true ; if ( jobsDone . All ( x => x . Value ) ) if ( ! File . Exists ( "fullsync.done" ) ) File . Create ( "fullsync.done" ) ; } ;
112124 job . Value . StartJob ( ) ;
125+
113126 }
114127 log . LogInformation ( "Press Ctrl+C to exit" ) ;
115128 while ( keepRunning )
0 commit comments