コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }