public ClockServer Start(ClockSettings settings)
 {
     Update(settings);
     PollingService.TryStartPolling();
     Multicaster.TryStartMulticast();
     return(this);
 }
        public void Update(ClockSettings settings)
        {
            if (settings == null)
            {
                return;
            }
            IsRealtime             = settings.IsRealTime;
            StartDayAndTime        = SetStartDayAndTime(settings.StartTime, settings.StartWeekday);
            Speed                  = settings.Speed ?? Speed;
            Duration               = settings.DurationHours.HasValue ? TimeSpan.FromHours(settings.DurationHours.Value) : Duration;
            PauseTime              = settings.PauseTime;
            PauseReason            = settings.PauseReason;
            ExpectedResumeTime     = settings.ExpectedResumeTime;
            ShowRealTimeWhenPaused = settings.ShowRealTimeWhenPaused;
            Elapsed                = settings.OverriddenElapsedTime.HasValue ? settings.OverriddenElapsedTime.Value - StartTime : Elapsed;
            Message                = settings.Message ?? Message;
            if (settings.ShouldRestart)
            {
                Elapsed = TimeSpan.Zero; IsRunning = false;
            }
            if (settings.IsRunning)
            {
                StartTick();
            }
            else
            {
                StopTick();
            }

            TimeSpan SetStartDayAndTime(TimeSpan?startTime, Weekday?startDay) =>
            new TimeSpan((int)(startDay ?? Weekday.NoDay), startTime?.Hours ?? Options.StartTime.Hours, startTime?.Minutes ?? Options.StartTime.Minutes, 0);
        }
        public bool Update(ClockSettings settings)
        {
            if (settings == null)
            {
                return(false);
            }
            if (Name?.Equals(settings.Name, StringComparison.OrdinalIgnoreCase) != true)
            {
                return(false);
            }
            if (!string.IsNullOrWhiteSpace(settings.Password))
            {
                Password = settings.Password;
            }
            IsRealtime             = settings.IsRealTime;
            StartDayAndTime        = SetStartDayAndTime(settings.StartTime, settings.StartWeekday);
            Speed                  = settings.Speed ?? Speed;
            Duration               = settings.DurationHours.HasValue ? TimeSpan.FromHours(settings.DurationHours.Value) : Duration;
            PauseTime              = settings.PauseTime;
            PauseReason            = settings.PauseReason;
            ExpectedResumeTime     = settings.ExpectedResumeTime;
            ShowRealTimeWhenPaused = settings.ShowRealTimeWhenPaused;
            Elapsed                = settings.OverriddenElapsedTime.HasValue ? settings.OverriddenElapsedTime.Value - StartTime : Elapsed;
            Message                = settings.Message ?? Message;
            if (settings.ShouldRestart)
            {
                Elapsed = TimeSpan.Zero; IsRunning = false;
            }
            if (settings.IsRunning)
            {
                StartTick(StoppingUser, Password);
            }
            else
            {
                StopTick();
            }

            TimeSpan SetStartDayAndTime(TimeSpan?startTime, Weekday?startDay) =>
            new TimeSpan((int)(startDay ?? Weekday.NoDay), startTime?.Hours ?? Options.StartTime.Hours, startTime?.Minutes ?? Options.StartTime.Minutes, 0);

            return(true);
        }
 public bool Update(ClockSettings settings, IPAddress ipAddress, string?userName)
 {
     UpdateUser(ipAddress, userName);
     return(Update(settings));
 }