private async Task <Stream> SendTargetedNotificationsRequestAsync(IEnumerable <string> previouslyCachedRuleIds)
        {
            Stream stream = null;

            apiTimer = Stopwatch.StartNew();
            try
            {
                CancellationTokenSource tokenSource = new CancellationTokenSource();
                Task.Delay(10000).ContinueWith(delegate
                {
                    tokenSource.Cancel();
                });
                CancellationToken cancelToken = CancellationTokenSource.CreateLinkedTokenSource(tokenSource.Token, cancellationTokenSource.Token).Token;
                string            parameters  = await BuildRequestParametersAsync(previouslyCachedRuleIds).ConfigureAwait(false);

                IHttpWebRequestFactory httpWebRequestFactory = webRequestFactory;
                IHttpWebRequest        request = httpWebRequestFactory.Create(await ResolveUrlRedirect("https://go.microsoft.com/fwlink/?LinkId=690387", cancelToken).ConfigureAwait(false));
                request.ContentType = "application/json";
                request.Method      = "POST";
                logger.LogVerbose("Sending request to TN backend", parameters);
                byte[] postData = Encoding.UTF8.GetBytes(parameters);
                request.ContentLength = postData.Length;
                Stream postStream = await request.GetRequestStreamAsync().ConfigureAwait(false);

                await postStream.WriteAsync(postData, 0, postData.Length, cancelToken).ConfigureAwait(false);

                postStream.Close();
                IHttpWebResponse httpWebResponse = await request.GetResponseAsync(cancelToken).ConfigureAwait(false);

                apiTimer.Stop();
                if (httpWebResponse.ErrorCode == ErrorCode.NoError)
                {
                    stream = httpWebResponse.GetResponseStream();
                }
                else
                {
                    string eventName   = "VS/Core/TargetedNotifications/ApiRequestFailed";
                    string description = "Request failed.";
                    Dictionary <string, object> dictionary = new Dictionary <string, object>
                    {
                        {
                            "VS.Core.TargetedNotifications.ErrorCode",
                            httpWebResponse.ErrorCode
                        },
                        {
                            "VS.Core.TargetedNotifications.ApiResponseMs",
                            apiTimer?.ElapsedMilliseconds
                        },
                        {
                            "VS.Core.TargetedNotifications.Iteration",
                            queryIteration
                        }
                    };
                    if (httpWebResponse.ErrorCode == ErrorCode.WebExceptionThrown)
                    {
                        dictionary.Add("VS.Core.TargetedNotifications.WebExceptionCode", httpWebResponse.ExceptionCode);
                    }
                    targetedNotificationsTelemetry.PostDiagnosticFault(eventName, description, null, dictionary);
                }
                return(stream);
            }
            catch (Exception exception)
            {
                apiTimer.Stop();
                string eventName2 = "VS/Core/TargetedNotifications/ApiRequestException";
                string text       = "Sending request to TN backend failed";
                Dictionary <string, object> additionalProperties = new Dictionary <string, object>
                {
                    {
                        "VS.Core.TargetedNotifications.ApiResponseMs",
                        apiTimer?.ElapsedMilliseconds
                    },
                    {
                        "VS.Core.TargetedNotifications.Iteration",
                        queryIteration
                    }
                };
                logger.LogError(text, exception);
                targetedNotificationsTelemetry.PostDiagnosticFault(eventName2, text, exception, additionalProperties);
                return(stream);
            }
        }