private static void NotifyAbouFutureEvent(DateTime scheduleDate) { using (var dataProvider = new DataProvider()) { var notifications = dataProvider.ExtractAndRecountNotifications(scheduleDate); foreach (var data in notifications) { if (data.Event == null) { continue; } var tenant = CoreContext.TenantManager.GetTenant(data.TenantId); if (tenant == null || tenant.Status != TenantStatus.Active) { continue; } CoreContext.TenantManager.SetCurrentTenant(tenant); var r = CalendarNotifySource.Instance.GetRecipientsProvider().GetRecipient(data.UserId.ToString()); var startDate = data.GetUtcStartDate().Add(data.TimeZone.GetUtcOffset(DateTime.UtcNow)); var endDate = data.GetUtcEndDate(); endDate = (endDate == DateTime.MinValue ? DateTime.MinValue : endDate.Add(data.TimeZone.GetUtcOffset(DateTime.UtcNow))); _notifyClient.SendNoticeAsync(CalendarNotifySource.EventAlert, null, r, true, new TagValue(new Tag("EventName"), data.Event.Name), new TagValue(new Tag("EventDescription"), data.Event.Description ?? ""), new TagValue(new Tag("EventStartDate"), startDate.ToShortDateString() + " " + startDate.ToShortTimeString()), new TagValue(new Tag("EventEndDate"), (endDate > startDate) ? (endDate.ToShortDateString() + " " + endDate.ToShortTimeString()) : "")); } } }
public void NotifyAboutSharingCalendar(ASC.Calendar.BusinessObjects.Calendar calendar, ASC.Calendar.BusinessObjects.Calendar oldCalendar) { var initatorInterceptor = new InitiatorInterceptor(new DirectRecipient(AuthContext.CurrentAccount.ID.ToString(), AuthContext.CurrentAccount.Name)); try { var usr = UserManager.GetUsers(AuthContext.CurrentAccount.ID); var userLink = PerformUrl(CommonLinkUtility.GetUserProfile(usr.ID.ToString(), false)); foreach (var item in calendar.SharingOptions.PublicItems) { if (oldCalendar != null && oldCalendar.SharingOptions.PublicItems.Exists(i => i.Id.Equals(item.Id))) { continue; } var r = CalendarNotifySource.GetRecipientsProvider().GetRecipient(item.Id.ToString()); if (r != null) { _notifyClient.SendNoticeAsync(CalendarNotifySource.CalendarSharing, null, r, true, new TagValue("SharingType", "calendar"), new TagValue("UserName", usr.DisplayUserName(DisplayUserSettingsHelper)), new TagValue("UserLink", userLink), new TagValue("CalendarName", calendar.Name)); } } _notifyClient.EndSingleRecipientEvent(_syncName); } finally { _notifyClient.RemoveInterceptor(initatorInterceptor.Name); } }
private static void NotifyAbouFutureEvent(DateTime scheduleDate) { try { using (var dataProvider = new DataProvider()) { foreach (var data in dataProvider.ExtractAndRecountNotifications(scheduleDate)) { if (data.Event == null) { continue; } var tenant = CoreContext.TenantManager.GetTenant(data.TenantId); if (tenant == null || tenant.Status != TenantStatus.Active || TariffState.NotPaid <= CoreContext.PaymentManager.GetTariff(tenant.TenantId).State) { continue; } CoreContext.TenantManager.SetCurrentTenant(tenant); var r = CalendarNotifySource.Instance.GetRecipientsProvider().GetRecipient(data.UserId.ToString()); if (r == null) { continue; } var startDate = data.GetUtcStartDate(); var endDate = data.GetUtcEndDate(); if (!data.Event.AllDayLong) { startDate = startDate.Add(data.TimeZone.BaseUtcOffset); endDate = (endDate == DateTime.MinValue ? DateTime.MinValue : endDate.Add(data.TimeZone.BaseUtcOffset)); } _notifyClient.SendNoticeAsync(CalendarNotifySource.EventAlert, null, r, true, new TagValue("EventName", data.Event.Name), new TagValue("EventDescription", data.Event.Description ?? ""), new TagValue("EventStartDate", startDate.ToShortDateString() + " " + startDate.ToShortTimeString()), new TagValue("EventEndDate", (endDate > startDate) ? (endDate.ToShortDateString() + " " + endDate.ToShortTimeString()) : ""), new TagValue("Priority", 1)); } } } catch (Exception error) { LogManager.GetLogger("ASC.Notify.Calendar").Error(error); } }
public void SendNewComment(ProjectEntity entity, Comment comment) { INotifyAction action; if (entity.GetType() == typeof(Issue)) { action = NotifyConstants.Event_NewCommentForIssue; } else if (entity.GetType() == typeof(Message)) { action = NotifyConstants.Event_NewCommentForMessage; } else if (entity.GetType() == typeof(Milestone)) { action = NotifyConstants.Event_NewCommentForMilestone; } else if (entity.GetType() == typeof(Task)) { action = NotifyConstants.Event_NewCommentForTask; } else { return; } var interceptor = new InitiatorInterceptor(new DirectRecipient(SecurityContext.CurrentAccount.ID.ToString(), "")); try { client.AddInterceptor(interceptor); client.SendNoticeAsync( action, entity.NotifyId, null, new TagValue(NotifyConstants.Tag_ProjectID, entity.Project.ID), new TagValue(NotifyConstants.Tag_ProjectTitle, entity.Project.Title), new TagValue(NotifyConstants.Tag_EntityTitle, entity.Title), new TagValue(NotifyConstants.Tag_EntityID, entity.ID), new TagValue(NotifyConstants.Tag_AdditionalData, comment.Content), GetReplyToEntityTag(entity, comment)); } finally { client.RemoveInterceptor(interceptor.Name); } }
public void SendMsgToAdminAboutProfileUpdated() { client.SendNoticeAsync(Actions.SelfProfileUpdated, null, null); }
public static void SendMsgWhatsNew(DateTime scheduleDate, INotifyClient client) { var log = LogManager.GetLogger("ASC.Notify.WhatsNew"); if (WebItemManager.Instance.GetItemsAll <IProduct>().Count == 0) { log.Info("No products. Return from function"); return; } log.Info("Start send whats new."); var products = WebItemManager.Instance.GetItemsAll().ToDictionary(p => p.GetSysName()); foreach (var tenantid in GetChangedTenants(scheduleDate)) { try { var tenant = CoreContext.TenantManager.GetTenant(tenantid); if (tenant == null || tenant.Status != TenantStatus.Active || !TimeToSendWhatsNew(TenantUtil.DateTimeFromUtc(tenant.TimeZone, scheduleDate)) || TariffState.NotPaid <= CoreContext.PaymentManager.GetTariff(tenantid).State) { continue; } CoreContext.TenantManager.SetCurrentTenant(tenant); log.InfoFormat("Start send whats new in {0} ({1}).", tenant.TenantDomain, tenantid); foreach (var user in CoreContext.UserManager.GetUsers()) { if (!StudioNotifyHelper.IsSubscribedToNotify(user, Actions.SendWhatsNew)) { continue; } SecurityContext.AuthenticateMe(CoreContext.Authentication.GetAccountByID(user.ID)); var culture = string.IsNullOrEmpty(user.CultureName) ? tenant.GetCulture() : user.GetCulture(); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; var feeds = FeedAggregateDataProvider.GetFeeds(new FeedApiFilter { From = scheduleDate.Date.AddDays(-1), To = scheduleDate.Date.AddSeconds(-1), Max = 100, }); var feedMinWrappers = feeds.ConvertAll(f => f.ToFeedMin()); var feedMinGroupedWrappers = feedMinWrappers .Where(f => (f.CreatedDate == DateTime.MaxValue || f.CreatedDate >= scheduleDate.Date.AddDays(-1)) && //'cause here may be old posts with new comments products.ContainsKey(f.Product) && !f.Id.StartsWith("participant") ) .GroupBy(f => products[f.Product]); var ProjectsProductName = products["projects"].Name; //from ASC.Feed.Aggregator.Modules.ModulesHelper.ProjectsProductName var activities = feedMinGroupedWrappers .Where(f => f.Key.Name != ProjectsProductName) //not for project product .ToDictionary( g => g.Key.Name, g => g.Select(f => new WhatsNewUserActivity { Date = f.CreatedDate, UserName = f.Author != null && f.Author.UserInfo != null ? f.Author.UserInfo.DisplayUserName() : string.Empty, UserAbsoluteURL = f.Author != null && f.Author.UserInfo != null ? CommonLinkUtility.GetFullAbsolutePath(f.Author.UserInfo.GetUserProfilePageURL()) : string.Empty, Title = HtmlUtil.GetText(f.Title, 512), URL = CommonLinkUtility.GetFullAbsolutePath(f.ItemUrl), BreadCrumbs = new string[0], Action = getWhatsNewActionText(f) }).ToList()); var projectActivities = feedMinGroupedWrappers .Where(f => f.Key.Name == ProjectsProductName) // for project product .SelectMany(f => f); var projectActivitiesWithoutBreadCrumbs = projectActivities.Where(p => String.IsNullOrEmpty(p.ExtraLocation)); var whatsNewUserActivityGroupByPrjs = new List <WhatsNewUserActivity>(); foreach (var prawbc in projectActivitiesWithoutBreadCrumbs) { whatsNewUserActivityGroupByPrjs.Add( new WhatsNewUserActivity { Date = prawbc.CreatedDate, UserName = prawbc.Author != null && prawbc.Author.UserInfo != null ? prawbc.Author.UserInfo.DisplayUserName() : string.Empty, UserAbsoluteURL = prawbc.Author != null && prawbc.Author.UserInfo != null ? CommonLinkUtility.GetFullAbsolutePath(prawbc.Author.UserInfo.GetUserProfilePageURL()) : string.Empty, Title = HtmlUtil.GetText(prawbc.Title, 512), URL = CommonLinkUtility.GetFullAbsolutePath(prawbc.ItemUrl), BreadCrumbs = new string[0], Action = getWhatsNewActionText(prawbc) }); } var groupByPrjs = projectActivities.Where(p => !String.IsNullOrEmpty(p.ExtraLocation)).GroupBy(f => f.ExtraLocation); foreach (var gr in groupByPrjs) { var grlist = gr.ToList(); for (var i = 0; i < grlist.Count(); i++) { var ls = grlist[i]; whatsNewUserActivityGroupByPrjs.Add( new WhatsNewUserActivity { Date = ls.CreatedDate, UserName = ls.Author != null && ls.Author.UserInfo != null ? ls.Author.UserInfo.DisplayUserName() : string.Empty, UserAbsoluteURL = ls.Author != null && ls.Author.UserInfo != null ? CommonLinkUtility.GetFullAbsolutePath(ls.Author.UserInfo.GetUserProfilePageURL()) : string.Empty, Title = HtmlUtil.GetText(ls.Title, 512), URL = CommonLinkUtility.GetFullAbsolutePath(ls.ItemUrl), BreadCrumbs = i == 0 ? new string[1] { gr.Key } : new string[0], Action = getWhatsNewActionText(ls) }); } } if (whatsNewUserActivityGroupByPrjs.Count > 0) { activities.Add(ProjectsProductName, whatsNewUserActivityGroupByPrjs); } if (0 < activities.Count) { log.InfoFormat("Send whats new to {0}", user.Email); client.SendNoticeAsync( Actions.SendWhatsNew, null, user, null, new TagValue(Tags.Activities, activities), new TagValue(Tags.Date, DateToString(scheduleDate.AddDays(-1), culture)), new TagValue(CommonTags.Priority, 1) ); } } } catch (Exception error) { log.Error(error); } } }
private void SendMsgWhatsNew(DateTime scheduleDate) { var log = LogManager.GetLogger("ASC.Notify.WhatsNew"); log.Info("Start send whats new."); SecurityContext.AuthenticateMe(ASC.Core.Configuration.Constants.CoreSystem); var products = new List <IProduct>(ProductManager.Instance.Products); if (products.Count == 0) { return; } products.Sort((p1, p2) => string.Compare(p1.Name, p2.Name)); var tenants = UserActivityManager.GetChangedTenants(scheduleDate.AddDays(-1), scheduleDate); foreach (var tenantid in tenants) { try { var tenant = CoreContext.TenantManager.GetTenant(tenantid); if (tenant == null || tenant.Status != TenantStatus.Active) { continue; } if (!TimeToSendWhatsNew(TenantUtil.DateTimeFromUtc(tenant, scheduleDate))) { continue; } CoreContext.TenantManager.SetCurrentTenant(tenant); log.InfoFormat("Start send whats new in {0} ({1}).", tenant.MappedDomain, tenantid); foreach (var user in CoreContext.UserManager.GetUsers()) { var recipient = user; if (!IsSubscribeToWhatsNew(recipient)) { continue; } var activities = new Dictionary <string, IList <WhatsNewUserActivity> >(); foreach (var product in products) { if (product.Context.WhatsNewHandler == null || string.IsNullOrEmpty(product.Name) || !WebItemSecurity.IsAvailableForUser(product.ID.ToString(), user.ID)) { continue; } if (!activities.ContainsKey(product.Name)) { var whatsNewActivities = product.Context.WhatsNewHandler.GetUserActivities(user.ID, scheduleDate.AddDays(-1), scheduleDate); if (whatsNewActivities != null && whatsNewActivities.Count != 0) { activities.Add(product.Name, whatsNewActivities); } } } if (0 < activities.Count) { log.InfoFormat("Send whats new to {0} <{1}>.", recipient.DisplayUserName(), recipient.Email); client.SendNoticeAsync( Constants.ActionSendWhatsNew, null, recipient, null, new TagValue(Constants.TagActivities, activities), new TagValue(Constants.TagDate, scheduleDate.AddDays(-1).ToString("M")) ); } } } catch (Exception error) { log.Error(error); } } }
private static void NotifyAbouFutureEvent(DateTime scheduleDate) { try { using (var provider = new DataProvider()) { foreach (var data in provider.ExtractAndRecountNotifications(scheduleDate)) { if (data.Event == null || data.Event.Status == EventStatus.Cancelled) { continue; } var tenant = CoreContext.TenantManager.GetTenant(data.TenantId); if (tenant == null || tenant.Status != TenantStatus.Active || TariffState.NotPaid <= CoreContext.PaymentManager.GetTariff(tenant.TenantId).State) { continue; } CoreContext.TenantManager.SetCurrentTenant(tenant); var r = CalendarNotifySource.Instance.GetRecipientsProvider().GetRecipient(data.UserId.ToString()); if (r == null) { continue; } var startDate = data.GetUtcStartDate(); var endDate = data.GetUtcEndDate(); if (!data.Event.AllDayLong) { startDate = startDate.Add(data.TimeZone.GetOffset()); endDate = (endDate == DateTime.MinValue ? DateTime.MinValue : endDate.Add(data.TimeZone.GetOffset())); } var attachmentText = string.Empty; Func <string> funcEventAttachmentResource = () => CalendarPatternResource.EventAttachments; if (data.Event.HasAttachments) { var eventHistory = provider.GetEventHistory(int.Parse(data.Event.Id)); if (eventHistory != null) { attachmentText = GetTagValueWithAttachmentText(eventHistory); } } _notifyClient.SendNoticeAsync(CalendarNotifySource.EventAlert, null, r, true, new TagValue("EventName", data.Event.Name), new TagValue("EventDescription", data.Event.Description ?? ""), new TagValue("EventStartDate", startDate.ToShortDateString() + " " + startDate.ToShortTimeString()), new TagValue("EventEndDate", (endDate > startDate) ? (endDate.ToShortDateString() + " " + endDate.ToShortTimeString()) : ""), new TagActionValue("EventAttachmentsHeader", funcEventAttachmentResource), new TagValue("EventAttachmentsBody", attachmentText), new TagValue("Priority", 1)); } } } catch (Exception error) { LogManager.GetLogger("ASC.Notify.Calendar").Error(error); } }