internal void UpdateProperties(InterfacingProperties theModel) { List <Task <ProcessResult> > Tasks = new List <Task <ProcessResult> >(); bool AskToRestart = false; RepopulateAndGetProperties(); Task <ProcessResult> SetCamera = null; if (Camera != theModel.Camera) { AskToRestart = true; LoggingActions.LogTaskAction(Log, theModel.Camera, EventLogEntryCodes.CameraSettingEnabling, EventLogEntryCodes.CameraSettingDisabling); SetCamera = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_camera " + (theModel.Camera ? c_Enabled : c_Disabled)); Tasks.Add(SetCamera); } Task <ProcessResult> SetSSH = null; if (SSH != theModel.SSH) { LoggingActions.LogTaskAction(Log, theModel.SSH, EventLogEntryCodes.SSHSettingEnabling, EventLogEntryCodes.SSHSettingDisabling); SetSSH = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_ssh " + (theModel.SSH ? c_Enabled : c_Disabled)); Tasks.Add(SetSSH); } Task <ProcessResult> SetVNC = null; if (VNC != theModel.VNC) { LoggingActions.LogTaskAction(Log, theModel.VNC, EventLogEntryCodes.VNCSettingEnabling, EventLogEntryCodes.VNCSettingDisabling); SetVNC = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_vnc " + (theModel.VNC ? c_Enabled : c_Disabled)); Tasks.Add(SetVNC); } Task <ProcessResult> SetSPI = null; if (SPI != theModel.SPI) { LoggingActions.LogTaskAction(Log, theModel.SPI, EventLogEntryCodes.SPISettingEnabling, EventLogEntryCodes.SPISettingDisabling); SetSPI = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_spi " + (theModel.SPI ? c_Enabled : c_Disabled)); Tasks.Add(SetSPI); } Task <ProcessResult> SetI2C = null; if (I2C != theModel.I2C) { LoggingActions.LogTaskAction(Log, theModel.I2C, EventLogEntryCodes.I2CSettingEnabling, EventLogEntryCodes.I2CSettingDisabling); SetI2C = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_i2c " + (theModel.I2C ? c_Enabled : c_Disabled)); Tasks.Add(SetI2C); } Task <ProcessResult> SetSerial = null; if (Serial != theModel.Serial) { AskToRestart = true; LoggingActions.LogTaskAction(Log, theModel.Serial, EventLogEntryCodes.SerialSettingEnabling, EventLogEntryCodes.SerialSettingDisabling); SetSerial = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_serial " + (theModel.Serial ? c_Enabled : c_Disabled)); Tasks.Add(SetSerial); } Task <ProcessResult> SetOneWire = null; if (OneWire != theModel.OneWire) { AskToRestart = true; LoggingActions.LogTaskAction(Log, theModel.OneWire, EventLogEntryCodes.OneWireSettingEnabling, EventLogEntryCodes.OneWireSettingDisabling); SetOneWire = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_onewire " + (theModel.OneWire ? c_Enabled : c_Disabled)); Tasks.Add(SetOneWire); } Task <ProcessResult> SetRemoteGPIO = null; if (RemoteGPIO != theModel.RemoteGPIO) { LoggingActions.LogTaskAction(Log, theModel.RemoteGPIO, EventLogEntryCodes.RemoteGPIOSettingEnabling, EventLogEntryCodes.RemoteGPIOSettingDisabling); SetRemoteGPIO = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_rgpio " + (theModel.RemoteGPIO ? c_Enabled : c_Disabled)); Tasks.Add(SetRemoteGPIO); } Task.WaitAll(Tasks.ToArray()); if (AskToRestart) { RestartDue?.Invoke(); } // Check if Tasks have completed Okay and Log result LoggingActions.LogTaskResult(Log, SetCamera, theModel.Camera, EventLogEntryCodes.CameraSettingEnabled, EventLogEntryCodes.CameraSettingDisabled, EventLogEntryCodes.CameraSettingError); LoggingActions.LogTaskResult(Log, SetSSH, theModel.SSH, EventLogEntryCodes.SSHSettingEnabled, EventLogEntryCodes.SSHSettingDisabled, EventLogEntryCodes.SSHSettingError); LoggingActions.LogTaskResult(Log, SetVNC, theModel.VNC, EventLogEntryCodes.VNCSettingEnabled, EventLogEntryCodes.VNCSettingDisabled, EventLogEntryCodes.VNCSettingError); LoggingActions.LogTaskResult(Log, SetSPI, theModel.SPI, EventLogEntryCodes.SPISettingEnabled, EventLogEntryCodes.SPISettingDisabled, EventLogEntryCodes.SPISettingError); LoggingActions.LogTaskResult(Log, SetI2C, theModel.I2C, EventLogEntryCodes.I2CSettingEnabled, EventLogEntryCodes.I2CSettingDisabled, EventLogEntryCodes.I2CSettingError); LoggingActions.LogTaskResult(Log, SetSerial, theModel.Serial, EventLogEntryCodes.SerialSettingEnabled, EventLogEntryCodes.SerialSettingDisabled, EventLogEntryCodes.SerialSettingError); LoggingActions.LogTaskResult(Log, SetOneWire, theModel.OneWire, EventLogEntryCodes.OneWireSettingEnabled, EventLogEntryCodes.OneWireSettingDisabled, EventLogEntryCodes.OneWireSettingError); LoggingActions.LogTaskResult(Log, SetRemoteGPIO, theModel.RemoteGPIO, EventLogEntryCodes.RemoteGPIOSettingEnabled, EventLogEntryCodes.RemoteGPIOSettingDisabled, EventLogEntryCodes.RemoteGPIOSettingError); }
internal void UpdateProperties(LocalisationProperties theModel) { List <Task <ProcessResult> > Tasks = new List <Task <ProcessResult> >(); RepopulateAndGetProperties(); bool AskToRestart = false; Task <ProcessResult> StartTimesyncd = null; Task <ProcessResult> DisableTimesyncd = null; if (TimeSyncdEnabled != theModel.TimeSyncdEnabled) { LoggingActions.LogTaskAction(Log, theModel.TimeSyncdEnabled, EventLogEntryCodes.TimesyncdEnabling, EventLogEntryCodes.TimesyncdStopping); if (theModel.TimeSyncdEnabled) { Task <ProcessResult> EnableTimesyncd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "enable systemd-timesyncd"); EnableTimesyncd.Wait(); LoggingActions.LogTaskResult(Log, EnableTimesyncd, EventLogEntryCodes.TimesyncdEnabled, EventLogEntryCodes.TimesyncdEnablingError); if (EnableTimesyncd.Result.Okay()) { Log?.Invoke(EventLogEntryCodes.TimesyncdStarting, null); StartTimesyncd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "start systemd-timesyncd"); Tasks.Add(StartTimesyncd); } } else { Task <ProcessResult> StopTimesyncd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "stop systemd-timesyncd"); StopTimesyncd.Wait(); LoggingActions.LogTaskResult(Log, StopTimesyncd, EventLogEntryCodes.TimesyncdStopped, EventLogEntryCodes.TimesyncdStoppingError); if (StopTimesyncd.Result.Okay()) { Log?.Invoke(EventLogEntryCodes.TimesyncdDisabling, null); DisableTimesyncd = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "disable systemd-timesyncd"); Tasks.Add(DisableTimesyncd); } } } Task <ProcessResult> StartFakeHWClock = null; Task <ProcessResult> DisableFakeHWClock = null; if (FakeHWClockEnabled != theModel.FakeHWClockEnabled) { LoggingActions.LogTaskAction(Log, theModel.FakeHWClockEnabled, EventLogEntryCodes.FakeHwClockEnabling, EventLogEntryCodes.FakeHwClockStopping); if (theModel.FakeHWClockEnabled) { Task <ProcessResult> EnableFakeHWClock = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "enable fake-hwclock"); EnableFakeHWClock.Wait(); LoggingActions.LogTaskResult(Log, EnableFakeHWClock, EventLogEntryCodes.FakeHwClockEnabled, EventLogEntryCodes.FakeHwClockEnablingError); if (EnableFakeHWClock.Result.Okay()) { Log?.Invoke(EventLogEntryCodes.TimesyncdEnabling, null); StartFakeHWClock = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "start fake-hwclock"); Tasks.Add(StartFakeHWClock); } } else { Task <ProcessResult> StopFakeHWClock = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "stop fake-hwclock"); StopFakeHWClock.Wait(); LoggingActions.LogTaskResult(Log, StopFakeHWClock, EventLogEntryCodes.FakeHwClockStopped, EventLogEntryCodes.FakeHwClockStoppingError); if (StopFakeHWClock.Result.Okay()) { Log?.Invoke(EventLogEntryCodes.FakeHwClockDisabling, null); DisableFakeHWClock = ProcessRunner.GetProcessResultAsync(c_LinuxSystemControlCommand, "disable fake-hwclock"); Tasks.Add(DisableFakeHWClock); } } } Task <ProcessResult> SetTimeZone = null; if (TimeZone != theModel.TimeZone) { Log?.Invoke(EventLogEntryCodes.TimeZoneSetting, new string[] { theModel.TimeZone }); SetTimeZone = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_change_timezone " + theModel.TimeZone); Tasks.Add(SetTimeZone); } Task <ProcessResult> SetWifiCountry = null; if (WifiCountry != theModel.WifiCountry) { if (theModel.WifiCountry == string.Empty) { AskToRestart = true; Log?.Invoke(EventLogEntryCodes.WifiCountrySetting, new string[] { "None" }); SetWifiCountry = UnsetWiFiSequence(); Tasks.Add(SetWifiCountry); } else { AskToRestart = true; Log?.Invoke(EventLogEntryCodes.WifiCountrySetting, new string[] { theModel.WifiCountry }); SetWifiCountry = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_wifi_country " + theModel.WifiCountry); Tasks.Add(SetWifiCountry); } } Task <ProcessResult> SetDate = null; if (theModel.SetDate) { DateTime DateConvert = DateTime.ParseExact(theModel.Date.Replace("/", ""), "ddMMyyyy", CultureInfo.InvariantCulture); string DateCommand = "+%Y%m%d -s \"" + DateConvert.ToString("yyyyMMdd") + "\""; Log?.Invoke(EventLogEntryCodes.DateSetting, new string[] { "date " + DateCommand }); SetDate = ProcessRunner.GetProcessResultAsync(c_DateCommand, DateCommand); Tasks.Add(SetDate); } Task <ProcessResult> SetTime = null; if (theModel.SetTime) { string TimeCommand = "+%T -s \"" + theModel.Time + "\""; Log?.Invoke(EventLogEntryCodes.TimeSetting, new string[] { "date " + TimeCommand }); SetTime = ProcessRunner.GetProcessResultAsync(c_DateCommand, TimeCommand); Tasks.Add(SetTime); } if (AskToRestart) { RestartDue?.Invoke(); } Task.WaitAll(Tasks.ToArray()); Task <ProcessResult> SyncRTC = null; if (HWClockPresent && (theModel.SetTime || theModel.SetDate || (theModel.TimeSyncdEnabled && !TimeSyncdEnabled)) && theModel.HWClockPresent) { Log?.Invoke(EventLogEntryCodes.RTCSyncing, null); SyncRTC = ProcessRunner.GetProcessResultAsync(c_HardwareClockCommand, "-w"); SyncRTC.Wait(); } // Check if Tasks have completed Okay and Log result LoggingActions.LogTaskResult(Log, StartTimesyncd, EventLogEntryCodes.TimesyncdStarted, EventLogEntryCodes.TimesyncdStartingError); LoggingActions.LogTaskResult(Log, DisableTimesyncd, EventLogEntryCodes.TimesyncdDisabled, EventLogEntryCodes.TimesyncdDisablingError); LoggingActions.LogTaskResult(Log, StartFakeHWClock, EventLogEntryCodes.FakeHwClockStarted, EventLogEntryCodes.FakeHwClockStartingError); LoggingActions.LogTaskResult(Log, DisableFakeHWClock, EventLogEntryCodes.FakeHwClockDisabled, EventLogEntryCodes.FakeHwClockDisablingError); LoggingActions.LogTaskResult(Log, SetTimeZone, EventLogEntryCodes.TimeZoneSet, EventLogEntryCodes.TimeZoneSettingError); LoggingActions.LogTaskResult(Log, SetWifiCountry, EventLogEntryCodes.WifiCountrySet, EventLogEntryCodes.WifiCountrySettingError); LoggingActions.LogTaskResult(Log, SetDate, EventLogEntryCodes.DateSet, EventLogEntryCodes.DateSettingError); LoggingActions.LogTaskResult(Log, SetTime, EventLogEntryCodes.TimeSet, EventLogEntryCodes.TimeSettingError); LoggingActions.LogTaskResult(Log, SyncRTC, EventLogEntryCodes.RTCSynced, EventLogEntryCodes.RTCSyncError); }
internal void UpdateProperties(BootProperties theModel) { List <Task <ProcessResult> > Tasks = new List <Task <ProcessResult> >(); bool AskToRestart = false; RepopulateAndGetProperties(); Task <ProcessResult> SetBootBehaviour = null; if (theModel.BootBehaviour != 0) { AskToRestart = true; LoggingActions.LogTaskAction(Log, (theModel.BootBehaviour - 1), new EventLogEntryCodes[] { EventLogEntryCodes.BootBehaviourSettingConsole, EventLogEntryCodes.BootBehaviourSettingConsoleAutologin, EventLogEntryCodes.BootBehaviourSettingDesktop, EventLogEntryCodes.BootBehaviourSettingDesktopAutologin }); SetBootBehaviour = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_boot_behaviour B" + theModel.BootBehaviour); Tasks.Add(SetBootBehaviour); } Task <ProcessResult> SetNetworkWait = null; if (NetworkWait != theModel.NetworkWait) { LoggingActions.LogTaskAction(Log, theModel.NetworkWait, EventLogEntryCodes.NetworkWaitSettingTrue, EventLogEntryCodes.NetworkWaitSettingFalse); SetNetworkWait = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_boot_wait " + (theModel.NetworkWait ? "0" : "1")); Tasks.Add(SetNetworkWait); } Task <ProcessResult> SetSplashScreen = null; if (SplashScreen != theModel.SplashScreen) { LoggingActions.LogTaskAction(Log, theModel.SplashScreen, EventLogEntryCodes.SplashScreenSettingTrue, EventLogEntryCodes.SplashScreenSettingFalse); SetSplashScreen = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_boot_splash " + (theModel.SplashScreen ? "0" : "1")); Tasks.Add(SetSplashScreen); } Task <ProcessResult> SetBootOrder = null; if (theModel.BootOrder != 0) { LoggingActions.LogTaskAction(Log, (theModel.BootOrder - 1), new EventLogEntryCodes[] { EventLogEntryCodes.BootOrderSettingUSB, EventLogEntryCodes.BootOrderSettingNetwork }); SetBootOrder = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_boot_order B" + theModel.BootOrder); Tasks.Add(SetBootOrder); } Task <ProcessResult> SetBootROM = null; if (theModel.BootROM != 0) { AskToRestart = true; LoggingActions.LogTaskAction(Log, (theModel.BootROM - 1), new EventLogEntryCodes[] { EventLogEntryCodes.BootROMSettingLatest, EventLogEntryCodes.BootROMSettingDefault }); SetBootROM = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_boot_rom E" + theModel.BootROM); Tasks.Add(SetBootROM); } if (AskToRestart) { RestartDue?.Invoke(); } Task.WaitAll(Tasks.ToArray()); // Check if Tasks have completed Okay and Log result LoggingActions.LogTaskResult(Log, SetBootBehaviour, EventLogEntryCodes.BootBehaviourSet, EventLogEntryCodes.BootBehaviourSettingError); LoggingActions.LogTaskResult(Log, SetNetworkWait, EventLogEntryCodes.NetworkWaitSet, EventLogEntryCodes.NetworkWaitSettingError); LoggingActions.LogTaskResult(Log, SetSplashScreen, EventLogEntryCodes.SplashScreenSet, EventLogEntryCodes.SplashScreenSettingError); LoggingActions.LogTaskResult(Log, SetBootOrder, EventLogEntryCodes.BootOrderSet, EventLogEntryCodes.BootOrderSettingError); LoggingActions.LogTaskResult(Log, SetBootROM, EventLogEntryCodes.BootROMSet, EventLogEntryCodes.BootROMSettingError); }