Esempio n. 1
0
        void heart_Beat(object sender, EventArgs e)
        {
            for (int i = 0; i < actions.Count; i++)
            {
                ScheduledAction action = actions[i];
                if (action.ShouldExecute())
                {
                    action.IsExecuting = true;
                    worker.DoWork(delegate
                    {
                        try
                        {
                            logger.Debug("Executing " + action.GetType().Name);
                            action.Engine = engine;
                            action.Execute();
                            action.ErrorCount = 0;
                        }
                        catch (Exception ex)
                        {
                            action.ErrorCount++;
                            action.OnError(ex);     // wayne: call custom action error handler
                        }
                        finally
                        {
                            try
                            {
                                IClosable closable = action as IClosable;
                                if (closable != null)
                                {
                                    closable.Dispose();
                                }
                            }
                            catch (Exception ex)
                            {
                                errorHandler.Notify(ex);
                            }
                        }
                        action.LastExecuted = Utility.CurrentTime();
                        action.IsExecuting  = false;

                        try
                        {
                            context.Close();
                        }
                        catch (Exception ex)
                        {
                            errorHandler.Notify(ex);
                        }
                    });

                    if (action.Repeat == Repeat.Once)
                    {
                        actions.RemoveAt(i);
                        --i;
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>Executes the scheduled actions that are scheduled for executions.</summary>
        public void ExecutActions()
        {
            if (!enabled)
            {
                return;
            }

            if (Debugger.IsAttached && !runWhileDebuggerAttached)
            {
                return;
            }

            for (int i = 0; i < actions.Count; i++)
            {
                ScheduledAction action = actions[i];
                if (action.ShouldExecute())
                {
                    Action work = delegate
                    {
                        try
                        {
                            var config = ((System.Web.Configuration.GlobalizationSection)System.Configuration.ConfigurationManager.GetSection("system.web/globalization"));
                            if (!string.IsNullOrEmpty(config.Culture))
                            {
                                Thread.CurrentThread.CurrentCulture = new CultureInfo(config.Culture);
                            }
                            if (!string.IsNullOrEmpty(config.UICulture))
                            {
                                Thread.CurrentThread.CurrentUICulture = new CultureInfo(config.UICulture);
                            }
                        }
                        catch (Exception ex)
                        {
                            logger.Warn(ex);
                        }

                        try
                        {
                            logger.Debug("Executing " + action.GetType().Name);
                            action.Engine = engine;
                            action.Execute();
                            action.ErrorCount = 0;
                        }
                        catch (Exception ex)
                        {
                            action.ErrorCount++;
                            action.OnError(ex);     // wayne: call custom action error handler
                        }
                        finally
                        {
                            try
                            {
                                IClosable closable = action as IClosable;
                                if (closable != null)
                                {
                                    closable.Dispose();
                                }
                            }
                            catch (Exception ex)
                            {
                                errorHandler.Notify(ex);
                            }
                        }
                        action.LastExecuted = Utility.CurrentTime();
                        action.IsExecuting  = false;

                        try
                        {
                            context.Close();
                        }
                        catch (Exception ex)
                        {
                            errorHandler.Notify(ex);
                        }
                    };

                    action.IsExecuting = true;
                    if (asyncActions)
                    {
                        worker.DoWork(work);
                    }
                    else
                    {
                        work();
                    }

                    if (action.Repeat == Repeat.Once)
                    {
                        actions.RemoveAt(i);
                        --i;
                    }
                }
            }
        }