public EdmDirectValueAnnotationsManager() { this.annotationsDictionaryLock = new object(); this.unsortedElements = VersioningList<IEdmElement>.Create(); this.unsortedElementsLock = new object(); this.annotationsDictionary = VersioningDictionary<IEdmElement, object>.Create(new Func<IEdmElement, IEdmElement, int>(this.CompareElements)); }
private int CompareElements(IEdmElement left, IEdmElement right) { if (left == right) { return(0); } /* Left and right are distinct. */ int leftHash = left.GetHashCode(); int rightHash = right.GetHashCode(); if (leftHash < rightHash) { return(-1); } if (leftHash > rightHash) { return(1); } /* Left and right are distinct and have identical hash codes. */ IEdmNamedElement leftNamed = left as IEdmNamedElement; IEdmNamedElement rightNamed = right as IEdmNamedElement; if (leftNamed == null) { if (rightNamed != null) { return(-1); } } else if (rightNamed == null) { return(1); } else { /* Left and right are both named. */ int nameComparison = string.Compare(leftNamed.Name, rightNamed.Name, StringComparison.Ordinal); if (nameComparison != 0) { return(nameComparison); } } /* Left and right are distinct, have identical hash codes, and have identical names. */ /* The first element to occur in the unsorted list is the greatest. */ while (true) { foreach (IEdmElement element in this.unsortedElements) { if (element == left) { return(1); } if (element == right) { return(-1); } } lock (this.unsortedElementsLock) { this.unsortedElements = this.unsortedElements.Add(left); } } }
private static void SetAnnotation(IEnumerable <IEdmDirectValueAnnotation> immutableAnnotations, ref object transientAnnotations, string namespaceName, string localName, object value) { bool needTombstone = false; if (immutableAnnotations != null) { if (immutableAnnotations.Any(existingAnnotation => existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName)) { needTombstone = true; } } if (value == null) { // "Removing" an immutable annotation leaves behind a transient annotation with a null value // as a tombstone to hide the immutable annotation. The normal logic below makes this happen. // Removing a transient annotation actually takes the annotation away. if (!needTombstone) { RemoveTransientAnnotation(ref transientAnnotations, namespaceName, localName); return; } } if (namespaceName == EdmConstants.DocumentationUri && value != null && !(value is IEdmDocumentation)) { throw new InvalidOperationException(Edm.Strings.Annotations_DocumentationPun(value.GetType().Name)); } IEdmDirectValueAnnotation newAnnotation = value != null ? new EdmDirectValueAnnotation(namespaceName, localName, value) : new EdmDirectValueAnnotation(namespaceName, localName); if (transientAnnotations == null) { transientAnnotations = newAnnotation; return; } IEdmDirectValueAnnotation singleAnnotation = transientAnnotations as IEdmDirectValueAnnotation; if (singleAnnotation != null) { if (singleAnnotation.NamespaceUri == namespaceName && singleAnnotation.Name == localName) { transientAnnotations = newAnnotation; } else { transientAnnotations = VersioningList <IEdmDirectValueAnnotation> .Create().Add(singleAnnotation).Add(newAnnotation); } return; } VersioningList <IEdmDirectValueAnnotation> annotationsList = (VersioningList <IEdmDirectValueAnnotation>)transientAnnotations; for (int index = 0; index < annotationsList.Count; index++) { IEdmDirectValueAnnotation existingAnnotation = annotationsList[index]; if (existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName) { annotationsList = annotationsList.RemoveAt(index); break; } } transientAnnotations = annotationsList.Add(newAnnotation); }
private int CompareElements(IEdmElement left, IEdmElement right) { if (left == right) { return 0; } /* Left and right are distinct. */ int leftHash = left.GetHashCode(); int rightHash = right.GetHashCode(); if (leftHash < rightHash) { return -1; } if (leftHash > rightHash) { return 1; } /* Left and right are distinct and have identical hash codes. */ IEdmNamedElement leftNamed = left as IEdmNamedElement; IEdmNamedElement rightNamed = right as IEdmNamedElement; if (leftNamed == null) { if (rightNamed != null) { return -1; } } else if (rightNamed == null) { return 1; } else { /* Left and right are both named. */ int nameComparison = string.Compare(leftNamed.Name, rightNamed.Name, StringComparison.Ordinal); if (nameComparison != 0) { return nameComparison; } } /* Left and right are distinct, have identical hash codes, and have identical names. */ /* The first element to occur in the unsorted list is the greatest. */ while (true) { foreach (IEdmElement element in this.unsortedElements) { if (element == left) { return 1; } if (element == right) { return -1; } } lock (this.unsortedElementsLock) { this.unsortedElements = this.unsortedElements.Add(left); } } }
public void IntegerVersioningLists() { VersioningList <int> list1 = VersioningList <int> .Create(); Assert.IsTrue(list1 is VersioningList <int> .EmptyVersioningList, "List type"); TestList(list1, 0); VersioningList <int> list2 = list1.Add(0); Assert.IsTrue(list2 is VersioningList <int> .ArrayVersioningList, "List type"); TestList(list2, 1); VersioningList <int> list3 = list1.Add(0); Assert.IsTrue(list3 is VersioningList <int> .ArrayVersioningList, "List type"); TestList(list3, 1); VersioningList <int> list4 = list2.Add(10); Assert.IsTrue(list4 is VersioningList <int> .ArrayVersioningList, "List type"); TestList(list4, 2); VersioningList <int> list5 = list4.Add(20); Assert.IsTrue(list5 is VersioningList <int> .ArrayVersioningList, "List type"); TestList(list5, 3); VersioningList <int> list6 = list5.Add(30); Assert.IsTrue(list6 is VersioningList <int> .ArrayVersioningList, "List type"); TestList(list6, 4); VersioningList <int> list7 = list6.Add(40); Assert.IsTrue(list7 is VersioningList <int> .ArrayVersioningList, "List type"); TestList(list7, 5); VersioningList <int> list8 = list7.Add(50); Assert.IsTrue(list8 is VersioningList <int> .ArrayVersioningList, "List type"); TestList(list8, 6); VersioningList <int> list9 = list8.Add(60); Assert.IsTrue(list9 is VersioningList <int> .ArrayVersioningList, "List type"); TestList(list9, 7); TestList(list8, 6); TestList(list7, 5); TestList(list6, 4); TestList(list5, 3); TestList(list4, 2); TestList(list3, 1); TestList(list2, 1); TestList(list1, 0); for (int index = 0; index < list9.Count; index++) { VersioningList <int> list00 = list9.RemoveAt(index); TestList(list00, 7, index); } TestList(list9, 7); VersioningList <int> shrinker = list9; int expectedCount = list9.Count; for (int index = 0; index < list9.Count; index++) { Assert.AreEqual(index * 10, shrinker[0], "Shrinking value"); expectedCount--; shrinker = shrinker.RemoveAt(0); Assert.AreEqual(expectedCount, shrinker.Count, "Shrinking count"); } shrinker = list9; expectedCount = list9.Count; for (int index = list9.Count - 1; index >= 0; index--) { Assert.AreEqual(index * 10, shrinker[index], "Shrinking value"); expectedCount--; shrinker = shrinker.RemoveAt(index); Assert.AreEqual(expectedCount, shrinker.Count, "Shrinking count"); } TestList(list9, 7); }
private int CompareElements(IEdmElement left, IEdmElement right) { int num; if (left != right) { int hashCode = left.GetHashCode(); int hashCode1 = right.GetHashCode(); if (hashCode >= hashCode1) { if (hashCode <= hashCode1) { IEdmNamedElement edmNamedElement = left as IEdmNamedElement; IEdmNamedElement edmNamedElement1 = right as IEdmNamedElement; if (edmNamedElement != null) { if (edmNamedElement1 != null) { int num1 = string.Compare(edmNamedElement.Name, edmNamedElement1.Name, StringComparison.Ordinal); if (num1 != 0) { return num1; } } else { return 1; } } else { if (edmNamedElement1 != null) { return -1; } } while (true) { foreach (IEdmElement unsortedElement in this.unsortedElements) { if (unsortedElement != left) { if (unsortedElement != right) { continue; } num = -1; return num; } else { num = 1; return num; } } lock (this.unsortedElementsLock) { this.unsortedElements = this.unsortedElements.Add(left); } } return num; } else { return 1; } } else { return -1; } } else { return 0; } }
private void TestList(VersioningList<int> list, int expectedCount, int skipIndex) { int count = 0; int skipped = 0; foreach (int i in list) { if (count == skipIndex) { skipped++; } Assert.AreEqual((count + skipped) * 10, i, "Element value"); Assert.AreEqual((count + skipped) * 10, list[count], "Element value"); count++; } if (skipIndex == list.Count) { skipped++; } Assert.AreEqual(expectedCount, count + skipped, "List count"); }
private void TestList(VersioningList<int> list, int expectedCount) { int count = 0; foreach (int i in list) { Assert.AreEqual(count * 10, i, "Element value"); Assert.AreEqual(count * 10, list[count], "Element value"); count++; } Assert.AreEqual(expectedCount, count, "List count"); }
private static bool IsDead(string namespaceName, string localName, VersioningList <IEdmDirectValueAnnotation> transientAnnotations) { return(FindTransientAnnotation(transientAnnotations, namespaceName, localName) != null); }
private static void SetAnnotation(IEnumerable <IEdmDirectValueAnnotation> immutableAnnotations, ref VersioningList <IEdmDirectValueAnnotation> transientAnnotations, string namespaceName, string localName, object value) { bool needTombstone = false; if (immutableAnnotations != null) { foreach (IEdmDirectValueAnnotation existingAnnotation in immutableAnnotations) { if (existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName) { needTombstone = true; break; } } } if (value == null) { // "Removing" an immutable annotation leaves behind a transient annotation with a null value // as a tombstone to hide the immutable annotation. The normal logic below makes this happen. // Removing a transient annotation actually takes the annotation away. if (!needTombstone) { RemoveTransientAnnotation(ref transientAnnotations, namespaceName, localName); return; } } IEdmDirectValueAnnotation newAnnotation = value != null ? new EdmDirectValueAnnotation(namespaceName, localName, value) : new EdmDirectValueAnnotation(namespaceName, localName); if (transientAnnotations == null) { transientAnnotations = VersioningList <IEdmDirectValueAnnotation> .Create().Add(newAnnotation); return; } for (int index = 0; index < transientAnnotations.Count; index++) { IEdmDirectValueAnnotation existingAnnotation = transientAnnotations[index]; if (existingAnnotation.NamespaceUri == namespaceName && existingAnnotation.Name == localName) { transientAnnotations = transientAnnotations.RemoveAt(index); break; } } transientAnnotations = transientAnnotations.Add(newAnnotation); }
private static void SetAnnotation(IEnumerable <IEdmDirectValueAnnotation> immutableAnnotations, ref object transientAnnotations, string namespaceName, string localName, object value) { IEdmDirectValueAnnotation edmDirectValueAnnotation; Func <IEdmDirectValueAnnotation, bool> func = null; bool flag = false; if (immutableAnnotations != null) { IEnumerable <IEdmDirectValueAnnotation> edmDirectValueAnnotations = immutableAnnotations; if (func == null) { func = (IEdmDirectValueAnnotation existingAnnotation) => { if (existingAnnotation.NamespaceUri != namespaceName) { return(false); } else { return(existingAnnotation.Name == localName); } } ; } if (edmDirectValueAnnotations.Any <IEdmDirectValueAnnotation>(func)) { flag = true; } } if (value != null || flag) { if (!(namespaceName == "http://schemas.microsoft.com/ado/2011/04/edm/documentation") || value == null || value as IEdmDocumentation != null) { if (value != null) { edmDirectValueAnnotation = new EdmDirectValueAnnotation(namespaceName, localName, value); } else { edmDirectValueAnnotation = new EdmDirectValueAnnotation(namespaceName, localName); } IEdmDirectValueAnnotation edmDirectValueAnnotation1 = edmDirectValueAnnotation; if (transientAnnotations != null) { IEdmDirectValueAnnotation edmDirectValueAnnotation2 = transientAnnotations as IEdmDirectValueAnnotation; if (edmDirectValueAnnotation2 == null) { VersioningList <IEdmDirectValueAnnotation> edmDirectValueAnnotations1 = (VersioningList <IEdmDirectValueAnnotation>)transientAnnotations; int num = 0; while (num < edmDirectValueAnnotations1.Count) { IEdmDirectValueAnnotation item = edmDirectValueAnnotations1[num]; if (!(item.NamespaceUri == namespaceName) || !(item.Name == localName)) { num++; } else { edmDirectValueAnnotations1 = edmDirectValueAnnotations1.RemoveAt(num); break; } } transientAnnotations = edmDirectValueAnnotations1.Add(edmDirectValueAnnotation1); return; } else { if (!(edmDirectValueAnnotation2.NamespaceUri == namespaceName) || !(edmDirectValueAnnotation2.Name == localName)) { transientAnnotations = VersioningList <IEdmDirectValueAnnotation> .Create().Add(edmDirectValueAnnotation2).Add(edmDirectValueAnnotation1); return; } else { transientAnnotations = edmDirectValueAnnotation1; return; } } } else { transientAnnotations = edmDirectValueAnnotation1; return; } } else { throw new InvalidOperationException(Strings.Annotations_DocumentationPun(value.GetType().Name)); } } else { EdmDirectValueAnnotationsManager.RemoveTransientAnnotation(ref transientAnnotations, namespaceName, localName); return; } }
private int CompareElements(IEdmElement left, IEdmElement right) { int num; if (left != right) { int hashCode = left.GetHashCode(); int hashCode1 = right.GetHashCode(); if (hashCode >= hashCode1) { if (hashCode <= hashCode1) { IEdmNamedElement edmNamedElement = left as IEdmNamedElement; IEdmNamedElement edmNamedElement1 = right as IEdmNamedElement; if (edmNamedElement != null) { if (edmNamedElement1 != null) { int num1 = string.Compare(edmNamedElement.Name, edmNamedElement1.Name, StringComparison.Ordinal); if (num1 != 0) { return(num1); } } else { return(1); } } else { if (edmNamedElement1 != null) { return(-1); } } while (true) { foreach (IEdmElement unsortedElement in this.unsortedElements) { if (unsortedElement != left) { if (unsortedElement != right) { continue; } num = -1; return(num); } else { num = 1; return(num); } } lock (this.unsortedElementsLock) { this.unsortedElements = this.unsortedElements.Add(left); } } return(num); } else { return(1); } } else { return(-1); } } else { return(0); } }