/// <summary> /// Populates the service provides /// </summary> /// <param name="services">List of service providers</param> private void PopulateServiceProviders(ServicesResultObject services) { // Get the selected service if it exists HttpCookie selectedServiceCookie = Request.Cookies["SelectedServiceId"]; string selectedServiceId = selectedServiceCookie == null ? string.Empty : selectedServiceCookie.Value; // Populate the services dropdown ServiceProviders.Items.Clear(); List <string> cookieValues = new List <string>(); foreach (var service in services.ServicesResult.Services.Service) { bool selected = service.ServiceId.Equals(selectedServiceId); ServiceProviders.Items.Add(new ListItem() { Text = service.Name, Value = service.ServiceId, Selected = selected }); cookieValues.Add(string.Format("{0}:::{1}", service.ServiceId, service.Name)); } if (selectedServiceCookie == null && services.ServicesResult.Services.Service.Count > 0) { // No selected service cookie existed -- save the first found service Response.Cookies.Add(new HttpCookie("SelectedServiceId", services.ServicesResult.Services.Service[0].ServiceId) { Expires = DateTime.MaxValue }); } // Remember the found services Response.Cookies.Add(new HttpCookie(ServiceProviders.ID, string.Join("|||", cookieValues)) { Expires = DateTime.MaxValue }); // Remember the user input TextBox[] values = new[] { PostalCode, CountryCode, this.ApiKey }; foreach (var v in values) { Response.Cookies.Add(new HttpCookie(v.ID, v.Text) { Expires = DateTime.MaxValue }); } ServiceProvidersPanel.Visible = true; ResultsPanel.Visible = false; }
/// <summary> /// GetServiceProviders Click event /// </summary> /// <param name="sender">What raised the event</param> /// <param name="e">Event arguments</param> protected void GetServiceProviders_Click(object sender, EventArgs e) { string url = "http://api.rovicorp.com/TVlistings/v9/listings/services/postalcode/{0}/info?locale=en-US&countrycode={1}&apikey={2}&sig=sig&format=json"; url = string.Format(url, PostalCode.Text, CountryCode.Text, this.ApiKey.Text); ServicesResultObject services = this.GetServiceProviders(url); if (services == null) { return; } GetServiceProvidersError.Visible = false; this.PopulateServiceProviders(services); }
/// <summary> /// Gets the service providers /// </summary> /// <param name="url">Service provider URL</param> /// <returns>List of service providers</returns> private ServicesResultObject GetServiceProviders(string url) { ServicesResultObject services = null; object cached = Cache[url]; if (cached == null) { HttpWebResponse webResponse; string response = this.GetResponse(url, out webResponse); if (this.HandleResponse(webResponse, response, this.GetServiceProvidersError)) { services = this.Deserialize <ServicesResultObject>(response); Cache.Insert(url, services, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration); } } else { services = cached as ServicesResultObject; } return(services); }