internal MemoryProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [2];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_DFCommand, "-h");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_FreeCommand, "-h -t");

            Task.WaitAll(Tasks);

            this.FreeDisk = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                            .Skip(1)
                            .Select(line => line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries))
                            .ToArray()
                : new string[0][];

            this.FreeRam = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
                           .Skip(1)
                           .Select(line => line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries))
                           .ToArray()
                : new string[0][];

            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.DiskFreeSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.RAMFreeSettingGetError);

            return(this);
        }
        internal NetworkProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [4];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/etc/hostname");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 get country");
            Tasks[2] = GetSSIDs();
            Tasks[3] = ProcessRunner.GetProcessResultAsync(c_IFConfigCommand);

            ReadResult ReadResult = DHCPCD.Read();

            var Eth0 = ReadResult.Properties.FirstOrDefault(nic => nic.Id == c_Eth0);

            Eth0IPAddress         = (Eth0 == null || Eth0.IPAddress == null) ? string.Empty : Eth0.IPAddress;
            Eth0IP6Address        = (Eth0 == null || Eth0.IP6Address == null) ? string.Empty : Eth0.IP6Address;
            Eth0Routers           = (Eth0 == null || Eth0.Routers == null) ? new string[0] : Eth0.Routers;
            Eth0DomainNameServers = (Eth0 == null || Eth0.DomainNameServers == null) ? new string[0] : Eth0.DomainNameServers;

            var Wlan0 = ReadResult.Properties.FirstOrDefault(nic => nic.Id == c_Wlan0);

            Wlan0IPAddress         = (Wlan0 == null || Wlan0.IPAddress == null) ? string.Empty : Wlan0.IPAddress;
            Wlan0IP6Address        = (Wlan0 == null || Wlan0.IP6Address == null) ? string.Empty : Wlan0.IP6Address;
            Wlan0Routers           = (Wlan0 == null || Wlan0.Routers == null) ? new string[0] : Wlan0.Routers;
            Wlan0DomainNameServers = (Wlan0 == null || Wlan0.DomainNameServers == null) ? new string[0] : Wlan0.DomainNameServers;

            ReadResult = null;

            Task.WaitAll(Tasks);

            var WiFiCountryResult = Tasks[1].Result.GetOutput().TrimEnd();

            WiFiCountrySet = WiFiCountryResult != c_WiFiCountryNotSet;

            HostName    = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().TrimEnd() : string.Empty;
            WiFiCountry = WiFiCountrySet ? WiFiCountryResult : string.Empty;
            SSIDs       = ProcessSSIDs(Tasks[2]);
            Interfaces  = Tasks[3].Result.Okay() ? IFCONFIG.Parse(Tasks[3].Result.GetOutput()) : new NICInterface[0];

            // Log only if errors have occured
            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.HostNameSettingsGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.WiFiCountrySettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.SSIDSettingsGetError);
            LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.NICInterfacesGetError);
            return(this);
        }
        internal HatProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            if (Directory.Exists("/proc/device-tree/hat/"))
            {
                Task <ProcessResult>[] Tasks = new Task <ProcessResult> [5];

                Tasks[0] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/hat/product");
                Tasks[1] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/hat/product_id");
                Tasks[2] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/hat/product_ver");
                Tasks[3] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/hat/uuid");
                Tasks[4] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/hat/vendor");

                Task.WaitAll(Tasks);

                Product        = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput() : string.Empty;
                ProductId      = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput() : string.Empty;
                ProductVersion = Tasks[2].Result.Okay() ? Tasks[2].Result.GetOutput() : string.Empty;
                UUID           = Tasks[3].Result.Okay() ? Tasks[3].Result.GetOutput() : string.Empty;
                Vendor         = Tasks[4].Result.Okay() ? Tasks[4].Result.GetOutput() : string.Empty;

                // Log only if errors have occured
                LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.HATSettingsGetProductError);
                LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.HATSettingsGetProductIdError);
                LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.HATSettingsGetProductVersionError);
                LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.HATSettingsGetUUIDError);
                LoggingActions.LogTaskResult(Log, Tasks[4], EventLogEntryCodes.HATSettingsGetVendorError);
            }
            else
            {
                Product        = string.Empty;
                ProductId      = string.Empty;
                ProductVersion = string.Empty;
                UUID           = string.Empty;
                Vendor         = string.Empty;
            }

            return(this);
        }
