Skip to content

Commit

Permalink
Issue #144
Browse files Browse the repository at this point in the history
Fix Remove-DSClientScheduleDetail and Remove-DSClientTimeRetentionOption retrieving details from DSClientSessionInfo
  • Loading branch information
McGlovin1337 committed Nov 4, 2021
1 parent b5166d3 commit 6181012
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
39 changes: 24 additions & 15 deletions PSAsigraDSClient/RemoveDSClientScheduleDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,31 @@ protected override void DSClientProcessRecord()
Schedule schedule = DSClientScheduleMgr.definedSchedule(ScheduleId);

// Get Schedule Detail Hash Dictionary from SessionState
Dictionary<string, int> detailHashes = SessionState.PSVariable.GetValue("ScheduleDetail", null) as Dictionary<string, int>;
Dictionary<string, int> detailHashes = DSClientSessionInfo.GetScheduleOrRetentionDictionary(true);
if (detailHashes == null)
throw new Exception("No Schedule Details found in Session State, use Get-DSClientScheduleDetail Cmdlet");

// Select the Schedule Detail
(ScheduleDetail scheduleDetail, string detailHash) = SelectScheduleDetail(schedule, DetailId, detailHashes);

if (scheduleDetail != null)
if (ShouldProcess($"Schedule: '{schedule.getName()}'", $"Remove {EnumToString(scheduleDetail.getType())} Schedule Detail with Id '{DetailId}'"))
schedule.removeDetail(scheduleDetail);

// Remove the Hash from SessionState Dictionary
detailHashes.Remove(detailHash);
SessionState.PSVariable.Set("ScheduleDetail", detailHashes);

schedule.Dispose();
{
ErrorRecord errorRecord = new ErrorRecord(
new Exception("No Schedule Details found in Session State, use Get-DSClientScheduleDetail Cmdlet"),
"Exception",
ErrorCategory.ObjectNotFound,
null);
WriteError(errorRecord);
}
else
{
// Select the Schedule Detail
(ScheduleDetail scheduleDetail, string detailHash) = SelectScheduleDetail(schedule, DetailId, detailHashes);

if (scheduleDetail != null)
if (ShouldProcess($"Schedule: '{schedule.getName()}'", $"Remove {EnumToString(scheduleDetail.getType())} Schedule Detail with Id '{DetailId}'"))
schedule.removeDetail(scheduleDetail);

// Remove the Hash from SessionState Dictionary
detailHashes.Remove(detailHash);
SessionState.PSVariable.Set("ScheduleDetail", detailHashes);

schedule.Dispose();
}
}
}
}
3 changes: 2 additions & 1 deletion PSAsigraDSClient/RemoveDSClientTimeRetentionOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ protected override void ProcessRetentionRule(RetentionRule[] retentionRules)
RetentionRule retentionRule = retentionRules.Single(rule => rule.getID() == RetentionRuleId);

// Get Time Retention Option Hash Dictionary from Session State
if (!(SessionState.PSVariable.GetValue("TimeRetention", null) is Dictionary<string, int> retentionHash))
Dictionary<string, int> retentionHash = DSClientSessionInfo.GetScheduleOrRetentionDictionary(false);
if (retentionHash == null)
{
ErrorRecord errorRecord = new ErrorRecord(
new Exception("There are no Time Retention Options Stored in Session State, use Get-DSClientTimeRetentionOption"),
Expand Down

0 comments on commit 6181012

Please sign in to comment.