ResourceListViewItem GetTopItem(ResourceListViewItem item) { while (item.ParentItem != null) { item = item.ParentItem; } return(item); }
/// <summary> /// 向结果中添加项 /// </summary> // <param name="items"></param> private void AppendItemsCore() { if (_queue.Count == 0) { return; } _timer.Enabled = false; using (this.CreateBatchOperationDispatcher()) { var st = new Stopwatch(); var guid = new Guid(); Trace.TraceInformation("开始刷新界面列表操作,GUID={0}", guid); BeginUpdate(); //foreach (var item in items) while (_queue.Count > 0) { var item = _queue.Dequeue(); var lvitem = item.Hash.IsNullOrEmpty() ? null : GetItemsByHash(item.Hash); if (lvitem == null) { lvitem = new ResourceListViewItem(item, Providers.Length > 1); if (!item.Hash.IsNullOrEmpty()) { _itemsCache.Add(item.Hash, lvitem); } if (!item.IsHashLoaded) { item.DetailLoaded += ResourceOperation.MainForm.SafeInvoke((s, e) => { var tinfo = s as IResourceInfo; if (!_itemsCache.ContainsKey(tinfo.Hash)) { var titem = Items.Cast <ResourceListViewItem>().FirstOrDefault(x => x.Resource == tinfo); if (titem != null) { _itemsCache.Add(tinfo.Hash, titem); titem.RefreshDownloadStatus(); titem.RefreshIllegalStatus(); } } }); } item.DownloadedChanged += (s, e) => { var tinfo = s as IResourceInfo; GetItemsByHash(tinfo?.Hash)?.RefreshDownloadStatus(); }; item.VerifyStateChanged += (s, e) => { var tinfo = s as IResourceInfo; GetItemsByHash(tinfo?.Hash)?.RefreshIllegalStatus(); }; lvitem.RefreshDownloadStatus(); lvitem.RefreshIllegalStatus(); Items.Add(lvitem); } else { Items.Remove(lvitem); lvitem.AppendSubResult(item); Items.Add(lvitem); } } Trace.TraceInformation("结束列表添加,开始调整列宽,GUID={0},耗时={1} ms", guid, st.ElapsedMilliseconds); AutoResizeColumns(BetterListViewColumnHeaderAutoResizeStyle.ColumnContent); Trace.TraceInformation("结束调整列宽,开始排序,GUID={0},耗时={1} ms", guid, st.ElapsedMilliseconds); Sort(); Trace.TraceInformation("排序完成,开始界面布局,GUID={0},耗时={1} ms", guid, st.ElapsedMilliseconds); EndUpdate(); Trace.TraceInformation("加载结束,GUID={0},耗时={1} ms", guid, st.ElapsedMilliseconds); OnLoadComplete(); } _timer.Enabled = true; }