Example #4
0
        internal LocalisationProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [9];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/usr/share/zoneinfo/iso3166.tab");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_WPACliCommand, "-i wlan0 get country");
            Tasks[2] = ProcessRunner.GetProcessResultAsync(c_TimeDateControlCommand, "list-timezones");
            Tasks[3] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/etc/timezone");
            Tasks[4] = ProcessRunner.GetProcessResultAsync(c_DateCommand, "+%d/%m/%Y");
            Tasks[5] = ProcessRunner.GetProcessResultAsync(c_DateCommand, "+%T");
            Tasks[6] = ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "is-active systemd-timesyncd");
            Tasks[7] = ProcessRunner.GetProcessResultAsync(c_SystemCtlCommand, "is-active fake-hwclock");
            Tasks[8] = ProcessRunner.GetProcessResultAsync(c_HardwareClockCommand, "-r");

            Task.WaitAll(Tasks);

            WifiCountry        = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput() : string.Empty;
            WifiCountries      = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Skip(25).Select(line => new string[] { line, line.StartsWith(WifiCountry) ? "selected=\"selected\"" : "" }).ToArray() : new string[0][];
            TimeZone           = Tasks[3].Result.Okay() ? Tasks[3].Result.GetOutput().TrimEnd() : string.Empty;
            TimeZones          = Tasks[2].Result.Okay() ? Tasks[2].Result.GetOutput().Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Skip(25).Select(line => new string[] { line, line.StartsWith(TimeZone) ? "selected=\"selected\"" : "" }).ToArray() : new string[0][];
            Date               = Tasks[4].Result.Okay() ? Tasks[4].Result.GetOutput().TrimEnd() : string.Empty;
            Time               = Tasks[5].Result.Okay() ? Tasks[5].Result.GetOutput().TrimEnd() : string.Empty;
            TimeSyncdEnabled   = Tasks[6].Result.Okay() ? Tasks[6].Result.GetOutput().TrimEnd().Equals(c_Active) : false;
            FakeHWClockEnabled = Tasks[7].Result.Okay() ? Tasks[7].Result.GetOutput().TrimEnd().Equals(c_Active) : false;
            HWClockPresent     = Tasks[8].Result.Okay();

            // Log only if errors have occured
            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.WiFiCountriesSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.WiFiCountrySettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.TimeZonesSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.TimeZoneSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[4], EventLogEntryCodes.DateSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[5], EventLogEntryCodes.TimeSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[6], EventLogEntryCodes.TimeSyncdEnabledSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[7], EventLogEntryCodes.FakeHWClockEnabledSettingGetError);

            return(this);
        }
        internal InterfacingProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [8];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_camera");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_ssh");
            Tasks[2] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_vnc");
            Tasks[3] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_spi");
            Tasks[4] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_i2c");
            Tasks[5] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_serial");
            Tasks[6] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_onewire");
            Tasks[7] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_rgpio");

            Task.WaitAll(Tasks);

            this.Camera     = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.SSH        = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.VNC        = Tasks[2].Result.Okay() ? Tasks[2].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.SPI        = Tasks[3].Result.Okay() ? Tasks[3].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.I2C        = Tasks[4].Result.Okay() ? Tasks[4].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.Serial     = Tasks[5].Result.Okay() ? Tasks[5].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.OneWire    = Tasks[6].Result.Okay() ? Tasks[6].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;
            this.RemoteGPIO = Tasks[7].Result.Okay() ? Tasks[7].Result.GetOutput().TrimEnd().Equals(c_Enabled) : false;

            // Log only if errors have occured
            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.CameraSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.SSHSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.VNCSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.SPISettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[4], EventLogEntryCodes.I2CSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[5], EventLogEntryCodes.SerialSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[6], EventLogEntryCodes.OneWireSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[7], EventLogEntryCodes.RemoteGPIOSettingGetError);

            return(this);
        }
        internal HomeProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [7];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/proc/device-tree/model");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/etc/debian_version");
            Tasks[2] = ProcessRunner.GetProcessResultAsync(c_CatCommand, "/etc/hostname");
            Tasks[3] = ProcessRunner.GetProcessResultAsync(c_DateCommand);
            Tasks[4] = GetGPUTemperature();
            Tasks[5] = GetCPUTemperature();
            Tasks[6] = GetDiskSpacePercentage();

            Task.WaitAll(Tasks);

            RaspberryPiModel   = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().TrimEnd() : string.Empty;
            OSVersion          = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput().TrimEnd() : string.Empty;
            HostName           = Tasks[2].Result.Okay() ? Tasks[2].Result.GetOutput().TrimEnd() : string.Empty;
            Date               = Tasks[3].Result.Okay() ? Tasks[3].Result.GetOutput().TrimEnd() : string.Empty;
            GPUTemperature     = ProcessGPUTemperature(Tasks[4]);
            CPUTemperature     = ProcessCPUTemperature(Tasks[5]);
            FreeDiskPercentage = ProcessDiskSpacePercentage(Tasks[6]);

            // Log only if errors have occured
            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.RaspberryPiModelSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.DebianVersionSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[2], EventLogEntryCodes.HostNameSettingsGetError);
            LoggingActions.LogTaskResult(Log, Tasks[3], EventLogEntryCodes.DateTimeSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[4], EventLogEntryCodes.GPUTemperatureSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[5], EventLogEntryCodes.CPUTemperatureSettingGetError);
            LoggingActions.LogTaskResult(Log, Tasks[6], EventLogEntryCodes.DiskFreeSettingGetError);

            return(this);
        }
