protected override void ProcessRecord()
        {
            var clusterConnection = this.GetClusterConnection();

            try
            {
                var queryDescription = new ApplicationHealthQueryDescription(this.ApplicationName);
                if (this.ConsiderWarningAsError.HasValue ||
                    this.MaxPercentUnhealthyDeployedApplications.HasValue ||
                    this.MaxPercentUnhealthyServices.HasValue ||
                    this.MaxPercentUnhealthyPartitionsPerService.HasValue ||
                    this.MaxPercentUnhealthyReplicasPerPartition.HasValue)
                {
                    queryDescription.HealthPolicy = new ApplicationHealthPolicy()
                    {
                        ConsiderWarningAsError = this.ConsiderWarningAsError.GetValueOrDefault(),
                        MaxPercentUnhealthyDeployedApplications = this.MaxPercentUnhealthyDeployedApplications.GetValueOrDefault(),
                        DefaultServiceTypeHealthPolicy          = new ServiceTypeHealthPolicy()
                        {
                            MaxPercentUnhealthyServices             = this.MaxPercentUnhealthyServices.GetValueOrDefault(),
                            MaxPercentUnhealthyPartitionsPerService = this.MaxPercentUnhealthyPartitionsPerService.GetValueOrDefault(),
                            MaxPercentUnhealthyReplicasPerPartition = this.MaxPercentUnhealthyReplicasPerPartition.GetValueOrDefault()
                        }
                    };
                }

                if (this.EventsHealthStateFilter.HasValue)
                {
                    this.WriteWarning(StringResources.PowerShell_EventsHealthStateFilter_Deprecated);
                    if (!this.EventsFilter.HasValue)
                    {
                        this.EventsFilter = (HealthStateFilter)this.EventsHealthStateFilter;
                    }
                }

                if (this.EventsFilter.HasValue)
                {
                    queryDescription.EventsFilter = new HealthEventsFilter()
                    {
                        HealthStateFilterValue = this.EventsFilter.Value,
                    };
                }

                if (this.ServicesHealthStateFilter.HasValue)
                {
                    this.WriteWarning(StringResources.PowerShell_ServicesHealthStateFilter_Deprecated);
                    if (!this.ServicesFilter.HasValue)
                    {
                        this.ServicesFilter = (HealthStateFilter)this.ServicesHealthStateFilter;
                    }
                }

                if (this.ServicesFilter.HasValue)
                {
                    queryDescription.ServicesFilter = new ServiceHealthStatesFilter()
                    {
                        HealthStateFilterValue = this.ServicesFilter.Value,
                    };
                }

                if (this.DeployedApplicationsHealthStateFilter.HasValue)
                {
                    this.WriteWarning(StringResources.PowerShell_DeployedApplicationsHealthStateFilter_Deprecated);
                    if (!this.DeployedApplicationsFilter.HasValue)
                    {
                        this.DeployedApplicationsFilter = (HealthStateFilter)this.DeployedApplicationsHealthStateFilter;
                    }
                }

                if (this.DeployedApplicationsFilter.HasValue)
                {
                    queryDescription.DeployedApplicationsFilter = new DeployedApplicationHealthStatesFilter()
                    {
                        HealthStateFilterValue = this.DeployedApplicationsFilter.Value,
                    };
                }

                if (this.ExcludeHealthStatistics)
                {
                    queryDescription.HealthStatisticsFilter = new ApplicationHealthStatisticsFilter()
                    {
                        ExcludeHealthStatistics = this.ExcludeHealthStatistics
                    };
                }

                var applicationHealth = clusterConnection.GetApplicationHealthAsync(
                    queryDescription,
                    this.GetTimeout(),
                    this.GetCancellationToken()).Result;
                this.WriteObject(this.FormatOutput(applicationHealth));
            }
            catch (AggregateException aggregateException)
            {
                aggregateException.Handle((ae) =>
                {
                    this.ThrowTerminatingError(
                        ae,
                        Constants.GetApplicationHealthErrorId,
                        clusterConnection);
                    return(true);
                });
            }
        }
 public GetApplicationHealthRequest(IFabricClient fabricClient, ApplicationHealthQueryDescription queryDescription, TimeSpan timeout)
     : base(fabricClient, timeout)
 {
     ThrowIf.Null(queryDescription, "queryDescription");
     this.QueryDescription = queryDescription;
 }