Ejemplo n.º 1
0
        public void DownloadHistory_Sync(IResourceSearchInfo infos)
        {
            var types = infos.Where(s => s.ResourceType == ResourceType.Ed2K || s.ResourceType == ResourceType.BitTorrent).GroupBy(s => s.ResourceType);
            var dh    = AppContext.Instance.DownloadHistory;

            foreach (var type in types)
            {
                foreach (var info in type)
                {
                    if (info.IsHashLoaded)
                    {
                        info.ChangeDownloadedStatus(dh.ContainsKey(info.Hash));
                        info.DownloadedChanged += (s, e) => DownloadHistory_Update(s as IResourceInfo);
                    }
                    else
                    {
                        info.DetailLoaded += (s, e) =>
                        {
                            DownloadHistory_Sync(new ResourceSearchInfo(infos.Provider)
                            {
                                s as IResourceInfo
                            });
                        };
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Check(IResourceSearchInfo infos)
        {
            var list  = infos.Where(s => s.VerifyState == VerifyState.Unknown).ToList();
            var rules = AppContext.Instance.Options.RssRuleCollection.Values.Union(new[] { AppContext.Instance.Options.RuleCollection }).ExceptNull().ToArray();

            foreach (var info in list)
            {
                Debug.WriteLine($"判断资源:{info.Title} 安全性(自动规则)");

                foreach (var checker in Checkers)
                {
                    var state = checker.Check(info);
                    if (state != VerifyState.Unknown)
                    {
                        info.ChangeVerifyState(state, 0);
                        break;
                    }
                }

                Debug.WriteLine($"判断资源:{info.Title} 安全性(订阅规则)");

                foreach (var rc in rules.ExceptNull())
                {
                    //过滤校验
                    if (rc.Count <= 0)
                    {
                        continue;
                    }

                    foreach (var rule in rc.ExceptNull())
                    {
                        if (!rule.IsMatch(info))
                        {
                            continue;
                        }

                        //标记or移除?
                        if (rule.Behaviour == FilterBehaviour.Hide)
                        {
                            infos.Remove(info);

                            break;
                        }
                        if (rule.Behaviour == FilterBehaviour.Mark && (info.VerifyState == VerifyState.Unknown || info.VerifyState == VerifyState.None))
                        {
                            //标记
                            info.ChangeVerifyState(VerifyState.Illegal, 0);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void DoSearch()
        {
            if (_worker.IsBusy)
            {
                return;
            }

            Debug.WriteLine("Request Search.");
            _requireCancel = false;
            HasMore        = true;      //假定有下一页
            Result         = null;
            OnSearchBegin();
            _worker.RunWorkASync();
        }
Ejemplo n.º 4
0
        public void Filter(IResourceSearchInfo result, string key)
        {
            //执行过滤
            var query = result.Where(s =>
                                     (_excludeKey.Count > 0 && _excludeKey.Any(x => s.Title.Contains(x, StringComparison.OrdinalIgnoreCase))) ||
                                     (_strictKey.Count > 0 && !_strictKey.Any(x => s.Title.Contains(x, StringComparison.OrdinalIgnoreCase))) ||
                                     (_sizeFilter.HasValue && (_sizeFilter.Value < s.DownloadSizeCalcauted ^ _greater))
                                     );
            var removed = query.ToArray();

            removed.ForEach(s => result.Remove(s));

            //计算排序
            var keys = key.Split(_keySplit, StringSplitOptions.RemoveEmptyEntries);

            result.ForEach(s => ((ResourceInfo)s).MatchWeight = keys.Count(x => s.Title.IndexOf(x, StringComparison.OrdinalIgnoreCase) != -1));
        }
Ejemplo n.º 5
0
        void LoadCore()
        {
            var page      = _lastLoadPage;
            var option    = Context.Instance.Options;
            var pagecount = option.LoadPages;
            var keys      = _lastSearchKey.Split(new[] { ' ', ',', '.', ' ', '/', '\\', '-' }, StringSplitOptions.RemoveEmptyEntries);

            _result = _result ?? new List <ITorrentResourceInfo>();
            for (var i = 0; i < pagecount; i++)
            {
                Context.Instance.Statistics.UpdateRunningStatistics(true, TorrentResourceProvider, 1, 0, 0, 0);
                page++;
                Invoke(new Action(() =>
                {
                    lblSearchProgress.Text   = string.Format("正在进行第 {0} 次搜索...", page);
                    pgSearchProgress.Maximum = pagecount;
                    pgSearchProgress.Value   = i + 1;
                }));

                var list = TorrentResourceProvider.Load(_lastSearchKey, option.SortType, option.SortDirection, option.PageSize, page);
                if (list == null)
                {
                    Context.Instance.Statistics.UpdateRunningStatistics(true, TorrentResourceProvider, 0, 0, 0, 1);
                    _lastLoadPage = page - 1;
                    //失败。。。
                    throw new LoadFailedException();
                }
                //挂起排序?
                _sorter.SuspendSort = list.SortType != null;
                Context.Instance.Statistics.UpdateRunningStatistics(true, TorrentResourceProvider, 0, 0, 1, 0);

                var validItems = list.Where(s => !Context.Instance.Options.StrictFilter || keys.Any(x => s.Title.Contains(x, StringComparison.OrdinalIgnoreCase))).ToArray();
                _result.AddRange(validItems);
                _lastResultGroup = list;
                Invoke(new Action(() => AppendItems(validItems)));

                _lastLoadPage = page;
                if (list.Count == 0 || !list.HasMore)
                {
                    //没有资源
                    break;
                }
            }
        }
        /// <summary>
        /// 资源已处理,准备供显示
        /// </summary>
        /// <param name="items"></param>
        public void ResourcesFetched(IResourceSearchInfo items)
        {
            var processors = AppContext.Instance.ResourceProcessors;

            if (processors == null)
            {
                return;
            }

            foreach (var processor in processors)
            {
                try
                {
                    processor.ResourcesFetched(items);
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }
        }
Ejemplo n.º 7
0
 public void VerifyState_Sync(IResourceSearchInfo infos)
 {
     //先自动判定
     AppContext.Instance.SecurityCheck.Check(infos);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 同步资源信息以及填充资源预览信息。
        /// </summary>
        /// <param name="infos"></param>
        public void PreviewInfo_Sync(IResourceSearchInfo infos)
        {
            var types = infos.GroupBy(s => s.ResourceType);

            //按照资源类型分组以便于查询
            List <IResourceInfo>    updatablePreviewInfo = new List <IResourceInfo>();
            HashSet <IResourceInfo> noValidInfo          = new HashSet <IResourceInfo>();

            foreach (var resourceType in types)
            {
                var hashes = resourceType.Where(s => s.IsHashLoaded).Select(s => s.Hash).ToArray();
                if (hashes.IsEmpty())
                {
                    continue;
                }

                //加载资源预览信息
                var data = PreviewInfo_Load(resourceType.Key, hashes);
                foreach (var resinfo in resourceType)
                {
                    //信息没加载完全,则跳过
                    if (!resinfo.IsHashLoaded)
                    {
                        resinfo.DetailLoaded += (s, e) =>
                        {
                            PreviewInfo_Sync(new ResourceSearchInfo(infos.Provider)
                            {
                                s as IResourceInfo
                            });
                        };
                        continue;
                    }

                    var info = data.FirstOrDefault(s => s.PreviewSource == resinfo.Provider.Info.Name && s.Hash == resinfo.Hash && s.SType == resinfo.ResourceType);
                    var type = resinfo.SupportPreivewType;

                    //如果没有预览信息,且现在有新的预览信息
                    if (info == null && type != PreviewType.None && resinfo.PreviewInfo != null)
                    {
                        Trace.TraceInformation($"[DB] Insert preview info. Hash={resinfo.Hash}, Engine={resinfo.Provider.Info.Name}");
                        //INSERT
                        _connection.Execute("INSERT INTO PreviewInfo (SType, Hash,PreviewSource,PreviewType, WebUrl, ImageUrl, Description, LastUsed, HitCount) VALUES (@stype, @hash, @source, @previewType, @weburl, @imageurl, @desc, datetime('now'), 1)",
                                            new
                        {
                            stype       = (int)resourceType.Key,
                            hash        = resinfo.Hash,
                            source      = resinfo.Provider.Info.Name,
                            previewType = (int)type,
                            weburl      = resinfo.PreviewInfo.WebUrl,
                            imageurl    = resinfo.PreviewInfo.ImageUrl,
                            desc        = resinfo.PreviewInfo.Description
                        });
                        updatablePreviewInfo.Add(resinfo);
                    }
                    else if (info != null && resinfo.PreviewInfo != null && type != PreviewType.None && (resinfo.PreviewInfo.WebUrl != info.WebUrl || resinfo.SupportPreivewType != type || resinfo.PreviewInfo.ImageUrl != info.ImageUrl || resinfo.PreviewInfo.Description != info.Description))
                    {
                        Trace.TraceInformation($"[DB] Update preview info. Hash={resinfo.Hash}, Engine={resinfo.Provider.Info.Name}");
                        //已有预览信息,且现在也有预览信息,且不一样,则更新
                        _connection.Execute("UPDATE PreviewInfo SET PreviewType=@previewType, WebUrl=@weburl, ImageUrl=@imageurl, Description=@desc, HitCount=HitCount+1, LastUsed=datetime('now') WHERE SType=@stype AND Hash=@hash AND PreviewSource=@source",
                                            new
                        {
                            stype       = (int)resourceType.Key,
                            hash        = resinfo.Hash,
                            source      = resinfo.Provider.Info.Name,
                            previewType = (int)type,
                            weburl      = resinfo.PreviewInfo.WebUrl,
                            imageurl    = resinfo.PreviewInfo.ImageUrl,
                            desc        = resinfo.PreviewInfo.Description
                        });
                        updatablePreviewInfo.Add(resinfo);
                    }
                    else if (info != null && info.PreviewType != resinfo.SupportPreivewType && resinfo.SupportPreivewType == PreviewType.None)
                    {
                        Trace.TraceInformation($"[DB] Remove preview info. Hash={info.Hash}, Engine={resinfo.Provider.Info.Name}");
                        //DELETE
                        _connection.Execute("DELETE FROM PreviewInfo WHERE SType=@stype AND Hash=@hash AND Source=@source", new
                        {
                            stype  = (int)resourceType.Key,
                            hash   = resinfo.Hash,
                            source = resinfo.Provider.Info.Name
                        });
                    }
                    else if (info != null && resinfo.SupportPreivewType != PreviewType.None && resinfo.PreviewInfo == null)
                    {
                        //set cached preview info.
                        resinfo.PreviewInfo = info;
                    }
                    resinfo.PreviewInfo        = resinfo.PreviewInfo ?? info;
                    resinfo.SupportPreivewType = info?.PreviewType ?? resinfo.SupportPreivewType;

                    //如果不支持预览或没有加载预览信息,则查找是否有相同的预览信息
                    if (resinfo.PreviewInfo == null)
                    {
                        info = data.FirstOrDefault(s => s.Hash == resinfo.Hash && s.SType == resinfo.ResourceType && s.PreviewSource != "");
                        resinfo.PreviewInfo        = resinfo.PreviewInfo ?? info;
                        resinfo.SupportPreivewType = info?.PreviewType ?? 0;
                    }
                    if (resinfo.PreviewInfo == null && data.Any(s => s.Hash == resinfo.Hash && s.SType == resinfo.ResourceType && s.PreviewSource == ""))
                    {
                        resinfo.SupportPreivewType = PreviewType.None;
                        noValidInfo.Add(resinfo);
                    }

                    resinfo.PreviewInfoLoaded += (s, e) =>
                    {
                        PreviewInfo_Sync(new ResourceSearchInfo(infos.Provider)
                        {
                            s as IResourceInfo
                        });
                    };
                }
            }
        }