Beispiel #1
0
        /// <summary>
        /// Get a filtered list of jobs based on filter type.
        /// </summary>
        /// <param name="filter">Object to use for filtering.</param>
        /// <param name="filterType">Type of filter, specifies which "get" from
        ///   JobSourceAdapter to call, and dictates the type for filter.</param>
        /// <param name="cmdlet">Cmdlet requesting this, for error processing.</param>
        /// <param name="writeErrorOnException"></param>
        /// <param name="writeObject"></param>
        /// <param name="recurse"></param>
        /// <param name="jobSourceAdapterTypes">Job source adapter type names.</param>
        /// <returns>Filtered list of jobs.</returns>
        /// <exception cref="Exception">If cmdlet parameter is null, throws exception on error from
        /// JobSourceAdapter implementation.</exception>
        private List <Job2> GetFilteredJobs(
            object filter,
            FilterType filterType,
            Cmdlet cmdlet,
            bool writeErrorOnException,
            bool writeObject,
            bool recurse,
            string[] jobSourceAdapterTypes)
        {
            Diagnostics.Assert(cmdlet != null, "Cmdlet should be passed to JobManager");

            List <Job2> allJobs = new List <Job2>();

            lock (_syncObject)
            {
                foreach (JobSourceAdapter sourceAdapter in _sourceAdapters.Values)
                {
                    List <Job2> jobs = null;

                    // Filter search based on job source adapter types if provided.
                    if (!CheckTypeNames(sourceAdapter, jobSourceAdapterTypes))
                    {
                        continue;
                    }

#pragma warning disable 56500
                    try
                    {
                        jobs = CallJobFilter(sourceAdapter, filter, filterType, recurse);
                    }
                    catch (Exception exception)
                    {
                        // Since we are calling into 3rd party code
                        // catching Exception is allowed. In all
                        // other cases the appropriate exception
                        // needs to be caught.

                        // sourceAdapter.GetJobsByFilter() threw unknown exception.
                        _tracer.TraceException(exception);
                        WriteErrorOrWarning(writeErrorOnException, cmdlet, exception, "JobSourceAdapterGetJobsError", sourceAdapter);
                    }
#pragma warning restore 56500

                    if (jobs == null)
                    {
                        continue;
                    }
                    allJobs.AddRange(jobs);
                }
            }

            if (writeObject)
            {
                foreach (Job2 job in allJobs)
                {
                    cmdlet.WriteObject(job);
                }
            }

            return(allJobs);
        }