/// <summary> /// Compare sourceAdapter name with the provided source adapter type /// name list. /// </summary> /// <param name="sourceAdapter"></param> /// <param name="jobSourceAdapterTypes"></param> /// <returns></returns> private bool CheckTypeNames(JobSourceAdapter sourceAdapter, string[] jobSourceAdapterTypes) { // If no type names were specified then allow all adapter types. if (jobSourceAdapterTypes == null || jobSourceAdapterTypes.Length == 0) { return(true); } string sourceAdapterName = GetAdapterName(sourceAdapter); Diagnostics.Assert(sourceAdapterName != null, "Source adapter should have name or type."); // Look for name match allowing wildcards. foreach (string typeName in jobSourceAdapterTypes) { WildcardPattern typeNamePattern = WildcardPattern.Get(typeName, WildcardOptions.IgnoreCase); if (typeNamePattern.IsMatch(sourceAdapterName)) { return(true); } } return(false); }
/// <summary> /// Creates a new job of the appropriate type given by JobDefinition passed in. /// </summary> /// <param name="specification">JobInvocationInfo defining the command.</param> /// <returns>Job2 object of the appropriate type specified by the definition.</returns> /// <exception cref="InvalidOperationException">If JobSourceAdapter type specified /// in definition is not registered.</exception> /// <exception cref="Exception">JobSourceAdapter implementation exception thrown on error. /// </exception> public Job2 NewJob(JobInvocationInfo specification) { if (specification == null) { throw new ArgumentNullException("specification"); } if (specification.Definition == null) { throw new ArgumentException(RemotingErrorIdStrings.NewJobSpecificationError, "specification"); } JobSourceAdapter sourceAdapter = GetJobSourceAdapter(specification.Definition); Job2 newJob = null; #pragma warning disable 56500 try { newJob = sourceAdapter.NewJob(specification); } 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.NewJob returned unknown error. _tracer.TraceException(exception); throw; } #pragma warning restore 56500 return(newJob); }
/// <summary> /// Saves the job to a persisted store. /// </summary> /// <param name="job">Job2 type job to persist.</param> /// <param name="definition">Job definition containing source adapter information.</param> public void PersistJob(Job2 job, JobDefinition definition) { if (job == null) { throw new PSArgumentNullException("job"); } if (definition == null) { throw new PSArgumentNullException("definition"); } JobSourceAdapter sourceAdapter = GetJobSourceAdapter(definition); try { sourceAdapter.PersistJob(job); } 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.NewJob returned unknown error. _tracer.TraceException(exception); throw; } }
public Job2 NewJob(JobInvocationInfo specification) { if (specification == null) { throw new ArgumentNullException("specification"); } if (specification.Definition == null) { throw new ArgumentException(ResourceManagerCache.GetResourceString("RemotingErrorIdStrings", "NewJobSpecificationError"), "specification"); } JobSourceAdapter jobSourceAdapter = this.GetJobSourceAdapter(specification.Definition); Job2 job = null; try { job = jobSourceAdapter.NewJob(specification); } catch (Exception exception) { this.Tracer.TraceException(exception); CommandProcessorBase.CheckForSevereException(exception); throw; } return(job); }
/// <summary> /// Creates a new job of the appropriate type given by JobDefinition passed in. /// </summary> /// <param name="definition">JobDefinition defining the command.</param> /// <returns>Job2 object of the appropriate type specified by the definition.</returns> /// <exception cref="InvalidOperationException">If JobSourceAdapter type specified /// in definition is not registered.</exception> /// <exception cref="Exception">JobSourceAdapter implementation exception thrown on error. /// </exception> public Job2 NewJob(JobDefinition definition) { if (definition == null) { throw new ArgumentNullException(nameof(definition)); } JobSourceAdapter sourceAdapter = GetJobSourceAdapter(definition); Job2 newJob; #pragma warning disable 56500 try { newJob = sourceAdapter.NewJob(definition); } 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.NewJob returned unknown error. _tracer.TraceException(exception); throw; } #pragma warning restore 56500 return(newJob); }
private static List <Job2> CallJobFilter(JobSourceAdapter sourceAdapter, object filter, FilterType filterType, bool recurse) { IList <Job2> jobsByCommand; List <Job2> list = new List <Job2>(); switch (filterType) { case FilterType.Command: jobsByCommand = sourceAdapter.GetJobsByCommand((string)filter, recurse); break; case FilterType.Filter: jobsByCommand = sourceAdapter.GetJobsByFilter((Dictionary <string, object>)filter, recurse); break; case FilterType.Name: jobsByCommand = sourceAdapter.GetJobsByName((string)filter, recurse); break; case FilterType.State: jobsByCommand = sourceAdapter.GetJobsByState((JobState)filter, recurse); break; default: jobsByCommand = sourceAdapter.GetJobs(); break; } if (jobsByCommand != null) { list.AddRange(jobsByCommand); } return(list); }
private string GetAdapterName(JobSourceAdapter sourceAdapter) { if (string.IsNullOrEmpty(sourceAdapter.Name)) { return(sourceAdapter.GetType().ToString()); } return(sourceAdapter.Name); }
private bool CheckTypeNames(JobSourceAdapter sourceAdapter, string[] jobSourceAdapterTypes) { if ((jobSourceAdapterTypes == null) || (jobSourceAdapterTypes.Length == 0)) { return(true); } string adapterName = this.GetAdapterName(sourceAdapter); foreach (string str2 in jobSourceAdapterTypes) { WildcardPattern pattern = new WildcardPattern(str2, WildcardOptions.IgnoreCase); if (pattern.IsMatch(adapterName)) { return(true); } } return(false); }
public Job2 NewJob(JobDefinition definition) { Job2 job; if (definition == null) { throw new ArgumentNullException("definition"); } JobSourceAdapter jobSourceAdapter = this.GetJobSourceAdapter(definition); try { job = jobSourceAdapter.NewJob(definition); } catch (Exception exception) { this.Tracer.TraceException(exception); CommandProcessorBase.CheckForSevereException(exception); throw; } return(job); }
public void PersistJob(Job2 job, JobDefinition definition) { if (job == null) { throw new PSArgumentNullException("job"); } if (definition == null) { throw new PSArgumentNullException("definition"); } JobSourceAdapter jobSourceAdapter = this.GetJobSourceAdapter(definition); try { jobSourceAdapter.PersistJob(job); } catch (Exception exception) { this.Tracer.TraceException(exception); CommandProcessorBase.CheckForSevereException(exception); throw; } }
/// <summary> /// Gets a filtered list of jobs from the given JobSourceAdapter. /// </summary> /// <param name="sourceAdapter">JobSourceAdapter to query.</param> /// <param name="filter">Filter object.</param> /// <param name="filterType">Filter type.</param> /// <param name="recurse"></param> /// <returns>List of jobs from sourceAdapter filtered on filterType.</returns> /// <exception cref="Exception">Throws exception on error from JobSourceAdapter /// implementation.</exception> private static List <Job2> CallJobFilter(JobSourceAdapter sourceAdapter, object filter, FilterType filterType, bool recurse) { List <Job2> jobs = new List <Job2>(); IList <Job2> matches; switch (filterType) { case FilterType.Command: matches = sourceAdapter.GetJobsByCommand((string)filter, recurse); break; case FilterType.Filter: matches = sourceAdapter.GetJobsByFilter((Dictionary <string, object>)filter, recurse); break; case FilterType.Name: matches = sourceAdapter.GetJobsByName((string)filter, recurse); break; case FilterType.State: matches = sourceAdapter.GetJobsByState((JobState)filter, recurse); break; case FilterType.None: default: matches = sourceAdapter.GetJobs(); break; } if (matches != null) { jobs.AddRange(matches); } return(jobs); }
private static void WriteErrorOrWarning(bool writeErrorOnException, Cmdlet cmdlet, Exception exception, string identifier, JobSourceAdapter sourceAdapter) { try { if (writeErrorOnException) { cmdlet.WriteError(new ErrorRecord(exception, identifier, ErrorCategory.OpenError, sourceAdapter)); } else { // Write a warning string message = string.Format(CultureInfo.CurrentCulture, RemotingErrorIdStrings.JobSourceAdapterError, exception.Message, sourceAdapter.Name); cmdlet.WriteWarning(message); } } catch (Exception) { // if this call is not made from a cmdlet thread or if // the cmdlet is closed this will thrown an exception // it is fine to eat that exception } }
private static string GetAdapterName(JobSourceAdapter sourceAdapter) { return(!string.IsNullOrEmpty(sourceAdapter.Name) ? sourceAdapter.Name : sourceAdapter.GetType().ToString()); }
private static void WriteErrorOrWarning(bool writeErrorOnException, Cmdlet cmdlet, Exception exception, string identifier, JobSourceAdapter sourceAdapter) { try { if (writeErrorOnException) { cmdlet.WriteError(new ErrorRecord(exception, identifier, ErrorCategory.OpenError, sourceAdapter)); } else { cmdlet.WriteWarning(ResourceManagerCache.FormatResourceString("RemotingErrorIdStrings", "JobSourceAdapterError", new object[] { exception.Message, sourceAdapter.Name })); } } catch (Exception) { } }