private async Task <HttpResponseMessage> HandleDeleteHistoryWithFiltersRequestAsync(HttpRequestMessage request)
        {
            DurableOrchestrationClientBase client = this.GetClient(request);
            var queryNameValuePairs = request.GetQueryNameValuePairs();
            var createdTimeFrom     =
                GetDateTimeQueryParameterValue(queryNameValuePairs, "createdTimeFrom", DateTime.MinValue);

            if (createdTimeFrom == DateTime.MinValue)
            {
                var badRequestResponse = request.CreateResponse(
                    HttpStatusCode.BadRequest,
                    "Please provide value for 'createdTimeFrom' parameter.");
                return(badRequestResponse);
            }

            var createdTimeTo =
                GetDateTimeQueryParameterValue(queryNameValuePairs, "createdTimeTo", DateTime.UtcNow);
            var runtimeStatusCollection =
                GetIEnumerableQueryParameterValue <OrchestrationStatus>(queryNameValuePairs, "runtimeStatus");

            PurgeHistoryResult purgeHistoryResult = await client.PurgeInstanceHistoryAsync(createdTimeFrom, createdTimeTo, runtimeStatusCollection);

            if (purgeHistoryResult == null || purgeHistoryResult.InstancesDeleted == 0)
            {
                return(request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(request.CreateResponse(HttpStatusCode.OK, purgeHistoryResult));
        }
        private async Task <HttpResponseMessage> HandleDeleteHistoryByIdRequestAsync(
            HttpRequestMessage request,
            string instanceId)
        {
            DurableOrchestrationClientBase client             = this.GetClient(request);
            PurgeHistoryResult             purgeHistoryResult = await client.PurgeInstanceHistoryAsync(instanceId);

            if (purgeHistoryResult == null || purgeHistoryResult.InstancesDeleted == 0)
            {
                return(request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(request.CreateResponse(HttpStatusCode.OK, purgeHistoryResult));
        }
        private async Task <HttpResponseMessage> HandleDeleteHistoryByIdRequestAsync(
            HttpRequestMessage request,
            string instanceId)
        {
            IDurableOrchestrationClient client = this.GetClient(request);
            DurableOrchestrationStatus  status = await client.GetStatusAsync(instanceId, showHistory : false);

            if (status == null)
            {
                return(request.CreateResponse(HttpStatusCode.NotFound));
            }

            PurgeHistoryResult purgeHistoryResult = await client.PurgeInstanceHistoryAsync(instanceId);

            return(request.CreateResponse(HttpStatusCode.OK, purgeHistoryResult));
        }