示例#1
0
        public static IPT GetPT(YUEnums.PTEnum type, params object[] args)
        {
            lock (thisLock)
            {
                if (notRegistered)
                {
                    RegisterPT();
                }
            }
            IPT instance = null;

            if (_mapServer.ContainsKey(type))
            {
                instance = TypesContainer.CreateInstance <IPT>(_mapServer[type], args);
            }
            else
            {
                var argList = args.ToList();
                argList.Add(type);
                instance = TypesContainer.CreateInstance <IPT>("YU.PT.ExtendPT,YU.PT", argList.ToArray());
            }
            if (instance == null)
            {
                throw new Exception("instance==null");
            }
            return(instance);
        }
示例#2
0
        private void DownLoadFiles(bool isOepn = false)
        {
            if (dgvTorrent.SelectedRows != null && dgvTorrent.SelectedRows.Count > 0)
            {
                var searchTorrents = dgvTorrent.Tag as List <PTTorrent>;
                DataGridViewCellCollection cells = dgvTorrent.SelectedRows[0].Cells;
                string         torrentId         = cells["Id"].Value.TryPareValue <string>();
                YUEnums.PTEnum siteId            = (YUEnums.PTEnum)EnumUtils.GetKeyByValue <YUEnums.PTEnum>(cells["SiteId"].Value.TryPareValue <string>());

                if (searchTorrents != null && searchTorrents.Count > 0)
                {
                    var torrent = searchTorrents.Where(x => x.Id == torrentId && x.SiteId == siteId).FirstOrDefault();
                    if (torrent != null)
                    {
                        Task t = Task.Run(() =>
                        {
                            IPT pt          = PTFactory.GetPT(siteId, Global.Users.Where(x => x.Site.Id == siteId).FirstOrDefault());
                            string fileName = pt.GetTorrentDownFileName(torrent);
                            string filePath = string.Empty;
                            this.Invoke(new Action(() =>
                            {
                                SaveFileDialog sfd = new SaveFileDialog();
                                sfd.FileName       = fileName;
                                sfd.Filter         = "TORRENT 文件|*.torrent;";
                                if (sfd.ShowDialog() == DialogResult.OK)
                                {
                                    filePath     = sfd.FileName;
                                    var downTask = Task.Run(() =>
                                    {
                                        HttpUtils.DownLoadFiles(torrent.DownUrl, filePath, 1024, (pt as AbstractPT).Cookie, isOepn);
                                    });
                                    TaskCallBack(downTask, "下载种子过程中出现错误,错误原因:");
                                }
                            }));
                        });
                        TaskCallBack(t, "下载种子过程中出现错误,错误原因:");
                    }
                }

                else
                {
                    LogMessage(PTSite.Sites.Where(x => x.Id == siteId).FirstOrDefault(), string.Format("下载失败,失败原因:获取种子信息失败。"), true);
                }
            }
        }
示例#3
0
 private void Sign()
 {
     if (Global.Users != null && Global.Users.Count > 0)
     {
         LogMessage(null, "正在启动签到。");
         foreach (var user in Global.Users)
         {
             IPT    pt  = PTFactory.GetPT(user.Site.Id, user);
             string msg = pt.Sign();
             LogMessage(user.Site, msg);
         }
         LogMessage(null, "全部签到完毕。");
     }
     else
     {
         LogMessage(null, "请先添加用户。");
     }
 }
示例#4
0
        public static IPT GetPT(YUEnums.PTEnum type, params object[] args)
        {
            lock (thisLock)
            {
                if (notRegistered)
                {
                    RegisterPT();
                }
            }
            IPT instance = null;

            if (_mapServer.ContainsKey(type))
            {
                instance = TypesContainer.CreateInstance <IPT>(_mapServer[type], args);
            }
            if (instance == null)
            {
                throw new Exception("instance==null");
            }
            return(instance);
        }
示例#5
0
        private void SyncPersonInfo(bool isBack = false)
        {
            this.Invoke(new Action(() =>
            {
                tabMain.SelectTab("tabPersonInfo");
            }));
            if (Global.Users != null || Global.Users.Count > 0)
            {
                bool          isFill = false;
                StringBuilder sb     = new StringBuilder();
                var           cts    = new CancellationTokenSource();
                Task          task   = new Task(() =>
                {
                    List <PTInfo> infos = new List <PTInfo>();
                    Parallel.ForEach(Global.Users, (user, state, i) =>
                    {
                        IPT pt = PTFactory.GetPT(user.Site.Id, Global.Users.Where(x => x.Site.Id == user.Site.Id).FirstOrDefault());
                        //IPT pt = PTFactory.GetPT(YUEnums.PTEnum.MTEAM, Global.Users.Where(x => x.Site.Id == YUEnums.PTEnum.MTEAM).FirstOrDefault());
                        //假设4核Cpu,5个任务,因为是并行的原因,如果前4个在并行执行的过程任意一个发生了异常,那么此时前4个中其他3个还会继续执行到结束,但最后一个是不会执行的,所以这里需要做异常捕获处理。
                        try
                        {
                            infos.Add(pt.GetPersonInfo());
                            lock (syncInfoObject)
                            {
                                FillPersonInfo(infos, ref isFill);
                            }
                        }
                        catch (Exception ex)
                        {
                            lock (syncInfoObject)
                                sb.AppendLine(ex.GetInnerExceptionMessage());
                        }
                    });
                }, cts.Token);
                if (!isBack)
                {
                    progressPanel.BeginLoading();
                }
                task.Start();
                cts.CancelAfter(20000);
                task.ContinueWith(result =>
                {
                    if (!isBack)
                    {
                        this.Invoke(new Action(() =>
                        {
                            progressPanel.StopLoading();
                        }));
                    }

                    bool isOpen = !isBack && !isFill;
                    if (cts.Token.IsCancellationRequested)
                    {
                        LogMessage(null, "同步过程出现错误,错误原因:超时。", isOpen);
                    }
                    else
                    {
                        string errMsg = sb.ToString();
                        if (!errMsg.IsNullOrEmptyOrWhiteSpace())
                        {
                            LogMessage(null, errMsg, isOpen);
                        }
                    }
                });
            }
        }