private void RemoveFromJobDefinition(IEnumerable <ScheduledJobDefinition> definitions) { List <int> nums = null; foreach (ScheduledJobDefinition scheduledJobDefinition in definitions) { nums = new List <int>(); try { nums = scheduledJobDefinition.RemoveTriggers(this._triggerIds, true); } catch (ScheduledJobException scheduledJobException1) { ScheduledJobException scheduledJobException = scheduledJobException1; string str = StringUtil.Format(ScheduledJobErrorStrings.CantRemoveTriggersFromDefinition, scheduledJobDefinition.Name); Exception runtimeException = new RuntimeException(str, scheduledJobException); ErrorRecord errorRecord = new ErrorRecord(runtimeException, "CantRemoveTriggersFromScheduledJobDefinition", ErrorCategory.InvalidOperation, scheduledJobDefinition); base.WriteError(errorRecord); } List <int> .Enumerator enumerator = nums.GetEnumerator(); try { while (enumerator.MoveNext()) { int num = enumerator.Current; base.WriteTriggerNotFoundError(num, scheduledJobDefinition.Name, scheduledJobDefinition); } } finally { enumerator.Dispose(); } } }
protected override void ProcessRecord() { ErrorRecord errorRecord; string parameterSetName = base.ParameterSetName; string str = parameterSetName; if (parameterSetName != null) { if (str == "Execution") { this.UpdateExecutionDefinition(); } else { if (str == "ScriptBlock" || str == "FilePath") { this.UpdateDefinition(); } } } try { if (this.Trigger != null || this.ScheduledJobOption != null || this.Credential != null) { this._definition.Save(); } else { this._definition.SaveToStore(); } } catch (ScheduledJobException scheduledJobException1) { ScheduledJobException scheduledJobException = scheduledJobException1; if (scheduledJobException.InnerException == null || scheduledJobException.InnerException as UnauthorizedAccessException == null) { if (scheduledJobException.InnerException == null || scheduledJobException.InnerException as IOException == null) { string str1 = StringUtil.Format(ScheduledJobErrorStrings.CantSetJobDefinition, this._definition.Name); errorRecord = new ErrorRecord(new RuntimeException(str1, scheduledJobException), "CantSetPropertiesToScheduledJobDefinition", ErrorCategory.InvalidOperation, this._definition); } else { string str2 = StringUtil.Format(ScheduledJobErrorStrings.IOFailureOnSetJobDefinition, this._definition.Name); errorRecord = new ErrorRecord(new RuntimeException(str2, scheduledJobException), "IOFailureOnSetJobDefinition", ErrorCategory.InvalidOperation, this._definition); } } else { string str3 = StringUtil.Format(ScheduledJobErrorStrings.NoAccessOnSetJobDefinition, this._definition.Name); errorRecord = new ErrorRecord(new RuntimeException(str3, scheduledJobException), "NoAccessFailureOnSetJobDefinition", ErrorCategory.InvalidOperation, this._definition); } base.WriteError(errorRecord); } if (this._passThru) { base.WriteObject(this._definition); } }
protected override void ProcessRecord() { string str; ScheduledJobDefinition jobDefinitionById = null; string parameterSetName = base.ParameterSetName; string str1 = parameterSetName; if (parameterSetName != null) { if (str1 == "Definition") { jobDefinitionById = this._definition; } else { if (str1 == "DefinitionId") { jobDefinitionById = base.GetJobDefinitionById(this._definitionId, true); } else { if (str1 == "DefinitionName") { jobDefinitionById = base.GetJobDefinitionByName(this._definitionName, true); } } } } if (this.Enabled) { str = "Enable"; } else { str = "Disable"; } string str2 = str; if (jobDefinitionById != null && base.ShouldProcess(jobDefinitionById.Name, str2)) { try { jobDefinitionById.SetEnabled(this.Enabled, true); } catch (ScheduledJobException scheduledJobException1) { ScheduledJobException scheduledJobException = scheduledJobException1; string str3 = StringUtil.Format(ScheduledJobErrorStrings.CantSetEnableOnJobDefinition, jobDefinitionById.Name); Exception runtimeException = new RuntimeException(str3, scheduledJobException); ErrorRecord errorRecord = new ErrorRecord(runtimeException, "CantSetEnableOnScheduledJobDefinition", ErrorCategory.InvalidOperation, jobDefinitionById); base.WriteError(errorRecord); } if (this._passThru) { base.WriteObject(jobDefinitionById); } } }
protected override void ProcessRecord() { TriggerFrequency triggerFrequency = TriggerFrequency.None; if (this.ValidateParameterSet(ref triggerFrequency)) { ScheduledJobTrigger[] scheduledJobTriggerArray = this._triggers; for (int i = 0; i < (int)scheduledJobTriggerArray.Length; i++) { ScheduledJobTrigger scheduledJobTrigger = scheduledJobTriggerArray[i]; ScheduledJobTrigger scheduledJobTrigger1 = new ScheduledJobTrigger(scheduledJobTrigger); if (this.UpdateTrigger(scheduledJobTrigger, triggerFrequency)) { ScheduledJobDefinition jobDefinition = scheduledJobTrigger.JobDefinition; if (jobDefinition != null) { bool flag = false; try { scheduledJobTrigger.UpdateJobDefinition(); } catch (ScheduledJobException scheduledJobException1) { ScheduledJobException scheduledJobException = scheduledJobException1; flag = true; object[] name = new object[2]; name[0] = jobDefinition.Name; name[1] = scheduledJobTrigger.Id; string str = StringUtil.Format(ScheduledJobErrorStrings.CantUpdateTriggerOnJobDef, name); Exception runtimeException = new RuntimeException(str, scheduledJobException); ErrorRecord errorRecord = new ErrorRecord(runtimeException, "CantSetPropertiesOnJobTrigger", ErrorCategory.InvalidOperation, scheduledJobTrigger); base.WriteError(errorRecord); } if (flag) { scheduledJobTrigger1.CopyTo(scheduledJobTrigger); } } if (this._passThru) { base.WriteObject(scheduledJobTrigger); } } } return; } else { return; } }
/// <summary> /// Creates a ScheduledJob definition directory with provided definition name /// along with a job run Output directory, and returns a file path/name. /// ...\ScheduledJobs\definitionName\fileName.xml /// ...\ScheduledJobs\definitionName\Output\ /// </summary> /// <param name="definitionName">Definition name</param> /// <param name="fileName">File name</param> /// <returns>File path/name</returns> private static string CreateFilePathName(string definitionName, string fileName) { string filePath = GetJobDefinitionPath(definitionName); string outputPath = GetJobRunOutputDirectory(definitionName); if (Directory.Exists(filePath)) { ScheduledJobException ex = new ScheduledJobException(StringUtil.Format(ScheduledJobErrorStrings.JobDefFileAlreadyExists, definitionName)); ex.FQEID = ScheduledJobDefExistsFQEID; throw ex; } Directory.CreateDirectory(filePath); Directory.CreateDirectory(outputPath); return string.Format(CultureInfo.InstalledUICulture, @"{0}\{1}.xml", filePath, fileName); }
private void AddToJobDefinition(IEnumerable <ScheduledJobDefinition> jobDefinitions) { foreach (ScheduledJobDefinition jobDefinition in jobDefinitions) { try { jobDefinition.AddTriggers(this._triggers, true); } catch (ScheduledJobException scheduledJobException1) { ScheduledJobException scheduledJobException = scheduledJobException1; string str = StringUtil.Format(ScheduledJobErrorStrings.CantAddJobTriggersToDefinition, jobDefinition.Name); Exception runtimeException = new RuntimeException(str, scheduledJobException); ErrorRecord errorRecord = new ErrorRecord(runtimeException, "CantAddJobTriggersToScheduledJobDefinition", ErrorCategory.InvalidOperation, jobDefinition); base.WriteError(errorRecord); } } }
private static string CreateFilePathName(string definitionName, string fileName) { string jobDefinitionPath = ScheduledJobStore.GetJobDefinitionPath(definitionName); string jobRunOutputDirectory = ScheduledJobStore.GetJobRunOutputDirectory(definitionName); if (!Directory.Exists(jobDefinitionPath)) { Directory.CreateDirectory(jobDefinitionPath); Directory.CreateDirectory(jobRunOutputDirectory); object[] objArray = new object[2]; objArray[0] = jobDefinitionPath; objArray[1] = fileName; return(string.Format(CultureInfo.InstalledUICulture, (OSHelper.IsUnix ? "{0}/{1}.xml" : "{0}\\{1}.xml"), objArray)); } else { ScheduledJobException scheduledJobException = new ScheduledJobException(StringUtil.Format(ScheduledJobErrorStrings.JobDefFileAlreadyExists, definitionName)); scheduledJobException.FQEID = "ScheduledJobDefExists"; throw scheduledJobException; } }
protected override void ProcessRecord() { List <ScheduledJobDefinition> scheduledJobDefinitions = null; string parameterSetName = base.ParameterSetName; string str = parameterSetName; if (parameterSetName != null) { if (str == "Definition") { scheduledJobDefinitions = new List <ScheduledJobDefinition>(this._definitions); } else { if (str == "DefinitionName") { scheduledJobDefinitions = base.GetJobDefinitionsByName(this._names, true); } else { if (str == "DefinitionId") { scheduledJobDefinitions = base.GetJobDefinitionsById(this._definitionIds, true); } } } } if (scheduledJobDefinitions != null) { foreach (ScheduledJobDefinition scheduledJobDefinition in scheduledJobDefinitions) { string str1 = StringUtil.Format(ScheduledJobErrorStrings.DefinitionWhatIf, scheduledJobDefinition.Name); if (!base.ShouldProcess(str1, "Unregister")) { continue; } try { scheduledJobDefinition.Remove(this._force); } catch (ScheduledJobException scheduledJobException1) { ScheduledJobException scheduledJobException = scheduledJobException1; string str2 = StringUtil.Format(ScheduledJobErrorStrings.CantUnregisterDefinition, scheduledJobDefinition.Name); Exception runtimeException = new RuntimeException(str2, scheduledJobException); ErrorRecord errorRecord = new ErrorRecord(runtimeException, "CantUnregisterScheduledJobDefinition", ErrorCategory.InvalidOperation, scheduledJobDefinition); base.WriteError(errorRecord); } } } if (this._names != null && (int)this._names.Length > 0 && (this._definitions == null || (int)this._definitions.Length < (int)this._names.Length)) { using (ScheduledJobWTS scheduledJobWT = new ScheduledJobWTS()) { string[] strArrays = this._names; for (int i = 0; i < (int)strArrays.Length; i++) { string str3 = strArrays[i]; scheduledJobWT.RemoveTaskByName(str3, true, true); } } } }
protected override void ProcessRecord() { string message; string str = StringUtil.Format(ScheduledJobErrorStrings.DefinitionWhatIf, this.Name); if (base.ShouldProcess(str, "Register")) { ScheduledJobDefinition scheduledJobDefinition = null; string parameterSetName = base.ParameterSetName; string str1 = parameterSetName; if (parameterSetName != null) { if (str1 == "ScriptBlock") { scheduledJobDefinition = this.CreateScriptBlockDefinition(); } else { if (str1 == "FilePath") { scheduledJobDefinition = this.CreateFilePathDefinition(); } } } if (scheduledJobDefinition != null) { if (base.MyInvocation.BoundParameters.ContainsKey("MaxResultCount")) { if (this.MaxResultCount >= 1) { scheduledJobDefinition.SetExecutionHistoryLength(this.MaxResultCount, false); } else { string str2 = StringUtil.Format(ScheduledJobErrorStrings.InvalidMaxResultCount, new object[0]); Exception runtimeException = new RuntimeException(str2); ErrorRecord errorRecord = new ErrorRecord(runtimeException, "InvalidMaxResultCountParameterForRegisterScheduledJobDefinition", ErrorCategory.InvalidArgument, null); base.WriteError(errorRecord); return; } } try { scheduledJobDefinition.Register(); base.WriteObject(scheduledJobDefinition); } catch (ScheduledJobException scheduledJobException1) { ScheduledJobException scheduledJobException = scheduledJobException1; if (scheduledJobException.InnerException == null || scheduledJobException.InnerException as UnauthorizedAccessException == null) { if (scheduledJobException.InnerException == null || scheduledJobException.InnerException as DirectoryNotFoundException == null) { if (scheduledJobException.InnerException == null || scheduledJobException.InnerException as InvalidDataContractException == null) { ErrorRecord errorRecord1 = new ErrorRecord(scheduledJobException, "CantRegisterScheduledJobDefinition", ErrorCategory.InvalidOperation, scheduledJobDefinition); base.WriteError(errorRecord1); } else { if (!string.IsNullOrEmpty(scheduledJobException.InnerException.Message)) { message = scheduledJobException.InnerException.Message; } else { message = string.Empty; } string str3 = message; object[] name = new object[2]; name[0] = scheduledJobDefinition.Name; name[1] = str3; string str4 = StringUtil.Format(ScheduledJobErrorStrings.CannotSerializeData, name); Exception exception = new RuntimeException(str4, scheduledJobException); ErrorRecord errorRecord2 = new ErrorRecord(exception, "CannotSerializeDataWhenRegisteringScheduledJobDefinition", ErrorCategory.InvalidData, scheduledJobDefinition); base.WriteError(errorRecord2); } } else { string str5 = StringUtil.Format(ScheduledJobErrorStrings.DirectoryNotFoundError, scheduledJobDefinition.Name); Exception runtimeException1 = new RuntimeException(str5, scheduledJobException); ErrorRecord errorRecord3 = new ErrorRecord(runtimeException1, "DirectoryNotFoundWhenRegisteringScheduledJobDefinition", ErrorCategory.ObjectNotFound, scheduledJobDefinition); base.WriteError(errorRecord3); } } else { string str6 = StringUtil.Format(ScheduledJobErrorStrings.UnauthorizedAccessError, scheduledJobDefinition.Name); Exception exception1 = new RuntimeException(str6, scheduledJobException); ErrorRecord errorRecord4 = new ErrorRecord(exception1, "UnauthorizedAccessToRegisterScheduledJobDefinition", ErrorCategory.PermissionDenied, scheduledJobDefinition); base.WriteError(errorRecord4); } } } return; } else { return; } }
private static string CreateFilePathName(string definitionName, string fileName) { string jobDefinitionPath = ScheduledJobStore.GetJobDefinitionPath(definitionName); string jobRunOutputDirectory = ScheduledJobStore.GetJobRunOutputDirectory(definitionName); if (!Directory.Exists(jobDefinitionPath)) { Directory.CreateDirectory(jobDefinitionPath); Directory.CreateDirectory(jobRunOutputDirectory); object[] objArray = new object[2]; objArray[0] = jobDefinitionPath; objArray[1] = fileName; return string.Format(CultureInfo.InstalledUICulture, (OSHelper.IsUnix ? "{0}/{1}.xml" : "{0}\\{1}.xml"), objArray); } else { ScheduledJobException scheduledJobException = new ScheduledJobException(StringUtil.Format(ScheduledJobErrorStrings.JobDefFileAlreadyExists, definitionName)); scheduledJobException.FQEID = "ScheduledJobDefExists"; throw scheduledJobException; } }