public Response Post(InterfacingProperties theModel) { Core.Instance.Interfacing.UpdateProperties(theModel); return(new Response { StatusCode = System.Net.HttpStatusCode.Moved, Location = new Uri(Context.Request.AbsoluteUri) }); }
public Response Get() { InterfacingProperties Properties = Core.Instance.Interfacing.RepopulateAndGetProperties(); if (Utils.Hardware.isRunningRaspberryPi) { return(new Response { Model = Properties, Template = Templates.Interfacing }); } else { return(new Response { StatusCode = System.Net.HttpStatusCode.Redirect, Location = new Uri(Context.Paths.Base + Context.Paths.Home) }); } }
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); }