예제 #1
0
        private KeyValue repeatCallWebAPI(WebAPI.Interface APIInterface, string APIName, Dictionary <string, string> APIArgs, int APIVersion = 1)
        {
            KeyValue keyValues = new KeyValue();

            try
            {
                keyValues = APIInterface.Call(APIName, APIVersion, APIArgs);
            }
            catch (WebException ex)
            {
                System.Threading.Thread.Sleep(31000);
                return(repeatCallWebAPI(APIInterface, APIName, APIArgs, APIVersion));
            }
            return(keyValues);
        }
예제 #2
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);
                            }
                        }
                    }
                }
            }
        }
예제 #3
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);
                        }
                    }
                }
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            // in order to interact with the Web APIs, you must first acquire an interface
            // for a certain API
            using (dynamic steamNews = WebAPI.GetInterface("ISteamNews"))
            {
                // note the usage of c#'s dynamic feature, which can be used
                // to make the api a breeze to use

                // the ISteamNews WebAPI has only 1 function: GetNewsForApp,
                // so we'll be using that

                // when making use of dynamic, we call the interface function directly
                // and pass any parameters as named arguments
                KeyValue kvNews = steamNews.GetNewsForApp(appid: 440);   // get news for tf2

                // the return of every WebAPI call is a KeyValue class that contains the result data

                // for this example we'll iterate the results and display the title
                foreach (KeyValue news in kvNews["newsitems"]["newsitem"].Children)
                {
                    Console.WriteLine("News: {0}", news["title"].AsString());
                }

                // for functions with multiple versions, the version can be specified by
                // adding a number after the function name when calling the API

                kvNews = steamNews.GetNewsForApp2(appid: 570);

                // if a number is not specified, version 1 is assumed by default

                // notice that the output of this version differs from the first version
                foreach (KeyValue news in kvNews["newsitems"].Children)
                {
                    Console.WriteLine("News: {0}", news["title"].AsString());
                }

                // note that the interface functions can throw WebExceptions when the API
                // is otherwise inaccessible (networking issues, server downtime, etc)
                // and these should be handled appropriately
                try
                {
                    kvNews = steamNews.GetNewsForApp002(appid: 730, maxlength: 100, count: 5);
                }
                catch (WebException ex)
                {
                    Console.WriteLine("Unable to make API request: {0}", ex.Message);
                }
            }

            // for WebAPIs that require an API key, the key can be specified in the GetInterface function
            using (dynamic steamUserAuth = WebAPI.GetInterface("ISteamUserAuth", "APIKEYGOESHERE"))
            {
                // as the interface functions are synchronous, it may be beneficial to specify a timeout for calls
                steamUserAuth.Timeout = ( int )TimeSpan.FromSeconds(5).TotalMilliseconds;

                // additionally, if the API you are using requires you to POST or use an SSL connection, you may specify
                // these settings with the "method" and "secure" reserved parameters
                steamUserAuth.AuthenticateUser(someParam: "someValue", method: WebRequestMethods.Http.Post, secure: true);
            }

            // if you are using a language that does not have dynamic object support, or you otherwise don't wish to use it
            // you can call interface functions through a Call method
            using (WebAPI.Interface steamNews = WebAPI.GetInterface("ISteamNews"))
            {
                Dictionary <string, string> newsArgs = new Dictionary <string, string>();
                newsArgs["appid"] = "440";

                KeyValue results = steamNews.Call("GetNewsForApp", /* version */ 1, newsArgs);
            }
        }