@@ -68,7 +68,7 @@ public FileSwapper(AppEntry appEntry, PreferencesXML preferencesXML)
6868 }
6969
7070
71- public void InitiateFileSwaps ( PowerLineStatus forPowerLineStatus , PreferencesXML preferencesXML )
71+ public async Task InitiateFileSwaps ( PowerLineStatus forPowerLineStatus , PreferencesXML preferencesXML )
7272 {
7373 Logger . inst . Log ( $ "Initiating FileSwap for AppEntry with target path { AppEntry . AppPath } ") ;
7474
@@ -96,12 +96,19 @@ public void InitiateFileSwaps(PowerLineStatus forPowerLineStatus, PreferencesXML
9696 ForPowerLineStatus = forPowerLineStatus ,
9797 } ;
9898
99- //fire and forget
100- _ = InitiateSingleFileSwap ( current , i ) ;
99+
100+ try
101+ {
102+ await InitiateSingleFileSwap ( current , i ) ;
103+ }
104+ catch ( AggregateException )
105+ {
106+ throw ;
107+ }
101108
102109 } //...repeat for every SwapPath
103110
104- Logger . inst . Log ( $ "Finished FileSwap for AppEntry with target path { AppEntry . AppPath } ") ;
111+ Logger . inst . Log ( $ "Finished firing FileSwap logic for AppEntry with target path { AppEntry . AppPath } ") ;
105112
106113 }
107114
@@ -191,15 +198,13 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
191198 //no need to cancel the save if the substitution fails
192199 FileCopyConsiderAccessRules ( swapPath , pluggedInStoredFilePath , true , false ) ; //save current config to PluggedIn store
193200 string s1 = $ "Saved SwapPath { swapPath } for app { AppEntry . AppPath } as PluggedIn";
194- Debug . WriteLine ( s1 ) ;
195- _ = Logger . inst . Log ( s1 ) ;
201+ Logger . inst . Log ( s1 ) ;
196202
197203 errorFlag = 1 ;
198204
199205 FileCopyConsiderAccessRules ( onBatteryStoredFilePath , swapPath , true , true ) ; //then substitute with OnBattery config
200206 string s2 = $ "Substituted OnBattery config into SwapPath { swapPath } for app { AppEntry . AppPath } ";
201- _ = Logger . inst . Log ( s2 ) ;
202- Debug . WriteLine ( s2 ) ;
207+ Logger . inst . Log ( s2 ) ;
203208
204209 }
205210 catch ( IOException )
@@ -237,25 +242,23 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
237242 //no need to cancel the save if the substitution fails
238243 FileCopyConsiderAccessRules ( swapPath , onBatteryStoredFilePath , true , false ) ; //save current config to OnBattery store
239244 string s1 = $ "Saved SwapPath { swapPath } for app { AppEntry . AppPath } as OnBattery";
240- Debug . WriteLine ( s1 ) ;
241- _ = Logger . inst . Log ( s1 ) ;
245+ Logger . inst . Log ( s1 ) ;
242246
243247 errorFlag = 1 ;
244248
245249 FileCopyConsiderAccessRules ( pluggedInStoredFilePath , swapPath , true , true ) ; //then substitute with PluggedIn config
246250 string s2 = $ "Substituted PluggedIn config into SwapPath { swapPath } for app { AppEntry . AppPath } ";
247- _ = Logger . inst . Log ( s2 ) ;
248- Debug . WriteLine ( s2 ) ;
251+ Logger . inst . Log ( s2 ) ;
249252 }
250253 catch ( IOException )
251254 {
252255 if ( errorFlag == 0 )
253256 {
254- _ = Logger . inst . Log ( $ "Could not copy to destination { onBatteryStoredFilePath } , retrying in some time.") ;
257+ Logger . inst . Log ( $ "Could not copy to destination { onBatteryStoredFilePath } , retrying in some time.") ;
255258 }
256259 else if ( errorFlag == 1 )
257260 {
258- _ = Logger . inst . Log ( $ "Could not copy to destination { swapPath } , retrying in some time.") ;
261+ Logger . inst . Log ( $ "Could not copy to destination { swapPath } , retrying in some time.") ;
259262 }
260263 await Task . Delay ( 5000 ) ;
261264 goto TryAgain ;
@@ -266,14 +269,16 @@ private async Task InitiateSingleFileSwap(FileSwapPathTask fileSwapPathTask, int
266269
267270 preferencesXML . ModifyAppEntryAndSave ( AppEntry . AppPath , modified ) ;
268271 string s3 = $ "Saved SwapPath state for SwapPath { swapPath } for app { AppEntry . AppPath } ";
269- _ = Logger . inst . Log ( s3 ) ;
272+ Logger . inst . Log ( s3 ) ;
270273 }
271274 }
272275 else
273276 {
274277 Debug . WriteLine ( $ "Unknown power state: " + forPowerLineStatus . ToString ( ) ) ;
275278 }
276279
280+ Logger . inst . Log ( $ "FileSwaps Task finished for { AppEntry . AppPath } ") ;
281+
277282 OngoingFileSwapTasks . Remove ( fileSwapPathTask ) ;
278283
279284 }
0 commit comments