Esempio n. 1
0
        public async Task<TVDBSearchResponse> Search(string query)
        {
            string apiCallURL = string.Format("{0}/api/GetSeries.php?seriesname={1}", _baseURL, query);
            string tvdbResponse = string.Empty;

            TVDBSearchResponse tvdbSearchResponse = new TVDBSearchResponse();
            try
            {
                tvdbResponse = await GetHTTPString(new Uri(apiCallURL));
            }
            catch(HttpRequestException)
            {
                tvdbSearchResponse.serverUnavailable = true;
                return tvdbSearchResponse;
            }

            // return an empty list if there was an empty response
            if (string.IsNullOrEmpty(tvdbResponse))
                return null;

            // read the response in through a memory stream and use the xml serializer
            using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(tvdbResponse)))
            {
                var serializer = new XmlSerializer(typeof(TVDBSearchResponse));
                tvdbSearchResponse = (serializer.Deserialize(memoryStream) as TVDBSearchResponse);
            }

            // we should have some info now so return it
            return tvdbSearchResponse;
        }
Esempio n. 2
0
        public async Task <TVDBSearchResponse> Search(string query)
        {
            string apiCallURL   = string.Format("{0}/api/GetSeries.php?seriesname={1}", _baseURL, query);
            string tvdbResponse = string.Empty;

            TVDBSearchResponse tvdbSearchResponse = new TVDBSearchResponse();

            try
            {
                tvdbResponse = await GetHTTPString(new Uri(apiCallURL));
            }
            catch (HttpRequestException)
            {
                tvdbSearchResponse.serverUnavailable = true;
                return(tvdbSearchResponse);
            }

            // return an empty list if there was an empty response
            if (string.IsNullOrEmpty(tvdbResponse))
            {
                return(null);
            }

            // read the response in through a memory stream and use the xml serializer
            using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(tvdbResponse)))
            {
                var serializer = new XmlSerializer(typeof(TVDBSearchResponse));
                tvdbSearchResponse = (serializer.Deserialize(memoryStream) as TVDBSearchResponse);
            }

            // we should have some info now so return it
            return(tvdbSearchResponse);
        }