예제 #1
0
        /// <summary>
        /// 绑定任务
        /// </summary>
        public static void BindTask(AppDomain domain = null)
        {
            if (domain == null)
            {
                domain = AppDomain.CurrentDomain;
            }
            TimingTasksHandler.ClearAllTask();
            var assemblies = domain.GetAssemblies();

            foreach (var ass in assemblies)
            {
                var types = ass.GetTypes();
                foreach (var type in types)
                {
                    TimingTasksClassAttribute timingTask = type.GetCustomAttributes(typeof(TimingTasksClassAttribute), true)?.FirstOrDefault() as TimingTasksClassAttribute;
                    if (timingTask != null)
                    {
                        BindTask(type);
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 绑定任务
        /// </summary>
        /// <param name="type"></param>
        private static void BindTask(Type type)
        {
            var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);

            foreach (var m in methods)
            {
                TimingTasksAttribute attribute = m.GetCustomAttributes(typeof(TimingTasksAttribute), true)?.FirstOrDefault() as TimingTasksAttribute;
                if (attribute != null)
                {
                    Dictionary <string, Type> paras = new Dictionary <string, Type>();
                    attribute.TaskAddress = string.Format("{0} 【{1}.{2}】", type.Assembly.Location, type.FullName, m.Name);
                    var instance = Activator.CreateInstance(type);
                    var resType  = m.ReturnType;
                    paras.Add("returns", resType);

                    if (string.IsNullOrEmpty(attribute.Name))
                    {
                        attribute.Name = string.Format("{0}.{1}", type.FullName, m.Name);
                    }

                    TimingTasksHandler.Register(attribute, Delegate.CreateDelegate(System.Linq.Expressions.Expression.GetDelegateType(paras.Values.ToArray()), instance, m));
                }
            }
        }
예제 #3
0
 public void StartTiming()
 {
     TimingTasksHandler.StartTiming();
 }
예제 #4
0
 public void StopTask(string taskKey)
 {
     TimingTasksHandler.StopTask(taskKey);
 }
예제 #5
0
 public void StopAllTask()
 {
     TimingTasksHandler.StopAllTask();
 }