Example #1
0
        /// <summary>
        /// 1. Retry old requests
        /// 2. Add completed list to a separate list
        /// 3. Add activities to respective Power Platform lists
        /// </summary>
        /// <param name="oldRequests"></param>
        /// <param name="retry"></param>
        /// <returns></returns>
        private async Task <(List <int>, List <Activity>, List <Activity>, List <Activity>)> RetryOldRequestsAsync(List <FailedUrlEntry> oldRequests)
        {
            List <int>      completedOldRequests    = new List <int>();
            List <Activity> powerAppActivities      = new List <Activity>();
            List <Activity> powerBIActivities       = new List <Activity>();;
            List <Activity> powerAutomateActivities = new List <Activity>();

            try
            {
                _log.Info("#################### OLD REQUESTS  ########################");
                int count = 0;
                foreach (var item in oldRequests)
                {
                    count++;

                    var response = await _retryClient.GetAsyncWithRetryAsync(item.Url, _O365ServiceAuthenticationContract).ConfigureAwait(false);

                    if (!response.IsSuccessStatusCode)
                    {
                        _log.Error($"The request failed with {await response.Content.ReadAsStringAsync()} for {item.Url}. Please try the request later.");
                    }
                    else
                    {
                        completedOldRequests.Add(item.Id);
                        string content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                        var jarray = JArray.Parse(content);
                        (powerAppActivities, powerBIActivities, powerAutomateActivities) = _o365ActivityApiWrapper.FilterAndAddObjectToPowerPlatformObjects(jarray);
                    }

                    _log.Info($"No of pages read {count} out of {oldRequests.Count} pages");
                }

                _log.Info($"No of activities available for Power BI between {_lastAuditLogTimeStampForPowerPlatform} and {_endTimeStampForPowerPlatform}: {powerBIActivities.Count}");
                _log.Info($"No of activities available for Power Apps between {_lastAuditLogTimeStampForPowerPlatform} and {_endTimeStampForPowerPlatform}:  {powerAppActivities.Count}");
                _log.Info($"No of activities available for Power Automate between {_lastAuditLogTimeStampForPowerPlatform} and {_endTimeStampForPowerPlatform}:  {powerAutomateActivities.Count}");
                _log.Info("#################### OLD REQUESTS ########################");

                return(completedOldRequests, powerAppActivities, powerBIActivities, powerAutomateActivities);
            }
            catch (AggregateException ex)
            {
                var aggregateException = ex.Flatten();
                for (int i = 0; i < aggregateException.InnerExceptions.Count; ++i)
                {
                    var canceledException = aggregateException.InnerExceptions[i];
                    _log.Error($"Error in retrieving content url {canceledException.Message}\n {canceledException.StackTrace}");
                }
                throw;
            }
            catch (TaskCanceledException ex)
            {
                throw;
            }
            catch (Exception ex)
            {
                _log.Error($"Error in retrieving content url {ex.Message}\n {ex.StackTrace}");
                throw;
            }
        }
Example #2
0
        /// <summary>
        /// List Office 365 Management Activity Api subscription
        /// </summary>
        /// <returns></returns>
        public async Task <HttpResponseMessage> ListSubscriptionAsync()
        {
            try
            {
                string endpoint = $"https://manage.office.com/api/v1.0/{_configuration.AppSettings.TenantId}/activity/feed/subscriptions/list";
                var    response = await _retryClient.GetAsyncWithRetryAsync(endpoint, _O365ServiceAuthenticationContract).ConfigureAwait(false);

                if (!response.IsSuccessStatusCode)
                {
                    _log.Error($"Unable to list subscription - Audit.General  {await response.Content.ReadAsStringAsync()}");
                    throw new Exception($"Unable to list subscription - Audit.General");;
                }
                else
                {
                    _log.Info($"Listing subscriptions for Audit.General {await response.Content.ReadAsStringAsync().ConfigureAwait(false)}");
                    return(response);
                }
            }
            catch (Exception ex)
            {
                _log.Error($"Unable to list subscriptions {ex.Message}\n {ex.StackTrace}");
                throw;
            }
        }