Skip to content

Commit

Permalink
Address annotation support comments
Browse files Browse the repository at this point in the history
  • Loading branch information
chinadragon0515 committed Aug 9, 2016
1 parent b83c4c8 commit 997269d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
41 changes: 21 additions & 20 deletions src/Microsoft.Restier.Publishers.OData/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ internal static class Extensions
private static PropertyInfo etagConcurrencyPropertiesProperty = typeof(ETag).GetProperty(
PropertyNameOfConcurrencyProperties, BindingFlags.NonPublic | BindingFlags.Instance);

// TODO GithubIssue#485 considering move to API class DI instance
private static ConcurrentDictionary<IEdmEntitySet, bool> concurrencyCheckFlags
= new ConcurrentDictionary<IEdmEntitySet, bool>();

// TODO GithubIssue#485 considering move to API class DI instance
private static ConcurrentDictionary<IEdmStructuredType, IDictionary<string, PropertyAttributes>>
typePropertiesAttributes
= new ConcurrentDictionary<IEdmStructuredType, IDictionary<string, PropertyAttributes>>();
Expand Down Expand Up @@ -80,7 +82,8 @@ public static IReadOnlyDictionary<string, object> CreatePropertyDictionary(
PropertyAttributes attributes;
if (propertiesAttributes != null && propertiesAttributes.TryGetValue(propertyName, out attributes))
{
if ((isCreation && attributes.IgnoreForCreation) || (!isCreation && attributes.IgnoreForUpdate))
if ((isCreation && (attributes & PropertyAttributes.IgnoreForCreation) != PropertyAttributes.None)
|| (!isCreation && (attributes & PropertyAttributes.IgnoreForUpdate) != PropertyAttributes.None))
{
// Will not get the properties for update or creation
continue;
Expand Down Expand Up @@ -116,7 +119,7 @@ public static IDictionary<string, PropertyAttributes> RetrievePropertiesAttribut
foreach (var property in edmType.DeclaredProperties)
{
var annotations = model.FindVocabularyAnnotations(property);
PropertyAttributes attributes = null;
var attributes = PropertyAttributes.None;
foreach (var annotation in annotations)
{
var valueAnnotation = annotation as EdmAnnotation;
Expand All @@ -125,34 +128,22 @@ public static IDictionary<string, PropertyAttributes> RetrievePropertiesAttribut
continue;
}

if (valueAnnotation.Term.Namespace == CoreVocabularyModel.ImmutableTerm.Namespace
&& valueAnnotation.Term.Name == CoreVocabularyModel.ImmutableTerm.Name)
if (valueAnnotation.Term.IsSameTerm(CoreVocabularyModel.ImmutableTerm))
{
var value = valueAnnotation.Value as EdmBooleanConstant;
if (value != null && value.Value)
{
if (attributes == null)
{
attributes = new PropertyAttributes();
}

attributes.IgnoreForUpdate = true;
attributes |= PropertyAttributes.IgnoreForUpdate;
}
}

if (valueAnnotation.Term.Namespace == CoreVocabularyModel.ComputedTerm.Namespace
&& valueAnnotation.Term.Name == CoreVocabularyModel.ComputedTerm.Name)
if (valueAnnotation.Term.IsSameTerm(CoreVocabularyModel.ComputedTerm))
{
var value = valueAnnotation.Value as EdmBooleanConstant;
if (value != null && value.Value)
{
if (attributes == null)
{
attributes = new PropertyAttributes();
}

attributes.IgnoreForUpdate = true;
attributes.IgnoreForCreation = true;
attributes |= PropertyAttributes.IgnoreForUpdate;
attributes |= PropertyAttributes.IgnoreForCreation;
}
}

Expand All @@ -161,7 +152,7 @@ public static IDictionary<string, PropertyAttributes> RetrievePropertiesAttribut
}

// Add property attributes to the dictionary
if (attributes != null)
if (attributes != PropertyAttributes.None)
{
if (propertiesAttributes == null)
{
Expand Down Expand Up @@ -241,5 +232,15 @@ public static IEdmTypeReference GetTypeReference(this Type type, IEdmModel model

return type.GetPrimitiveTypeReference();
}

public static bool IsSameTerm(this IEdmTerm sourceTerm, IEdmTerm targetTerm)
{
if (sourceTerm.Namespace == targetTerm.Namespace && sourceTerm.Name == targetTerm.Name)
{
return true;
}

return false;
}
}
}
18 changes: 13 additions & 5 deletions src/Microsoft.Restier.Publishers.OData/Model/PropertyAttributes.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;

namespace Microsoft.Restier.Publishers.OData
{
internal class PropertyAttributes
[Flags]
internal enum PropertyAttributes
{
/// <summary>
/// No flag is set for the property
/// </summary>
None = 0x0,

/// <summary>
/// Gets or sets a value indicating whether the property should be ignored during update
/// </summary>
public bool IgnoreForUpdate { get; set; }
IgnoreForUpdate = 0x1,

/// <summary>
/// Gets or sets a value indicating whether the property should be ignored during creation
/// </summary>
public bool IgnoreForCreation { get; set; }
IgnoreForCreation = 0x2,

/// <summary>
/// Gets or sets a value indicating whether there is permission to read the property
/// </summary>
public bool NoReadPermission { get; set; }
NoReadPermission = 0x4,

/// <summary>
/// Gets or sets a value indicating whether there is permission to write the property
/// </summary>
public bool NoWritePermission { get; set; }
NoWritePermission = 0x8
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ private void ResouceTimeoutHandler(object source, EventArgs e)

private class DataStoreUnit
{
public TKey DatastoreKey { get; }
public TKey DatastoreKey { get; private set; }

public TDataStoreType DataStore { get; }
public TDataStoreType DataStore { get; private set; }

public DateTime DataStoreLastUsedDateTime { get; private set; }

Expand Down

0 comments on commit 997269d

Please sign in to comment.