public CalendarNotifyClient(
            AuthContext authContext,
            IServiceProvider serviceProvider,
            UserManager userManager,
            CalendarNotifySource calendarNotifySource,
            CommonLinkUtility commonLinkUtility,
            DisplayUserSettingsHelper displayUserSettingsHelper)
        {
            AuthContext               = authContext;
            ServiceProvider           = serviceProvider;
            CalendarNotifySource      = calendarNotifySource;
            UserManager               = userManager;
            CommonLinkUtility         = commonLinkUtility;
            DisplayUserSettingsHelper = displayUserSettingsHelper;

            NotifyContext = new NotifyContext(serviceProvider);
            _notifyClient = NotifyContext.NotifyService.RegisterClient(CalendarNotifySource, ServiceProvider.CreateScope());
        }
        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);
        }