private bool MatchesOnMethod(JobName jobName, TriggeredJob job)
 {
     // Caller supplied only a name - could be class or method
     return(!jobName.HasClassName &&
            !jobName.HasMethodName &&
            job.InvokedMethod.Name.Equals(jobName.FullName, StringComparison.InvariantCultureIgnoreCase));
 }
        public TriggeredJob FindTriggeredJob(AdHocJobParams jobParams)
        {
            var jobName = new JobName(jobParams.JobName);

            var possibleJobs = GetAllTriggeredJobs()
                               .Where(tj => MatchesOnClassAndMethod(jobName, tj) || MatchesOnClass(jobName, tj) || MatchesOnMethod(jobName, tj))
                               .ToArray();

            if (possibleJobs.Length == 1)
            {
                return(possibleJobs[0]);
            }

            if (possibleJobs.Length == 0)
            {
                Log.Warn($"A request to run {jobName.FullName} failed because the specified job could not be found - available jobs are {BuildAvailableJobMessages()}");
            }

            if (possibleJobs.Length > 0)
            {
                Log.Warn($"A request to run {jobName.FullName} failed because more than one specified jobs could not be found - available jobs are {BuildAvailableJobMessages()}. Of these {BuildPossibleJobMessages(possibleJobs)} were matched.");
            }

            return(null);
        }
 private bool MatchesOnClassAndMethod(JobName jobName, TriggeredJob job)
 {
     // Caller supplied class.method, so unambiguous
     return(jobName.HasClassName &&
            jobName.HasMethodName &&
            job.ContainingClass.Name.Equals(jobName.ClassName, StringComparison.InvariantCultureIgnoreCase) &&
            job.InvokedMethod.Name.Equals(jobName.MethodName, StringComparison.InvariantCultureIgnoreCase));
 }