Microsoft.Azure.Commands.Insights.EventCmdletBase.ProcessRecordInternal C# (CSharp) Method

ProcessRecordInternal() protected method

Execute the cmdlet
protected ProcessRecordInternal ( ) : void
return void
        protected override void ProcessRecordInternal()
        {
            string queryFilter = this.ProcessParameters();

            // Retrieve the records
            var fullDetails = this.DetailedOutput.IsPresent;

            //Number of records to retrieve
            int maxNumberOfRecords = this.MaxEvents > 0 ? this.MaxEvents : MaxNumberOfReturnedRecords;

            // Call the proper API methods to return a list of raw records. In the future this pattern can be extended to include DigestRecords
            // If fullDetails is present do not select fields, if not present fetch only the SelectedFieldsForQuery
            var query = new ODataQuery<EventData>(queryFilter);
            IPage<EventData> response = this.InsightsClient.Events.ListAsync(odataQuery: query, select: fullDetails ? null : PSEventDataNoDetails.SelectedFieldsForQuery, cancellationToken: CancellationToken.None).Result;
            var records = new List<IPSEventData>();
            var enumerator = response.GetEnumerator();
            enumerator.ExtractCollectionFromResult(fullDetails: fullDetails, records: records, keepTheRecord: this.KeepTheRecord);
            string nextLink = response.NextPageLink;

            // Adding a safety check to stop returning records if too many have been read already.
            while (!string.IsNullOrWhiteSpace(nextLink) && records.Count < maxNumberOfRecords)
            {
                response = this.InsightsClient.Events.ListNextAsync(nextPageLink: nextLink, cancellationToken: CancellationToken.None).Result;
                enumerator.ExtractCollectionFromResult(fullDetails: fullDetails, records: records, keepTheRecord: this.KeepTheRecord);
                nextLink = response.NextPageLink;
            }

            var recordsReturned = new List<IPSEventData>();
            if (records.Count > maxNumberOfRecords)
            {
                recordsReturned.AddRange(records.Take(maxNumberOfRecords));
            }
            else
            {
                recordsReturned = records;
            }

            // Returns an object that contains a link to the set of subsequent records or null if not more records are available, called Next, and an array of records, called Value
            WriteObject(sendToPipeline: recordsReturned, enumerateCollection: true);
        }
    }