Exemplo n.º 1
0
        public Response Post(LocalisationProperties theModel)
        {
            Core.Instance.Localisation.UpdateProperties(theModel);

            return(new Response
            {
                StatusCode = System.Net.HttpStatusCode.Moved,
                Location = new Uri(Context.Request.AbsoluteUri)
            });
        }
Exemplo n.º 2
0
        public Response Get()
        {
            LocalisationProperties Properties = Core.Instance.Localisation.RepopulateAndGetProperties();

            if (Utils.Hardware.isRunningRaspberryPi)
            {
                return(new Response
                {
                    Model = Properties,
                    Template = Templates.Localisation
                });
            }
            else
            {
                return(new Response
                {
                    StatusCode = System.Net.HttpStatusCode.Redirect,
                    Location = new Uri(Context.Paths.Base + Context.Paths.Home)
                });
            }
        }
Exemplo n.º 3
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);
        }