/// <summary> /// Overridden because a root collection container is not /// managed in the same manner as a typical /// <see cref="CpMediaContainer"/>. /// Immediately after adding the spider to the container's listing /// of spiders, the current listing of roots is compared against /// the spider's IsMatch() method and then the spider is notified /// of its matches. /// </summary> /// <param name="spider"></param> /// <param name="stateObject">allows additional information to be sent along with the spider</param> protected override void SubscribeSpider(CdsSpider spider, object stateObject) { lock (this.m_Spiders.SyncRoot) { // attempt to find the spider in the current list bool hasSpider = this.IsSpiderSubscribed(spider); // don't add the spider if it's already added if (hasSpider == false) { this.m_Spiders.Add(new WeakReference(spider, true)); } } ArrayList matched; lock (this.m_Roots) { matched = new ArrayList(this.m_Roots.Count); foreach (CpRootContainer r in this.m_Roots) { if (spider.IsMatch(r) == true) { matched.Add(r); r.IncrementSpiderMatches(); } } } spider.NotifySinkAdd(this, matched); }
private CdsSpider GetSpider(CpMediaContainer mc) { if (InvokeRequired == true) { int tt = 5; } CdsSpider spider; lock (this.m_ContainerToSpider) { spider = (CdsSpider) this.m_ContainerToSpider[mc]; if (spider == null) { spider = new CdsSpider(); spider.OnMatchesAdded += new CdsSpider.Delegate_OnMatchesChanged(this.Sink_SpiderOnMatchesAdded); spider.OnMatchesCleared += new CdsSpider.Delegate_OnMatchesChanged(this.Sink_SpiderOnMatchesCleared); spider.OnMatchesRemoved += new CdsSpider.Delegate_OnMatchesChanged(this.Sink_SpiderOnMatchesRemoved); spider.OnUpdateDone += new CdsSpider.Delegate_OnMatchesChanged(this.Sink_SpiderOnMatchesUpdated); if (deviceTree.SelectedNode != null) { IMediaContainer selected = deviceTree.SelectedNode.Tag as IMediaContainer; if (selected != null) { if (mc.Parent == selected) { spider.Comparer = MainForm.MatchContainers; } else if (mc.Parent != null) { if ( (mc.Parent.Parent == selected) && (! (selected is CpRootCollectionContainer)) && (selected != null) ) { spider.Comparer = MainForm.MatchContainers; } else { spider.Comparer = MainForm.MatchNever; } } else { spider.Comparer = MainForm.MatchNever; } } else { spider.Comparer = MainForm.MatchNever; } } else { spider.Comparer = MainForm.MatchNever; } spider.Sorter = null; spider.MonitorThis = mc; this.m_ContainerToSpider[mc] = spider; } spider.Tag = DateTime.Now; } return spider; }
/// <summary> /// Clears the GUI's listing of items for the currently selected container. /// </summary> /// <param name="spider"></param> /// <param name="objects">should be null</param> private void ClearItemView(CdsSpider spider, IList emptyList) { lock (this.LockGuiListing) { mediaListView.BeginUpdate(); mediaListView.Items.Clear(); mediaListView.EndUpdate(); } }
/// <summary> /// Adds to the GUI's listing of items for the currently selected container. /// </summary> /// <param name="spider"></param> /// <param name="addThese"></param> private void AddItemView(CdsSpider spider, IList addThese) { lock (this.LockGuiListing) { mediaListView.BeginUpdate(); foreach (ICpMedia media in addThese) { if (media.IsItem) { CpMediaItem item = (CpMediaItem) media; string artist = ""; if (item.MergedProperties[CommonPropertyNames.creator] != null && item.MergedProperties[CommonPropertyNames.creator].Count > 0) { ICdsElement propValue = (ICdsElement) item.MergedProperties[CommonPropertyNames.creator][0]; artist = propValue.StringValue; } string size = ""; if (item.MergedResources.Length > 0) { MediaResource res = (MediaResource)item.MergedResources[0]; if (res.Size.IsValid) { size = BuildSizeString((long) res.Size.m_Value);//BuildSizeString(long.Parse(res.Size.ToString())); } } int icon = 4; string classtype = item.Class.ToString(); switch (classtype) { case "object.item": icon = 8; break; case "object.item.imageItem": case "object.item.imageItem.photo": icon = 7; break; case "object.item.videoItem": case "object.item.videoItem.movie": icon = 6; break; case "object.item.audioItem": case "object.item.audioItem.musicTrack": icon = 5; break; } ListViewItem l = new ListViewItem(new string[] {item.Title,artist,size},icon); l.Tag = item; mediaListView.Items.Add(l); } } mediaListView.EndUpdate(); } }
private void UpdateItemView(CdsSpider spider, IList ignore) { lock (this.LockGuiListing) { ArrayList al = new ArrayList((ICollection) mediaListView.Items); mediaListView.BeginUpdate(); foreach (ListViewItem lvi in al) { CpMediaItem item = (CpMediaItem) lvi.Tag; string artist = ""; if (item.MergedProperties[CommonPropertyNames.creator] != null && item.MergedProperties[CommonPropertyNames.creator].Count > 0) { ICdsElement propValue = (ICdsElement) item.MergedProperties[CommonPropertyNames.creator][0]; artist = propValue.StringValue; } string size = ""; if (item.MergedResources.Length > 0) { MediaResource res = (MediaResource)item.MergedResources[0]; if (res.Size.IsValid) { size = BuildSizeString((long) res.Size.m_Value);//BuildSizeString(long.Parse(res.Size.ToString())); } } int icon = 4; string classtype = item.Class.ToString(); switch (classtype) { case "object.item": icon = 8; break; case "object.item.imageItem": case "object.item.imageItem.photo": icon = 7; break; case "object.item.videoItem": case "object.item.videoItem.movie": icon = 6; break; case "object.item.audioItem": case "object.item.audioItem.musicTrack": icon = 5; break; } lvi.SubItems[0].Text = item.Title; lvi.SubItems[1].Text = artist; lvi.SubItems[2].Text = size; lvi.ImageIndex = icon; if (mediaPropertyForm != null) { if (item == this.mediaPropertyForm.MediaObj) { this.mediaPropertyForm.MediaObj = item; } } } mediaListView.EndUpdate(); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="mediaObjects"></param> private void Sink_SpiderOnMatchesUpdated(CdsSpider sender, IList mediaObjects) { this.Invoke(new Delegate_UpdateItemView(this.UpdateItemView), sender, mediaObjects); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="mediaObjects"></param> private void Sink_SpiderOnMatchesRemoved(CdsSpider sender, IList mediaObjects) { if (mediaObjects.Count > 0) this.Invoke(new Delegate_UpdateItemView(this.RemoveItemView), sender, mediaObjects); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="mediaObjects"></param> private void Sink_SpiderOnMatchesCleared(CdsSpider sender, IList mediaObjects) { if (InvokeRequired == true) { Invoke(new CdsSpider.Delegate_OnMatchesChanged(Sink_SpiderOnMatchesCleared), sender, mediaObjects); return; } if (deviceTree.SelectedNode.Tag == sender.MonitorThis) ClearItemView(sender, null); }
/// <summary> /// Removes from the GUI's listing of items for the currently selected container. /// </summary> /// <param name="spider"></param> /// <param name="removeThese"></param> private void RemoveItemView(CdsSpider spider, IList removeThese) { lock (this.LockGuiListing) { ArrayList removeLVI = new ArrayList(removeThese.Count); foreach (ListViewItem lvi in mediaListView.Items) { if (removeThese.Contains(lvi.Tag)) { removeLVI.Add(lvi); } } if (removeLVI.Count > 0) { mediaListView.BeginUpdate(); foreach (ListViewItem lvi in removeLVI) { mediaListView.Items.Remove(lvi); } mediaListView.EndUpdate(); } } }