Esempio n. 1
0
		/// <summary>
		/// Exposes the ContentDirectory's Search action (for returning sorted results) as a method of a container. 
		/// </summary>
		/// <param name="expression">IMediaComparer object that will indicate if a media object is a match</param>
		/// <param name="sorter">IMediaSorter object that determines the sorting criteria for the results</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="totalMatches">total number of possible matches, sometimes has uint.MaxValue if the total possible is unknown</param>
		/// <returns></returns>
		public virtual IList SearchSorted(IMediaComparer expression, IMediaSorter sorter, UInt32 startingIndex, UInt32 requestedCount, out UInt32 totalMatches)
		{
			SortedList sorted = null;
			ArrayList results = null;
			if (this.m_Listing != null)
			{
				sorted = new SortedList(sorter, this.m_Listing.Count);
				this.SearchCollection(expression, ref sorted);

				int size = Convert.ToInt32(requestedCount);

				if (sorted.Count < size) size = sorted.Count;

				results = new ArrayList(size);

				int i=0;
				foreach (IUPnPMedia entry in sorted.Values)
				{
					if (i >= startingIndex)
					{
						results.Add(entry);
					}

					i++;

					if ((results.Count >= requestedCount) && (requestedCount != 0))
					{
						break;
					}
				}

				totalMatches = Convert.ToUInt32(sorted.Count);
			}
			else
			{
				results = new ArrayList(0);
				totalMatches = 0;
			}

			return results;
		}
Esempio n. 2
0
		/// <summary>
		/// Exposes the ContentDirectory's Browse action (for returning sorted results) as a method of a container. 
		/// </summary>
		/// <param name="startingIndex">starting index for the browse results, 0-based index</param>
		/// <param name="requestedCount">maximum number of children requested</param>
		/// <param name="sorter">IMediaSorter object that determines the sorting criteria for the results</param>
		/// <param name="totalMatches">total number of possible matches</param>
		/// <returns></returns>
		public virtual IList BrowseSorted(UInt32 startingIndex, UInt32 requestedCount, IMediaSorter sorter, out UInt32 totalMatches)
		{
			this.m_LockListing.AcquireReaderLock(-1);
			SortedList sorted = null;
			IList results = null;
			if (this.m_Listing != null)
			{

				sorted = new SortedList(sorter, this.m_Listing.Count);

				//NKIDD-DEBUG : BEGIN - Please preserve as it's useful for finding bugs in the sorting logic
//				MediaContainer tempContainer = new MediaContainer();
//				tempContainer.ID = this.ID;
//				foreach (IUPnPMedia child in this.m_Listing)
//				{
//					IUPnPMedia copy = child.MetadataCopy();
//					copy.ID = child.ID;
//					tempContainer.AddObject(copy, true);
//				}
//				IList other = tempContainer.CompleteList;
//				SortedList sorted2 = new SortedList((IMediaSorter)sorter.Clone(), this.m_Listing.Count);
				//NKIDD-DEBUG : END

				for (int i=0; i < this.m_Listing.Count; i++)
				{
					IUPnPMedia child = (IUPnPMedia) this.m_Listing[i];

					//NKIDD-DEBUG : BEGIN - Please preserve as it's useful for finding bugs in the sorting logic
//					IUPnPMedia child2 = (IUPnPMedia) other[i];
					//NKIDD-DEBUG : END

					try
					{
						//NKIDD-DEBUG : BEGIN - Please preserve as it's useful for finding bugs in the sorting logic
//						IDictionaryEnumerator ide1 = sorted.GetEnumerator();
//						IDictionaryEnumerator ide2 = sorted2.GetEnumerator();
//						for (int j=0; j < sorted2.Count; j++)
//						{
//							ide1.MoveNext();
//							ide2.MoveNext();
//							IUPnPMedia s1 = (IUPnPMedia) ide1.Value;
//							IUPnPMedia s2 = (IUPnPMedia) ide2.Value;
//
//							int cmp1 = sorter.Compare(child, s1);
//							int cmp2 = sorter.Compare(child2, s2);
//
//							if (cmp1 != cmp2)
//							{
//								sorter.Compare(child, s1);
//								sorter.Compare(child2, s2);
//							}
//						}
						//NKIDD-DEBUG : END

						sorted.Add(child, child);

						//NKIDD-DEBUG : BEGIN - Please preserve as it's useful for finding bugs in the sorting logic
//						sorted2.Add(child2, child2);
						//NKIDD-DEBUG : END
					}
					catch (Exception ie)
					{
						throw new ApplicationException("MediaContainer.BrowseSorted() had error adding child to sorted list.", ie);
					}
				}

				results = this.BrowseCollection(startingIndex, requestedCount, sorted.Values, out totalMatches);
			}
			else
			{
				results = new object[0];
				totalMatches = 0;
			}
			this.m_LockListing.ReleaseReaderLock();

			return results;
		}