Exemple #1
0
        /// <summary>Create an OData response based on the URL</summary>
        private Response GetResponse(ODataVersion version)
        {
            // Parse the URL and specify the number of segments at the root of the
            // path
            var uri = OData.Parse(Request.Url.ToString(), version)
                      .WithRootSegmentCount(2);

            // Return response for the root of the path
            var path = uri.PathBuilder().ToString();

            if (string.IsNullOrEmpty(path))
            {
                return(GetResponse(ODataResponse.FromModel_Service(uri, _model)));
            }
            if (path.StartsWith("$metadata", StringComparison.OrdinalIgnoreCase))
            {
                return(GetResponse(ODataResponse.FromModel_Edmx(uri, _model)));
            }
            if (path.StartsWith("$swagger", StringComparison.OrdinalIgnoreCase))
            {
                return(GetResponse(ODataResponse.FromModel_Swagger(uri, _model, new Version(1, 0))));
            }

            // Query the data source and return the appropriate response
            ODataResponse oResp;

            try
            {
                oResp = uri
                        .Execute(_products, new ExecutionSettings().WithEdmModel(_model))
                        .CreateResponse(_model, null);
            }
            catch (Exception ex)
            {
                oResp = ODataResponse.FromException(uri, ex, false);
            }
            return(GetResponse(oResp));
        }
Exemple #2
0
 /// <summary>
 /// Clone the URL to create a new copy in memory
 /// </summary>
 public ODataUri Clone()
 {
     return(OData.Parse(ToString(), _version).WithRootSegmentCount(_rootSegmentCount));
 }