Beispiel #1
0
        internal void QueueActions(Context ctx, DateTime curtime, RealPlugin.MutexInformation mtx)
        {
            RealPlugin p = ctx.plug;

            System.Diagnostics.Debug.WriteLine("### queuing actions for " + ctx.ToString());
            if (_Sequential == false)
            {
                var ix = from tx in Actions
                         orderby tx.OrderNumber ascending
                         select tx;
                foreach (Action a in ix)
                {
                    if (a._Enabled == true)
                    {
                        curtime = curtime.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, a._ExecutionDelayExpression));
                        p.QueueAction(ctx, this, mtx, a, curtime);
                    }
                }
            }
            else
            {
                Action prev  = null;
                Action first = null;
                var    ix    = from tx in Actions
                               orderby tx.OrderNumber ascending
                               select tx;
                foreach (Action a in ix)
                {
                    if (a._Enabled == false)
                    {
                        continue;
                    }
                    if (prev != null)
                    {
                        prev.NextAction = a;
                    }
                    else
                    {
                        first   = a;
                        curtime = curtime.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, a._ExecutionDelayExpression));
                    }
                    prev = a;
                }
                if (first != null)
                {
                    p.QueueAction(ctx, this, mtx, first, curtime);
                }
            }
        }
Beispiel #2
0
 internal void Fire(RealPlugin p, Context ctx)
 {
     try
     {
         if ((ctx.force & Action.TriggerForceTypeEnum.SkipConditions) == 0)
         {
             if (Condition != null && Condition.Enabled == true)
             {
                 if (Condition.CheckCondition(ctx, TriggerContextLogger, ctx.plug) == false)
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/trignotfired", "Trigger '{0}' not fired, condition not met", LogName));
                     return;
                 }
             }
         }
         DateTime prevLastFired = LastFired;
         LastFired = DateTime.Now;
         if (_PeriodRefire == RefireEnum.Deny)
         {
             RefireDelayedUntil = LastFired.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, _RefirePeriodExpression));
             AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/delayingrefire", "Delaying trigger '{0}' refire to {1}", LogName, RefireDelayedUntil));
         }
         else
         {
             RefireDelayedUntil = DateTime.MinValue;
         }
         DateTime curtime = DateTime.Now;
         if (_Scheduling == SchedulingEnum.FromLastAction)
         {
             // get the last queued action as curTime
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           orderby ax.when descending
                           select ax;
                 if (ixy.Count() > 0)
                 {
                     curtime = ixy.ElementAt(0).when;
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/lastactionfound", "Last action for trigger '{0}' found at {1}", LogName, curtime));
                 }
             }
         }
         else if (_Scheduling == SchedulingEnum.FromRefirePeriod)
         {
             curtime = prevLastFired.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, _RefirePeriodExpression));
             if (curtime < LastFired)
             {
                 curtime = LastFired;
                 AddToLog(p, RealPlugin.DebugLevelEnum.Verbose, I18n.Translate("internal/Trigger/beforelastfired", "Current time is before last fired for trigger '{0}'", LogName));
             }
         }
         if (_PrevActions == PrevActionsEnum.Interrupt)
         {
             int exx = 0;
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           select ax;
                 if (ixy.Count() > 0)
                 {
                     List <RealPlugin.QueuedAction> rems = new List <RealPlugin.QueuedAction>();
                     rems.AddRange(ixy);
                     foreach (RealPlugin.QueuedAction qa in rems)
                     {
                         ctx.plug.ActionQueue.Remove(qa);
                         exx++;
                     }
                 }
             }
             if (exx > 0)
             {
                 if (_PrevActionsRefire == RefireEnum.Deny)
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/removefromqueuenorefire", "Removed {0} instance(s) of trigger '{1}' actions from queue, refire denied", exx, LogName));
                     return;
                 }
                 else
                 {
                     AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/removefromqueue", "Removed {0} instance(s) of trigger '{1}' actions from queue", exx, LogName));
                 }
             }
         }
         else if (_PrevActionsRefire == RefireEnum.Deny)
         {
             int exx = 0;
             lock (ctx.plug.ActionQueue)
             {
                 var ixy = from ax in ctx.plug.ActionQueue
                           where ax.ctx.trig.Id == Id
                           select ax;
                 exx = ixy.Count();
             }
             if (exx > 0)
             {
                 AddToLog(p, RealPlugin.DebugLevelEnum.Info, I18n.Translate("internal/Trigger/refiredenied", "{0} instance(s) of trigger '{1}' actions in queue, refire denied", exx, LogName));
                 return;
             }
         }
         if (_Sequential == false)
         {
             var ix = from tx in Actions
                      orderby tx.OrderNumber ascending
                      select tx;
             foreach (Action a in ix)
             {
                 if (a._Enabled == true)
                 {
                     curtime = curtime.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, a._ExecutionDelayExpression));
                     p.QueueAction(ctx, this, a, curtime);
                 }
             }
         }
         else
         {
             Action prev  = null;
             Action first = null;
             var    ix    = from tx in Actions
                            orderby tx.OrderNumber ascending
                            select tx;
             foreach (Action a in ix)
             {
                 if (a._Enabled == false)
                 {
                     continue;
                 }
                 if (prev != null)
                 {
                     prev.NextAction = a;
                 }
                 else
                 {
                     first   = a;
                     curtime = curtime.AddMilliseconds(ctx.EvaluateNumericExpression(TriggerContextLogger, p, a._ExecutionDelayExpression));
                 }
                 prev = a;
             }
             if (first != null)
             {
                 p.QueueAction(ctx, this, first, curtime);
             }
         }
     }
     catch (Exception ex)
     {
         AddToLog(p, RealPlugin.DebugLevelEnum.Error, I18n.Translate("internal/Trigger/firingexception", "Trigger '{0}' didn't fire due to exception: {1}", LogName, ex.Message));
     }
 }