Beispiel #1
0
		/// <summary>
		/// Implements the core logic for a sorted Search.
		/// </summary>
		/// <param name="exoression">IMediaComparer object that will indicate if a media object is a match</param>
		/// <param name="sorted">sorted list of IUPnPMedia objects that make up result set</param>
		private void SearchCollection(IMediaComparer expression, ref SortedList sorted)
		{
			this.m_LockListing.AcquireReaderLock(-1);
			ArrayList containers = null;
			if (this.m_Listing != null)
			{
				containers = new ArrayList(this.m_Listing.Count);
				foreach (IUPnPMedia entry in this.m_Listing)
				{
					// If the item is a match, add it to the list of results.
					// 
					if (expression.IsMatch(entry))
					{
						sorted.Add(entry,entry);
					}
					if (entry.IsContainer)
					{
						containers.Add(entry);
					}
				}
			}
			this.m_LockListing.ReleaseReaderLock();

			if (containers != null)
			{
				foreach (MediaContainer container in containers)
				{
					container.SearchCollection(expression, ref sorted);
				}
			}
		}
Beispiel #2
0
		/// <summary>
		/// Implements the core logic for packaging up the results for a Search.
		/// </summary>
		/// <param name="expression">IMediaComparer object that will indicate if a media object is a match</param>
		/// <param name="startingIndex">starting index for the search results, 0-based index</param>
		/// <param name="requestedCount">maximum number of children requested</param>
		/// <param name="searchedEntireSubtree">True, if the entire subtree was searched.</param>
		/// <param name="results">ArrayList of the desired results.</param>
		private void SearchCollection(IMediaComparer expression, UInt32 startingIndex, UInt32 requestedCount, out bool searchedEntireSubtree, ref ArrayList results)
		{
			searchedEntireSubtree = true;
			if (this.m_Listing != null)
			{
				ArrayList containers = new ArrayList(this.m_Listing.Count);
				this.m_LockListing.AcquireReaderLock(-1);
				foreach (IUPnPMedia entry in this.m_Listing)
				{
					// If the item is a match, add it to the list of results.
					// 
					if (expression.IsMatch(entry))
					{
						results.Add(entry);
					}

					// If we've reached the max number of results, then indicate
					// that we will not end up searching the entire subtree.
					// 
					if ((results.Count >= requestedCount) && (requestedCount != 0))
					{
						searchedEntireSubtree = false;
						break;
					}

					if (entry.IsContainer)
					{
						containers.Add(entry);
					}
				}

				this.m_LockListing.ReleaseReaderLock();

				// If we're still intent on searching the entire subtree, then
				// recurse through each sub-container.
				// 
				if (searchedEntireSubtree)
				{
					foreach (MediaContainer container in containers)
					{
						// After recursing each subtree, check to see if we stopped
						// searching the entire subtee. If so, then do not continue.
						if (searchedEntireSubtree)
						{
							container.SearchCollection(expression, startingIndex, requestedCount, out searchedEntireSubtree, ref results);
						}
						else
						{
							break;
						}
					}
				}
			}
		}