Beispiel #1
0
        internal static void OnTimeServiceEventCallback(TimeServiceEvent timeServiceEvent)
        {
            switch (timeServiceEvent.EventType)
            {
            case TimeServiceEventType.SystemTimeChanged:
            {
                if (SystemTimeChanged != null)
                {
                    SystemTimeChangedEventArgs args = new SystemTimeChangedEventArgs(timeServiceEvent.EventTime);

                    SystemTimeChanged(null, args);
                }
                break;
            }

            case TimeServiceEventType.TimeSyncFailed:
            {
                if (TimeSyncFailed != null)
                {
                    TimeSyncFailedEventArgs args = new TimeSyncFailedEventArgs(timeServiceEvent.EventTime, timeServiceEvent.Status);

                    TimeSyncFailed(null, args);
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }
 // check and return status
 private static TimeServiceStatus CheckResults(uint tolerance, DateTime ntpTime)
 {
     if (ntpTime == DateTime.MinValue)
     {
         // fail: call failEvent
         status.Flags = TimeServiceStatus.TimeServiceStatusFlags.SyncFailed;
         TimeSyncFailedEventArgs failEvent = new TimeSyncFailedEventArgs(DateTime.Now, errorCode);
         TimeSyncFailed(null, failEvent);
     }
     else
     {
         // succeed: if (change > tolerance) then set time & call changed Event
         status.Flags = TimeServiceStatus.TimeServiceStatusFlags.SyncSucceeded;
         TimeSpan syncTimeOffset = DateTime.Now - ntpTime;
         status.SyncTimeOffset = (syncTimeOffset.Ticks / TimeSpan.TicksPerMillisecond);
         if (System.Math.Abs(status.SyncTimeOffset) > tolerance)
         {
             SetUtcTime(ntpTime.Ticks);
             SystemTimeChangedEventArgs changedEvent = new SystemTimeChangedEventArgs(DateTime.Now);
             SystemTimeChanged(null, changedEvent);
         }
         SystemTimeChangedEventArgs checkedEvent = new SystemTimeChangedEventArgs(DateTime.Now);
         SystemTimeChecked(null, checkedEvent);
     }
     return(status);
 }
 void TimeService_SystemTimeChanged(object sender, SystemTimeChangedEventArgs e)
 {
     timerEvent.Set();
 }
Beispiel #4
0
 void TimeService_SystemTimeChanged(object sender, SystemTimeChangedEventArgs e)
 {
     Debug.Print("Network time received.");
     if (!timeSynchronized)
         timeSynchronized = true;
 }
Beispiel #5
0
 void TimeService_SystemTimeChanged(object sender, SystemTimeChangedEventArgs evt)
 {
     Debug.Print("System Time Changed.");
 }
Beispiel #6
0
 /// <summary>
 /// TimeService SystemTimeChanged Event, when the system time changes, we need to set offset depending on daylight savings
 /// </summary>
 /// <param name="sender">Sender object</param>
 /// <param name="e">SystemTimeChangedEvent Arguments</param>
 private void TimeService_SystemTimeChanged(object sender, SystemTimeChangedEventArgs e)
 {
     //Daylight savings are the last sunday of march and october
     DateTime march = new DateTime(DateTime.Now.Year, 3, 1);
     DateTime october = new DateTime(DateTime.Now.Year, 10, 1);
     //Get last sunday in both months
     DateTime daylightstart = LastDayInMonth(march, DayOfWeek.Sunday);
     DateTime daylightstop = LastDayInMonth(october, DayOfWeek.Sunday);
     //If we are within thoose dates, add daylight saving time
     if (daylightstart.Ticks < DateTime.Now.Ticks && daylightstop.Ticks > DateTime.Now.Ticks)
         TimeService.SetTimeZoneOffset(TimeZoneMinutes + DaylightSavingTime);
     else
         TimeService.SetTimeZoneOffset(TimeZoneMinutes);
 }
Beispiel #7
0
        // Called on successful NTP Synchronization
        private void OnSystemTimeChanged(Object sender, SystemTimeChangedEventArgs e)
        {
            var now = DateTime.Now; // Used to manipulate dates and time

            #region Check if we are in summer time and thus daylight savings apply

            // Check if we are in Daylight savings. The following algorithm works pour Europe and associated countries
            // In Europe, daylight savings (+60 min) starts the last Sunday of march and ends the last sunday of october

            var aprilFirst = new DateTime(now.Year, 4, 1);
            var novemberFirst = new DateTime(now.Year, 11, 1);
            var sundayshift = new[] {0, -1, -2, -3, -4, -5, -6};
            var marchLastSunday = aprilFirst.DayOfYear + sundayshift[(int) aprilFirst.DayOfWeek];
            var octoberLastSunday = novemberFirst.DayOfYear + sundayshift[(int) novemberFirst.DayOfWeek];

            if ((now.DayOfYear >= marchLastSunday) && (now.DayOfYear < octoberLastSunday))
                _daylightSavingsShift = 60;
            else
                _daylightSavingsShift = 0;

            TimeService.SetTimeZoneOffset(LocalTimeZone + _daylightSavingsShift);

            #endregion

            // Display the synchronized date on the Debug Console

            now = DateTime.Now;
            var date = now.ToString("dd/MM/yyyy");
            var here = now.ToString("HH:mm:ss");
            Debug.Print(date + " // " + here);
        }
        internal static void OnTimeServiceEventCallback(TimeServiceEvent timeServiceEvent)
        {
            switch (timeServiceEvent.EventType)
            {
                case TimeServiceEventType.SystemTimeChanged:
                    {
                        if (SystemTimeChanged != null)
                        {
                            SystemTimeChangedEventArgs args = new SystemTimeChangedEventArgs(timeServiceEvent.EventTime);

                            SystemTimeChanged(null, args);
                        }
                        break;
                    }
                case TimeServiceEventType.TimeSyncFailed:
                    {
                        if (TimeSyncFailed != null)
                        {
                            TimeSyncFailedEventArgs args = new TimeSyncFailedEventArgs(timeServiceEvent.EventTime, timeServiceEvent.Status);

                            TimeSyncFailed(null, args);
                        }
                        break;
                    }
                default:
                    {
                        break;
                    }
            }
        }
Beispiel #9
0
 void TimeService_SystemTimeChanged(object sender, SystemTimeChangedEventArgs e)
 {
     Debug.Print("DateTime = " + DateTime.Now.ToString());
     this.WriteOnDisplay(0, 0, "DateTime:");
     this.WriteOnDisplay(1, 0, DateTime.Now.ToString());
 }
 private static void TimeService_SystemTimeChecked(object sender, SystemTimeChangedEventArgs e)
 {
     RealTimeClock.SetTime(e.EventTime);
 }
 private static void TimeService_SystemTimeChanged(object sender, SystemTimeChangedEventArgs e)
 {
 }
Beispiel #12
0
 void TimeService_SystemTimeChanged(object sender, SystemTimeChangedEventArgs e)
 {
     Debug.Print("System time changed." + e.EventTime);
 }
Beispiel #13
0
 private void TimeService_SystemTimeChanged(object sender, SystemTimeChangedEventArgs e)
 {
     lock (this)
     {
         hasTimeFixed = true;
     }
     Debug.Print("Time Fixed");
 }