protected void Button1_Click(object sender, EventArgs e) { NotificationManager notification = new NotificationManager(); notification.PrepareNotification(NotificationType.ContactUsMessage, null); notification.SendNotification(NotificationType.ContactUsMessage); }
public bool SendContactUsMessage(string senderName, string senderEmail, string comment) { try { //send notification NotificationManager notification = new NotificationManager(); Hashtable msgParams = new Hashtable(); msgParams.Add("Description", (comment.Length > 64 ? comment.Substring(0, 64) + ".." : comment)); msgParams.Add("Name", senderName); msgParams.Add("Email", senderEmail); msgParams.Add("Comment", comment); notification.PrepareNotification(NotificationType.ContactUsMessage, msgParams); //notify default system recipients return(notification.SendNotification(NotificationType.ContactUsMessage)); } catch (Exception exp) { System.Diagnostics.Debug.WriteLine(exp.ToString()); return(false); //failed } }
public int SendAllPendingSubscriptionNotifications(string templateFolderPath) { int notificationsSent = 0; List <int> subscriptionsNotified = new List <int>(); List <int> subscriptionsSkipped = new List <int>(); var allSubscriptionMatches = GetAllSubscriptionMatches(true); var userManager = new UserManager(); NotificationManager notificationManager = new NotificationManager(); notificationManager.TemplateFolderPath = templateFolderPath; foreach (var subscriptionMatch in allSubscriptionMatches) { if (subscriptionMatch.SubscriptionMatches != null && subscriptionMatch.SubscriptionMatches.Count > 0) { bool hasItemMatches = subscriptionMatch.SubscriptionMatches.Any(m => m.ItemList.Count > 0); if (hasItemMatches) { string summaryHTML = GetSubscriptionMatchHTMLSummary(subscriptionMatch); var userDetails = userManager.GetUser(subscriptionMatch.Subscription.UserID); //prepare and send email Hashtable msgParams = new Hashtable(); msgParams.Add("SummaryContent", summaryHTML); msgParams.Add("SubscriptionTitle", subscriptionMatch.Subscription.Title); msgParams.Add("UserName", userDetails.Username); msgParams.Add("SubscriptionEditURL", "https://openchargemap.org/site/profile/subscriptionedit?id=" + subscriptionMatch.Subscription.ID); if (!String.IsNullOrEmpty(userDetails.EmailAddress)) { notificationManager.PrepareNotification(NotificationType.SubscriptionNotification, msgParams); bool sentOK = notificationManager.SendNotification(userDetails.EmailAddress); if (sentOK) { notificationsSent++; subscriptionsNotified.Add(subscriptionMatch.Subscription.ID); } } } else { subscriptionsSkipped.Add(subscriptionMatch.Subscription.ID); } //mark all subscriptions notified where sent ok var dataModel = new OCM.Core.Data.OCMEntities(); foreach (var subscriptionId in subscriptionsNotified) { var s = dataModel.UserSubscriptions.Find(subscriptionId); s.DateLastNotified = DateTime.UtcNow; } //mark all subscriptions with no matching items as processed/skipped foreach (var subscriptionId in subscriptionsSkipped) { var s = dataModel.UserSubscriptions.Find(subscriptionId); s.DateLastNotified = DateTime.UtcNow; } dataModel.SaveChanges(); } } return(notificationsSent); }
public static void ReportWebException(HttpServerUtility Server, AuditEventType eventType, string msg=null) { bool ignoreException = false; string body = "An error has occurred while a user was browsing OCM:<br><br>"; if (msg!=null) { body = msg; } object exceptionObject = null; if (Server.GetLastError() != null) { Exception exp = Server.GetLastError(); exceptionObject = exp; if (exp.InnerException != null) { exceptionObject = exp.InnerException; } body += ((Exception)exceptionObject).ToString(); if (HttpContext.Current != null) { HttpContext con = HttpContext.Current; if (con.Request.Url != null) { body += "<br><br>Request Url:" + con.Request.Url.ToString(); //special case to avoid reporting /trackback url exceptions if (con.Request.Url.ToString().EndsWith("/trackback/")) ignoreException = true; } if (con.Request.UserAgent != null) { body += "<br>User Agent: " + con.Request.UserAgent; } } body += "<br><br>" + DateTime.UtcNow.ToString(); } if (exceptionObject is System.Web.HttpRequestValidationException || exceptionObject is System.Web.UI.ViewStateException) ignoreException = true; if (!ignoreException) { if (ConfigurationManager.AppSettings["EnableErrorNotifications"] == "true") { NotificationManager notification = new NotificationManager(); var msgParams = new Hashtable(){ {"Description", "System Error"}, {"Name", "OCM Website"}, {"Email", "*****@*****.**"}, {"Comment", body} }; notification.PrepareNotification(NotificationType.ContactUsMessage, msgParams); notification.SendNotification(NotificationType.ContactUsMessage); } AuditLogManager.Log(null, eventType, body, null); } }
public static void ReportWebException(HttpServerUtility Server, AuditEventType eventType) { bool ignoreException = false; string body = "An error has occurred while a user was browsing OCM:<br><br>"; object exceptionObject = null; if (Server.GetLastError() != null) { Exception exp = Server.GetLastError(); exceptionObject = exp; if (exp.InnerException != null) { exceptionObject = exp.InnerException; } body += ((Exception)exceptionObject).ToString(); HttpContext con = HttpContext.Current; if (con.Request.Url != null) { body += "<br><br>Request Url:" + con.Request.Url.ToString(); //special case to avoid reporting /trackback url exceptions if (con.Request.Url.ToString().EndsWith("/trackback/")) { ignoreException = true; } } if (con.Request.UserAgent != null) { body += "<br>User Agent: " + con.Request.UserAgent; } body += "<br><br>" + DateTime.UtcNow.ToString(); } if (exceptionObject is System.Web.HttpRequestValidationException || exceptionObject is System.Web.UI.ViewStateException) { ignoreException = true; } if (!ignoreException) { if (ConfigurationManager.AppSettings["EnableErrorNotifications"] == "true") { NotificationManager notification = new NotificationManager(); var msgParams = new Hashtable() { { "Description", "System Error" }, { "Name", "OCM Website" }, { "Email", "*****@*****.**" }, { "Comment", body } }; notification.PrepareNotification(NotificationType.ContactUsMessage, msgParams); notification.SendNotification(NotificationType.ContactUsMessage); } AuditLogManager.Log(null, eventType, body, null); } }
public static void ReportWebException(bool enableNotifications, string contextUrl, AuditEventType eventType, string msg = null, Exception exp = null) { bool ignoreException = false; string body = "An error has occurred while a user was browsing OCM:<br><br>"; if (msg != null) { body = msg; } if (exp != null) { object exceptionObject = exp; if (exp.InnerException != null) { exceptionObject = exp.InnerException; } body += ((Exception)exceptionObject).ToString(); if (contextUrl != null) { body += "<br><br>Request Url:" + contextUrl.ToString(); //special case to avoid reporting /trackback url exceptions if (contextUrl.ToString().EndsWith("/trackback/")) { ignoreException = true; } } /*if (con.Request.UserAgent != null) * { * body += "<br>User Agent: " + con.Request.UserAgent; * }*/ } body += "<br><br>" + DateTime.UtcNow.ToString(); //if (exp is System.Web.HttpRequestValidationException || exceptionObject is System.Web.UI.ViewStateException) ignoreException = true; if (!ignoreException) { if (enableNotifications) { NotificationManager notification = new NotificationManager(); var msgParams = new Hashtable() { { "Description", "System Error" }, { "Name", "OCM Website" }, { "Email", "*****@*****.**" }, { "Comment", body } }; notification.PrepareNotification(NotificationType.ContactUsMessage, msgParams); notification.SendNotification(NotificationType.ContactUsMessage); } AuditLogManager.Log(null, eventType, body, null); } }
public bool BeginPasswordReset(string email) { var user = dataModel.Users.FirstOrDefault(u => u.EmailAddress.ToLower() == email.ToLower()); if (user != null) { //update session token and send as verification token AssignNewSessionToken(user.ID); string resetConfirmationURL = "http://openchargemap.org/site/loginprovider/confirmpasswordreset?token=" + System.Web.HttpUtility.UrlEncode(user.CurrentSessionToken) + "&email=" + System.Web.HttpUtility.UrlEncode(email.ToLower()); //send notification var msgParams = new Hashtable(); msgParams.Add("Email", user.EmailAddress.ToLower()); msgParams.Add("ResetConfirmationURL", resetConfirmationURL); var notificationManager = new NotificationManager(); notificationManager.PrepareNotification(NotificationType.PasswordReset, msgParams); bool sentOK = notificationManager.SendNotification(user.EmailAddress); return sentOK; } else { //user not found, can't begin password reset return false; } }
private static void SendPOICommentSubmissionNotifications(Common.Model.UserComment comment, Model.User user, Core.Data.UserComment dataComment) { try { //prepare notification NotificationManager notification = new NotificationManager(); Hashtable msgParams = new Hashtable(); msgParams.Add("Description", ""); msgParams.Add("ChargePointID", comment.ChargePointID); msgParams.Add("ItemURL", "http://openchargemap.org/site/poi/details/" + comment.ChargePointID); msgParams.Add("UserName", user != null ? user.Username : comment.UserName); msgParams.Add("MessageBody", "Comment (" + dataComment.UserCommentType.Title + ") added to OCM-" + comment.ChargePointID + ": " + dataComment.Comment); //if fault report, attempt to notify operator if (dataComment.UserCommentType.ID == (int)StandardCommentTypes.FaultReport) { //decide if we can send a fault notification to the operator notification.PrepareNotification(NotificationType.FaultReport, msgParams); //notify default system recipients bool operatorNotified = false; if (dataComment.ChargePoint.Operator != null) { if (!String.IsNullOrEmpty(dataComment.ChargePoint.Operator.FaultReportEmail)) { try { notification.SendNotification(dataComment.ChargePoint.Operator.FaultReportEmail, ConfigurationManager.AppSettings["DefaultRecipientEmailAddresses"].ToString()); operatorNotified = true; } catch (Exception) { System.Diagnostics.Debug.WriteLine("Fault report: failed to notify operator"); } } } if (!operatorNotified) { notification.Subject += " (OCM: Could not notify Operator)"; notification.SendNotification(NotificationType.LocationCommentReceived); } } else { //normal comment, notification to OCM only notification.PrepareNotification(NotificationType.LocationCommentReceived, msgParams); //notify default system recipients notification.SendNotification(NotificationType.LocationCommentReceived); } } catch (Exception) { ; ; // failed to send notification } }
private static void SendNewPOISubmissionNotification(Model.ChargePoint poi, Model.User user, Core.Data.ChargePoint cpData) { try { string approvalStatus = cpData.SubmissionStatusType.Title; //send notification NotificationManager notification = new NotificationManager(); Hashtable msgParams = new Hashtable(); msgParams.Add("Description", "OCM-" + cpData.ID + " : " + poi.AddressInfo.Title); msgParams.Add("SubmissionStatusType", approvalStatus); msgParams.Add("ItemURL", "http://openchargemap.org/site/poi/details/" + cpData.ID); msgParams.Add("ChargePointID", cpData.ID); msgParams.Add("UserName", user != null ? user.Username : "******"); msgParams.Add("MessageBody", "New Location " + approvalStatus + " OCM-" + cpData.ID + " Submitted: " + poi.AddressInfo.Title); notification.PrepareNotification(NotificationType.LocationSubmitted, msgParams); //notify default system recipients notification.SendNotification(NotificationType.LocationSubmitted); } catch (Exception) { ; ; //failed to send notification } }
public bool SendContactUsMessage(string senderName, string senderEmail, string comment) { try { //send notification NotificationManager notification = new NotificationManager(); Hashtable msgParams = new Hashtable(); msgParams.Add("Description", (comment.Length > 64 ? comment.Substring(0, 64) + ".." : comment)); msgParams.Add("Name", senderName); msgParams.Add("Email", senderEmail); msgParams.Add("Comment", comment); notification.PrepareNotification(NotificationType.ContactUsMessage, msgParams); //notify default system recipients return notification.SendNotification(NotificationType.ContactUsMessage); } catch (Exception) { return false; //failed } }