public bool IsPlayingSender(ModelSender aSender) { bool playingSender = false; if (this.Channel != null && aSender != null) { if (this.TransportState == ModelSourceReceiver.ETransportState.ePlaying || this.TransportState == ModelSourceReceiver.ETransportState.eBuffering || this.TransportState == ModelSourceReceiver.ETransportState.eWaiting) { if (aSender.Metadata.Count > 0 && this.Channel.DidlLite.Count > 0) { upnpObject sender = aSender.Metadata[0]; upnpObject receiver = this.Channel.DidlLite[0]; if (sender.Res.ToString() == receiver.Res.ToString() && DidlLiteAdapter.Title(sender) == DidlLiteAdapter.Title(receiver)) { playingSender = true; } } } } return(playingSender); }
private void EnsureLoaded() { lock (iLock) { if (!iIsLoaded) { if (iIsHeaderItem) { iDisplayField1 = DidlLiteAdapter.Album(iItem); iDisplayField2 = DidlLiteAdapter.AlbumArtist(iItem); if (iDisplayField2 == string.Empty) { iDisplayField2 = DidlLiteAdapter.Artist(iItem); } } else { ItemInfo info = new ItemInfo(iItem); iDisplayField1 = info.DisplayItem(0).HasValue ? info.DisplayItem(0).Value.Value : null; iDisplayField2 = info.DisplayItem(1).HasValue ? info.DisplayItem(1).Value.Value : null; iDisplayField3 = info.DisplayItem(2).HasValue ? info.DisplayItem(2).Value.Value : null; iTechnicalInfo = DidlLiteAdapter.Duration(iItem); if (iTechnicalInfo == string.Empty) { iTechnicalInfo = DidlLiteAdapter.Bitrate(iItem); } } iItem = null; iIsLoaded = true; } } }
private void EventUpdated(object sender, EventArgsArtwork e) { iMutex.WaitOne(); for (int i = iStartIndex; i < iStartIndex + 2 && i < iPlaylist.Count; ++i) { upnpObject upnpObject = iPlaylist[i].DidlLite[0]; Uri uri = DidlLiteAdapter.ArtworkUri(upnpObject); if (uri.AbsoluteUri == e.Artwork.Uri.AbsoluteUri) { Invalidate(); } } for (int i = iStartIndex; i < iStartIndex + 2 && i < iPresets.Count; ++i) { upnpObject upnpObject = iPresets[i].DidlLite[0]; Uri uri = DidlLiteAdapter.ArtworkUri(upnpObject); if (uri.AbsoluteUri == e.Artwork.Uri.AbsoluteUri) { Invalidate(); } } iMutex.ReleaseMutex(); }
/// <summary> /// /// </summary> /// <param name="aObject"> /// A <see cref="Upnp.upnpObject"/> /// </param> public void SetItem(Upnp.upnpObject aObject) { if (iConnection != null) { iConnection.Cancel(); iConnection = null; } if (aObject != null) { Uri uri = DidlLiteAdapter.ArtworkUri(aObject); if (uri != null) { NSUrl url = new NSUrl(iUriConverter.Convert(uri.AbsoluteUri)); NSUrlRequest request = new NSUrlRequest(url); iConnection = new NSUrlConnection(request, new Delegate(this), true); } else { SetImage(KinskyTouch.Properties.ResourceManager.Loading); } } else { SetImage(KinskyTouch.Properties.ResourceManager.Loading); } }
/// <summary> /// /// </summary> /// <param name="aObject"> /// A <see cref="Upnp.upnpObject"/> /// </param> public void SetMetatext(Upnp.upnpObject aObject) { if (aObject != null) { iMetatext = DidlLiteAdapter.Title(aObject); iMetatext2 = string.Empty; } }
public Icon <ImageType> GetIcon(upnpObject aUpnpObject) { if (aUpnpObject != null) { Uri uri = DidlLiteAdapter.ArtworkUri(aUpnpObject); if (uri != null) { return(new Icon <ImageType>(uri)); } if (aUpnpObject is container) { if (aUpnpObject is musicAlbum) { return(IconAlbum); } else if (aUpnpObject is person) { return(IconArtist); } else if (aUpnpObject is playlistContainer) { return(IconPlaylistContainer); } else if (aUpnpObject.ParentId == MediaProviderLibrary.kLibraryId || aUpnpObject.Id == MediaProviderLibrary.kLibraryId) { return(IconLibrary); } else { return(IconDirectory); } } if (aUpnpObject is item) { if (aUpnpObject is audioBroadcast) { return(IconRadio); } else if (aUpnpObject is videoItem) { return(IconVideo); } else if (aUpnpObject is playlistItem) { return(IconPlaylistItem); } else if (aUpnpObject.Title == "Access denied") { return(IconError); } else { return(IconTrack); } } } return(IconNoArtwork); }
public void SetMetatext(upnpObject aObject) { iMutex.WaitOne(); if (aObject != null) { iAlbum = DidlLiteAdapter.Title(aObject); iArtist = string.Empty; } iMutex.ReleaseMutex(); }
/// <summary> /// /// </summary> /// <param name="aObject"> /// A <see cref="Upnp.upnpObject"/> /// </param> public void SetItem(Upnp.upnpObject aObject) { if (aObject != null) { iTitle = DidlLiteAdapter.Title(aObject); iMetatext = DidlLiteAdapter.Album(aObject); iMetatext2 = DidlLiteAdapter.Artist(aObject); } else { iTitle = string.Empty; iMetatext = string.Empty; iMetatext2 = string.Empty; } }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { try { if (value != null && value is upnpObject) { Type t = typeof(DidlLiteAdapter); MemberInfo[] mi = t.FindMembers(MemberTypes.Method, BindingFlags.Public | BindingFlags.Static, (m, c) => { return(m.Name.Equals(c)); }, parameter); if (mi.Length > 0) { object invokeResult = (mi[0] as MethodInfo).Invoke(null, new Object[] { value }); string result = string.Empty; if (invokeResult != null) { result = invokeResult.ToString(); } if (parameter.ToString() == "Artist" && !(value is Upnp.musicTrack || value is Upnp.musicAlbum)) { result = string.Empty; } if (parameter.ToString() == "Count" && result == "0") { result = string.Empty; } if (parameter.ToString() == "OriginalTrackNumber" && result != string.Empty) { result = result + ". "; } if (parameter.ToString() == "AlbumArtist" && result == string.Empty) { result = DidlLiteAdapter.Artist(value as upnpObject); } return(result); } } } catch (Exception ex) { UserLog.WriteLine("Error caught in DidlLiteConverter: " + ex); } return(null); }
public Bookmark(Location aLocation) : this() { BreadcrumbTrail = aLocation.BreadcrumbTrail; Title = DidlLiteAdapter.Title(aLocation.Current.Metadata); Class = aLocation.Current.Metadata.Class; Uri uri = DidlLiteAdapter.ArtworkUri(aLocation.Current.Metadata); if (uri != null) { Image = uri.OriginalString; } else { Image = string.Empty; } }
public void SetItem(upnpObject aObject) { iMutex.WaitOne(); if (aObject != null) { iTitle = DidlLiteAdapter.Title(aObject); iArtist = DidlLiteAdapter.Artist(aObject); iAlbum = DidlLiteAdapter.Album(aObject); iArtworkUri = DidlLiteAdapter.ArtworkUri(aObject); if (iArtworkUri == null) { SetNoArtwork(); } else { DownloadArtwork(iArtworkUri); } } else { iTitle = string.Empty; iArtist = string.Empty; iAlbum = string.Empty; iCodec = string.Empty; iBitDepth = 0; iSampleRate = 0; iBitrate = 0; iLossless = false; iArtworkUri = null; SetNoArtwork(); } iMutex.ReleaseMutex(); }
private void PaintPresets(PaintEventArgs e) { e.Graphics.Clip = new Region(ClientRectangle); iMutex.WaitOne(); e.Graphics.FillRectangle(Brushes.Black, ClientRectangle); int height = (int)(ClientSize.Height * 0.5f); int width = height; int offsetY = (int)((ClientSize.Height - (height * 1.5f)) * 0.5f); for (int i = iStartIndex; i < iStartIndex + 2 && i < iPresets.Count; ++i) { int offsetX = ClientRectangle.X + -iOffset + (i * kItemWidth); upnpObject o = iPresets[i].DidlLite[0]; PaintItem(e.Graphics, width, height, offsetX, offsetY, DidlLiteAdapter.ArtworkUri(o), iTitle, iAlbum, iArtist, DidlLiteAdapter.Genre(o), i == iPresetIndex); } iMutex.ReleaseMutex(); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { upnpObject obj = null; if (value is upnpObject) { obj = value as upnpObject; } else if (value is MrItem) { obj = (value as MrItem).DidlLite[0]; } if (obj != null) { string artist = DidlLiteAdapter.Artist(obj); string albumArtist = DidlLiteAdapter.AlbumArtist(obj); if (albumArtist != string.Empty && artist != albumArtist) { return(Visibility.Visible); } } return(Visibility.Collapsed); }
private Uri GetArtwork(IContainer aContainer, uint aLevel) { try { uint count = aContainer.Open(); if (count > 0) { int index = iRandom.Next((int)count); DidlLite didl = aContainer.Items((uint)index, 1); foreach (upnpObject o in didl) { if (o is item || o is musicAlbum) { Uri uri = DidlLiteAdapter.ArtworkUri(o); if (uri != null) { Console.WriteLine("aLevel=" + aLevel + " uri=" + uri.AbsoluteUri); return(uri); } } if (o is container) { IContainer c = aContainer.ChildContainer(o as container); return(GetArtwork(c, ++aLevel)); } return(null); } } } catch (Exception) { } return(null); }
private void EventStateMetadataResponse(object sender, EventArgs e) { lock (this) { try { iMetadata = new DidlLite(iServiceSender.Metadata); string metadata = (iMetadata.Count > 0) ? DidlLiteAdapter.Title(iMetadata[0]) : "Unknown"; ParseName(metadata, out iRoom, out iName); iFullName = string.Format("{0} ({1})", iRoom, iName); } catch (Exception ex) { UserLog.WriteLine("Logging for ticket #1125: " + ex); UserLog.WriteLine("Logging for ticket #1125: " + iServiceSender.Metadata); iMetadata = null; } } if (EventMetadataChanged != null) { EventMetadataChanged(this, EventArgs.Empty); } }
protected override void EventListViewLibrary_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) { TextFormatFlags flags = TextFormatFlags.VerticalCenter | TextFormatFlags.NoPrefix | TextFormatFlags.EndEllipsis; // Because of a bug in the underlying Win32 control, the DrawItem event occurs without accompanying DrawSubItem events once per row in the // details view when the mouse pointer moves over the row, causing anything painted in a DrawSubItem event handler to be painted over by a // custom background drawn in a DrawItem event handler. See the example in the OwnerDraw reference topic for a workaround that invalidates // each row when the extra event occurs. An alternative workaround is to put all your custom drawing code in a DrawSubItem event handler // and paint the background for the entire item (including subitems) only when the DrawListViewSubItemEventArgs.ColumnIndex value is 0. if (e.ColumnIndex == 0) { e.Graphics.FillRectangle(iBackBrush, e.Bounds); if (iIsAlbum && Items.Count > 0) { ListViewKinsky.Item item = Items[0] as ListViewKinsky.Item; musicTrack track = item.Tag as musicTrack; int iconHeight = (int)(Columns[0].Width * 0.5f); int iconOffset = 5;// (int)((Columns[0].Width - iconHeight) * 0.5f); Image albumArt = item.Icon; if (albumArt != null) { e.Graphics.FillRectangle(iBackBrush, item.Bounds.Left + iconOffset, item.Bounds.Top + iconOffset, iconHeight, iconHeight); try { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; e.Graphics.DrawImage(albumArt, item.Bounds.Left + iconOffset, item.Bounds.Top + iconOffset, iconHeight, iconHeight); } catch (ArgumentException ex) { Trace.WriteLine(Trace.kKinsky, "ListViewLibrary.EventListViewLibrary_DrawSubItem: " + ex.Message); } } if (track != null) { int x = item.Bounds.Left + iconOffset + iconHeight + iconOffset; int y = item.Bounds.Top + iconOffset; int width = Columns[0].Width + item.Bounds.Left; int height = iFont.Height; e.Graphics.FillRectangle(iBackBrush, new Rectangle(x, y, width - x, height * 4)); string album = DidlLiteAdapter.Album(track); if (!string.IsNullOrEmpty(album)) { TextRenderer.DrawText(e.Graphics, album, iFont, new Rectangle(x, y, width - x, height), ForeColor, flags); y += height; } string artist = DidlLiteAdapter.AlbumArtist(track); if (!string.IsNullOrEmpty(artist)) { TextRenderer.DrawText(e.Graphics, artist, iFont, new Rectangle(x, y, width - x, height), Color.DarkGray, flags); y += height; } string genre = DidlLiteAdapter.Genre(track); if (!string.IsNullOrEmpty(genre)) { TextRenderer.DrawText(e.Graphics, genre, iFont, new Rectangle(x, y, width - x, height), Color.DarkGray, flags); y += height; } TextRenderer.DrawText(e.Graphics, DidlLiteAdapter.ReleaseYear(track), iFont, new Rectangle(x, y, width - x, height), Color.DarkGray, flags); } } } //Console.WriteLine("columIndex=" + e.ColumnIndex + ", header=" + e.Header + ", item=" + e.Item + ", itemIndex=" + e.ItemIndex + ", subItem=" + e.SubItem); //e.DrawDefault = true; //return; if (e.ColumnIndex > 0) { if (e.Item.Selected) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; e.Graphics.FillRectangle(iHighlightBackBrush, e.Bounds); } else { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; e.Graphics.FillRectangle(iBackBrush, e.Bounds); } } ListViewItem.ListViewSubItem subItem = null; for (int i = 0; i < e.Item.SubItems.Count; ++i) { if (e.Item.SubItems[i].Name == e.Header.Name) { subItem = e.Item.SubItems[i]; break; } } if (subItem != null) { if (e.Item.Selected) { TextRenderer.DrawText(e.Graphics, subItem.Text, iFont, e.Bounds, HighlightForeColour, flags); } else { if (e.Header.Name != "Title") { TextRenderer.DrawText(e.Graphics, subItem.Text, iFont, e.Bounds, ForeColorMuted, flags); } else { TextRenderer.DrawText(e.Graphics, subItem.Text, iFont, e.Bounds, ForeColor, flags); } } } }
private void Parse() { lock (iLock) { if (!iParsed) { List <KeyValuePair <string, string> > displayList = new List <KeyValuePair <string, string> >(); List <KeyValuePair <string, string> > fullList = new List <KeyValuePair <string, string> >(); if (iItem != null) { string type = GetItemType(iItem); fullList.Add(new KeyValuePair <string, string>("Type", type)); string title = DidlLiteAdapter.Title(iItem); if (title != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Title", title)); fullList.Add(new KeyValuePair <string, string>("Title", title)); } string album = DidlLiteAdapter.Album(iItem); // if parent is a musicAlbum and album is blank, try to get album info from parent if (album == string.Empty && iParent is musicAlbum) { album = DidlLiteAdapter.Album(iParent); } // don't display album field if we are a musicAlbum as it will be same as Title if (album != string.Empty && !(iItem is musicAlbum)) { // only insert album info for display if parent not a musicAlbum if (!(iParent is musicAlbum)) { displayList.Add(new KeyValuePair <string, string>("Album", album)); } fullList.Add(new KeyValuePair <string, string>("Album", album)); } string artist = DidlLiteAdapter.Artist(iItem); string albumArtist = DidlLiteAdapter.AlbumArtist(iItem); string parentArtist = string.Empty; if (iParent != null) { parentArtist = DidlLiteAdapter.Artist(iParent); } // don't display artist field if we are a person, as it will be same as title if (artist != string.Empty && !(iItem is person)) { // only display artist field when: // our parent is not a music album // or we are a music album and album artist field is blank // our parent is a music album but artist field is different from album artist field and different from parent's artist field if (!(iParent is musicAlbum) || (iItem is musicAlbum && albumArtist == string.Empty) || (iParent is musicAlbum && albumArtist != artist && parentArtist != artist)) { displayList.Add(new KeyValuePair <string, string>("Artist", artist)); } fullList.Add(new KeyValuePair <string, string>("Artist", artist)); } if (albumArtist != string.Empty) { // only display albumartist field when: // we are a musicAlbum and album artist is different from artist // or artist field is blank and album artist is not the same as parent's artist field if ((iItem is musicAlbum && albumArtist != artist) || (artist == string.Empty && parentArtist != albumArtist)) { displayList.Add(new KeyValuePair <string, string>("Album Artist", albumArtist)); } fullList.Add(new KeyValuePair <string, string>("Album Artist", albumArtist)); } string count = DidlLiteAdapter.Count(iItem); if (count != string.Empty && count != "0") { displayList.Add(new KeyValuePair <string, string>("Count", count)); fullList.Add(new KeyValuePair <string, string>("Count", count)); } string composer = DidlLiteAdapter.Composer(iItem); if (composer != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Composer", composer)); fullList.Add(new KeyValuePair <string, string>("Composer", composer)); } string genre = DidlLiteAdapter.Genre(iItem); if (genre != string.Empty) { string parentGenre = string.Empty; if (iParent != null) { parentGenre = DidlLiteAdapter.Genre(iParent); } if (parentGenre != genre) { displayList.Add(new KeyValuePair <string, string>("Genre", genre)); } fullList.Add(new KeyValuePair <string, string>("Genre", genre)); } string releaseYear = DidlLiteAdapter.ReleaseYear(iItem); if (releaseYear != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Release Year", releaseYear)); fullList.Add(new KeyValuePair <string, string>("Release Year", releaseYear)); } string originalTrackNumber = DidlLiteAdapter.OriginalTrackNumber(iItem); if (originalTrackNumber != string.Empty) { fullList.Add(new KeyValuePair <string, string>("Original Track No.", originalTrackNumber)); } string conductor = DidlLiteAdapter.Conductor(iItem); if (conductor != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Conductor", conductor)); fullList.Add(new KeyValuePair <string, string>("Conductor", conductor)); } string actor = DidlLiteAdapter.Actor(iItem); if (actor != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Actor", actor)); fullList.Add(new KeyValuePair <string, string>("Actor", actor)); } string director = DidlLiteAdapter.Director(iItem); if (director != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Director", director)); fullList.Add(new KeyValuePair <string, string>("Director", director)); } string publisher = DidlLiteAdapter.Publisher(iItem); if (publisher != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Publisher", publisher)); fullList.Add(new KeyValuePair <string, string>("Publisher", publisher)); } string contributer = DidlLiteAdapter.Contributor(iItem); if (contributer != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Contributor", contributer)); fullList.Add(new KeyValuePair <string, string>("Contributor", contributer)); } string duration = DidlLiteAdapter.Duration(iItem); if (duration != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Duration", duration)); fullList.Add(new KeyValuePair <string, string>("Duration", duration)); } string size = DidlLiteAdapter.Size(iItem); if (size != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Size", size)); fullList.Add(new KeyValuePair <string, string>("Size", size)); } string bitrate = DidlLiteAdapter.Bitrate(iItem); if (bitrate != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Bitrate", bitrate)); fullList.Add(new KeyValuePair <string, string>("Bitrate", bitrate)); } string sampleRate = DidlLiteAdapter.SampleRate(iItem); if (sampleRate != string.Empty) { displayList.Add(new KeyValuePair <string, string>("SampleRate", sampleRate)); fullList.Add(new KeyValuePair <string, string>("SampleRate", sampleRate)); } string bitDepth = DidlLiteAdapter.BitDepth(iItem); if (bitDepth != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Bit Depth", bitDepth)); fullList.Add(new KeyValuePair <string, string>("Bit Depth", bitDepth)); } string mimeType = DidlLiteAdapter.MimeType(iItem); if (mimeType != string.Empty) { fullList.Add(new KeyValuePair <string, string>("Mime Type", mimeType)); } string protocolInfo = DidlLiteAdapter.ProtocolInfo(iItem); if (protocolInfo != string.Empty) { fullList.Add(new KeyValuePair <string, string>("Protocol Info", protocolInfo)); } string description = DidlLiteAdapter.Description(iItem); if (description != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Description", description)); fullList.Add(new KeyValuePair <string, string>("Description", description)); } string info = DidlLiteAdapter.Info(iItem); if (info != string.Empty) { displayList.Add(new KeyValuePair <string, string>("Info", description)); fullList.Add(new KeyValuePair <string, string>("Info", description)); } string uri = DidlLiteAdapter.Uri(iItem); if (uri != string.Empty) { fullList.Add(new KeyValuePair <string, string>("Uri", uri)); } Uri artworkUri = DidlLiteAdapter.ArtworkUri(iItem); if (artworkUri != null) { fullList.Add(new KeyValuePair <string, string>("Artwork Uri", artworkUri.OriginalString)); } } iFullInfoList = fullList; iDisplayInfoList = displayList; iParsed = true; } } }
public TrackMetadata(Upnp.upnpObject aMusicTrack) { Assert.Check(aMusicTrack is Upnp.musicTrack); // File Info if (aMusicTrack.Res.Count > 0) { FilePath = aMusicTrack.Res[0].Uri; } try { AlbumArtPath = DidlLiteAdapter.ArtworkUri(aMusicTrack).AbsoluteUri; } catch { // invlid or missing album art } // populate metadata from upnp music track if it is there try { Title = aMusicTrack.Title; if (((Upnp.musicTrack)aMusicTrack).Album.Count > 0) { Album = ((Upnp.musicTrack)aMusicTrack).Album[0]; } if (((Upnp.musicTrack)aMusicTrack).Artist.Count > 0) { Artist = ((Upnp.musicTrack)aMusicTrack).Artist[0].Artist; foreach (Upnp.artist artist in ((Upnp.musicTrack)aMusicTrack).Artist) { if (artist.Role == null || artist.Role == "" || artist.Role == "Performer") { Artist = artist.Artist; } else if (artist.Role == "Composer") { Composer = artist.Artist; } else if (artist.Role == "AlbumArtist") { AlbumArtist = artist.Artist; } else if (artist.Role == "Conductor") { Conductor = artist.Artist; } } } if (((Upnp.musicTrack)aMusicTrack).Genre.Count > 0) { Genre = ((Upnp.musicTrack)aMusicTrack).Genre[0]; } Track = (uint)(((Upnp.musicTrack)aMusicTrack).OriginalTrackNumber); if (aMusicTrack is Upnp.musicTrack) { Disc = (uint)(((Upnp.musicTrack)aMusicTrack).OriginalDiscNumber); DiscCount = (uint)(((Upnp.musicTrack)aMusicTrack).OriginalDiscCount); } Year = ((Upnp.musicTrack)aMusicTrack).Date; if (aMusicTrack.Res.Count > 0) { Duration = aMusicTrack.Res[0].Duration; MimeType = aMusicTrack.Res[0].ProtocolInfo.Replace("http-get:*:", "").Replace(":*", ""); } } catch (Exception) { } // deal with missing data and unwanted data if (Title == null) { Title = "Unknown"; } if (Album == null) { Album = "Unknown"; } if (Artist == null) { Artist = "Unknown"; } if (Genre == null) { Genre = "Unknown"; } if (Composer == null) { Composer = "Unknown"; } if (Conductor == null) { Conductor = "Unknown"; } if (AlbumArtist == null) { AlbumArtist = "Unknown"; } if (Year == null) { Year = "Unknown"; } if (Duration == null) { Duration = "Unknown"; } if (MimeType == null) { MimeType = "Unknown"; } }
private void Run() { bool errorRaised = false; uint total = 0; try { total = iContainer.Open(); } catch (Exception e) { // container has died UserLog.WriteLine(DateTime.Now + ": Exception caught opening container (" + e.Message + (e.InnerException != null ? (", " + e.InnerException.Message) : "") + ")"); IContentHandler handler; lock (iContentHandlerLock) { handler = iContentHandler; } if (handler != null) { handler.ContentError(this, e.Message); } errorRaised = true; } iMutex.WaitOne(); iContent = new upnpObject[(int)total]; iMutex.ReleaseMutex(); if (!errorRaised) { IContentHandler handler; lock (iContentHandlerLock) { handler = iContentHandler; } if (handler != null) { handler.Open(this, total); } } iMutex.WaitOne(); while (!iExit) { iMutex.ReleaseMutex(); iEvent.WaitOne(); iMutex.WaitOne(); IContentHandler handler; lock (iContentHandlerLock) { handler = iContentHandler; } if (iRangeUpdated) { Assert.Check(iExit || iStartIndex >= 0); Assert.Check(iExit || iCount >= 0); uint startIndex = (uint)iStartIndex; uint index = (uint)iStartIndex; uint totalCount = (uint)iCount; uint count = 0; iRangeUpdated = false; while (!iExit && !iRangeUpdated && count < totalCount) { iMutex.ReleaseMutex(); DidlLite didl = new DidlLite(); try { uint callCount = (startIndex + totalCount) - index; if (callCount > kCountPerCall) { callCount = kCountPerCall; } for (int i = (int)index; i < (int)(index + callCount) && i < iContent.Length; ++i) { if (iContent[i] != null) { didl.Add(iContent[i]); } else { break; } } if (didl.Count == 0) { didl = iContainer.Items(index, callCount); } } catch (Exception e) { iMutex.WaitOne(); // container has died UserLog.WriteLine(DateTime.Now + ": Exception caught retrieving container content (" + e.Message + (e.InnerException != null ? (", " + e.InnerException.Message) : "") + ")"); UserLog.WriteLine(DateTime.Now + e.StackTrace); if (!errorRaised) { lock (iContentHandlerLock) { handler = iContentHandler; } if (handler != null) { handler.ContentError(this, e.Message); } errorRaised = true; } break; } iMutex.WaitOne(); if (iExit || total < index + didl.Count) { if (total < index + didl.Count) { UserLog.WriteLine(DateTime.Now + ": Error: " + iContainer.Metadata.Title + " returned more items than expected"); lock (iContentHandlerLock) { handler = iContentHandler; } if (handler != null) { handler.ContentError(this, iContainer.Metadata.Title + " returned more items than expected"); } } break; } iMutex.ReleaseMutex(); for (uint i = 0; i < didl.Count; ++i) { upnpObject o = didl[(int)i]; iContent[index + i] = o; lock (iContentHandlerLock) { handler = iContentHandler; } if (handler != null) { handler.Item(this, index + i, o); } } lock (iContentHandlerLock) { handler = iContentHandler; } if (handler != null) { handler.Items(this, index, didl); } index += (uint)didl.Count; count += (uint)didl.Count; iMutex.WaitOne(); if (!iRangeUpdated) { iStartIndex = -1; iCount = -1; } } } } iMutex.ReleaseMutex(); iContainer.Close(); Trace.WriteLine(Trace.kKinsky, "ContentCollector for " + DidlLiteAdapter.Title(iContainer.Metadata) + " disposed"); }
private void EnsureLoaded() { lock (iLock) { if (!iIsLoaded) { if (iIsHeaderItem) { iDisplayField1 = DidlLiteAdapter.Album(iItem); iDisplayField2 = DidlLiteAdapter.AlbumArtist(iItem); if (iDisplayField2 == string.Empty) { iDisplayField2 = DidlLiteAdapter.Artist(iItem); } } else { ItemInfo info = new ItemInfo(iItem); if (iIsGrouped) { ReadOnlyCollection <KeyValuePair <string, string> > displayItems = info.DisplayItems; int counter = 0; foreach (KeyValuePair <string, string> item in displayItems) { if (item.Key == "Album Artist" || item.Key == "Album" || (item.Key == "Artist" && DidlLiteAdapter.AlbumArtist(iItem) == item.Value)) { // don't show this info for a grouped item continue; } if (counter == 0) { iDisplayField1 = item.Value; } else if (counter == 1) { iDisplayField2 = item.Value; } else if (counter == 2) { iDisplayField3 = item.Value; } else { continue; } counter++; } } else { iDisplayField1 = info.DisplayItem(0).HasValue ? info.DisplayItem(0).Value.Value : null; iDisplayField2 = info.DisplayItem(1).HasValue ? info.DisplayItem(1).Value.Value : null; iDisplayField3 = info.DisplayItem(2).HasValue ? info.DisplayItem(2).Value.Value : null; } iTechnicalInfo = DidlLiteAdapter.Duration(iItem); if (iTechnicalInfo == string.Empty) { iTechnicalInfo = DidlLiteAdapter.Bitrate(iItem); } } iItem = null; iIsLoaded = true; } } }