/// <summary> /// Allows a programmer to query the MediaServer through the Browse action. /// </summary> /// <param name="ObjectID"></param> /// <param name="BrowseFlag"></param> /// <param name="Filter"></param> /// <param name="StartingIndex"></param> /// <param name="RequestedCount"></param> /// <param name="SortCriteria"></param> /// <param name="_Tag"></param> /// <param name="callback">Returns output args and error info.</param> public void RequestBrowse(System.String ObjectID, OpenSource.UPnP.AV.CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag BrowseFlag, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, object _Tag, Delegate_OnBrowseDone2 callback) { _RequestState state = new _RequestState(); state.Callback_Browse2 = callback; state.Tag = _Tag; this.ContentDirectory.Browse(ObjectID, BrowseFlag, Filter, StartingIndex, RequestedCount, SortCriteria, state, new OpenSource.UPnP.AV.CpContentDirectory.Delegate_OnResult_Browse(OnBrowseDone)); }
/// <summary> /// Processes the results of Browse requests. /// </summary> /// <param name="sender"></param> /// <param name="ObjectID"></param> /// <param name="BrowseFlag"></param> /// <param name="Filter"></param> /// <param name="StartingIndex"></param> /// <param name="RequestedCount"></param> /// <param name="SortCriteria"></param> /// <param name="Result"></param> /// <param name="NumberReturned"></param> /// <param name="TotalMatches"></param> /// <param name="UpdateID"></param> /// <param name="e"></param> /// <param name="_Tag"></param> private void OnBrowseDone(CpContentDirectory sender, System.String ObjectID, OpenSource.UPnP.AV.CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag BrowseFlag, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, System.String Result, System.UInt32 NumberReturned, System.UInt32 TotalMatches, System.UInt32 UpdateID, UPnPInvokeException e, object _Tag) { _RequestState state = (_RequestState)_Tag; if (e != null) { if (state.Callback_Browse1 != null) { state.Callback_Browse1(this, ObjectID, BrowseFlag, Filter, StartingIndex, RequestedCount, SortCriteria, e, null, state.Tag, null, NumberReturned, TotalMatches, UpdateID); } else if (state.Callback_Browse2 != null) { state.Callback_Browse2(this, e, null, state.Tag, null, NumberReturned, TotalMatches, UpdateID); } } else { ArrayList al = null; try { al = CpMediaBuilder.BuildMediaBranches(Result); } catch (Exception parseError) { if (state.Callback_Browse1 != null) { state.Callback_Browse1(this, ObjectID, BrowseFlag, Filter, StartingIndex, RequestedCount, SortCriteria, e, parseError, state.Tag, null, NumberReturned, TotalMatches, UpdateID); } else if (state.Callback_Browse2 != null) { state.Callback_Browse2(this, e, parseError, state.Tag, null, NumberReturned, TotalMatches, UpdateID); } al = null; } if (al != null) { if (state.Callback_Browse1 != null) { state.Callback_Browse1(this, ObjectID, BrowseFlag, Filter, StartingIndex, RequestedCount, SortCriteria, e, null, state.Tag, (IUPnPMedia[])al.ToArray(typeof(IUPnPMedia)), NumberReturned, TotalMatches, UpdateID); } else if (state.Callback_Browse2 != null) { state.Callback_Browse2(this, e, null, state.Tag, (IUPnPMedia[])al.ToArray(typeof(IUPnPMedia)), NumberReturned, TotalMatches, UpdateID); } } } }
private void Sink_OnBrowse(CpMediaServer server, System.String ObjectID, OpenSource.UPnP.AV.CpContentDirectory.Enum_A_ARG_TYPE_BrowseFlag BrowseFlag, System.String Filter, System.UInt32 StartingIndex, System.UInt32 RequestedCount, System.String SortCriteria, UPnPInvokeException e, Exception parseError, object _Tag, IUPnPMedia[] Result, System.UInt32 NumberReturned, System.UInt32 TotalMatches, System.UInt32 UpdateID) { IMediaContainer[] tagC, ec; bool ok = true; bool nomore = false; // ensure we're processing results for the current context lock (this) { tagC = (IMediaContainer[])_Tag; ec = this.CurrentContext.EntireContext; for (int i = 0; i < ec.Length; i++) { if (ec[i] != tagC[i]) { ok = false; break; } } } if (ok) { // results are for current context, merge metadata results // with existing child list if ((e == null) && (parseError == null)) { lock (this) { // add to our media object this.m_Children.AddRange(Result); this.CurrentContext.ContainerContext.AddObjects(Result, true); if ( ((this.m_Children.Count < TotalMatches) && (NumberReturned > 0)) || ((TotalMatches == 0) && (NumberReturned > 0)) ) { // more items to come this.m_CurrentIndex = NumberReturned; } else { // no more items, prune children from m_Container ArrayList remove = new ArrayList(); foreach (IUPnPMedia m1 in this.CurrentContext.ContainerContext.CompleteList) { bool found = false; foreach (IUPnPMedia m2 in this.m_Children) { if (m1 == m2) { found = true; break; } } if (found == false) { remove.Add(m1); } } this.CurrentContext.ContainerContext.RemoveObjects(remove); nomore = true; } } if (this.OnIncrementalUpdate != null) { this.OnIncrementalUpdate(this, Result); } if (nomore) { if (this.OnRefreshComplete != null) { IUPnPMedia[] list = (IUPnPMedia[])this.m_Children.ToArray(typeof(IUPnPMedia)); this.OnRefreshComplete(this, list); } } } else { // error occurred with the results... // how should we report this? } } }