public override void DoWork() { try { var mifnexsoEntities = new MIFNEXSOEntities(); var listCampaignLog = from c in mifnexsoEntities.CampaignLogs where c.Status == "NEW" select c; foreach (var item in listCampaignLog.Take(100)) { CampaignLogComponent campaignLogComponent = new CampaignLogComponent(item.CampaignLogId); try { var img = string.Format(@"<div style=""display:none""><img src=""{0}clog/" + item.CampaignLogId + "\" /></div>", "http://www.nexso.org/en-us/cheese/"); item.MailContent += img; campaignLogComponent.CampaignLog.SentOn = DateTime.Now; campaignLogComponent.CampaignLog.Status = "SENT"; if (campaignLogComponent.Save() == -1) { this.ScheduleHistoryItem.Succeeded = false; Exception ee = new Exception("error database cheese"); DotNetNuke.Services.Exceptions.Exceptions.LogException(ee); } else { DotNetNuke.Services.Mail.Mail.SendEmail("*****@*****.**", item.email, item.MailSubject, item.MailContent); System.Threading.Thread.Sleep(5500); } } catch { campaignLogComponent.CampaignLog.Status = "ERROR"; if (campaignLogComponent.Save() == -1) { this.ScheduleHistoryItem.Succeeded = false; Exception ee = new Exception("error database cheese 2"); DotNetNuke.Services.Exceptions.Exceptions.LogException(ee); // return; } } } this.ScheduleHistoryItem.AddLogNote("Schedule Succeded"); //Show success this.ScheduleHistoryItem.Succeeded = true; } catch (Exception ex) { this.ScheduleHistoryItem.Succeeded = false; //InsertLogNote("Exception= " + ex.ToString()); this.Errored(ref ex); DotNetNuke.Services.Exceptions.Exceptions.LogException(ex); } }
/// <summary> /// Update the log of the email: Change status to read, obtain information to the hour, date, ip and place. /// </summary> private void ProcessCampaignTracker() { try { HttpRequest request = base.Request; string ip = request.UserHostAddress; var req = Request; CampaignLogComponent campaignLogComponent = new CampaignLogComponent(campaignLog); campaignLogComponent.CampaignLog.ReadOn = DateTime.Now; campaignLogComponent.CampaignLog.Status = "READ"; campaignLogComponent.Save(); //end the resposne var ipLocation = MIFWebServices.IpLocationService.getIpLocation(ip); if (ipLocation.isp == null) { IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName()); IPAddress[] addr = ipEntry.AddressList; ip = addr[1].ToString(); ipLocation = MIFWebServices.IpLocationService.getIpLocation(ip); } string device = "DESKTOP"; if (Request.Browser.IsMobileDevice) { device = "MOBILE"; } MailTrackerLogComponent mailTrackerLog = new MailTrackerLogComponent(); mailTrackerLog.MailTrackerLog.CampaingLogId = campaignLogComponent.CampaignLog.CampaignLogId; mailTrackerLog.MailTrackerLog.Browser = Request.Browser.Browser; mailTrackerLog.MailTrackerLog.Country = ipLocation.country; mailTrackerLog.MailTrackerLog.City = ipLocation.city; mailTrackerLog.MailTrackerLog.Latitude = Convert.ToDecimal(ipLocation.latitude); mailTrackerLog.MailTrackerLog.Longitude = Convert.ToDecimal(ipLocation.longitude); mailTrackerLog.MailTrackerLog.Device = device; mailTrackerLog.MailTrackerLog.IP = ipLocation.ip; if (Request.UserLanguages != null) { if (Request.UserLanguages.Count() > 0) { mailTrackerLog.MailTrackerLog.Language = Request.UserLanguages[0]; } } mailTrackerLog.MailTrackerLog.Network = ipLocation.isp; mailTrackerLog.Save(); } catch { } Response.ContentType = "image/png"; Response.WriteFile(MapPath(ControlPath + "/images/i_dn.png")); Response.End(); }
public static int CreateMailLog(Guid CampaignId, string trackKey, int attemp, string content, string subject, string email, int userId, Guid CampaignLogId, DateTime createdOn) { CampaignLogComponent campaignLog = new CampaignLogComponent(CampaignLogId); campaignLog.CampaignLog.Attemp = attemp; campaignLog.CampaignLog.TrackKey = trackKey; campaignLog.CampaignLog.CampaignId = CampaignId; campaignLog.CampaignLog.email = email; campaignLog.CampaignLog.MailContent = content; campaignLog.CampaignLog.MailSubject = subject; campaignLog.CampaignLog.CreatedOn = createdOn; campaignLog.CampaignLog.userId = userId; campaignLog.CampaignLog.Status = "NEW"; return(campaignLog.Save()); }
/// <summary> /// load the campaign through a CampaingLogId /// </summary> private void LoadObjects() { if (CampaingLogId != Guid.Empty) { if (Session["MailPreview"] != null) { var obj = (List <CampaignLog>)Session["MailPreview"]; campaingLog = obj.FirstOrDefault(a => a.CampaignLogId == CampaingLogId); } else { var cmm = new CampaignLogComponent(CampaingLogId); campaingLog = cmm.CampaignLog; } } }
/// <summary> /// Campaign statistics per email status (Error, seen, sent) and country /// </summary> private void DataReportCampaign() { var listCampaignLog = CampaignLogComponent.GetCampaignLog(campaignId).ToList(); if (listCampaignLog.Count > 0) { //Separates campaign for creation date var listCampaignLogGroup = listCampaignLog.GroupBy(a => a.CreatedOn); var report = new List <ReportCampaign>(); foreach (var item in listCampaignLogGroup) { //Status var errors = item.Where(a => a.Status == "ERROR"); var viewMails = item.Where(a => a.Status == "READ"); var pendingViews = item.Where(a => a.Status == "SENT"); // calculate statistics emails seen decimal effectiveness = 0; if (viewMails.ToList().Count != 0) { effectiveness = Convert.ToDecimal(viewMails.ToList().Count) / Convert.ToDecimal(item.ToList().Count); } List <string> ListCountry = new List <string>(); foreach (var item2 in viewMails.ToList()) { MailTrackerLog mailTrackerLog = MailTrackerLogComponentByCampaignLogId(item2.CampaignLogId); if (mailTrackerLog != null) { ListCountry.Add(mailTrackerLog.Country); } } //calculate statistics per cuntry: total view and percentage var ListCountryGroup = ListCountry.GroupBy(a => a); List <GeographicView> viewGeographic = new List <GeographicView>(); foreach (var country in ListCountryGroup) { var viewsPercentage = (Convert.ToDecimal(country.Count()) / Convert.ToDecimal(item.Count())) * 100; var countryName = country.Key; if (string.IsNullOrEmpty(country.Key)) { countryName = "NULL"; } viewGeographic.Add(new GeographicView { Country = countryName, TotalViews = country.Count(), ViewsPercentage = decimal.Round(viewsPercentage, 2, MidpointRounding.AwayFromZero) }); } if (viewGeographic.Count == 0) { viewGeographic = null; } else { viewGeographic = viewGeographic.OrderByDescending(a => a.TotalViews).ToList(); } report.Add(new ReportCampaign { Created = Convert.ToDateTime(item.Key), SentMails = item.Count(), Errors = errors.Count(), BouncedMail = 0, ViewMails = viewMails.Count(), PendingViews = pendingViews.Count(), Effectiveness = decimal.Round(effectiveness, 2, MidpointRounding.AwayFromZero), ViewGeographic = viewGeographic }); } var list = report.OrderByDescending(a => a.Created).ToList(); if (report.Count >= 10) { list = report.OrderByDescending(a => a.Created).ToList().GetRange(0, 10); } rpReport.DataSource = list; rpReport.DataBind(); lblMessage.Visible = false; } else { lblMessage.Visible = true; } }