示例#1
0
        private void BuildInvokeMethodInfo(string invokeMethodName)
        {
            InvokeMethodInfo = JobClassType.GetMethod(invokeMethodName);

            if (InvokeMethodInfo == null)
            {
                throw new SchedulerInitializationException($"Method {invokeMethodName} not found in class {JobClassType.Name}");
            }

            var methodParameters = InvokeMethodInfo.GetParameters();

            if (!methodParameters.Any())
            {
                InvokeMethodParameterType = InvokeMethodParameterType.Parameterless;
                return;
            }

            if (methodParameters[0].ParameterType == typeof(string))
            {
                InvokeMethodParameterType = InvokeMethodParameterType.AppName;
            }

            if (methodParameters[0].ParameterType == typeof(IJobArgs))
            {
                InvokeMethodParameterType = InvokeMethodParameterType.Args;
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceJob{T}"/> class.
        /// </summary>
        /// <param name="invokeMethodName">Name of the invoke method.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ServiceInitializationException"></exception>
        public ServiceJob(string invokeMethodName = "Run")
        {
            if (invokeMethodName == null)
            {
                throw new ArgumentNullException(nameof(invokeMethodName));
            }

            JobClassType     = typeof(T);
            InvokeMethodInfo = JobClassType.GetMethod(invokeMethodName);

            if (InvokeMethodInfo == null)
            {
                throw new ServiceInitializationException($"Method {invokeMethodName} not found in class {JobClassType.Name}");
            }

            IsParameterlessMethod = !InvokeMethodInfo.GetParameters().Any();
        }