Example #7
0
        internal BootProperties RepopulateAndGetProperties()
        {
            if (!Utils.Hardware.isRunningRaspberryPi)
            {
                return(this);
            }

            Task <ProcessResult>[] Tasks = new Task <ProcessResult> [2];

            Tasks[0] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_boot_wait");
            Tasks[1] = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint get_boot_splash");

            Task.WaitAll(Tasks);

            NetworkWait  = Tasks[0].Result.Okay() ? Tasks[0].Result.GetOutput().TrimEnd().Equals("0") : false;
            SplashScreen = Tasks[1].Result.Okay() ? Tasks[1].Result.GetOutput().TrimEnd().Equals("0") : false;

            // Log only if errors have occured
            LoggingActions.LogTaskResult(Log, Tasks[0], EventLogEntryCodes.NetworkWaitSettingsGetError);
            LoggingActions.LogTaskResult(Log, Tasks[1], EventLogEntryCodes.SplashScreenSettingsGetError);

            return(this);
        }
Example #8
0
        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(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(NetworkProperties theModel)
        {
            List <Task <ProcessResult> > Tasks = new List <Task <ProcessResult> >();
            bool AskToRestart = false;

            bool Eth0Changes  = false;
            bool Wlan0Changes = false;

            NetworkProperties CurrentSettings = Core.Instance.Network.RepopulateAndGetProperties();

            if (theModel.Eth0Routers == null)
            {
                theModel.Eth0Routers = new string[0];
            }
            if (theModel.Eth0DomainNameServers == null)
            {
                theModel.Eth0DomainNameServers = new string[0];
            }
            if (theModel.Wlan0Routers == null)
            {
                theModel.Wlan0Routers = new string[0];
            }
            if (theModel.Wlan0DomainNameServers == null)
            {
                theModel.Wlan0DomainNameServers = new string[0];
            }

            if (CurrentSettings.Eth0IPAddress != theModel.Eth0IPAddress)
            {
                Eth0Changes = true;
                if (string.IsNullOrEmpty(theModel.Eth0IPAddress))
                {
                    Log?.Invoke(EventLogEntryCodes.NICIP4DynamicChanging, new string[] { c_Eth0 });
                }
                else
                {
                    Log?.Invoke(EventLogEntryCodes.NICIP4StaticChanging, new string[] { c_Eth0, theModel.Eth0IPAddress });
                }
            }

            if (CurrentSettings.Eth0IP6Address != theModel.Eth0IP6Address)
            {
                Eth0Changes = true;
                if (string.IsNullOrEmpty(theModel.Eth0IP6Address))
                {
                    Log?.Invoke(EventLogEntryCodes.NICIP6DynamicChanging, new string[] { c_Eth0 });
                }
                else
                {
                    Log?.Invoke(EventLogEntryCodes.NICIP6StaticChanging, new string[] { c_Eth0, theModel.Eth0IP6Address });
                }
            }

            if (!CurrentSettings.Eth0Routers.OrderBy(e => e).SequenceEqual(theModel.Eth0Routers.OrderBy(e => e)))
            {
                Eth0Changes = true;
                Log?.Invoke(EventLogEntryCodes.NICRoutersChanging, new string[] { c_Eth0, string.Join(" ", theModel.Eth0Routers) });
            }

            if (!CurrentSettings.Eth0DomainNameServers.OrderBy(e => e).SequenceEqual(theModel.Eth0DomainNameServers.OrderBy(e => e)))
            {
                Eth0Changes = true;
                Log?.Invoke(EventLogEntryCodes.NICDNSChanging, new string[] { c_Eth0, string.Join(" ", theModel.Eth0DomainNameServers) });
            }

            if (CurrentSettings.Wlan0IPAddress != theModel.Wlan0IPAddress)
            {
                Wlan0Changes = true;
                if (string.IsNullOrEmpty(theModel.Wlan0IPAddress))
                {
                    Log?.Invoke(EventLogEntryCodes.NICIP6DynamicChanging, new string[] { c_Wlan0 });
                }
                else
                {
                    Log?.Invoke(EventLogEntryCodes.NICIP6StaticChanging, new string[] { c_Wlan0, theModel.Wlan0IPAddress });
                }
            }

            if (CurrentSettings.Wlan0IP6Address != theModel.Wlan0IP6Address)
            {
                Wlan0Changes = true;
                if (string.IsNullOrEmpty(theModel.Eth0IP6Address))
                {
                    Log?.Invoke(EventLogEntryCodes.NICIP6DynamicChanging, new string[] { c_Wlan0 });
                }
                else
                {
                    Log?.Invoke(EventLogEntryCodes.NICIP6StaticChanging, new string[] { c_Wlan0, theModel.Wlan0IP6Address });
                }
            }

            if (!CurrentSettings.Wlan0Routers.OrderBy(e => e).SequenceEqual(theModel.Wlan0Routers.OrderBy(e => e)))
            {
                Wlan0Changes = true;
                Log?.Invoke(EventLogEntryCodes.NICDNSChanging, new string[] { c_Wlan0, string.Join(" ", theModel.Wlan0Routers) });
            }

            if (!CurrentSettings.Wlan0DomainNameServers.OrderBy(e => e).SequenceEqual(theModel.Wlan0DomainNameServers.OrderBy(e => e)))
            {
                Wlan0Changes = true;
                Log?.Invoke(EventLogEntryCodes.NICDNSChanging, new string[] { c_Wlan0, string.Join(" ", theModel.Wlan0DomainNameServers) });
            }

            Task <ProcessResult> IPAddressTask = null;

            if (Eth0Changes || Wlan0Changes)
            {
                NICProperties eth0 = new NICProperties(c_Eth0);
                eth0.IPAddress         = theModel.Eth0IPAddress;
                eth0.IP6Address        = theModel.Eth0IP6Address;
                eth0.Routers           = theModel.Eth0Routers;
                eth0.DomainNameServers = theModel.Eth0DomainNameServers;

                NICProperties wlan0 = new NICProperties(c_Wlan0);
                wlan0.IPAddress         = theModel.Wlan0IPAddress;
                wlan0.IP6Address        = theModel.Wlan0IP6Address;
                wlan0.Routers           = theModel.Wlan0Routers;
                wlan0.DomainNameServers = theModel.Wlan0DomainNameServers;

                IPAddressTask = FlushNetworkSequence(Eth0Changes, Wlan0Changes, eth0, wlan0);
                Tasks.Add(IPAddressTask);
            }

            Task <ProcessResult> HostNameTask = null;

            if (CurrentSettings.HostName != theModel.HostName)
            {
                AskToRestart = true;
                HostNameTask = ProcessRunner.GetProcessResultAsync(c_LinuxRaspconfigCommand, "nonint do_hostname " + theModel.HostName);
                Tasks.Add(HostNameTask);
                Log?.Invoke(EventLogEntryCodes.HostNameChanging, new string[] { theModel.HostName });
            }

            Task <ProcessResult> SetWiFiSSIDPassphrase = null;

            if (!string.IsNullOrEmpty(theModel.NewSSID))
            {
                SetWiFiSSIDPassphrase = SetWiFiSSIDPassphraseSequence(theModel);
                Tasks.Add(SetWiFiSSIDPassphrase);
            }

            if (AskToRestart)
            {
                RestartDue?.Invoke();
            }

            Task.WaitAll(Tasks.ToArray());

            // Check if Tasks have completed Okay and Log result

            LoggingActions.LogTaskResult(Log, IPAddressTask, EventLogEntryCodes.NICIPChangesComplete, EventLogEntryCodes.NICIPChangesError);
            LoggingActions.LogTaskResult(Log, HostNameTask, EventLogEntryCodes.HostNameChanged, EventLogEntryCodes.HostNameChangeError);
            LoggingActions.LogTaskResult(Log, SetWiFiSSIDPassphrase, EventLogEntryCodes.SSIDChanged, EventLogEntryCodes.SSIDChangeError);
        }
Example #11
0
        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);
        }