示例#1
0
 public static SubscribedLineupsResponse GetSubscribedLineups()
 {
     return(JSONClient.GetJSONResponse <SubscribedLineupsResponse>(UrlBuilder.BuildWithAPIPrefix("/lineups"),
                                                                   null, SDTokenManager.token_manager.token));
 }
        private List <SDStationScheduleResponse> GetStationScheduleResponses(IDictionary <string, List <string> > daysByStationID)
        {
            Console.WriteLine("Downloading station schedules from SchedulesDirect");
            const int kBatchSize = 5000;
            List <SDScheduleStationRequest>  request   = new List <SDScheduleStationRequest>();
            List <SDStationScheduleResponse> responses = new List <SDStationScheduleResponse>();

            Func <int> DoBatch = new Func <int>(() => {
                var batchResponses = JSONClient.GetJSONResponse <List <SDStationScheduleResponse> >(UrlBuilder.BuildWithAPIPrefix("/schedules"),
                                                                                                    request, SDTokenManager.token_manager.token);
                // Some of the reponses may be errors!  Loop through and exclude these so we don't replace good data!
                foreach (var response in batchResponses)
                {
                    if (response.code > 0)
                    {
                        Console.WriteLine(
                            "Portions of the schedule for station ID {0} failed to download, SchedulesDirect response code: {1} - {2}",
                            response.stationID, response.code, response.reponse);
                        continue;
                    }
                    responses.Add(response);
                }
                request.Clear();
                return(0);
            });

            foreach (var stationIDAndDays in daysByStationID)
            {
                request.Add(new SDScheduleStationRequest(stationIDAndDays.Key, stationIDAndDays.Value));
                if (request.Count > kBatchSize)
                {
                    DoBatch();
                }
            }
            if (request.Count > 0)
            {
                DoBatch();
            }
            return(responses);
        }