static void TestGetUser() { // Test GetUser() try { PrintTitle("Testing GetUser()"); FoeUser user = FoeServerUser.GetUser(sampleEmail); if (user == null) { Console.WriteLine("Cannot find " + sampleEmail); } else { Console.WriteLine("User found."); Console.WriteLine("ID: " + user.Id); Console.WriteLine("Email: " + user.Email); Console.WriteLine("User ID: " + user.UserId); Console.WriteLine("Date Created: " + user.DtCreated.ToString()); Console.WriteLine("Verification Code: " + user.VerificationCode); Console.WriteLine("Is Verified: " + (user.IsVerified ? "true" : "false")); Console.WriteLine("Date Verified: " + ((user.DtVerified == null) ? "NULL" : user.DtVerified.ToString())); Console.WriteLine("Processor Email: " + user.ProcessorEmail); } } catch (Exception except) { Console.WriteLine(except.ToString()); } }
static void TestAssignProcessorEmail() { // Test AssignProcessorEmail PrintTitle("Testing AssignProcessorEmail()"); Console.WriteLine("Processor email: " + FoeServerUser.AssignProcessorEmail(sampleEmail)); }
static void TestGenerateUserId() { // Test GenerateUserId() PrintTitle("Testing GenerateUserId()"); string email = sampleEmail; for (int i = 0; i < 20; i++) { Console.WriteLine(i.ToString() + ": " + FoeServerUser.GenerateUserId(email)); } }
static void TestRegisterUser() { // Test RegisterUser() try { PrintTitle("Testing RegisterUser()"); FoeServerUser.RegisterUser(sampleEmail); Console.WriteLine("User registered."); } catch (Exception except) { Console.WriteLine(except.ToString()); } }
static void TestUpdateUser() { // Test UpdateUser() try { PrintTitle("Test UpdateUser()"); Console.WriteLine("Loading user info for " + sampleEmail); FoeUser updateUser = FoeServerUser.GetUser(sampleEmail); Console.WriteLine("Resetting IsVerified and clear DtVerified."); updateUser.IsVerified = false; updateUser.DtVerified = null; Console.WriteLine("Calling UpdateUser()."); FoeServerUser.UpdateUser(updateUser); Console.WriteLine("Done."); } catch (Exception except) { Console.WriteLine(except.ToString()); } }
private void DoFeedAdd() { //FoeDebug.Print("Loading requests..."); bool hasError = false; string message = ""; // Load content requests FoeRequester req = null; FoeServerRequest requestManager = new FoeServerRequest(RequestType.Feed, FoeServerRegistry.Get("ProcessorEmail")); while ((req = requestManager.GetNextRequest()) != null) { //FoeDebug.Print("Processing request from " + req.UserEmail + " with request ID " + req.RequestId); // Check what contents are requested // Get user info FoeUser user = FoeServerUser.GetUser(req.UserEmail); if (user == null) { //FoeDebug.Print("User not registered. Skip this request."); //FoeDebug.Print("---------------------------------------"); // User is not registered, mark this request as "E" (Error) and skip to the next one requestManager.UpdateRequestStatus(req, "E"); FoeServerLog.Add(_processName, FoeServerLog.LogType.Warning, "User " + user.Email + " not registered. Discard content request."); continue; } //FoeDebug.Print("User verified."); // Process request List <CatalogItem> catalogs = FoeServerCatalog.GetCatalog(); // get all the catalogs on server if (catalogs != null) { //FoeDebug.Print("Generated Foe Message."); foreach (CatalogItem catalog in catalogs) { message += catalog.Code + ","; } // Send reply to user try { FoeServerMessage.SendMessage( FoeServerMessage.GetDefaultSmtpServer(), FoeServerRegistry.Get("ProcessorEmail"), req.UserEmail, SubjectGenerator.ReplySubject(RequestType.Catalog, req.RequestId, FoeServerUser.GetUser(req.UserEmail).UserId), message); //FoeDebug.Print("Sent reply to user."); } catch (Exception except) { //FoeDebug.Print("Error sending email."); //FoeDebug.Print(except.ToString()); hasError = true; FoeServerLog.Add(_processName, FoeServerLog.LogType.Error, "Error delivering content to " + user.Email + "\r\n" + except.ToString()); } } // If there is no error, then we'll mark the request as 'C' (Completed). // Otherwise, we'll leave it as 'P' (Pending). if (!hasError) { // mark request as "C" (Completed) requestManager.UpdateRequestStatus(req, "C"); FoeServerLog.Add(_processName, FoeServerLog.LogType.Message, "Sent " + message + "to " + user.Email + " and added user to AutoSubscription."); //FoeDebug.Print("Marked request as 'C' (Completed)."); //FoeDebug.Print("----------------------------------"); } else { //FoeDebug.Print("Leave request as 'P' (Pending)."); //FoeDebug.Print("-------------------------------"); FoeServerLog.Add(_processName, FoeServerLog.LogType.Error, "Error delivering content but error is likely caused by temporary email downtime. " + "Leave status as 'P' (Pending) so process can try again later."); } } // Close all requestManager connections requestManager.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(); }