private static void AnnotationsThreadFunction(object o) { IEdmModel model = (IEdmModel)o; IEdmEntityType person = model.FindEntityType("foo.Person"); IEdmProperty name = person.FindProperty("Name"); string bogus = "http://bogus.com"; string goop = "goop"; string droop = "droop"; string scoop = "scoop"; int index = ++ThreadIndex; for (int i = 0; i < 10000; i++) { var setters = new IEdmDirectValueAnnotationBinding[] { new EdmDirectValueAnnotationBinding(person, bogus, goop, index), new EdmDirectValueAnnotationBinding(person, bogus, droop, index), new EdmDirectValueAnnotationBinding(person, bogus, scoop, index), new EdmDirectValueAnnotationBinding(name, bogus, goop, index), new EdmDirectValueAnnotationBinding(name, bogus, droop, index), new EdmDirectValueAnnotationBinding(name, bogus, scoop, index) }; model.SetAnnotationValues(setters); } }
internal static void ClearInMemoryEpmAnnotations(this IEdmModel model, IEdmElement annotatable) { IEdmDirectValueAnnotationBinding[] annotations = new IEdmDirectValueAnnotationBinding[] { new EdmTypedDirectValueAnnotationBinding <ODataEntityPropertyMappingCollection>(annotatable, null), new EdmTypedDirectValueAnnotationBinding <ODataEntityPropertyMappingCache>(annotatable, null) }; model.SetAnnotationValues(annotations); }
/// <summary> /// Removes the in-memory EPM annotations from an entity type; potentially also drops an existing EPM cache. /// </summary> /// <param name="model">The <see cref="IEdmModel"/> containing the annotation.</param> /// <param name="annotatable">The <see cref="IEdmElement"/> to remove the EPM annotation from.</param> internal static void ClearInMemoryEpmAnnotations(this IEdmModel model, IEdmElement annotatable) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(model != null, "model != null"); Debug.Assert(annotatable != null, "annotatable != null"); IEdmDirectValueAnnotationBinding[] annotationSetters = new IEdmDirectValueAnnotationBinding[2]; // remove the in-memory annotation annotationSetters[0] = new EdmTypedDirectValueAnnotationBinding<ODataEntityPropertyMappingCollection>(annotatable, null); // remove the cache annotationSetters[1] = new EdmTypedDirectValueAnnotationBinding<ODataEntityPropertyMappingCache>(annotatable, null); model.SetAnnotationValues(annotationSetters); }
public void MultithreadedAnnotations() { this.SetupModels(); IEdmEntityType person = baseModel.FindEntityType("foo.Person"); Assert.IsNotNull(person, "Personage"); IEdmProperty name = person.FindProperty("Name"); Assert.IsNotNull(name, "Person Name"); string bogus = "http://bogus.com"; string goop = "goop"; string droop = "droop"; string scoop = "scoop"; var setters = new IEdmDirectValueAnnotationBinding[] { new EdmDirectValueAnnotationBinding(person, bogus, goop, 0), new EdmDirectValueAnnotationBinding(person, bogus, droop, 0), new EdmDirectValueAnnotationBinding(person, bogus, scoop, 0), new EdmDirectValueAnnotationBinding(name, bogus, goop, 0), new EdmDirectValueAnnotationBinding(name, bogus, droop, 0), new EdmDirectValueAnnotationBinding(name, bogus, scoop, 0) }; var getters = new IEdmDirectValueAnnotationBinding[] { new EdmDirectValueAnnotationBinding(person, bogus, goop), new EdmDirectValueAnnotationBinding(person, bogus, droop), new EdmDirectValueAnnotationBinding(person, bogus, scoop), new EdmDirectValueAnnotationBinding(name, bogus, goop), new EdmDirectValueAnnotationBinding(name, bogus, droop), new EdmDirectValueAnnotationBinding(name, bogus, scoop) }; baseModel.SetAnnotationValues(setters); bool foundNonzero = false; ThreadIndex = 0; System.Threading.ParameterizedThreadStart threadStart = new System.Threading.ParameterizedThreadStart(AnnotationsThreadFunction); for (int i = 0; i < 100; i++) { System.Threading.Thread newThread = new System.Threading.Thread(threadStart); newThread.Start(baseModel); object[] values = baseModel.GetAnnotationValues(getters); int firstValue = (int)values[0]; foreach (object value in values) { Assert.AreEqual(firstValue, (int)value, "Person and name values"); } } for (int i = 0; i < 10000; i++) { object[] values = baseModel.GetAnnotationValues(getters); int firstValue = (int)values[0]; if (firstValue != 0) { foundNonzero = true; } foreach (object value in values) { Assert.AreEqual(firstValue, (int)value, "Person and name values"); } } Assert.IsTrue(foundNonzero, "Nonzero value"); }
internal static void ClearInMemoryEpmAnnotations(this IEdmModel model, IEdmElement annotatable) { IEdmDirectValueAnnotationBinding[] annotations = new IEdmDirectValueAnnotationBinding[] { new EdmTypedDirectValueAnnotationBinding<ODataEntityPropertyMappingCollection>(annotatable, null), new EdmTypedDirectValueAnnotationBinding<ODataEntityPropertyMappingCache>(annotatable, null) }; model.SetAnnotationValues(annotations); }