Ejemplo n.º 1
0
        /// <summary>
        /// Checks if a device polling session of the device is required.
        /// </summary>
        private bool CheckSessionIsRequired(DeviceLogic deviceLogic, DateTime utcNow)
        {
            PollingOptions pollingOptions = deviceLogic.PollingOptions;
            bool           timeIsSet      = pollingOptions.Time > TimeSpan.Zero;
            bool           periodIsSet    = pollingOptions.Period > TimeSpan.Zero;

            if (timeIsSet || periodIsSet)
            {
                DateTime localNow        = utcNow.ToLocalTime();
                DateTime nowDate         = localNow.Date;
                TimeSpan nowTime         = localNow.TimeOfDay;
                DateTime lastSessionDate = deviceLogic.LastSessionTime.Date;
                TimeSpan lastSessionTime = deviceLogic.LastSessionTime.TimeOfDay;

                if (periodIsSet)
                {
                    // periodic polling
                    double timeInSec   = pollingOptions.Time.TotalSeconds;
                    double periodInSec = pollingOptions.Period.TotalSeconds;
                    int    n           = (int)((nowTime.TotalSeconds - timeInSec) / periodInSec) + 1;

                    return(pollingOptions.Time <= nowTime /*time to poll*/ &&
                           (lastSessionTime.TotalSeconds <= n * periodInSec + timeInSec ||
                            lastSessionTime > nowTime /*session was yesterday*/));
                }
                else if (timeIsSet)
                {
                    // polling once a day at a specified time
                    return(pollingOptions.Time <= nowTime /*time to poll*/ &&
                           (lastSessionDate < nowDate || lastSessionTime < pollingOptions.Time /*after an extra poll*/));
                }
            }

            // continuous cyclic polling
            return(true);
        }
Ejemplo n.º 2
0
 public ClockPollingService(PollingOptions options, ClockServer server)
 {
     Options = options;
     Server  = server;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets the default polling options for the device.
 /// </summary>
 public virtual PollingOptions GetPollingOptions()
 {
     return(PollingOptions.CreateDefault());
 }