public async Task <PartitionDataLossProgress> GetInvokeDataLossProgressAsync(
            Guid operationId,
            TimeSpan timeout,
            CancellationToken cancellationToken)
        {
            this.ThrowIfNotReady();
            PartitionDataLossProgress progress = null;

            TestabilityTrace.TraceSource.WriteInfo(TraceType, "Inside GetInvokeDataLossProgressAsync, operationId = {0}", operationId);

            try
            {
                ActionStateBase actionState = await this.MessageProcessor.ProcessGetProgressAsync(operationId, timeout, cancellationToken);

                StepStateNames stateName = actionState.StateProgress.Peek();

                TestCommandProgressState state = FaultAnalysisServiceUtility.ConvertState(actionState, TraceType);

                InvokeDataLossState invokeDataLossState = actionState as InvokeDataLossState;
                if (invokeDataLossState == null)
                {
                    throw new InvalidCastException("State object could not be converted");
                }

                StepStateNames stepState         = actionState.StateProgress.Peek();
                var            selectedPartition = new SelectedPartition
                {
                    ServiceName = invokeDataLossState.Info.PartitionSelector.ServiceName,
                    PartitionId = invokeDataLossState.Info.PartitionId
                };

                PartitionDataLossResult result = new PartitionDataLossResult(selectedPartition, actionState.ErrorCausingRollback);

                progress = new PartitionDataLossProgress(state, result);
                TestabilityTrace.TraceSource.WriteInfo(
                    TraceType,
                    "{0} - {1} progress - {2}, Exception - {3}",
                    operationId,
                    ActionType.InvokeDataLoss,
                    progress.Result != null ? progress.Result.SelectedPartition.ToString() : FASConstants.UnavailableMessage,
                    (progress.Result != null && progress.Result.Exception != null) ? progress.Result.Exception.ToString() : FASConstants.UnavailableMessage);
            }
            catch (Exception e)
            {
                TestabilityTrace.TraceSource.WriteWarning(TraceType, "{0} - Caught {1}", operationId, e.ToString());
                FaultAnalysisServiceUtility.ThrowTransientExceptionIfRetryable(e);

                throw;
            }

            return(progress);
        }
        public async Task <PartitionRestartProgress> GetRestartPartitionProgressAsync(
            Guid operationId,
            TimeSpan timeout,
            CancellationToken cancellationToken)
        {
            this.ThrowIfNotReady();
            PartitionRestartProgress progress = null;

            try
            {
                TestabilityTrace.TraceSource.WriteInfo(TraceType, "GetRestartPartitionProgressAsync calling message processor");
                ActionStateBase actionState = await this.MessageProcessor.ProcessGetProgressAsync(operationId, timeout, cancellationToken);

                StepStateNames stateName = actionState.StateProgress.Peek();

                TestCommandProgressState state = FaultAnalysisServiceUtility.ConvertState(actionState, TraceType);
                RestartPartitionState    restartPartitionState = actionState as RestartPartitionState;
                TestabilityTrace.TraceSource.WriteInfo(
                    TraceType,
                    "RestartPartition - serviceName={0}, partitionId={1}",
                    restartPartitionState.Info.PartitionSelector.ServiceName.ToString(),
                    restartPartitionState.Info.PartitionId);

                var selectedPartition = new SelectedPartition
                {
                    ServiceName = restartPartitionState.Info.PartitionSelector.ServiceName,
                    PartitionId = restartPartitionState.Info.PartitionId
                };

                PartitionRestartResult result = new PartitionRestartResult(selectedPartition, actionState.ErrorCausingRollback);

                progress = new PartitionRestartProgress(state, result);
                TestabilityTrace.TraceSource.WriteInfo(
                    TraceType,
                    "{0} - {1} progress - {2}, Exception - {3}",
                    operationId,
                    ActionType.RestartPartition,
                    progress.Result != null ? progress.Result.SelectedPartition.ToString() : FASConstants.UnavailableMessage,
                    (progress.Result != null && progress.Result.Exception != null) ? progress.Result.Exception.ToString() : FASConstants.UnavailableMessage);
            }
            catch (Exception e)
            {
                TestabilityTrace.TraceSource.WriteWarning(TraceType, "{0} - Caught {1}", operationId, e.ToString());
                FaultAnalysisServiceUtility.ThrowTransientExceptionIfRetryable(e);

                throw;
            }

            return(progress);
        }
        public async Task <TestCommandQueryResult> ProcessGetTestCommandListAsync(TestCommandListDescription description)
        {
            // 5728192
            const int MaxNumberOfItems           = 10000;
            IEnumerable <ActionStateBase> result = await this.actionStore.GetSelectedActionsAsync(description);

            List <TestCommandStatus> list = new List <TestCommandStatus>();

            int end = Math.Min(result.Count(), MaxNumberOfItems);

            for (int i = 0; i < end; i++)
            {
                TestCommandProgressState state = FaultAnalysisServiceUtility.ConvertState(result.ElementAt(i), TraceType);
                TestCommandType          type  = ConvertType(result.ElementAt(i));

                list.Add(new TestCommandStatus(result.ElementAt(i).OperationId, state, type));
            }

            TestCommandQueryResult testCommandQueryResult = new TestCommandQueryResult(list);

            return(testCommandQueryResult);
        }
        public async Task <NodeTransitionProgress> GetNodeTransitionProgressAsync(
            Guid operationId,
            TimeSpan timeout,
            CancellationToken cancellationToken)
        {
            this.ThrowIfNotReady();
            NodeTransitionProgress progress = null;

            try
            {
                TestabilityTrace.TraceSource.WriteInfo(TraceType, "GetNodeTransitionProgressAsync got operation id {0}", operationId);
                ActionStateBase actionState = await this.MessageProcessor.ProcessGetProgressAsync(operationId, timeout, cancellationToken);

                StepStateNames           stateName = actionState.StateProgress.Peek();
                TestCommandProgressState state     = FaultAnalysisServiceUtility.ConvertState(actionState, TraceType);

                TestabilityTrace.TraceSource.WriteInfo(TraceType, "{0} - GetNodeTransitionProgressAsync reading nodecommandstate", operationId);
                NodeCommandState nodeState = actionState as NodeCommandState;
                TestabilityTrace.TraceSource.WriteInfo(TraceType, "{0} NodeCommandState is null={1}", operationId, nodeState == null);

                TestabilityTrace.TraceSource.WriteInfo(TraceType, "{0} - GetNodeTransitionProgressAsync node name={1}, node instance id={2}", operationId, nodeState.Info.NodeName, nodeState.Info.InputNodeInstanceId);
                NodeResult        nodeResult = new NodeResult(nodeState.Info.NodeName, nodeState.Info.InputNodeInstanceId);
                NodeCommandResult result     = new NodeCommandResult(nodeResult, actionState.ErrorCausingRollback);

                progress = new NodeTransitionProgress(state, result);
            }
            catch (Exception e)
            {
                TestabilityTrace.TraceSource.WriteWarning(TraceType, "{0} - Caught {1}", operationId, e.ToString());
                FaultAnalysisServiceUtility.ThrowTransientExceptionIfRetryable(e);

                throw;
            }

            return(progress);
        }