Skip to content

Commit

Permalink
OData V3 5.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LaylaLiu committed Nov 23, 2015
1 parent f10d515 commit f1934b3
Show file tree
Hide file tree
Showing 110 changed files with 4,074 additions and 928 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public override IEnumerable<IEdmVocabularyAnnotation> FindDeclaredVocabularyAnno

List<CsdlSemanticsAnnotations> elementAnnotations;
string fullName = EdmUtil.FullyQualifiedName(element);

if (fullName != null && this.outOfLineAnnotations.TryGetValue(fullName, out elementAnnotations))
{
List<IEdmVocabularyAnnotation> result = new List<IEdmVocabularyAnnotation>();
Expand Down Expand Up @@ -451,22 +451,17 @@ internal IEnumerable<IEdmVocabularyAnnotation> WrapInlineVocabularyAnnotations(C

private IEdmVocabularyAnnotation WrapVocabularyAnnotation(CsdlVocabularyAnnotationBase annotation, CsdlSemanticsSchema schema, IEdmVocabularyAnnotatable targetContext, CsdlSemanticsAnnotations annotationsContext, string qualifier)
{
CsdlSemanticsVocabularyAnnotation result;

// Guarantee that multiple calls to wrap a given annotation all return the same object.
if (this.wrappedAnnotations.TryGetValue(annotation, out result))
{
return result;
}

CsdlValueAnnotation valueAnnotation = annotation as CsdlValueAnnotation;
result =
valueAnnotation != null
? (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsValueAnnotation(schema, targetContext, annotationsContext, valueAnnotation, qualifier)
: (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsTypeAnnotation(schema, targetContext, annotationsContext, (CsdlTypeAnnotation)annotation, qualifier);

this.wrappedAnnotations[annotation] = result;
return result;
return EdmUtil.DictionaryGetOrUpdate(
this.wrappedAnnotations,
annotation,
ann =>
{
CsdlValueAnnotation valueAnnotation = ann as CsdlValueAnnotation;
return
valueAnnotation != null
? (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsValueAnnotation(schema, targetContext, annotationsContext, valueAnnotation, qualifier)
: (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsTypeAnnotation(schema, targetContext, annotationsContext, (CsdlTypeAnnotation)annotation, qualifier);
});
}

private void AddSchema(CsdlSchema schema)
Expand Down Expand Up @@ -554,4 +549,4 @@ private void AddSchema(CsdlSchema schema)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,45 @@ public static bool EqualsOrdinalIgnoreCase(this string string1, string string2)
return string.Equals(string1, string2, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Query dictionary for certain key, and update it if not exist
/// </summary>
/// <typeparam name="TKey">Key type for dictionary</typeparam>
/// <typeparam name="TValue">Value type for dictionary</typeparam>
/// <param name="dictionary">The dictionary to look up</param>
/// <param name="key">The key property</param>
/// <param name="computeValue">The function to compute value if key not exist in dictionary</param>
/// <returns>The value for the key</returns>
internal static TValue DictionaryGetOrUpdate<TKey, TValue>(
IDictionary<TKey, TValue> dictionary,
TKey key,
Func<TKey, TValue> computeValue)
{
CheckArgumentNull(dictionary, "dictionary");
CheckArgumentNull(computeValue, "computeValue");

TValue val;
lock (dictionary)
{
if (dictionary.TryGetValue(key, out val))
{
return val;
}
}

TValue val1 = computeValue(key);
lock (dictionary)
{
if (!dictionary.TryGetValue(key, out val))
{
val = val1;
dictionary.Add(key, val1);
}
}

return val;
}

// Hack to alert FXCop that we do check for null.
private sealed class ValidatedNotNullAttribute : Attribute
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public override IEnumerable<IEdmVocabularyAnnotation> FindDeclaredVocabularyAnno

List<CsdlSemanticsAnnotations> elementAnnotations;
string fullName = EdmUtil.FullyQualifiedName(element);

if (fullName != null && this.outOfLineAnnotations.TryGetValue(fullName, out elementAnnotations))
{
List<IEdmVocabularyAnnotation> result = new List<IEdmVocabularyAnnotation>();
Expand Down Expand Up @@ -451,22 +451,17 @@ internal IEnumerable<IEdmVocabularyAnnotation> WrapInlineVocabularyAnnotations(C

private IEdmVocabularyAnnotation WrapVocabularyAnnotation(CsdlVocabularyAnnotationBase annotation, CsdlSemanticsSchema schema, IEdmVocabularyAnnotatable targetContext, CsdlSemanticsAnnotations annotationsContext, string qualifier)
{
CsdlSemanticsVocabularyAnnotation result;

// Guarantee that multiple calls to wrap a given annotation all return the same object.
if (this.wrappedAnnotations.TryGetValue(annotation, out result))
{
return result;
}

CsdlValueAnnotation valueAnnotation = annotation as CsdlValueAnnotation;
result =
valueAnnotation != null
? (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsValueAnnotation(schema, targetContext, annotationsContext, valueAnnotation, qualifier)
: (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsTypeAnnotation(schema, targetContext, annotationsContext, (CsdlTypeAnnotation)annotation, qualifier);

this.wrappedAnnotations[annotation] = result;
return result;
return EdmUtil.DictionaryGetOrUpdate(
this.wrappedAnnotations,
annotation,
ann =>
{
CsdlValueAnnotation valueAnnotation = ann as CsdlValueAnnotation;
return
valueAnnotation != null
? (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsValueAnnotation(schema, targetContext, annotationsContext, valueAnnotation, qualifier)
: (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsTypeAnnotation(schema, targetContext, annotationsContext, (CsdlTypeAnnotation)annotation, qualifier);
});
}

private void AddSchema(CsdlSchema schema)
Expand Down Expand Up @@ -554,4 +549,4 @@ private void AddSchema(CsdlSchema schema)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,45 @@ public static bool EqualsOrdinalIgnoreCase(this string string1, string string2)
return string.Equals(string1, string2, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Query dictionary for certain key, and update it if not exist
/// </summary>
/// <typeparam name="TKey">Key type for dictionary</typeparam>
/// <typeparam name="TValue">Value type for dictionary</typeparam>
/// <param name="dictionary">The dictionary to look up</param>
/// <param name="key">The key property</param>
/// <param name="computeValue">The function to compute value if key not exist in dictionary</param>
/// <returns>The value for the key</returns>
internal static TValue DictionaryGetOrUpdate<TKey, TValue>(
IDictionary<TKey, TValue> dictionary,
TKey key,
Func<TKey, TValue> computeValue)
{
CheckArgumentNull(dictionary, "dictionary");
CheckArgumentNull(computeValue, "computeValue");

TValue val;
lock (dictionary)
{
if (dictionary.TryGetValue(key, out val))
{
return val;
}
}

TValue val1 = computeValue(key);
lock (dictionary)
{
if (!dictionary.TryGetValue(key, out val))
{
val = val1;
dictionary.Add(key, val1);
}
}

return val;
}

// Hack to alert FXCop that we do check for null.
private sealed class ValidatedNotNullAttribute : Attribute
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public override IEnumerable<IEdmVocabularyAnnotation> FindDeclaredVocabularyAnno

List<CsdlSemanticsAnnotations> elementAnnotations;
string fullName = EdmUtil.FullyQualifiedName(element);

if (fullName != null && this.outOfLineAnnotations.TryGetValue(fullName, out elementAnnotations))
{
List<IEdmVocabularyAnnotation> result = new List<IEdmVocabularyAnnotation>();
Expand Down Expand Up @@ -451,22 +451,17 @@ internal IEnumerable<IEdmVocabularyAnnotation> WrapInlineVocabularyAnnotations(C

private IEdmVocabularyAnnotation WrapVocabularyAnnotation(CsdlVocabularyAnnotationBase annotation, CsdlSemanticsSchema schema, IEdmVocabularyAnnotatable targetContext, CsdlSemanticsAnnotations annotationsContext, string qualifier)
{
CsdlSemanticsVocabularyAnnotation result;

// Guarantee that multiple calls to wrap a given annotation all return the same object.
if (this.wrappedAnnotations.TryGetValue(annotation, out result))
{
return result;
}

CsdlValueAnnotation valueAnnotation = annotation as CsdlValueAnnotation;
result =
valueAnnotation != null
? (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsValueAnnotation(schema, targetContext, annotationsContext, valueAnnotation, qualifier)
: (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsTypeAnnotation(schema, targetContext, annotationsContext, (CsdlTypeAnnotation)annotation, qualifier);

this.wrappedAnnotations[annotation] = result;
return result;
return EdmUtil.DictionaryGetOrUpdate(
this.wrappedAnnotations,
annotation,
ann =>
{
CsdlValueAnnotation valueAnnotation = ann as CsdlValueAnnotation;
return
valueAnnotation != null
? (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsValueAnnotation(schema, targetContext, annotationsContext, valueAnnotation, qualifier)
: (CsdlSemanticsVocabularyAnnotation)new CsdlSemanticsTypeAnnotation(schema, targetContext, annotationsContext, (CsdlTypeAnnotation)annotation, qualifier);
});
}

private void AddSchema(CsdlSchema schema)
Expand Down Expand Up @@ -554,4 +549,4 @@ private void AddSchema(CsdlSchema schema)
}
}
}

39 changes: 39 additions & 0 deletions ODataLib/EdmLib/Silverlight/Microsoft/Data/Edm/Internal/EdmUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,45 @@ public static bool EqualsOrdinalIgnoreCase(this string string1, string string2)
return string.Equals(string1, string2, StringComparison.OrdinalIgnoreCase);
}

/// <summary>
/// Query dictionary for certain key, and update it if not exist
/// </summary>
/// <typeparam name="TKey">Key type for dictionary</typeparam>
/// <typeparam name="TValue">Value type for dictionary</typeparam>
/// <param name="dictionary">The dictionary to look up</param>
/// <param name="key">The key property</param>
/// <param name="computeValue">The function to compute value if key not exist in dictionary</param>
/// <returns>The value for the key</returns>
internal static TValue DictionaryGetOrUpdate<TKey, TValue>(
IDictionary<TKey, TValue> dictionary,
TKey key,
Func<TKey, TValue> computeValue)
{
CheckArgumentNull(dictionary, "dictionary");
CheckArgumentNull(computeValue, "computeValue");

TValue val;
lock (dictionary)
{
if (dictionary.TryGetValue(key, out val))
{
return val;
}
}

TValue val1 = computeValue(key);
lock (dictionary)
{
if (!dictionary.TryGetValue(key, out val))
{
val = val1;
dictionary.Add(key, val1);
}
}

return val;
}

// Hack to alert FXCop that we do check for null.
private sealed class ValidatedNotNullAttribute : Attribute
{
Expand Down
2 changes: 2 additions & 0 deletions ODataLib/OData/Desktop/.Net3.5/Microsoft.Data.OData.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@
<Compile Include="Microsoft\Data\OData\Atom\ODataAtomReaderNavigationLinkDescriptor.cs" />
<Compile Include="Microsoft\Data\OData\CollectionWithoutExpectedTypeValidator.cs" />
<Compile Include="Microsoft\Data\OData\BufferingReadStream.cs" />
<Compile Include="Microsoft\Data\OData\ODataJsonLightRawAnnotationSet.cs" />
<Compile Include="Microsoft\Data\OData\ODataUntypedValue.cs" />
<Compile Include="Microsoft\Data\OData\Evaluation\IODataEntryMetadataContext.cs" />
<Compile Include="Microsoft\Data\OData\Evaluation\NoOpEntityMetadataBuilder.cs" />
<Compile Include="Microsoft\Data\OData\Evaluation\ODataEntryMetadataContext.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private object ReadPropertyValue(
bool lastSegment = epmInfo.PropertyValuePath.Length == sourceSegmentIndex + 1;

IEdmStructuredType structuredType = structuredTypeReference.StructuredDefinition();
IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(propertyName, structuredType);
IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(propertyName, structuredType, this.atomOutputContext.MessageWriterSettings.UndeclaredPropertyBehaviorKinds);
IEdmTypeReference propertyTypeReference = null;
if (edmProperty != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,13 @@ internal void WriteStreamProperty(

WriterValidationUtils.ValidatePropertyName(propertyName);
duplicatePropertyNamesChecker.CheckForDuplicatePropertyNames(streamProperty);
IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(streamProperty.Name, owningType);
IEdmProperty edmProperty = WriterValidationUtils.ValidatePropertyDefined(streamProperty.Name, owningType, this.MessageWriterSettings.UndeclaredPropertyBehaviorKinds);
WriterValidationUtils.ValidateStreamReferenceProperty(streamProperty, edmProperty, this.Version, this.WritingResponse);
ODataStreamReferenceValue streamReferenceValue = (ODataStreamReferenceValue)streamProperty.Value;
WriterValidationUtils.ValidateStreamReferenceValue(streamReferenceValue, false /*isDefaultStream*/);
if (owningType != null && owningType.IsOpen && edmProperty == null)
{
ValidationUtils.ValidateOpenPropertyValue(streamProperty.Name, streamReferenceValue);
ValidationUtils.ValidateOpenPropertyValue(streamProperty.Name, streamReferenceValue, this.MessageWriterSettings.UndeclaredPropertyBehaviorKinds);
}

AtomStreamReferenceMetadata streamReferenceMetadata = streamReferenceValue.GetAnnotation<AtomStreamReferenceMetadata>();
Expand Down
Loading

0 comments on commit f1934b3

Please sign in to comment.