/// <summary>
        /// This method should not be used by the Quartz client.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Called by the scheduler at the time a <see cref="ITrigger" /> is first
        /// added to the scheduler, in order to have the <see cref="ITrigger" />
        /// compute its first fire time, based on any associated calendar.
        /// </para>
        ///
        /// <para>
        /// After this method has been called, <see cref="ITrigger.GetNextFireTimeUtc" />
        /// should return a valid answer.
        /// </para>
        /// </remarks>
        /// <returns>
        /// The first time at which the <see cref="ITrigger" /> will be fired
        /// by the scheduler, which is also the same value <see cref="ITrigger.GetNextFireTimeUtc" />
        /// will return (until after the first firing of the <see cref="ITrigger" />).
        /// </returns>
        public override DateTimeOffset?ComputeFirstFireTimeUtc(ICalendar calendar)
        {
            DateTimeOffset startTime          = StartTimeUtc.ToLocalTime();
            DateTimeOffset?startTimeOfDayDate = StartTimeOfDay.GetTimeOfDayForDate(startTime);

            // If startTime is after the timeOfDay, then use starTime
            if (startTime > startTimeOfDayDate)
            {
                nextFireTimeUtc = GetFireTimeAfter(startTime);
            }
            else
            {
                nextFireTimeUtc = AdvanceToNextDayOfWeek(startTimeOfDayDate.Value, false);
            }

            // Check calendar for date-time exclusion
            while (nextFireTimeUtc != null && calendar != null &&
                   !calendar.IsTimeIncluded(nextFireTimeUtc.Value))
            {
                nextFireTimeUtc = GetFireTimeAfter(nextFireTimeUtc);

                if (nextFireTimeUtc == null)
                {
                    break;
                }

                //avoid infinite loop
                if (nextFireTimeUtc.Value.Year > YearToGiveupSchedulingAt)
                {
                    return(null);
                }
            }

            return(nextFireTimeUtc);
        }
        /// <summary>
        /// Returns the first time the <see cref="NthIncludedDayTrigger" /> will fire
        /// after the specified date.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Because of the conceptual design of <see cref="NthIncludedDayTrigger" />,
        /// it is not always possible to decide with certainty that the trigger
        /// will <i>never</i> fire again. Therefore, it will search for the next
        /// fire time up to a given cutoff. These cutoffs can be changed by using the
        /// <see cref="NextFireCutoffInterval" /> property. The default cutoff is 12
        /// of the intervals specified by <see cref="IntervalType" /> intervalType.
        /// </para>
        /// <para>
        /// Therefore, for triggers with intervalType =
        /// <see cref="IntervalTypeWeekly" />, if the trigger
        /// will not fire within 12
        /// weeks after the given date/time, <see langword="null" /> will be returned. For
        /// triggers with intervalType =
        /// <see cref="IntervalTypeMonthly" />
        /// , if the trigger will not fire within 12
        /// months after the given date/time, <see langword="null" /> will be returned.
        /// For triggers with intervalType =
        /// <see cref="IntervalTypeYearly" />
        /// , if the trigger will not fire within 12
        /// years after the given date/time, <see langword="null" /> will be returned.  In
        /// all cases, if the trigger will not fire before <see field="endTime" />,
        /// <see langword="null" /> will be returned.
        /// </para>
        /// </remarks>
        /// <param name="afterTimeUtc">The time after which to find the nearest fire time.
        /// This argument is treated as exclusive &#x8212; that is,
        /// if afterTime is a valid fire time for the trigger, it
        /// will not be returned as the next fire time.
        /// </param>
        /// <returns>
        /// the first time the trigger will fire following the specified date
        /// </returns>
        public override DateTimeOffset?GetFireTimeAfter(DateTimeOffset?afterTimeUtc)
        {
            if (!afterTimeUtc.HasValue)
            {
                afterTimeUtc = SystemTime.UtcNow();
            }

            if ((afterTimeUtc.Value < StartTimeUtc))
            {
                afterTimeUtc = StartTimeUtc.AddMilliseconds(-1 * 1000);
            }

            if (intervalType == IntervalTypeWeekly)
            {
                return(GetWeeklyFireTimeAfter(afterTimeUtc.Value));
            }
            else if (intervalType == IntervalTypeMonthly)
            {
                return(GetMonthlyFireTimeAfter(afterTimeUtc.Value));
            }
            else if (intervalType == IntervalTypeYearly)
            {
                return(GetYearlyFireTimeAfter(afterTimeUtc.Value));
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// Returns the first time the <see cref="NthIncludedDayTrigger" /> will fire
        /// after the specified date.
        /// </summary>
        /// <remarks>
        /// <p>
        /// Because of the conceptual design of <see cref="NthIncludedDayTrigger" />,
        /// it is not always possible to decide with certainty that the trigger
        /// will <i>never</i> fire again. Therefore, it will search for the next
        /// fire time up to a given cutoff. These cutoffs can be changed by using the
        /// <see cref="NextFireCutoffInterval" /> property. The default cutoff is 12
        /// of the intervals specified by <see cref="IntervalType" /> intervalType.
        /// </p>
        /// <p>
        /// Therefore, for triggers with intervalType =
        /// <see cref="IntervalTypeWeekly" />, if the trigger
        /// will not fire within 12
        /// weeks after the given date/time, <see langword="null" /> will be returned. For
        /// triggers with intervalType =
        /// <see cref="IntervalTypeMonthly" />
        /// , if the trigger will not fire within 12
        /// months after the given date/time, <see langword="null" /> will be returned.
        /// For triggers with intervalType =
        /// <see cref="IntervalTypeYearly" />
        /// , if the trigger will not fire within 12
        /// years after the given date/time, <see langword="null" /> will be returned.  In
        /// all cases, if the trigger will not fire before <see field="endTime" />,
        /// <see langword="null" /> will be returned.
        /// </p>
        /// </remarks>
        /// <param name="afterTimeUtc">The time after which to find the nearest fire time.
        /// This argument is treated as exclusive &#x8212; that is,
        /// if afterTime is a valid fire time for the trigger, it
        /// will not be returned as the next fire time.
        /// </param>
        /// <returns>
        /// the first time the trigger will fire following the specified date
        /// </returns>
        public override NullableDateTime GetFireTimeAfter(NullableDateTime afterTimeUtc)
        {
            afterTimeUtc = DateTimeUtil.AssumeUniversalTime(afterTimeUtc);
            if (!afterTimeUtc.HasValue)
            {
                afterTimeUtc = DateTime.UtcNow;
            }

            if ((afterTimeUtc.Value < StartTimeUtc))
            {
                afterTimeUtc = StartTimeUtc.AddMilliseconds(-1 * 1000);
            }

            if (intervalType == IntervalTypeWeekly)
            {
                return(GetWeeklyFireTimeAfter(afterTimeUtc.Value));
            }
            else if (intervalType == IntervalTypeMonthly)
            {
                return(GetMonthlyFireTimeAfter(afterTimeUtc.Value));
            }
            else if (intervalType == IntervalTypeYearly)
            {
                return(GetYearlyFireTimeAfter(afterTimeUtc.Value));
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Called by the scheduler at the time a <see cref="ITrigger" /> is first
        /// added to the scheduler, in order to have the <see cref="ITrigger" />
        /// compute its first fire time, based on any associated calendar.
        /// <para>
        /// After this method has been called, <see cref="GetNextFireTimeUtc" />
        /// should return a valid answer.
        /// </para>
        ///
        /// </summary>
        /// <returns> the first time at which the <see cref="ITrigger" /> will be fired
        /// by the scheduler, which is also the same value
        /// <see cref="GetNextFireTimeUtc" /> will return (until after the first
        /// firing of the <see cref="ITrigger" />).
        /// </returns>
        public override DateTimeOffset?ComputeFirstFireTimeUtc(ICalendar cal)
        {
            calendar = cal;
            DateTimeOffset dt = StartTimeUtc.AddMilliseconds(-1 * 1000);

            nextFireTimeUtc = GetFireTimeAfter(dt);

            return(nextFireTimeUtc);
        }
Exemple #5
0
        /// <summary>
        /// Returns the last UTC time at which the <see cref="ISimpleTrigger" /> will
        /// fire, before the given time. If the trigger will not fire before the
        /// given time, <see langword="null" /> will be returned.
        /// </summary>
        public virtual DateTimeOffset?GetFireTimeBefore(DateTimeOffset?endUtc)
        {
            if (endUtc.Value < StartTimeUtc)
            {
                return(null);
            }

            int numFires = ComputeNumTimesFiredBetween(StartTimeUtc, endUtc);

            return(StartTimeUtc.AddMilliseconds(numFires * repeatInterval.TotalMilliseconds));
        }
Exemple #6
0
        public string BuildDescription()
        {
            StringBuilder sb = new StringBuilder();

            zBuildDescription(sb);
            sb.AppendFormat(" effective {0}", StartTimeUtc.ToLocalTime());
            if (EndTimeUtc.HasValue)
            {
                sb.AppendFormat(" until {0}", EndTimeUtc.Value.ToLocalTime());
            }
            return(sb.ToString());
        }
Exemple #7
0
        /// <summary>
        /// Returns the last UTC time at which the <see cref="ZmanimTrigger" /> will
        /// fire, before the given time. If the trigger will not fire before the
        /// given time, <see langword="null" /> will be returned.
        /// </summary>
        public virtual DateTime?GetFireTimeBefore(DateTime?endUtc)
        {
            endUtc = ComputePreviousZmanTime(DateTimeUtil.AssumeUniversalTime(endUtc));
            if (endUtc.Value < StartTimeUtc)
            {
                return(null);
            }

            int numFires = ComputeNumTimesFiredBetween(StartTimeUtc, endUtc);

            return(StartTimeUtc.AddMilliseconds(numFires * repeatInterval.TotalMilliseconds));
        }
Exemple #8
0
        /// <summary>
        /// Returns the last UTC time at which the <see cref="Trigger" /> will
        /// fire, before the given time. If the trigger will not fire before the
        /// given time, <see langword="null" /> will be returned.
        /// </summary>
        public virtual NullableDateTime GetFireTimeBefore(NullableDateTime endUtc)
        {
            endUtc = DateTimeUtils.AssumeUniversalTime(endUtc);
            if (endUtc.Value < StartTimeUtc)
            {
                return(null);
            }

            int numFires = ComputeNumTimesFiredBetween(StartTimeUtc, endUtc);

            return(StartTimeUtc.AddMilliseconds(numFires * _repeatInterval));
        }
Exemple #9
0
 protected override void zBuildDescription(StringBuilder sb)
 {
     if (RepeatsDailyOnInterval)
     {
         sb.AppendFormat("repeating {0} between {1} and {2}",
                         DescriptionUtils.GetIntervalDescription(DailyRepetitionInterval),
                         DailyRepetitionStartTimeUtc.ToLocalTime().ToLongTimeString(),
                         DailyRepetitionEndTimeUtc.ToLocalTime().ToLongTimeString());
     }
     else
     {
         sb.AppendFormat("at {0}", StartTimeUtc.ToLocalTime().ToLongTimeString());
     }
 }
        public Dictionary <string, string> ToProperties()
        {
            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties.Add("Id", Id);
            properties.Add("FileName", FileName);
            properties.Add("UploadEndPoint", UploadEndPoint);
            properties.Add("StartTimeUtc", StartTimeUtc.ToString());
            properties.Add("EndTimeUtc", EndTimeUtc.ToString());
            properties.Add("FileCreationTimeUtc", FileCreationTimeUtc.ToString());
            properties.Add("Status", Status.ToString());
            properties.Add("IsRetake", IsRetake.ToString());
            properties.Add("SourceMachineName", SourceMachineName);
            properties.Add("ErrorMessage", ErrorMessage);

            return(properties);
        }
Exemple #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriptionRequest"/> class
        /// </summary>
        public SubscriptionRequest(bool isUniverseSubscription,
                                   Universe universe,
                                   Security security,
                                   SubscriptionDataConfig configuration,
                                   DateTime startTimeUtc,
                                   DateTime endTimeUtc)
            : base(startTimeUtc, endTimeUtc, security.Exchange.Hours, configuration.TickType)
        {
            IsUniverseSubscription = isUniverseSubscription;
            Universe      = universe;
            Security      = security;
            Configuration = configuration;

            // open interest data comes in once a day before market open,
            // make the subscription start from midnight and use always open exchange
            if (Configuration.TickType == TickType.OpenInterest)
            {
                StartTimeUtc = StartTimeUtc.ConvertFromUtc(ExchangeHours.TimeZone).Date.ConvertToUtc(ExchangeHours.TimeZone);
            }
        }
Exemple #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SubscriptionRequest"/> class
        /// </summary>
        public SubscriptionRequest(bool isUniverseSubscription,
                                   Universe universe,
                                   Security security,
                                   SubscriptionDataConfig configuration,
                                   DateTime startTimeUtc,
                                   DateTime endTimeUtc)
        {
            IsUniverseSubscription = isUniverseSubscription;
            Universe      = universe;
            Security      = security;
            Configuration = configuration;

            // open interest data comes in once a day before market open,
            // make the subscription start from midnight
            StartTimeUtc = configuration.TickType == TickType.OpenInterest ?
                           startTimeUtc.ConvertFromUtc(Configuration.ExchangeTimeZone).Date.ConvertToUtc(Configuration.ExchangeTimeZone) :
                           startTimeUtc;

            EndTimeUtc = endTimeUtc;

            _localStartTime = new Lazy <DateTime>(() => StartTimeUtc.ConvertFromUtc(Configuration.ExchangeTimeZone));
            _localEndTime   = new Lazy <DateTime>(() => EndTimeUtc.ConvertFromUtc(Configuration.ExchangeTimeZone));
        }
Exemple #13
0
        /// <summary>
        /// This method should not be used by the Quartz client.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Called by the scheduler at the time a <see cref="ITrigger" /> is first
        /// added to the scheduler, in order to have the <see cref="ITrigger" />
        /// compute its first fire time, based on any associated calendar.
        /// </para>
        ///
        /// <para>
        /// After this method has been called, <see cref="ITrigger.GetNextFireTimeUtc" />
        /// should return a valid answer.
        /// </para>
        /// </remarks>
        /// <returns>
        /// The first time at which the <see cref="ITrigger" /> will be fired
        /// by the scheduler, which is also the same value <see cref="ITrigger.GetNextFireTimeUtc" />
        /// will return (until after the first firing of the <see cref="ITrigger" />).
        /// </returns>
        public override DateTimeOffset?ComputeFirstFireTimeUtc(ICalendar calendar)
        {
            nextFireTimeUtc = GetFireTimeAfter(StartTimeUtc.AddSeconds(-1));

            // Check calendar for date-time exclusion
            while (nextFireTimeUtc != null && calendar != null &&
                   !calendar.IsTimeIncluded(nextFireTimeUtc.Value))
            {
                nextFireTimeUtc = GetFireTimeAfter(nextFireTimeUtc);

                if (nextFireTimeUtc == null)
                {
                    break;
                }

                //avoid infinite loop
                if (nextFireTimeUtc.Value.Year > YearToGiveupSchedulingAt)
                {
                    return(null);
                }
            }

            return(nextFireTimeUtc);
        }
Exemple #14
0
 public override int GetHashCode()
 {
     unchecked {
         return((StartTimeUtc.GetHashCode() * 397) ^ (Duration.GetHashCode() * 397) ^ (Name?.GetHashCode() ?? 0));
     }
 }