예제 #1
0
 /// <summary>
 /// Replace a specified TimedFunction with another. Either all occurences are converted
 /// or a given amount.
 /// </summary>
 /// <param name="oldTF"></param>
 /// <param name="newTF"></param>
 /// <param name="replaceAll"></param>
 /// <param name="amount"></param>
 public void Replace(TimedFunction oldTF, TimedFunction newTF, bool replaceAll, int amount)
 {
     lock (_bufferLock)
     {
         storageBuffer.Add(new MI_Replace(oldTF, newTF, replaceAll, amount));
     }
 }
예제 #2
0
 /// <summary>
 /// Add a TimedFunction to the query amount-times, possibly ignoring
 /// that the same TimedFunction is already listed.
 /// </summary>
 /// <param name="f"></param>
 /// <param name="amount"></param>
 /// <param name="allowDuplicate"></param>
 public void Add(TimedFunction f, int amount, bool allowDuplicate)
 {
     lock (_bufferLock)
     {
         storageBuffer.Add(new MI_Add(f, amount, allowDuplicate));
     }
 }
예제 #3
0
 /// <summary>
 /// Remove a specified TimedFunction from storage and schedule. Either all
 /// occurrences can be deleted or a certain amount.
 /// </summary>
 /// <param name="f"></param>
 /// <param name="removeAll"></param>
 /// <param name="amount"></param>
 public void Remove(TimedFunction f, bool removeAll, int amount)
 {
     lock (_bufferLock)
     {
         storageBuffer.Add(new MI_Remove(f, removeAll, amount));
     }
 }
예제 #4
0
        /// <summary>
        /// Invoke a TimedFunction and pass it the calculated new state parameters.
        /// </summary>
        /// <param name="tf"></param>
        /// <returns></returns>
        protected int InvokeFunction(TimedFunction tf)
        {
            int callAmount;

            if (storage.TryGetValue(tf, out callAmount))
            {
                return(tf.InvokeFunction(callAmount));
            }
            else
            {
                return(0);
            }
        }
예제 #5
0
        /// <summary>
        /// Removes a TimedFunction from the timed schedule.
        /// </summary>
        /// <param name="tf"></param>
        /// <returns></returns>
        protected bool RemoveFromSchedule(TimedFunction tf)
        {
            // get copy of all schedule times (keys)
            var times = schedule.Keys.ToArray();

            // iterate and search for the right one
            foreach (var t in times)
            {
                if (RemoveFromSchedule(t, tf))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #6
0
 /// <summary>
 /// Adds a TimedFunction to the time schedule if not already present.
 /// </summary>
 /// <param name="time"></param>
 /// <param name="tf"></param>
 protected void AddToSchedule(DateTime time, TimedFunction tf)
 {
     if (schedule.ContainsKey(time))
     {
         // only add to schedule if not already there
         // (would result in duplicate invocations at the same time otherwise!)
         var timedFunctions = schedule[time];
         if (!timedFunctions.Contains(tf))
         {
             timedFunctions.Add(tf);
         }
     }
     else
     {
         schedule.Add(time, new List <TimedFunction>()
         {
             tf
         });
     }
 }
예제 #7
0
        /// <summary>
        /// Removes a possible TimedFunction-entry in the schedule at the given time.
        /// </summary>
        /// <param name="time"></param>
        /// <param name="tf"></param>
        /// <returns></returns>
        protected bool RemoveFromSchedule(DateTime time, TimedFunction tf)
        {
            List <TimedFunction> timedFunctions;

            if (schedule.TryGetValue(time, out timedFunctions))
            {
                if (timedFunctions.Contains(tf))
                {
                    // possibly remove the schedule entry if it would'nt contain any TimedFunctions anyway
                    if (timedFunctions.Count < 2)
                    {
                        schedule.Remove(time);
                    }
                    else
                    {
                        timedFunctions.Remove(tf);
                    }
                    return(true);
                }
            }

            return(false);
        }