private void DoAutoSubscription() { // Connect to DB and prepare command SqlConnection conn = FoeServerDb.OpenDb(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from AutoSubscriptions where DtSubscribed>=@oldestTime"; cmd.Parameters.Add("@oldestTime", System.Data.SqlDbType.DateTime); cmd.Prepare(); // Calculate the oldest time that we will support DateTime oldest = DateTime.Now.Subtract(new TimeSpan(2, 0, 0)); // Run query cmd.Parameters["@oldestTime"].Value = oldest; SqlDataReader reader = cmd.ExecuteReader(); // Get subscribers FoeServerAutoSubscriber sub = null; while ((sub = FoeServerAutoSubscribe.GetNextAutoSubscriberFromSqlReader(reader)) != null) { // Compare the dates to see if last updated is newer than the RSS cache FoeServerRssFeed feed = FoeServerCatalog.GetRssFeedCache(sub.CatalogCode); if ((feed != null) && (feed.DtLastUpdated > sub.DtLastUpdated)) { try { // we need to send the latest news to user FoeServerCatalog.SendRssCache(sub.CatalogCode, sub.UserEmail, sub.RequestId, true); FoeServerLog.Add(_processName, FoeServerLog.LogType.Message, "Sent updated RSS feed to " + sub.UserEmail); } catch (Exception except) { FoeServerLog.Add(_processName, FoeServerLog.LogType.Error, "Error sending updated RSS feed to " + sub.UserEmail + ":\r\n" + except.ToString()); } } else { // User already has the latest feed. } } reader.Close(); conn.Close(); }
/// <summary> /// Check if there is anything new in the feed provided. /// This function will check against the database and see if there are any new /// RSS items. If so, it will return true. /// </summary> /// <param name="feed">Feed to check.</param> /// <returns>If the feed is newer than what is in the DB, then returns true. Otherwise, return false.</returns> static int CheckIfNewer(string catalogCode, string rss) { //0 old, 1 new, 2 newer int isNewer = 0; // Prepare SQL connection SqlConnection conn = FoeServerDb.OpenDb(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from RssFeeds where Code=@catalogCode"; cmd.Parameters.Add("@catalogCode", System.Data.SqlDbType.NVarChar, 10); cmd.Prepare(); cmd.Parameters["@catalogCode"].Value = catalogCode; //check if update the catalog the first time SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { //Rss in the cache XmlDocument oldRss = new XmlDocument(); oldRss.LoadXml((string)reader["Rss"]); XmlNodeList oldItems = oldRss.GetElementsByTagName("item"); XmlNode oldItem = oldItems[0]; string oldTitle = oldItem["title"].InnerText; //Rss now XmlDocument newRss = new XmlDocument(); newRss.LoadXml(rss); XmlNodeList newItems = newRss.GetElementsByTagName("item"); XmlNode newItem = newItems[0]; string newTitle = newItem["title"].InnerText; if (oldTitle != newTitle) { isNewer = 2; } } else { isNewer = 1; } reader.Close(); conn.Close(); return(isNewer); }
private static void doTest(string rss) { SqlConnection conn = FoeServerDb.OpenDb(); SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "insert into RssFeeds (Code, Rss, DtLastUpdated) values (@code, @rss, @dtLastUpdated)"; cmd.Parameters.Add("@code", SqlDbType.NVarChar, 10); cmd.Parameters.Add("@rss", SqlDbType.NVarChar, -1); cmd.Parameters.Add("@dtLastUpdated", SqlDbType.DateTime); cmd.Prepare(); cmd.Parameters["@code"].Value = "CKXX"; cmd.Parameters["@rss"].Value = rss; cmd.Parameters["@dtLastUpdated"].Value = DateTime.Now; cmd.ExecuteNonQuery(); conn.Close(); }
private void DoRegistration() { SqlConnection conn = FoeServerDb.OpenDb(); SqlConnection completeConn = FoeServerDb.OpenDb(); // Query that gets all pending requests. SqlCommand cmd = conn.CreateCommand(); cmd.CommandText = "select * from Requests where Status='P' and ProcessorEmail=@processorEmail and RequestType=@requestType"; cmd.Parameters.Add("@processorEmail", System.Data.SqlDbType.NVarChar, 256); cmd.Parameters.Add("@requestType", System.Data.SqlDbType.NVarChar, 10); cmd.Prepare(); // Query that marks request as "C" (Completed) SqlCommand completeCmd = completeConn.CreateCommand(); completeCmd.CommandText = "update Requests set DtProcessed=@dtProcessed, Status='C' where id=@id"; completeCmd.Parameters.Add("@dtProcessed", System.Data.SqlDbType.DateTime); completeCmd.Parameters.Add("@id", System.Data.SqlDbType.Int); completeCmd.Prepare(); //FoeDebug.Print("Getting pending requests."); // Get all pending requests cmd.Parameters["@processorEmail"].Value = FoeServerRegistry.Get("ProcessorEmail"); cmd.Parameters["@requestType"].Value = FoeServerRequest.RequestTypeToString(RequestType.Registration); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = (int)FoeServerDb.GetInt32(reader, "Id"); string userEmail = FoeServerDb.GetString(reader, "UserEmail"); string requestId = FoeServerDb.GetString(reader, "RequestId"); //FoeDebug.Print("Processing " + userEmail); // Create new user account FoeUser user = FoeServerUser.RegisterUser(userEmail); // Mark request as "C" (Completed) completeCmd.Parameters["@dtProcessed"].Value = DateTime.Now; completeCmd.Parameters["@id"].Value = id; completeCmd.ExecuteNonQuery(); // Send response back to user SmtpServer server = FoeServerMessage.GetDefaultSmtpServer(); string subject = "Re: Register " + requestId + " by Newbie"; FoeServerMessage.SendMessage(server, FoeServerRegistry.Get("ProcessorEmail"), user.Email, subject, user.UserId); FoeServerLog.Add(_processName, FoeServerLog.LogType.Message, "Completed registration for " + userEmail); //FoeDebug.Print("Sent reply to " + userEmail); //FoeDebug.Print(""); } reader.Close(); // Close connections conn.Close(); completeConn.Close(); }