private static void AsyncProcessMailerQueue(object data) { if (mailerLock) { return; } try { mailerLock = true; BirthdaySearch search = new BirthdaySearch(); UserSearchResults results = search.GetResults(); if (results != null) { foreach (string username in results.Usernames) { User user = null; try { user = User.Load(username); } catch (NotFoundException) { continue; } Event evt = new Event(username); evt.Type = Event.eType.FriendBirthday; evt.Save(); string[] usernames = User.FetchMutuallyFriends(username); foreach (string recipient in usernames) { User u = null; try { u = User.Load(recipient); } catch (NotFoundException) { continue; } MiscTemplates.FriendBirthday friendBirthdayTemplate = new MiscTemplates.FriendBirthday(u.LanguageId); Message.Send(Config.Users.SystemUsername, recipient, friendBirthdayTemplate.Message.Replace("%%USERNAME%%", username), 0); if (Config.Users.NewEventNotification) { int imageID = 0; try { imageID = Photo.GetPrimary(user.Username).Id; } catch (NotFoundException) { imageID = ImageHandler.GetPhotoIdByGender(user.Gender); } string text = String.Format("{0} has a birthday today".Translate(), "<b>" + user.Username + "</b>"); string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true); User.SendOnlineEventNotification(user.Username, recipient, text, thumbnailUrl, UrlRewrite.CreateShowUserUrl(user.Username)); } } } } } catch (Exception err) { Global.Logger.LogError("FriendBirthdayEmails", err); } finally { mailerLock = false; } }
private static void AsyncProcessMailerQueue(object data) { if (mailerLock) { return; } try { mailerLock = true; if (DateTime.Now.DayOfWeek == DayOfWeek.Monday) { using (var db = new AspNetDatingDataContext()) { var friendsWithCommingBirthdays = CompiledQueries.FetchActiveFriendsByBirthday(db, 7); var usernames = friendsWithCommingBirthdays.Select(f => f.u_username).Distinct(); foreach (string recipient in usernames) { User u = null; try { u = User.Load(recipient); } catch (NotFoundException) { continue; } var hisBirthdaysFriends = friendsWithCommingBirthdays .Where(f => f.u_username == recipient) .Select(f => f.f_username).ToArray(); MiscTemplates.FriendBirthday friendBirthdayTemplate = new MiscTemplates.FriendBirthday(u.LanguageId); var frUsernames = string.Join(",\r\n", hisBirthdaysFriends); Message.Send(Config.Users.SystemUsername, recipient, friendBirthdayTemplate.Message.Replace("%%USERNAMES%%", frUsernames), 0); } } } BirthdaySearch search = new BirthdaySearch(); UserSearchResults results = search.GetResults(); if (results != null && results.Usernames != null) { foreach (string username in results.Usernames) { User user = null; try { user = User.Load(username); } catch (NotFoundException) { continue; } Event evt = new Event(username); evt.Type = Event.eType.FriendBirthday; evt.Save(); string[] usernames = User.FetchMutuallyFriends(username); foreach (string recipient in usernames) { User u = null; try { u = User.Load(recipient); } catch (NotFoundException) { continue; } //MiscTemplates.FriendBirthday friendBirthdayTemplate = // new MiscTemplates.FriendBirthday(u.LanguageId); //Message.Send(Config.Users.SystemUsername, recipient, // friendBirthdayTemplate.Message.Replace("%%USERNAME%%", username), 0); if (Config.Users.NewEventNotification) { int imageID = 0; try { imageID = Photo.GetPrimary(user.Username).Id; } catch (NotFoundException) { imageID = ImageHandler.GetPhotoIdByGender(user.Gender); } string text = String.Format("{0} has a birthday today".Translate(), "<b>" + user.Username + "</b>"); string thumbnailUrl = ImageHandler.CreateImageUrl(imageID, 50, 50, false, true, true); User.SendOnlineEventNotification(user.Username, recipient, text, thumbnailUrl, UrlRewrite.CreateShowUserUrl(user.Username)); } } } } } catch (Exception err) { Global.Logger.LogError("FriendBirthdayEmails", err); } finally { mailerLock = false; } }