Skip to content

Commit

Permalink
Adopt some new WAO public API
Browse files Browse the repository at this point in the history
  • Loading branch information
chinadragon0515 committed Aug 30, 2016
1 parent 080cb28 commit 33bc98e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
#endregion

#region CA2000 Dispose objects
[assembly: SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.RestierController.#CreateQueryResponse(System.Linq.IQueryable,Microsoft.OData.Edm.IEdmType,System.Boolean,System.Web.OData.Formatter.ETag)")]
[assembly: SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.RestierController.#CreateQueryResponse(System.Linq.IQueryable,Microsoft.OData.Edm.IEdmType,System.Web.OData.Formatter.ETag)")]
[assembly: SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Scope = "member", Target = "Microsoft.Restier.Publishers.OData.RestierExceptionFilterAttribute.#HandleCommonException(System.Web.Http.Filters.HttpActionExecutedContext,System.Boolean,System.Threading.CancellationToken)")]
#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ internal static object ConvertValue(
Request = request
};

// Enum logic can be removed after RestierEnumDeserializer extends ODataEnumDeserializer
var deserializerProvider = serviceProvider.GetService<ODataDeserializerProvider>();
var enumValue = odataValue as ODataEnumValue;
if (enumValue != null)
{
ODataEdmTypeDeserializer deserializer
= deserializerProvider.GetEdmTypeDeserializer(propertyType.AsEnum());
return deserializer.ReadInline(enumValue, propertyType, readContext);
}

var returnValue = ODataModelBinderConverter.Convert(
odataValue, propertyType, expectedReturnType, parameterName, readContext, serviceProvider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ namespace Microsoft.Restier.Publishers.OData.Formatter
/// <summary>
/// The serializer for enum result.
/// </summary>
internal class RestierEnumDeserializer : ODataEdmTypeDeserializer
internal class RestierEnumDeserializer : ODataEnumDeserializer
{
private ODataEnumDeserializer enumDeserializer = new ODataEnumDeserializer();

public RestierEnumDeserializer()
: base(ODataPayloadKind.Property)
{
}

/// <inheritdoc />
public override object Read(
ODataMessageReader messageReader,
Expand Down
22 changes: 8 additions & 14 deletions src/Microsoft.Restier.Publishers.OData/RestierController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ public async Task<HttpResponseMessage> Get(
IQueryable queryable = this.GetQuery(path);
ETag etag;

// TODO This flag can be removed when Etag isIfNoneMatch is changed to public.
bool isIfNoneMatch;

// TODO #365 Do not support additional path segment after function call now
if (lastSegment is OperationImportSegment)
{
Expand All @@ -97,7 +94,7 @@ public async Task<HttpResponseMessage> Get(
Func<string, object> getParaValueFunc = p => unboundSegment.GetParameterValue(p);
result = await ExecuteOperationAsync(
getParaValueFunc, operation.Name, true, null, cancellationToken);
result = ApplyQueryOptions(result, path, true, out isIfNoneMatch, out etag);
result = ApplyQueryOptions(result, path, true, out etag);
}
else
{
Expand All @@ -119,16 +116,16 @@ public async Task<HttpResponseMessage> Get(
result = await ExecuteOperationAsync(
getParaValueFunc, operation.Name, true, result, cancellationToken);

result = ApplyQueryOptions(result, path, true, out isIfNoneMatch, out etag);
result = ApplyQueryOptions(result, path, true, out etag);
}
else
{
queryable = ApplyQueryOptions(queryable, path, false, out isIfNoneMatch, out etag);
queryable = ApplyQueryOptions(queryable, path, false, out etag);
result = await ExecuteQuery(queryable, cancellationToken);
}
}

return this.CreateQueryResponse(result, path.EdmType, isIfNoneMatch, etag);
return this.CreateQueryResponse(result, path.EdmType, etag);
}

/// <summary>
Expand Down Expand Up @@ -330,7 +327,7 @@ public async Task<HttpResponseMessage> PostAction(
return this.Request.CreateResponse(HttpStatusCode.NoContent);
}

return this.CreateQueryResponse(result, path.EdmType, false, null);
return this.CreateQueryResponse(result, path.EdmType, null);
}

private static IEdmTypeReference GetTypeReference(IEdmType edmType)
Expand Down Expand Up @@ -418,7 +415,7 @@ private async Task<IHttpActionResult> Update(
}

private HttpResponseMessage CreateQueryResponse(
IQueryable query, IEdmType edmType, bool isIfNoneMatch, ETag etag)
IQueryable query, IEdmType edmType, ETag etag)
{
IEdmTypeReference typeReference = GetTypeReference(edmType);
BaseSingleResult singleResult = null;
Expand Down Expand Up @@ -504,7 +501,7 @@ private HttpResponseMessage CreateQueryResponse(
etag.EntityType = query.ElementType;
query = etag.ApplyTo(query);
entityResult = query.SingleOrDefault();
if (entityResult == null && !isIfNoneMatch)
if (entityResult == null && !etag.IsIfNoneMatch)
{
return this.Request.CreateResponse(HttpStatusCode.PreconditionFailed);
}
Expand Down Expand Up @@ -537,10 +534,8 @@ private IQueryable GetQuery(ODataPath path)
}

private IQueryable ApplyQueryOptions(
IQueryable queryable, ODataPath path, bool applyCount, out bool isIfNoneMatch, out ETag etag)
IQueryable queryable, ODataPath path, bool applyCount, out ETag etag)
{
// ETAG IsIfNoneMatch is changed to public access, this flag can be removed.
isIfNoneMatch = false;
etag = null;

if (this.shouldWriteRawValue)
Expand All @@ -562,7 +557,6 @@ private IQueryable ApplyQueryOptions(
}
else if (queryOptions.IfNoneMatch != null)
{
isIfNoneMatch = true;
etag = queryOptions.IfNoneMatch;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.OData.Extensions;
using Microsoft.OData.Service.Sample.Northwind.Models;
using Microsoft.OData.UriParser;
using Microsoft.Restier.Tests;
using Xunit;

Expand Down

0 comments on commit 33bc98e

Please sign in to comment.