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 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 override void Init()
        {
            context = new ProductContext
                          {
                              MasterPageFile = String.Concat(PathProvider.BaseVirtualPath, "Masters/BasicTemplate.Master"),
                              DisabledIconFileName = "product_disabled_logo.png",
                              IconFileName = "product_logo.png",
                              LargeIconFileName = "product_logolarge.png",
                              SubscriptionManager = new ProductSubscriptionManager(),
                              DefaultSortOrder = 20,
                              SpaceUsageStatManager = new ProjectsSpaceUsageStatManager(),
                              AdminOpportunities = () => ProjectsCommonResource.ProductAdminOpportunities.Split('|').ToList(),
                              UserOpportunities = () => ProjectsCommonResource.ProductUserOpportunities.Split('|').ToList(),
                              HasComplexHierarchyOfAccessRights = true,
                          };

            FilesIntegration.RegisterFileSecurityProvider("projects", "project", new SecurityAdapterProvider());
            SearchHandlerManager.Registry(new SearchHandler());

            var securityInterceptor = new SendInterceptorSkeleton(
                "ProjectInterceptorSecurity",
                InterceptorPlace.DirectSend,
                InterceptorLifetime.Global,
                (r, p) =>
                    {
                        try
                        {
                            var data = r.ObjectID.Split('_');
                            var entityType = data[0];
                            var entityId = Convert.ToInt32(data[1]);

                            var projectId = 0;
                            
                            if(data.Length == 3)
                                projectId = Convert.ToInt32(r.ObjectID.Split('_')[2]);

                            switch (entityType)
                            {
                                case "Task":
                                    var task = Global.EngineFactory.GetTaskEngine().GetByID(entityId, false);

                                    if (task == null && projectId != 0)
                                    {
                                        var project = Global.EngineFactory.GetProjectEngine().GetByID(projectId, false);
                                        return !ProjectSecurity.CanRead(project, new Guid(r.Recipient.ID));
                                    }

                                    return !ProjectSecurity.CanRead(task, new Guid(r.Recipient.ID));
                                case "Message":
                                    var discussion = Global.EngineFactory.GetMessageEngine().GetByID(entityId, false);

                                    if (discussion == null && projectId != 0)
                                    {
                                        var project = Global.EngineFactory.GetProjectEngine().GetByID(projectId, false);
                                        return !ProjectSecurity.CanRead(project, new Guid(r.Recipient.ID));
                                    }

                                    return !ProjectSecurity.CanRead(discussion, new Guid(r.Recipient.ID));
                                case "Milestone":
                                    var milestone = Global.EngineFactory.GetMilestoneEngine().GetByID(entityId, false);

                                    if (milestone == null && projectId != 0)
                                    {
                                        var project = Global.EngineFactory.GetProjectEngine().GetByID(projectId, false);
                                        return !ProjectSecurity.CanRead(project, new Guid(r.Recipient.ID));
                                    }

                                    return !ProjectSecurity.CanRead(milestone, new Guid(r.Recipient.ID));
                            }
                        }
                        catch (Exception ex)
                        {
                            LogManager.GetLogger("ASC.Projects.Tasks").Error("Send", ex);
                        }
                        return false;
                    });

            NotifyClient.Instance.Client.AddInterceptor(securityInterceptor);
        }