示例#1
0
        public void downloadAReplay(string downloadFolder, MyMatch theMatch)
        {
            string match_replay_url = "http://replay" + theMatch.matchDetail.cluster.ToString() + ".valve.net/570/" + theMatch.matchDetail.match_id.ToString() + "_" + theMatch.matchDetail.replay_salt.ToString() + ".dem.bz2";
            string downloadFileName = downloadFolder + theMatch.matchDetail.match_id.ToString() + ".dem.bz2";

            //已经成功下载并解压
            if (File.Exists(downloadFolder + theMatch.matchDetail.match_id.ToString() + ".dem"))
            {
                return;
            }
            //该录像正在被下载
            if (downloadingMatchs.ContainsKey(theMatch.matchDetail.match_id))
            {
                return;
            }
            else
            {
                downloadingMatchs.Add(theMatch.matchDetail.match_id, true);
            }
            //该录像正在被下载
            if (File.Exists(downloadFileName))
            {
                return;
            }
            //没下载并解压完成,删掉重新下载
            //            if ((File.Exists(downloadFileName)) && (!File.Exists(downloadFolder + theMatch.matchDetail.match_id.ToString() + ".dem")))
            //              File.Delete(downloadFileName);
            WebClient webClient = new WebClient();

            //webClient.DownloadFile(new Uri(match_replay_url), System.AppDomain.CurrentDomain.BaseDirectory + @"\Assets\" + theMatch.matchDetail.match_id.ToString() + ".dem.bz2");
            ServicePointManager.DefaultConnectionLimit = 1024;
            webClient.DownloadProgressChanged         += (sender, e) => MyProgressChanged(sender, e, theMatch.matchDetail.match_id);
            webClient.DownloadFileAsync(new Uri(match_replay_url), downloadFileName);
            webClient.DownloadFileCompleted += (sender, e) => Completed(sender, e, downloadFileName, theMatch.matchDetail.match_id);
        }
示例#2
0
        private void downloadAGame_Click(object sender, RoutedEventArgs e)
        {
            MyMatch theMatch = new MyMatch();

            theMatch.matchDetail = dota2Client.getMatchDetail(Convert.ToUInt64(matchIdTB.Text));
            if (theMatch.matchDetail.replay_state == CMsgDOTAMatch.ReplayState.REPLAY_AVAILABLE)
            {
                string match_replay_url = "http://replay" + theMatch.matchDetail.cluster.ToString() + ".valve.net/570/" + theMatch.matchDetail.match_id.ToString() + "_" + theMatch.matchDetail.replay_salt.ToString() + ".dem.bz2";
                matchIdTB.Text = match_replay_url;
                downloadAReplay(downloadFolder, theMatch);
            }
            else
            {
                MessageBox.Show("无法下载此录像:" + theMatch.matchDetail.replay_state.ToString());
            }
        }
示例#3
0
        private void downloadALeagueGames(int leagueId, ulong beginTime)
        {
            using (WebAPI.Interface DOTA2Match_570 = WebAPI.GetInterface("IDOTA2Match_570", "5F578BA33DC48279C5C3026BBB7A6E2D"))
            {
                int      results_remaining = int.MaxValue;
                ulong    lastMatchId       = 0;
                KeyValue kvMatchs          = new KeyValue();
                while (results_remaining != 0)
                {
                    if (results_remaining == int.MaxValue)//第一次调用GetMatchHistory接口
                    {
                        Dictionary <string, string> newsArgs = new Dictionary <string, string>();
                        newsArgs["league_id"] = leagueId.ToString();
                        kvMatchs = repeatCallWebAPI(DOTA2Match_570, "GetMatchHistory", newsArgs);
                    }
                    else
                    {
                        Dictionary <string, string> newsArgs = new Dictionary <string, string>();
                        newsArgs["league_id"]         = leagueId.ToString();
                        newsArgs["start_at_match_id"] = lastMatchId.ToString();
                        kvMatchs = repeatCallWebAPI(DOTA2Match_570, "GetMatchHistory", newsArgs);
                    }

                    results_remaining = kvMatchs["results_remaining"].AsInteger();
                    foreach (KeyValue aMatch in kvMatchs["matches"].Children)
                    {
                        ulong start_time = aMatch["start_time"].AsUnsignedLong();
                        lastMatchId = aMatch["match_id"].AsUnsignedLong();
                        if (start_time >= beginTime)
                        {
                            MyMatch theMatch = new MyMatch();
                            theMatch.matchDetail = dota2Client.getMatchDetail(lastMatchId);

                            if (theMatch.matchDetail.replay_state == CMsgDOTAMatch.ReplayState.REPLAY_AVAILABLE)
                            {
                                downloadAReplay(downloadFolder, theMatch);
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        private void downloadCNReplaysB_func()
        {
            using (WebAPI.Interface DOTA2Teams_570 = WebAPI.GetInterface("IDOTA2Teams_570", "5F578BA33DC48279C5C3026BBB7A6E2D"))
            {
                foreach (var aTeam in allTeams)
                {
                    KeyValue kvMatchs = new KeyValue();
                    Dictionary <string, string> newsArgs = new Dictionary <string, string>();
                    newsArgs["team_id"] = aTeam.Key.ToString();
                    kvMatchs            = repeatCallWebAPI(DOTA2Teams_570, "GetTeamInfo", newsArgs);

                    foreach (KeyValue aMatch in kvMatchs["teams"]?.Children[0]?["recent_match_ids"]?.Children)
                    {
                        MyMatch theMatch = new MyMatch();
                        theMatch.matchDetail = dota2Client.getMatchDetail(Convert.ToUInt64(aMatch.Value));
                        if ((theMatch.matchDetail.replay_state == CMsgDOTAMatch.ReplayState.REPLAY_AVAILABLE) &&
                            (theMatch.matchDetail.startTime >= Time_687))
                        {
                            downloadAReplay(downloadFolder, theMatch);
                        }
                    }
                }
            }
        }