示例#1
0
        /// <summary>
        /// Checks if the specified <paramref name="variable"/> is moderated, calculates the next eventing
        /// time for the variable and adapts internal moderation data.
        /// </summary>
        /// <remarks>
        /// The specified <paramref name="variable"/> will be added to the pending event notifications.
        /// </remarks>
        /// <param name="variable">Variable which was changed.</param>
        public void ModerateChangeEvent(DvStateVariable variable)
        {
            ModerationData md;
            bool           wasCreated = false;

            if (!_moderationData.TryGetValue(variable, out md))
            {
                wasCreated = true;
                _moderationData[variable] = md = new ModerationData();
            }
            DateTime now = DateTime.Now;
            DateTime scheduleTime;

            if (variable.ModeratedMaximumRate.HasValue)
            {
                if (wasCreated || md.LastEventTime + variable.ModeratedMaximumRate < now)
                {
                    scheduleTime = now;
                }
                else
                {
                    scheduleTime = now + variable.ModeratedMaximumRate.Value;
                }
            }
            else if (variable.ModeratedMinimumDelta != 0)
            {
                if (!(variable.DataType is DvStandardDataType))
                {
                    scheduleTime = now;
                }
                else
                {
                    if (!wasCreated &&
                        Math.Abs(((DvStandardDataType)variable.DataType).GetNumericDelta(md.LastValue, variable.Value)) < variable.ModeratedMinimumDelta)
                    {
                        return;
                    }
                    scheduleTime = now;
                }
            }
            else
            {
                scheduleTime = now;
            }

            HashSet <DvStateVariable> scheduledVariables;

            if (_scheduledEventNotifications.TryGetValue(scheduleTime, out scheduledVariables) && scheduledVariables != null)
            {
                scheduledVariables.Add(variable);
            }
            else
            {
                _scheduledEventNotifications[scheduleTime] = new HashSet <DvStateVariable> {
                    variable
                }
            };
        }
示例#2
0
        /// <summary>
        /// Updates internal data structures that are necessary for event moderation.
        /// This method needs to be called when an event message for the given <paramref name="variable"/> is sent.
        /// </summary>
        public void UpdateModerationData(DvStateVariable variable)
        {
            ModerationData md;

            if (!_moderationData.TryGetValue(variable, out md))
            {
                _moderationData[variable] = md = new ModerationData();
            }
            DateTime now = DateTime.Now;

            md.LastEventTime = now;
            md.LastValue     = variable.Value;
        }
示例#3
0
    /// <summary>
    /// Checks if the specified <paramref name="variable"/> is moderated, calculates the next eventing
    /// time for the variable and adapts internal moderation data.
    /// </summary>
    /// <remarks>
    /// The specified <paramref name="variable"/> will be added to the pending event notifications.
    /// </remarks>
    /// <param name="variable">Variable which was changed.</param>
    public void ModerateChangeEvent(DvStateVariable variable)
    {
      ModerationData md;
      bool wasCreated = false;
      if (!_moderationData.TryGetValue(variable, out md))
      {
        wasCreated = true;
        _moderationData[variable] = md = new ModerationData();
      }
      DateTime now = DateTime.Now;
      DateTime scheduleTime;
      if (variable.ModeratedMaximumRate.HasValue)
      {
        if (wasCreated || md.LastEventTime + variable.ModeratedMaximumRate < now)
          scheduleTime = now;
        else
          scheduleTime = now + variable.ModeratedMaximumRate.Value;
      }
      else if (variable.ModeratedMinimumDelta != 0)
      {
        if (!(variable.DataType is DvStandardDataType))
          scheduleTime = now;
        else
        {
          if (!wasCreated &&
              Math.Abs(((DvStandardDataType) variable.DataType).GetNumericDelta(md.LastValue, variable.Value)) < variable.ModeratedMinimumDelta)
            return;
          scheduleTime = now;
        }
      }
      else
        scheduleTime = now;

      HashSet<DvStateVariable> scheduledVariables;
      if (_scheduledEventNotifications.TryGetValue(scheduleTime, out scheduledVariables) && scheduledVariables != null)
        scheduledVariables.Add(variable);
      else
        _scheduledEventNotifications[scheduleTime] = new HashSet<DvStateVariable> {variable};
    }
示例#4
0
 /// <summary>
 /// Updates internal data structures that are necessary for event moderation.
 /// This method needs to be called when an event message for the given <paramref name="variable"/> is sent.
 /// </summary>
 public void UpdateModerationData(DvStateVariable variable)
 {
   ModerationData md;
   if (!_moderationData.TryGetValue(variable, out md))
     _moderationData[variable] = md = new ModerationData();
   DateTime now = DateTime.Now;
   md.LastEventTime = now;
   md.LastValue = variable.Value;
 }