/// <summary> /// Determines the index of the specific item in the list using the /// unique thing identifier. /// </summary> /// /// <param name="key"> /// The unique thing key used to locate the /// item in the list. /// </param> /// /// <returns> /// The index of item, if found in the list; otherwise, -1. /// </returns> /// public int IndexOf(ThingKey key) { lock (_abstractResults) { int result = -1; for (int index = 0; index < _abstractResults.Count; ++index) { ThingKey abstractThingKey; IThing thing = _abstractResults[index] as IThing; if (thing != null) { abstractThingKey = thing.Key; } else { abstractThingKey = (ThingKey)_abstractResults[index]; } if (abstractThingKey.Equals(key)) { result = index; break; } } return(result); } }
internal void ParseXml(XPathNavigator relationshipNav) { XPathNavigator thingIdNav = relationshipNav.SelectSingleNode("thing-id"); if (thingIdNav != null) { Guid itemId = new Guid(thingIdNav.Value); XPathNavigator versionStampNav = relationshipNav.SelectSingleNode("version-stamp"); if (versionStampNav != null) { Guid versionStamp = new Guid(versionStampNav.Value); ItemKey = new ThingKey(itemId, versionStamp); } else { ItemKey = new ThingKey(itemId); } } else { XPathNavigator clientIdNav = relationshipNav.SelectSingleNode("client-thing-id"); if (clientIdNav != null) { ClientId = clientIdNav.Value; } } RelationshipType = XPathHelper.GetOptNavValue(relationshipNav, "relationship-type"); }
/// <summary> /// Gets a value indicating whether the collection contains a /// <see cref="IThing"/> with the specified /// <see cref="ThingKey"/>. /// </summary> /// /// <param name="itemKey"> /// The unique <see cref="ThingKey"/> used to locate the /// <see cref="ThingBase"/>item in the collection. The key /// contains a unique identifier for the <see cref="ThingBase"/> /// and a unique version stamp identifying the version of /// the <see cref="IThing"/>. /// </param> /// /// <returns> /// <b>true</b> if a matching object is found; otherwise, <b>false</b>. /// </returns> /// public bool Contains(ThingKey itemKey) { lock (_abstractResults) { bool result = false; for (int index = 0; index < _abstractResults.Count; ++index) { ThingKey abstractThingKey; IThing thing = _abstractResults[index] as IThing; if (thing != null) { abstractThingKey = thing.Key; } else { abstractThingKey = (ThingKey)_abstractResults[index]; } if (abstractThingKey.Equals(itemKey)) { result = true; break; } } return(result); } }
/// <summary> /// Constructs a <see cref="ThingRelationship" /> instance for a relationship /// to the item with the specified ID. /// </summary> /// /// <param name="itemId"> /// The unique identifier of the thing to related to. /// </param> /// /// <exception cref="ArgumentException"> /// If <paramref name="itemId"/> is <see cref="System.Guid.Empty"/>. /// </exception> /// public ThingRelationship(Guid itemId) { if (itemId == Guid.Empty) { throw new ArgumentException(Resources.RelationshipItemIDNotSpecified, nameof(itemId)); } ItemKey = new ThingKey(itemId); }
/// <summary> /// Compares one <see cref="ThingKey"/> to another. /// </summary> /// /// <param name="obj"> /// The <see cref="ThingKey"/> to compare against this. /// </param> /// /// <returns> /// <b>true</b> if both the thing keys have /// the same ID and version stamp; otherwise, <b>false</b>. /// </returns> /// public override bool Equals(object obj) { bool result = false; ThingKey rVal = obj as ThingKey; if (rVal != null) { result = (_versionStamp == rVal.VersionStamp) && (_thingId == rVal.Id); } return(result); }
/// <summary> /// Constructs a <see cref="ThingRelationship" /> instance for a relationship /// to the item with the specified key. /// </summary> /// /// <param name="itemKey"> /// The unique key of the thing to related to, including the item ID and /// optionally the item version stamp. /// </param> /// /// <exception cref="ArgumentNullException"> /// If <paramref name="itemKey"/> is <b>null</b>. /// </exception> /// public ThingRelationship(ThingKey itemKey) { Validator.ThrowIfArgumentNull(itemKey, nameof(itemKey), Resources.RelationshipItemKeyNotSpecified); ItemKey = itemKey; }
/// <summary> /// Constructs a <see cref="ThingRelationship" /> instance for a relationship /// to the item with the specified key and relationship type. /// </summary> /// /// <param name="itemKey"> /// The unique key of the thing to related to, including the item ID and /// optionally the item version stamp. /// </param> /// /// <param name="relationshipType"> /// The application defined type for the relationship. This is usually a descriptive tagging /// for the relationship. For example, a Annotation item may have a /// "annotation" relationship with a Problem item. /// </param> /// /// <exception cref="ArgumentNullException"> /// If <paramref name="itemKey"/> is <b>null</b>. /// </exception> /// public ThingRelationship(ThingKey itemKey, string relationshipType) : this(itemKey) { RelationshipType = relationshipType; }
internal void AddResult(ThingKey thingKey) { _abstractResults.Add(thingKey); }
private async Task GetPartialThingsAsync(int index) { // We must have a partial thing at this index. Get // the next MaxResultsPerRequest number of partial // items. List <ThingKey> partialThings = new List <ThingKey>(); for ( int partialThingIndex = index; (partialThings.Count < MaxResultsPerRequest || MaxResultsPerRequest == int.MinValue) && partialThingIndex < _abstractResults.Count; ++partialThingIndex) { var key = _abstractResults[partialThingIndex] as ThingKey; if (key != null) { partialThings.Add( key); } else { // We break if we hit something that is // not a Guid (like ThingBase). This means // that we will retrieve fewer things than // MaxResultsPerRequest but it will be simpler // to replace the partial things with the real // things. break; } } ThingCollection things = await GetPartialThingsAsync(partialThings).ConfigureAwait(false); bool atEndOfPartialThings = false; int newThingIndex = index; foreach (IThing thing in things) { // We need to start at the current index but look until // we find a matching thing ID. It is possible that the // thing may have been removed while holding on to the // partial thing ID from the original query. for (; newThingIndex < _abstractResults.Count; ++newThingIndex) { ThingKey abstractResultKey = _abstractResults[newThingIndex] as ThingKey; if (abstractResultKey != null) { if (abstractResultKey.Equals(thing.Key)) { // replace the partial thing with the real // thing _abstractResults[newThingIndex++] = thing; break; } } else { atEndOfPartialThings = true; break; } } if (atEndOfPartialThings) { break; } } }