Added better responses and logging around pause function.

systray
Sean McArdle 2016-11-21 16:15:35 -08:00
parent 3caf35d905
commit 174e0fae7f
1 changed files with 23 additions and 8 deletions

View File

@ -393,14 +393,29 @@ namespace WifiSitter
break; break;
case "take_five": case "take_five":
try { try {
LogLine("Taking 5 minute break and restoring interfaces."); if (_paused) {
OnPause(); response = new WifiSitterIpcMessage("taking_five", _wsIpc.MyChannelName, "", "already_paused");
Task.Delay(5 * 60 * 1000).ContinueWith((task) => { _wsIpc.MsgBroadcaster.SendToChannel(_msg.Target, response.IpcMessageJsonString());
netstate.ShouldCheckState(); // Main loop should check state again when resuming from paused state }
OnContinue(); }); else {
ResetNicState(netstate); int minutes = 5;
response = new WifiSitterIpcMessage("taking_five", _wsIpc.MyChannelName, "", ""); #if DEBUG
_wsIpc.MsgBroadcaster.SendToChannel(_msg.Target, response.IpcMessageJsonString()); minutes = 1; // I'm impatient while debugging
#endif
WriteLog(LogType.info, "Taking {0} minute break and restoring interfaces to initial state.", minutes.ToString());
OnPause();
Task.Delay(minutes * 60 * 1000).ContinueWith((task) => {
WriteLog(LogType.info, "Break elapsed. Resuming operation.");
netstate.ShouldCheckState(); // Main loop should check state again when resuming from paused state
OnContinue();
response = new WifiSitterIpcMessage("taking_five", _wsIpc.MyChannelName, "", "resuming");
_wsIpc.MsgBroadcaster.SendToChannel(_msg.Target, response.IpcMessageJsonString());
});
ResetNicState(netstate);
response = new WifiSitterIpcMessage("taking_five", _wsIpc.MyChannelName, "", "pausing");
_wsIpc.MsgBroadcaster.SendToChannel(_msg.Target, response.IpcMessageJsonString());
}
} }
catch { WriteLog(LogType.error, "Failed to enter paused state after 'take_five' request received."); } catch { WriteLog(LogType.error, "Failed to enter paused state after 'take_five' request received."); }
break; break;