internal void Invoke_NotifyClientRegistration(INotifyClient client) { if (NotifyClientRegistration != null) { NotifyClientRegistration(this, client); } }
public StudioNotifyService() { source = new StudioNotifySource(); client = WorkContext.NotifyContext.NotifyService.RegisterClient(source); //Register for web messages WebNotifyHandler.NotifyAction += WebNotifyHandler_NotifyAction; }
internal void RegisterSendMethod(INotifyClient client, Action<DateTime> method, Func<DateTime, DateTime?> nextDate) { if (!Scheduling) return; if (client == null) throw new ArgumentNullException("client"); if (method == null) throw new ArgumentNullException("method"); if (nextDate == null) throw new ArgumentNullException("nextDate"); var w = new SendMethodWrapper(client, method, nextDate); lock (sendMethods) { if (!notifyScheduler.IsAlive) { notifyScheduler.Start(); } sendMethods.Remove(w); sendMethods.Add(w); } methodsEvent.Set(); }
public StudioNotifyServiceSender() { client = WorkContext.NotifyContext.NotifyService.RegisterClient(StudioNotifyHelper.NotifySource); cache = new KafkaCache <NotifyItem>(); cache.Subscribe(OnMessage, CacheNotifyAction.Any); }
private StudioNotifyService() { source = new StudioNotifySource(); client = WorkContext.NotifyContext.NotifyService.RegisterClient(source); }
private NotifyClient(INotifyClient client, INotifySource source) { this.client = client; this.source = source; }
static CalendarNotifyClient() { _notifyClient = ASC.Core.WorkContext.NotifyContext.NotifyService.RegisterClient(CalendarNotifySource.Instance); }
static ForumNotifyClient() { NotifyClient = ASC.Core.WorkContext.NotifyContext.NotifyService.RegisterClient(ForumNotifySource.Instance); }
public static void NotifyClientRegisterCallback(Context context, INotifyClient client) { client.SetStaticTags(_CommonTags); client.AddInterceptor( new SendInterceptorSkeleton( "Web.UrlAbsoluter", InterceptorPlace.MessageSend, InterceptorLifetime.Global, (nreq, place) => { if (nreq != null && nreq.CurrentMessage != null && nreq.CurrentMessage.ContentType == Pattern.HTMLContentType) { DoNotifyRequestAbsoluteUrl(nreq.CurrentMessage); } return(false); } ) ); var productSecurityAndCulture = new SendInterceptorSkeleton( "ProductSecurityInterceptor", InterceptorPlace.DirectSend, InterceptorLifetime.Global, (r, p) => { var u = ASC.Core.Users.Constants.LostUser; try { if (32 <= r.Recipient.ID.Length) { var guid = default(Guid); try { guid = new Guid(r.Recipient.ID); } catch (FormatException) { } catch (OverflowException) { } if (guid != default(Guid)) { u = CoreContext.UserManager.GetUsers(guid); } } if (ASC.Core.Users.Constants.LostUser.Equals(u)) { u = CoreContext.UserManager.GetUserByEmail(r.Recipient.ID); } if (ASC.Core.Users.Constants.LostUser.Equals(u)) { u = CoreContext.UserManager.GetUserByUserName(r.Recipient.ID); } if (!ASC.Core.Users.Constants.LostUser.Equals(u)) { var culture = !string.IsNullOrEmpty(u.CultureName) ? u.GetCulture() : CoreContext.TenantManager.GetCurrentTenant().GetCulture(); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; } } catch (Exception error) { LogManager.GetLogger(typeof(WorkContext)).Error(error); } if (r.Properties.ContainsKey("asc.web.product_id")) { var pid = (Guid)r.Properties["asc.web.product_id"]; var userid = Guid.Empty; try { userid = new Guid(r.Recipient.ID); } catch { } if (pid != Guid.Empty && !ASC.Core.Users.Constants.LostUser.Equals(u)) { return(!WebItemSecurity.IsAvailableForUser(pid.ToString(), u.ID)); } } return(false); }); client.AddInterceptor(productSecurityAndCulture); }
public static void NotifyClientRegisterCallback(Context context, INotifyClient client) { client.SetStaticTags(_CommonTags); client.AddInterceptor( new SendInterceptorSkeleton( "Web.UrlAbsoluter", InterceptorPlace.MessageSend, InterceptorLifetime.Global, (nreq, place) => { if (nreq != null && nreq.CurrentMessage != null && nreq.CurrentMessage.ContentType == Pattern.HTMLContentType) DoNotifyRequestAbsoluteUrl(nreq.CurrentMessage); return false; } ) ); var productSecurityAndCulture = new SendInterceptorSkeleton( "ProductSecurityInterceptor", InterceptorPlace.DirectSend, InterceptorLifetime.Global, (r, p) => { var u = ASC.Core.Users.Constants.LostUser; try { if (32 <= r.Recipient.ID.Length) { var guid = default(Guid); try { guid = new Guid(r.Recipient.ID); } catch (FormatException) { } catch (OverflowException) { } if (guid != default(Guid)) { u = CoreContext.UserManager.GetUsers(guid); } } if (ASC.Core.Users.Constants.LostUser.Equals(u)) { u = CoreContext.UserManager.GetUserByEmail(r.Recipient.ID); } if (ASC.Core.Users.Constants.LostUser.Equals(u)) { u = CoreContext.UserManager.GetUserByUserName(r.Recipient.ID); } if (!ASC.Core.Users.Constants.LostUser.Equals(u)) { var culture = !string.IsNullOrEmpty(u.CultureName) ? u.GetCulture() : CoreContext.TenantManager.GetCurrentTenant().GetCulture(); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; } } catch (Exception error) { LogManager.GetLogger(typeof(WorkContext)).Error(error); } if (r.Properties.ContainsKey("asc.web.product_id")) { var pid = (Guid)r.Properties["asc.web.product_id"]; var userid = Guid.Empty; try { userid = new Guid(r.Recipient.ID); } catch { } if (pid != Guid.Empty && !ASC.Core.Users.Constants.LostUser.Equals(u)) { return !WebItemSecurity.IsAvailableForUser(pid.ToString(), u.ID); } } return false; }); client.AddInterceptor(productSecurityAndCulture); }
private static void NotifyClientRegisterCallback(Context context, INotifyClient client) { var absoluteUrl = new SendInterceptorSkeleton( "Web.UrlAbsoluter", InterceptorPlace.MessageSend, InterceptorLifetime.Global, (r, p) => { if (r != null && r.CurrentMessage != null && r.CurrentMessage.ContentType == Pattern.HTMLContentType) { var body = r.CurrentMessage.Body; body = urlReplacer.Replace(body, m => { var url = m.Groups["url"].Value; var ind = m.Groups["url"].Index - m.Index; return string.IsNullOrEmpty(url) && ind > 0 ? m.Value.Insert(ind, CommonLinkUtility.GetFullAbsolutePath(string.Empty)) : m.Value.Replace(url, CommonLinkUtility.GetFullAbsolutePath(url)); }); body = textileLinkReplacer.Replace(body, m => { var url = m.Groups["link"].Value; var ind = m.Groups["link"].Index - m.Index; return string.IsNullOrEmpty(url) && ind > 0 ? m.Value.Insert(ind, CommonLinkUtility.GetFullAbsolutePath(string.Empty)) : m.Value.Replace(url, CommonLinkUtility.GetFullAbsolutePath(url)); }); r.CurrentMessage.Body = body; } return false; }); client.AddInterceptor(absoluteUrl); var securityAndCulture = new SendInterceptorSkeleton( "ProductSecurityInterceptor", InterceptorPlace.DirectSend, InterceptorLifetime.Global, (r, p) => { try { // culture var u = ASC.Core.Users.Constants.LostUser; if (32 <= r.Recipient.ID.Length) { var guid = default(Guid); try { guid = new Guid(r.Recipient.ID); } catch (FormatException) { } catch (OverflowException) { } if (guid != default(Guid)) { u = CoreContext.UserManager.GetUsers(guid); } } if (ASC.Core.Users.Constants.LostUser.Equals(u)) { u = CoreContext.UserManager.GetUserByEmail(r.Recipient.ID); } if (ASC.Core.Users.Constants.LostUser.Equals(u)) { u = CoreContext.UserManager.GetUserByUserName(r.Recipient.ID); } if (!ASC.Core.Users.Constants.LostUser.Equals(u)) { var culture = !string.IsNullOrEmpty(u.CultureName) ? u.GetCulture() : CoreContext.TenantManager.GetCurrentTenant().GetCulture(); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; // security var tag = r.Arguments.Find(a => a.Tag == CommonTags.ModuleID); var productId = tag != null ? (Guid)tag.Value : Guid.Empty; if (productId == Guid.Empty) { tag = r.Arguments.Find(a => a.Tag == CommonTags.ProductID); productId = tag != null ? (Guid)tag.Value : Guid.Empty; } if (productId == Guid.Empty) { productId = (Guid)(CallContext.GetData("asc.web.product_id") ?? Guid.Empty); } if (productId != Guid.Empty && productId != new Guid("f4d98afdd336433287783c6945c81ea0") /* ignore people product */) { return !WebItemSecurity.IsAvailableForUser(productId.ToString(), u.ID); } } } catch (Exception error) { LogManager.GetLogger(typeof(NotifyConfiguration)).Error(error); } return false; }); client.AddInterceptor(securityAndCulture); }
public static async Task <HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "assessment/notify/email")] HttpRequest req, ILogger log, [Inject] IHttpRequestHelper httpRequestHelper, [Inject] IHttpResponseMessageHelper httpResponseMessageHelper, [Inject] IUserSessionRepository userSessionRepository, [Inject] INotifyClient notifyClient) { try { var correlationId = httpRequestHelper.GetDssCorrelationId(req); if (string.IsNullOrEmpty(correlationId)) { log.LogInformation("Unable to locate 'DssCorrelationId' in request header"); } if (!Guid.TryParse(correlationId, out var correlationGuid)) { log.LogInformation("Unable to parse 'DssCorrelationId' to a Guid"); correlationGuid = Guid.NewGuid(); } SendSessionEmailRequest sendSessionEmailRequest; using (var streamReader = new StreamReader(req.Body)) { var body = streamReader.ReadToEnd(); sendSessionEmailRequest = JsonConvert.DeserializeObject <SendSessionEmailRequest>(body); } if (sendSessionEmailRequest == null || string.IsNullOrEmpty(sendSessionEmailRequest.SessionId)) { log.LogError($"CorrelationId: {correlationGuid} - Session Id not supplied"); return(httpResponseMessageHelper.BadRequest()); } if (string.IsNullOrEmpty(sendSessionEmailRequest.Domain)) { log.LogError($"CorrelationId: {correlationGuid} - Domain not supplied"); return(httpResponseMessageHelper.BadRequest()); } if (string.IsNullOrEmpty(sendSessionEmailRequest.TemplateId)) { log.LogError($"CorrelationId: {correlationGuid} - TemplateId not supplied"); return(httpResponseMessageHelper.BadRequest()); } if (string.IsNullOrEmpty(sendSessionEmailRequest.EmailAddress)) { log.LogError($"CorrelationId: {correlationGuid} - EmailAddress not supplied"); return(httpResponseMessageHelper.BadRequest()); } var userSession = await userSessionRepository.GetUserSession(sendSessionEmailRequest.SessionId); if (userSession == null) { log.LogError($"CorrelationId: {correlationGuid} - Session Id does not exist {sendSessionEmailRequest.SessionId}"); return(httpResponseMessageHelper.NoContent()); } await notifyClient.SendEmail(sendSessionEmailRequest.Domain, sendSessionEmailRequest.EmailAddress, sendSessionEmailRequest.TemplateId, userSession.UserSessionId); var result = new SendSessionEmailResponse() { IsSuccess = true, }; return(httpResponseMessageHelper.Ok(JsonConvert.SerializeObject(result))); } catch (Exception ex) { var result = new SendSessionEmailResponse() { IsSuccess = false, Message = ex.Message }; return(httpResponseMessageHelper.Ok(JsonConvert.SerializeObject(result))); } }
public SendMethodWrapper(INotifyClient client, Action<DateTime> method, Func<DateTime, DateTime?> nextDateMethod) { this.client = client; this.method = method; this.nextDateMethod = nextDateMethod; UpdateScheduleDate(DateTime.UtcNow); }
internal void UnregisterSendMethod(INotifyClient client, Action<DateTime> method) { if (!Scheduling) return; if (client == null) throw new ArgumentNullException("client"); if (method == null) throw new ArgumentNullException("method"); lock (sendMethods) { sendMethods.Remove(new SendMethodWrapper(client, method, null)); } }
static WikiNotifyClient() { NotifyClient = WorkContext.NotifyContext.NotifyService.RegisterClient(WikiNotifySource.Instance); }
private static void NotifyClientRegisterCallback(Context context, INotifyClient client) { #region url correction var absoluteUrl = new SendInterceptorSkeleton( "Web.UrlAbsoluter", InterceptorPlace.MessageSend, InterceptorLifetime.Global, (r, p) => { if (r != null && r.CurrentMessage != null && r.CurrentMessage.ContentType == Pattern.HTMLContentType) { var body = r.CurrentMessage.Body; body = urlReplacer.Replace(body, m => { var url = m.Groups["url"].Value; var ind = m.Groups["url"].Index - m.Index; return(string.IsNullOrEmpty(url) && ind > 0 ? m.Value.Insert(ind, CommonLinkUtility.GetFullAbsolutePath(string.Empty)) : m.Value.Replace(url, CommonLinkUtility.GetFullAbsolutePath(url))); }); body = textileLinkReplacer.Replace(body, m => { var url = m.Groups["link"].Value; var ind = m.Groups["link"].Index - m.Index; return(string.IsNullOrEmpty(url) && ind > 0 ? m.Value.Insert(ind, CommonLinkUtility.GetFullAbsolutePath(string.Empty)) : m.Value.Replace(url, CommonLinkUtility.GetFullAbsolutePath(url))); }); r.CurrentMessage.Body = body; } return(false); }); client.AddInterceptor(absoluteUrl); #endregion #region security and culture var securityAndCulture = new SendInterceptorSkeleton( "ProductSecurityInterceptor", InterceptorPlace.DirectSend, InterceptorLifetime.Global, (r, p) => { try { // culture var u = Constants.LostUser; if (!(CoreContext.Configuration.Personal && r.NotifyAction.ID == Actions.PersonalConfirmation.ID)) { if (32 <= r.Recipient.ID.Length) { var guid = default(Guid); try { guid = new Guid(r.Recipient.ID); } catch (FormatException) { } catch (OverflowException) { } if (guid != default(Guid)) { u = CoreContext.UserManager.GetUsers(guid); } } if (Constants.LostUser.Equals(u)) { u = CoreContext.UserManager.GetUserByEmail(r.Recipient.ID); } if (Constants.LostUser.Equals(u)) { u = CoreContext.UserManager.GetUserByUserName(r.Recipient.ID); } if (!Constants.LostUser.Equals(u)) { var culture = !string.IsNullOrEmpty(u.CultureName) ? u.GetCulture() : CoreContext.TenantManager.GetCurrentTenant().GetCulture(); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; // security var tag = r.Arguments.Find(a => a.Tag == CommonTags.ModuleID); var productId = tag != null ? (Guid)tag.Value : Guid.Empty; if (productId == Guid.Empty) { tag = r.Arguments.Find(a => a.Tag == CommonTags.ProductID); productId = tag != null ? (Guid)tag.Value : Guid.Empty; } if (productId == Guid.Empty) { productId = (Guid)(CallContext.GetData("asc.web.product_id") ?? Guid.Empty); } if (productId != Guid.Empty && productId != new Guid("f4d98afdd336433287783c6945c81ea0") /* ignore people product */) { return(!WebItemSecurity.IsAvailableForUser(productId, u.ID)); } } } var tagCulture = r.Arguments.FirstOrDefault(a => a.Tag == CommonTags.Culture); if (tagCulture != null) { var culture = CultureInfo.GetCultureInfo((string)tagCulture.Value); Thread.CurrentThread.CurrentCulture = culture; Thread.CurrentThread.CurrentUICulture = culture; } } catch (Exception error) { LogManager.GetLogger("ASC").Error(error); } return(false); }); client.AddInterceptor(securityAndCulture); #endregion #region white label correction var whiteLabel = new SendInterceptorSkeleton( "WhiteLabelInterceptor", InterceptorPlace.MessageSend, InterceptorLifetime.Global, (r, p) => { try { var tags = r.Arguments; var logoTextTag = tags.FirstOrDefault(a => a.Tag == CommonTags.LetterLogoText); var logoText = logoTextTag != null ? (String)logoTextTag.Value : string.Empty; if (!string.IsNullOrEmpty(logoText)) { r.CurrentMessage.Body = r.CurrentMessage.Body .Replace(string.Format("${{{0}}}", CommonTags.LetterLogoText), logoText); } } catch (Exception error) { LogManager.GetLogger("ASC").Error(error); } return(false); }); client.AddInterceptor(whiteLabel); #endregion }
private BirthdaysNotifyClient(INotifyClient client) { this.client = client; }
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(tenant)) { if (!StudioNotifyHelper.IsSubscribedToNotify(tenant, user, Actions.SendWhatsNew)) { continue; } SecurityContext.AuthenticateMe(CoreContext.Authentication.GetAccountByID(tenant.TenantId, 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 (activities.Count > 0) { log.InfoFormat("Send whats new to {0}", user.Email); client.SendNoticeAsync( Actions.SendWhatsNew, null, user, 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); } } }
static NotifyClient() { Instance = WorkContext.NotifyContext.NotifyService.RegisterClient(NotifySource.Instance); }
static BookmarkingNotifyClient() { NotifyClient = ASC.Core.WorkContext.NotifyContext.NotifyService.RegisterClient(BookmarkingNotifySource.Instance); }