示例#1
0
        private static void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            aTimer.Enabled = false;

            Status.TickCount++;

            // Check for timeout
            WebServiceSession.Refresh();

            // Read Messages

            if ((DateTime.Now > Status.NextTaskTime))
            {
                Status.NextTaskTime = DateTime.Now.AddMinutes(Status.IntervalMinutes);
                // do timed stuff here
                ServiceLogger.Info("***** OnTimedEvent START short interval");
                DoTasks();
                ServiceLogger.Info("***** OnTimedEvent END short interval");
            }

            if ((DateTime.Now > Status.NextLongTaskTime))
            {
                //aTimer.Enabled = false;
                Status.NextLongTaskTime = DateTime.Now.AddMinutes(Status.IntervalMinutesLong);
                ServiceLogger.Info("***** OnTimedEvent START long interval");
                DoTasksLong();
                ServiceLogger.Info("***** OnTimedEvent END long interval");
                //aTimer.Enabled = true;
            }

            // Do Scheduled
            DoScheduled();

            aTimer.Enabled = true;
        }
示例#2
0
        public static void DoTasks(string ExecuteMethods, object[] parameters = null)
        {
            try
            {
                Status.TaskCount++;
                Status.TaskCalledTime = DateTime.Now;

                if (!string.IsNullOrEmpty(ExecuteMethods))
                {
                    Type TasksType   = typeof(ServiceTasks);
                    var  MethodNames = ExecuteMethods.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    var  Methods     = TasksType.GetMethods();
                    var  toExecute   = Methods.Where(m => MethodNames.Contains(m.Name)).ToList();
                    foreach (var Method in toExecute)
                    {
                        try
                        {
                            // We only accept MethodName() and MethodName(ServiceSchedule schedule = null)
                            // You cannot call MethodName() from Schedule so make sure you have an overload
                            // WARNING: MethodName() is mandatory! The ServiceSchedule one is optional
                            int paraCount = Method.GetParameters().Length;
                            if (paraCount > 0)
                            {
                                if (parameters != null)
                                {
                                    Method.Invoke(null, parameters);
                                }
                            }
                            else if (parameters == null)
                            {
                                Method.Invoke(null, null);
                            }
                        }
                        catch (Exception ex)
                        {
                            string message = ex.Message;
                            if (ex.InnerException != null)
                            {
                                message += " InnerException: " + ex.InnerException.Message;
                            }
                            ServiceLogger.Error("DoTasks invoke method error, Method: '" + Method.Name + "', details: " + message);
                        }
                    }
                }
                else
                {
                    //ServiceLogger.Error("DoTasks ExecuteMethods or ExecuteMethodsLong in .config is empty, please configure methods to execute!!!");
                }
            }
            catch (Exception ex)
            {
                ServiceLogger.Error("DoTasks Error, details: " + ex.Message);
            }
        }
 public static void TestOperation()
 {
     ServiceLogger.Info("TestOperation called.");
 }