private void timerCallbackSet(object state)
        {
            timelineEventArgs args = new timelineEventArgs();
            args.newValue = new pinDataBool(true, this, pinInfo["IntervalIsNow"]);
            onRequestNewTimelineEvent(args);

            timelineEventArgs cancelArgs = new timelineEventArgs();
            cancelArgs.newValue = new pinDataBool(false, this, pinInfo["IntervalIsNow"]);
            onRequestNewTimelineEventInFuture(cancelArgs, 2);

            //    _timer.setTo(false);
        }
Example #2
0
        private void checkTime(object state)
        {
            DateTime now = DateTime.Now;
            DateTime targettime = new DateTime(now.Year, now.Month, now.Day, (int)hours, (int)minutes, 00);
            DateTime lasttime = new DateTime(now.Year, now.Month, now.Day, (int)this._lastHours, (int)this._lastMinutes, 00);

            if (!this._running)
            {
                // This is the first time we have been called. Set the last time and return
                this._lastHours = now.Hour;
                this._lastMinutes = now.Minute;
                this._running = true;
                return;
            }
            bool doit = false;
            switch (options.when)
            {
                    case TimeToRun.Daily:
                        doit = (targettime > lasttime ) &&       // was time of last check before the target time?
                                (targettime < now      );
                        break;
                    case TimeToRun.Weekly:
                        doit = (targettime > lasttime) &&       // was time of last check before the target time?
                                (targettime < now) &&
                                ((int)now.DayOfWeek) == options.Day;
                        break;
                    case TimeToRun.Monthly:
                        int dayToRun = DateTime.DaysInMonth(now.Year, now.Month);
                        // if greater than the days in the month use the last day
                        if (options.Day < dayToRun) dayToRun = options.Day;
                        doit = (targettime > lasttime) && // was time of last check before the target time?
                               (targettime < now) &&
                               now.Day == dayToRun;
                        break;
                    case TimeToRun.Yearly:
                        doit = (targettime > lasttime) && // was time of last check before the target time?
                               (targettime < now) &&
                               now.Month == options.Month &&
                               now.Year == options.Year;
                        break;
            }

            // Otherwise, see if the specified date has passed since the last call.

            if (targettime.CompareTo(now) == 0)     // or it is exactly time
                doit = true;

            if (doit == true)
            {
                timelineEventArgs startArgs = new timelineEventArgs();
                startArgs.newValue = new pinDataBool(true, this, pinInfo["timeIsNow"]);
                onRequestNewTimelineEvent(startArgs);

                timelineEventArgs cancelArgs = new timelineEventArgs();
                cancelArgs.newValue = new pinDataBool(false, this, pinInfo["timeIsNow"]);
                onRequestNewTimelineEventInFuture(cancelArgs, 2);
            }

            this._lastHours = now.Hour;
            this._lastMinutes = now.Minute;
        }