protected override void ProcessRecordInternal() { if (ShouldProcess( target: string.Format(Resources.Target, string.IsNullOrWhiteSpace(SmartGroupId) ? InputObject.Id : SmartGroupId), action: Resources.UpdateSmartGroupState_Action)) { string id = SmartGroupId; switch (ParameterSetName) { case ByIdParameterSet: id = CommonUtils.GetIdFromARMResourceId(SmartGroupId); break; case ByInputObjectParameterSet: id = CommonUtils.GetIdFromARMResourceId(InputObject.Id); break; } PSSmartGroup smartGroup = new PSSmartGroup( this.AlertsManagementClient.SmartGroups.ChangeStateWithHttpMessagesAsync(id, State).Result.Body); WriteObject(sendToPipeline: smartGroup); } }
protected override void ProcessRecordInternal() { switch (ParameterSetName) { case SmartGroupsListByFilterParameterSet: IPage <SmartGroup> pageResult = new Page <SmartGroup>(); List <SmartGroup> resultList = new List <SmartGroup>(); pageResult = this.AlertsManagementClient.SmartGroups.GetAllWithHttpMessagesAsync( sortBy: SortBy, sortOrder: SortOrder, timeRange: TimeRange ).Result.Body; // Deal with paging in response ulong first = MyInvocation.BoundParameters.ContainsKey("First") ? this.PagingParameters.First : ulong.MaxValue; ulong skip = MyInvocation.BoundParameters.ContainsKey("Skip") ? this.PagingParameters.Skip : 0; // Any items before this count should be return ulong lastCount = MyInvocation.BoundParameters.ContainsKey("First") ? skip + first : ulong.MaxValue; ulong currentCount = 0; var nextPageLink = pageResult.NextPageLink; do { List <SmartGroup> tempList = pageResult.ToList(); if (currentCount + (ulong)tempList.Count - 1 < skip) { // skip the whole chunk if they are all in skip currentCount += (ulong)tempList.Count; } else { foreach (SmartGroup currentSmartGroup in tempList) { // not return "skip" count of items in the begin, and only return "first" count of items after that. if (currentCount >= skip && currentCount < lastCount) { resultList.Add(currentSmartGroup); } currentCount++; if (currentCount >= lastCount) { break; } } } if (!string.IsNullOrEmpty(nextPageLink)) { pageResult = this.AlertsManagementClient.SmartGroups.GetAllNextWithHttpMessagesAsync(nextPageLink).Result.Body; nextPageLink = pageResult.NextPageLink; } } while (!string.IsNullOrEmpty(nextPageLink) && currentCount < lastCount); WriteObject(resultList.Select((r) => new PSSmartGroup(r)), enumerateCollection: true); break; case SmartGroupByIdParameterSet: string id = CommonUtils.GetIdFromARMResourceId(SmartGroupId); PSSmartGroup smartGroup = new PSSmartGroup(this.AlertsManagementClient.SmartGroups.GetByIdWithHttpMessagesAsync(id).Result.Body); WriteObject(sendToPipeline: smartGroup); break; } }