public static List <FoeClientCatalogItem> GetAll() { List <FoeClientCatalogItem> catalog = new List <FoeClientCatalogItem>(); // Open data and prepare command SQLiteConnection conn = FoeClientDb.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from catalog order by name"; cmd.Prepare(); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { // Get catalog item from database FoeClientCatalogItem item = new FoeClientCatalogItem(); item.Code = reader.GetString(reader.GetOrdinal("code")); string isSubscribed = reader.GetString(reader.GetOrdinal("issubscribed")); item.IsSubscribed = ((isSubscribed == "T") ? true : false); item.ContentType = reader.GetString(reader.GetOrdinal("contenttype")); item.Name = reader.GetString(reader.GetOrdinal("name")); item.Description = reader.GetString(reader.GetOrdinal("description")); item.DtLastUpdated = reader.GetDateTime(reader.GetOrdinal("dtlastupdated")); catalog.Add(item); } reader.Close(); conn.Close(); return(catalog); }
public static void Add(FoeClientCatalogItem item) { // First delete existing item if it exists Delete(item.Code); // Connect to DB SQLiteConnection conn = FoeClientDb.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = "insert into catalog (code, issubscribed, name, description, contenttype, dtlastupdated)" + "values (@code, @issubscribed, @name, @description, @contenttype, @dtlastupdated)"; cmd.Parameters.Add("@name", System.Data.DbType.String, 128); cmd.Parameters.Add("@description", System.Data.DbType.String, 512); cmd.Parameters.Add("@contenttype", System.Data.DbType.String, 32); cmd.Parameters.Add("@issubscribed", System.Data.DbType.String, 1); cmd.Parameters.Add("@code", System.Data.DbType.String, 10); cmd.Parameters.Add("@dtlastupdated", System.Data.DbType.Time); cmd.Prepare(); cmd.Parameters["@name"].Value = item.Name; cmd.Parameters["@description"].Value = item.Description; cmd.Parameters["@contenttype"].Value = item.ContentType; cmd.Parameters["@issubscribed"].Value = (item.IsSubscribed ? "T" : "F"); cmd.Parameters["@code"].Value = item.Code; cmd.Parameters["@dtlastupdated"].Value = item.DtLastUpdated; cmd.ExecuteNonQuery(); conn.Close(); }
public static FoeClientCatalogItem Get(string catalogCode) { FoeClientCatalogItem item = null; // Connect to DB SQLiteConnection conn = FoeClientDb.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from catalog where code=@code"; cmd.Parameters.Add("@code", System.Data.DbType.String, 10); cmd.Prepare(); cmd.Parameters["@code"].Value = catalogCode; SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { // Get catalog item from database item = new FoeClientCatalogItem(); item.Code = reader.GetString(reader.GetOrdinal("code")); item.IsSubscribed = ((reader.GetString(reader.GetOrdinal("issubscribed")) == "T") ? true : false); item.ContentType = reader.GetString(reader.GetOrdinal("contenttype")); item.Name = reader.GetString(reader.GetOrdinal("name")); item.Description = reader.GetString(reader.GetOrdinal("description")); item.DtLastUpdated = reader.GetDateTime(reader.GetOrdinal("dtlastupdated")); } reader.Close(); conn.Close(); return(item); }
public static FoeClientCatalogItem Get(string catalogCode) { FoeClientCatalogItem item = null; // Connect to DB SQLiteConnection conn = FoeClientDb.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from catalog where code=@code"; cmd.Parameters.Add("@code", System.Data.DbType.String, 10); cmd.Prepare(); cmd.Parameters["@code"].Value = catalogCode; SQLiteDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { // Get catalog item from database item = new FoeClientCatalogItem(); item.Code = reader.GetString(reader.GetOrdinal("code")); item.IsSubscribed = ((reader.GetString(reader.GetOrdinal("issubscribed")) == "T") ? true : false); item.ContentType = reader.GetString(reader.GetOrdinal("contenttype")); item.Name = reader.GetString(reader.GetOrdinal("name")); item.Description = reader.GetString(reader.GetOrdinal("description")); item.DtLastUpdated = reader.GetDateTime(reader.GetOrdinal("dtlastupdated")); } reader.Close(); conn.Close(); return item; }
private static void ProcessContentReply(string xml) { // Load the xml document XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); // Get RSS Feed string rssBase64 = doc.GetElementsByTagName("Rss")[0].InnerText; // Get Catalog Code string catalogCode = doc.GetElementsByTagName("CatalogCode")[0].InnerText; // The RSS is base64 encoded, so we need to decode it string rss = Encoding.UTF8.GetString(Convert.FromBase64String(rssBase64)); // Save RSS feed to file TextWriter writer = new StreamWriter("rss\\" + catalogCode + ".rss", false); writer.Write(rss); writer.Close(); // Update catalog last updated time FoeClientCatalogItem item = FoeClientCatalog.Get(catalogCode); item.DtLastUpdated = DateTime.Now; FoeClientCatalog.Add(item); }
private static void ProcessCatalogReply(string xml) { List <FoeClientCatalogItem> catalog = new List <FoeClientCatalogItem>(); // Load the xml document XmlDocument rawDoc = new XmlDocument(); rawDoc.LoadXml(xml); // Get RSS Feed string rssBase64 = rawDoc.GetElementsByTagName("Rss")[0].InnerText; // The RSS is base64 encoded, so we need to decode it string rss = Encoding.UTF8.GetString(Convert.FromBase64String(rssBase64)); // Within the RSS is the catalog in XML format XmlDocument doc = new XmlDocument(); doc.LoadXml(rss); // Get catalog list XmlNodeList nodes = doc.GetElementsByTagName("CatalogItem"); foreach (XmlNode item in nodes) { FoeClientCatalogItem newItem = new FoeClientCatalogItem(); newItem.Code = item["Code"].InnerText; newItem.ContentType = item["ContentType"].InnerText; newItem.Name = item["Name"].InnerText; newItem.Description = item["Description"].InnerText; newItem.IsSubscribed = false; newItem.DtLastUpdated = DateTime.Now; // Check if the catalog item already exists FoeClientCatalogItem curr = FoeClientCatalog.Get(newItem.Code); if (curr != null) { // It already existed, we'll update it but keep the subscription status newItem.IsSubscribed = curr.IsSubscribed; newItem.DtLastUpdated = curr.DtLastUpdated; } catalog.Add(newItem); } // Check if list is empty if (catalog.Count > 0) { // Delete current catalog FoeClientCatalog.DeleteAll(); foreach (FoeClientCatalogItem item in catalog) { FoeClientCatalog.Add(item); } } }
private static void ProcessContentReply(string catalog, string foe) { // Save RSS to file TextWriter writer = new StreamWriter(@"rss\\" + catalog + ".rss", false); writer.Write(foe); writer.Close(); // Update catalog last updated time FoeClientCatalogItem item = FoeClientCatalog.Get(catalog); item.DtLastUpdated = DateTime.Now; FoeClientCatalog.Add(item); }
private static void ProcessCatalogReply(string foe) { string[] catalogs = foe.Trim().Split(new char[] { ',' }); // Check if list is empty if (catalogs.Length > 0) { // Delete current catalog FoeClientCatalog.DeleteAll(); for (int i = 0; i < catalogs.Length - 1; i++) { FoeClientCatalogItem item = new FoeClientCatalogItem(); item.Code = catalogs[i]; item.IsSubscribed = false; item.DtLastUpdated = DateTime.Now; FoeClientCatalog.Add(item); } } }
private static void ProcessCatalogReply(string xml) { List<FoeClientCatalogItem> catalog = new List<FoeClientCatalogItem>(); // Load the xml document XmlDocument rawDoc = new XmlDocument(); rawDoc.LoadXml(xml); // Get RSS Feed string rssBase64 = rawDoc.GetElementsByTagName("Rss")[0].InnerText; // The RSS is base64 encoded, so we need to decode it string rss = Encoding.UTF8.GetString(Convert.FromBase64String(rssBase64)); // Within the RSS is the catalog in XML format XmlDocument doc = new XmlDocument(); doc.LoadXml(rss); // Get catalog list XmlNodeList nodes = doc.GetElementsByTagName("CatalogItem"); foreach(XmlNode item in nodes) { FoeClientCatalogItem newItem = new FoeClientCatalogItem(); newItem.Code = item["Code"].InnerText; newItem.ContentType = item["ContentType"].InnerText; newItem.Name = item["Name"].InnerText; newItem.Description = item["Description"].InnerText; newItem.IsSubscribed = false; newItem.DtLastUpdated = DateTime.Now; // Check if the catalog item already exists FoeClientCatalogItem curr = FoeClientCatalog.Get(newItem.Code); if (curr != null) { // It already existed, we'll update it but keep the subscription status newItem.IsSubscribed = curr.IsSubscribed; newItem.DtLastUpdated = curr.DtLastUpdated; } catalog.Add(newItem); } // Check if list is empty if (catalog.Count > 0) { // Delete current catalog FoeClientCatalog.DeleteAll(); foreach (FoeClientCatalogItem item in catalog) { FoeClientCatalog.Add(item); } } }
public static List<FoeClientCatalogItem> GetAll() { List<FoeClientCatalogItem> catalog = new List<FoeClientCatalogItem>(); // Open data and prepare command SQLiteConnection conn = FoeClientDb.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from catalog order by name"; cmd.Prepare(); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { // Get catalog item from database FoeClientCatalogItem item = new FoeClientCatalogItem(); item.Code = reader.GetString(reader.GetOrdinal("code")); string isSubscribed = reader.GetString(reader.GetOrdinal("issubscribed")); item.IsSubscribed = ((isSubscribed == "T") ? true : false); item.ContentType = reader.GetString(reader.GetOrdinal("contenttype")); item.Name = reader.GetString(reader.GetOrdinal("name")); item.Description = reader.GetString(reader.GetOrdinal("description")); item.DtLastUpdated = reader.GetDateTime(reader.GetOrdinal("dtlastupdated")); catalog.Add(item); } reader.Close(); conn.Close(); return catalog; }