public async virtual Task <IActionResult> GetLastOperation(string instance_id) { LastOperationProvisionResponse response; // 1. Construct the ServiceProvisionRequest from various input sources ServiceProvisionRequest request = BuildLastOperationRequest(instance_id); // 2. Validate the request // 2.a If validation fails, return List <ResponseBase> responses = request.IsValid(ProvisionOpType.LastOperation); if (responses.Count > 0) { response = new LastOperationProvisionResponse { Description = responses.ToMessageString() }; return(ServerError(response)); } // 3. If provider is not set, send 500 error with ServiceProvisionResponse if (_provisionProvider == null) { string description = "Internal server error. Service Provision Provider is not set"; Console.WriteLine(description); response = new LastOperationProvisionResponse { Description = description }; return(ServerError(response)); } // 4. Check the incomplete request support // From the SPEC: // For a broker to return an asynchronous response, the query parameter accepts_incomplete=true MUST be included the request. // If the parameter is not included or is set to false, and the broker cannot fulfill the request synchronously // (guaranteeing that the operation is complete on response), then the broker SHOULD reject the request with the // status code 422 Unprocessable Entit if (this._provisionProvider.SupportAsynchronousRequest(request) && !request.AcceptsIncomplete) { response = new LastOperationProvisionResponse { Error = "AsyncRequired", Description = "This service plan requires client support for asynchronous service operations." }; return(UnprocessableEntity(response)); } // 5. Invoke the Provider response = this._provisionProvider.GetLastOperationResponse(request); // 6. Capture the response and send return(GetLastOperationResponse(response)); }
/// <summary> /// <summary> /// Gets the action result for the last operation request. Modifies response object based on the spec. /// </summary> /// <param name="response"></param> /// <returns></returns> private IActionResult GetLastOperationResponse(LastOperationProvisionResponse response) { IActionResult actionResult; switch (response.ResponseCode) { case LastOperationResponseCode.Success: actionResult = Ok(response); break; case LastOperationResponseCode.Gone: actionResult = Gone(response); break; default: actionResult = ServerError(response); break; } return(actionResult); }