public static HomeTheme GetEditorialTags() { string tagFile = "https://s3-us-west-2.amazonaws.com/fkconfigs/homeThemes.json"; System.Net.ServicePointManager.Expect100Continue = false; HomeTheme hpThemes = new HomeTheme(); Schedule themeSchedule = new Schedule(); using (WebClient client = new WebClient()) { try { using (Stream stream = client.OpenRead(tagFile)) { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Schedule)); //stream.Position = 0; themeSchedule = (Schedule)ser.ReadObject(stream); } } catch (WebException ex) { } } foreach (HomeTheme theme in themeSchedule.schedule) { DateTime scheduleDate = DateTime.Parse(theme.date); if (scheduleDate < DateTime.UtcNow) { hpThemes = theme; } else { break; } } return(hpThemes); }
public static Dictionary <int, List <Object> > getHPFeaturedTags(long userId, string db) { Dictionary <int, List <Object> > featuredTags = new Dictionary <int, List <Object> >(); HomeTheme edTags = GetEditorialTags(); //add the editorial info List <Object> editorialInfo = new List <Object>(); editorialInfo.Add(edTags.editionType); editorialInfo.Add(edTags.editionNumber); editorialInfo.Add(edTags.headline); featuredTags.Add(0, editorialInfo); string hpTags = string.Empty; foreach (Theme theme in edTags.themes) { hpTags += (theme.themeName + ","); } hpTags = hpTags.TrimEnd(','); string query = "EXEC [stp_SS_GetHPFeaturedTags] @userId=" + userId + ",@hpTags='" + hpTags.Replace("'", "''") + "'"; SqlConnection myConnection = new SqlConnection(db); try { myConnection.Open(); using (SqlDataAdapter adp = new SqlDataAdapter(query, myConnection)) { SqlCommand cmd = adp.SelectCommand; cmd.CommandTimeout = 300000; System.Data.SqlClient.SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { Tag tag = Tag.GetTagFromSqlReader(dr); int slot = 0; if (ColumnExists(dr, "slot") && !string.IsNullOrEmpty(dr["slot"].ToString())) { slot = int.Parse(dr["slot"].ToString()); } if (!featuredTags.ContainsKey(slot)) { List <Object> tags = new List <Object>(); tags.Add(tag); featuredTags.Add(slot, tags); } else { featuredTags[slot].Add(tag); } } } } finally { myConnection.Close(); } return(featuredTags); }