public async Task RunPollingThreadAsync(IOperationContext context)
        {
            Trace.WriteInfo(TraceType, "PollingThread initialized");

            var pollRequest = new UpgradeServicePollRequest();

            var result = await this.commandProcessors[ResourceType.Cluster].ProcessAsync(
                new List <IOperationDescription>()
            {
                null
            },
                new OperationContext(
                    context.CancellationToken,
                    context.OperationTimeout,
                    context.ContinuationToken));

            pollRequest.ClusterOperationStatus = result.Cast <ClusterOperationStatus>().FirstOrDefault();

            while (!context.CancellationToken.IsCancellationRequested)
            {
                var operationContext =
                    new OperationContext(
                        context.CancellationToken,
                        context.OperationTimeout,
                        context.ContinuationToken);
                try
                {
                    Trace.WriteInfo(TraceType, "Poll WRP - started");
                    var pollResponse = await this.packageRetriever.GetWrpResponseAsync(pollRequest, context.CancellationToken);

                    Trace.WriteInfo(TraceType, "Poll WRP - end");

                    Trace.WriteInfo(TraceType, "Handle poll response - started");
                    pollRequest = await this.ProcessWrpServicePollResponseAsync(
                        pollResponse,
                        new OperationContext(
                            operationContext.CancellationToken,
                            operationContext.GetRemainingTimeOrThrow(),
                            operationContext.ContinuationToken));

                    Trace.WriteInfo(TraceType, "Handle poll response - ended");

                    this.exceptionPolicy.ReportSuccess();
                }
                catch (Exception e)
                {
                    this.exceptionPolicy.ReportError(e, context.CancellationToken.IsCancellationRequested);
                }

                await Task.Delay(operationContext.GetRemainingTime(), operationContext.CancellationToken);
            }

            Trace.WriteInfo(TraceType, "PollingThread cancelled");
        }
        public async Task <UpgradeServicePollResponse> GetWrpResponseAsync(UpgradeServicePollRequest request, CancellationToken token)
        {
            Trace.WriteNoise(TraceType, "GetWrpServiceApplicationResponseAsync begin");


            var response = await this.GetWrpServiceResponseAsync <UpgradeServicePollRequest, UpgradeServicePollResponse>(
                this.BaseUrl,
                HttpMethod.Post,
                request,
                token);

            Trace.WriteNoise(TraceType, "GetWrpServiceApplicationResponseAsync end");
            return(response);
        }
        public async Task RunPollingThreadAsync(IOperationContext context)
        {
            Trace.WriteInfo(TraceType, "PollingThread initialized");

            var pollRequest = new UpgradeServicePollRequest();

            var result = await this.commandProcessors[ResourceType.Cluster].ProcessAsync(
                new List <IOperationDescription>()
            {
                null
            },
                new OperationContext(
                    context.CancellationToken,
                    context.OperationTimeout,
                    context.ContinuationToken));

            pollRequest.ClusterOperationStatus = result.Cast <ClusterOperationStatus>().FirstOrDefault();

            // Temporary workaround to clean up in KVS the node status for non primary node types.
            // TODO: Remove this logic once all clusters managed by SFRP are migrated to SF 6.2+
            if (!this.filteredPrimaryNodesStatus)
            {
                await FilterPrimaryNodesStatusAsync(context.CancellationToken);

                this.filteredPrimaryNodesStatus = true;
            }

            while (!context.CancellationToken.IsCancellationRequested)
            {
                var operationContext =
                    new OperationContext(
                        context.CancellationToken,
                        context.OperationTimeout,
                        context.ContinuationToken);
                try
                {
                    Trace.WriteInfo(TraceType, "Poll WRP - started");
                    var pollResponse = await this.packageRetriever.GetWrpResponseAsync(pollRequest, context.CancellationToken);

                    Trace.WriteInfo(TraceType, "Poll WRP - end");

                    Trace.WriteInfo(TraceType, "Handle poll response - started");
                    pollRequest = await this.ProcessWrpServicePollResponseAsync(
                        pollResponse,
                        new OperationContext(
                            operationContext.CancellationToken,
                            operationContext.GetRemainingTimeOrThrow(),
                            operationContext.ContinuationToken));

                    Trace.WriteInfo(TraceType, "Handle poll response - ended");

                    this.exceptionPolicy.ReportSuccess();
                }
                catch (Exception e)
                {
                    this.exceptionPolicy.ReportError(e, context.CancellationToken.IsCancellationRequested);
                }

                await Task.Delay(operationContext.GetRemainingTime(), operationContext.CancellationToken);
            }

            Trace.WriteInfo(TraceType, "PollingThread cancelled");
        }