Пример #1
0
        /// <summary>
        /// Gets the site from the site cache in the following order:
        /// 1. check the query string and try to get the site
        /// 2. Get the site using the domain of the current request
        /// 3. Get the last site from the site cookie
        /// </summary>
        /// <returns></returns>
        private SiteCache GetSite(HttpContext context)
        {
            SiteCache site       = null;
            string    siteCookie = context.Request.Cookies[SITE_COOKIE_NAME];
            string    host       = context.Request.Host.Host;

            // First check to see if site was specified in querystring
            int?siteId = context.Request.Query["SiteId"].ToString().AsIntegerOrNull();

            if (siteId.HasValue)
            {
                site = SiteCache.Get(siteId.Value);
            }

            // Then check to see if site can be determined by domain
            if (site == null)
            {
                site = SiteCache.GetSiteByDomain(host);
            }

            // Then check the last site
            if (site == null)
            {
                if (siteCookie != null)
                {
                    site = SiteCache.Get(siteCookie.AsInteger());
                }
            }

            return(site);
        }
Пример #2
0
        public HttpResponseMessage GetApplicationScript(int applicationId)
        {
            var response = new HttpResponseMessage();

            // Get the site and validate the the request is valid (api key is valid)
            var site = SiteCache.Get(applicationId);

            // If the site was not found then return 404
            if (site == null)
            {
                response.StatusCode = System.Net.HttpStatusCode.NotFound;
                return(response);
            }

            // Return the script content
            try
            {
                var applicationSettings = JsonConvert.DeserializeObject <AppleTvApplicationSettings>(site.AdditionalSettings);
                response.Content = new StringContent(applicationSettings.ApplicationScript, Encoding.UTF8, "application/javascript");
            }
            catch (Exception)
            {
                // Ooops...
                response.StatusCode = System.Net.HttpStatusCode.InternalServerError;
                return(response);
            }

            return(response);
        }
Пример #3
0
        /// <summary>
        /// Loads the drop downs.
        /// </summary>
        private void LoadDropDowns()
        {
            ddlLayout.Items.Clear();
            ddlLayout.Items.Add(new ListItem(string.Empty, None.IdValue));

            var site = SiteCache.Get(hfSiteId.ValueAsInt());

            if (site != null)
            {
                string virtualFolder  = string.Format("~/Themes/{0}/Layouts", site.Theme);
                string physicalFolder = Request.MapPath(virtualFolder);

                // search for all layouts (aspx files) under the physical path
                var           layoutFiles = new List <string>();
                DirectoryInfo di          = new DirectoryInfo(physicalFolder);
                if (di.Exists)
                {
                    foreach (var file in di.GetFiles("*.aspx", SearchOption.AllDirectories))
                    {
                        ddlLayout.Items.Add(new ListItem(file.FullName.Replace(physicalFolder, virtualFolder).Replace(@"\", "/"), Path.GetFileNameWithoutExtension(file.Name)));
                    }
                }
            }

            ddlLayout.Required = true;
        }
Пример #4
0
        public static LabelManageInfo GetCacheLabelByName(string labelName)
        {
            string str2;
            string key = "CK_Label_LabelManageInfo_" + labelName;

            if (HttpContext.Current != null)
            {
                str2 = HttpContext.Current.Server.MapPath("~/" + LabelLibPath) + @"\" + labelName + ".config";
            }
            else
            {
                str2 = AppDomain.CurrentDomain.BaseDirectory + LabelLibPath + @"\" + labelName + ".config";
            }
            LabelManageInfo labelByName = SiteCache.Get(key) as LabelManageInfo;

            if (labelByName == null)
            {
                labelByName = GetLabelByName(labelName);
                if (File.Exists(str2))
                {
                    SiteCache.Insert(key, labelByName, new System.Web.Caching.CacheDependency(str2));//将EasyOne.Components.改了
                }
            }
            return(labelByName);
        }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string key  = BasePage.RequestString("CacheKey");
            object obj2 = SiteCache.Get(key);

            if (obj2 == null)
            {
                AdminPage.WriteErrMsg("<li>未找到对应的缓存信息!</li>");
            }
            if (obj2.GetType().IsGenericType)
            {
                IList         list = (IList)obj2;
                StringBuilder sb   = new StringBuilder();
                foreach (object obj3 in list)
                {
                    StringHelper.AppendString(sb, obj3.ToString(), "\n");
                }
                this.TxtCacheContent.Text = sb.ToString();
            }
            else
            {
                this.TxtCacheContent.Text = obj2.ToString();
            }
            this.LblTitle.Text = key;
        }
Пример #6
0
        public static string ReplaceInsideLink(string inputText)
        {
            inputText = inputText.Replace("&lt;", "<");
            inputText = inputText.Replace("&gt;", ">");
            IList <WordReplaceInfo> list = SiteCache.Get("CK_Accessories_ReplaceInsideLinkList") as List <WordReplaceInfo>;
            string input = inputText;

            if (list == null)
            {
                list = dal.GetInsideLink(0, 0, "", 2);
                SiteCache.Insert("CK_Accessories_ReplaceInsideLinkList", list);
            }
            foreach (WordReplaceInfo info in list)
            {
                int replaceTimes = 0;
                s_SourceWord   = info.SourceWord;
                s_ReplaceTimes = info.ReplaceTimes;
                if (info.OpenType)
                {
                    s_LinkType = "<a class=\"insidelink\" href=\"" + info.TargetWord + "\">" + info.SourceWord + "</a>";
                }
                else
                {
                    s_LinkType = "<a class=\"insidelink\" href=\"" + info.TargetWord + "\" target=\"_blank\">" + info.SourceWord + "</a>";
                }
                if (input.IndexOf("</a>", StringComparison.Ordinal) > 0)
                {
                    Regex regex = new Regex(@"((^|</a>)[\s\S]*?<a|</a>[\s\S]*$)", RegexOptions.IgnoreCase);
                    foreach (Match match in regex.Matches(input))
                    {
                        Regex regex2 = new Regex("(?<!<[^<>]*)" + s_SourceWord + "(?![^<>]*>)", RegexOptions.IgnoreCase);
                        int   count  = regex2.Matches(match.Value).Count;
                        if (count <= (info.ReplaceTimes - replaceTimes))
                        {
                            input         = input.Replace(match.Value, regex2.Replace(match.Value, s_LinkType));
                            replaceTimes += count;
                        }
                        else
                        {
                            input        = input.Replace(match.Value, regex2.Replace(match.Value, s_LinkType, (int)(info.ReplaceTimes - replaceTimes)));
                            replaceTimes = info.ReplaceTimes;
                        }
                    }
                    continue;
                }
                Regex regex3 = new Regex("(?<!<[^<>]*)" + s_SourceWord + "(?![^<>]*>)", RegexOptions.IgnoreCase);
                if (regex3.Matches(input).Count <= (info.ReplaceTimes - replaceTimes))
                {
                    input = input.Replace(input, regex3.Replace(input, s_LinkType));
                }
                else
                {
                    input        = input.Replace(input, regex3.Replace(input, s_LinkType, (int)(info.ReplaceTimes - replaceTimes)));
                    replaceTimes = info.ReplaceTimes;
                }
            }
            return(input.Replace("<", "&lt;").Replace(">", "&gt;"));
        }
        private SiteCache GetSiteFromLastSite(RequestContext requestContext)
        {
            var siteCookie = requestContext.HttpContext.Request.Cookies["last_site"];

            if (siteCookie != null && siteCookie.Value != null)
            {
                return(SiteCache.Get(siteCookie.Value.AsInteger()));
            }
            return(null);
        }
        // Site Functions

        private SiteCache GetSiteByQueryString(RequestContext requestContext)
        {
            int?query_SiteId = requestContext.HttpContext.Request.QueryString["SiteId"].AsIntegerOrNull();

            if (query_SiteId.HasValue)
            {
                return(SiteCache.Get(query_SiteId.Value));
            }
            return(null);
        }
Пример #9
0
        public static IList <PagerManageInfo> GetPagerList(string type)
        {
            string key = "CK_Label_PagerLabelList_Type_" + type;
            List <PagerManageInfo> list = new List <PagerManageInfo>();

            if (SiteCache.Get(key) == null)
            {
                string str2;
                if (HttpContext.Current != null)
                {
                    str2 = HttpContext.Current.Server.MapPath("~/" + PagerLabelLibPath);
                }
                else
                {
                    str2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PagerLabelLibPath);
                }
                DirectoryInfo info = new DirectoryInfo(str2);
                if (info.Exists)
                {
                    foreach (FileInfo info2 in info.GetFiles())
                    {
                        try
                        {
                            using (StreamReader reader = info2.OpenText())
                            {
                                XmlDocument document = new XmlDocument();
                                document.Load(reader);
                                PagerManageInfo item = new PagerManageInfo();
                                item.Name  = Path.GetFileNameWithoutExtension(info2.Name);
                                item.Type  = document.SelectSingleNode("root/LabelType").InnerText;
                                item.Image = document.SelectSingleNode("root/LabelImage").InnerText;
                                item.Intro = document.SelectSingleNode("root/LabelIntro").InnerText;
                                if (string.IsNullOrEmpty(item.Image))
                                {
                                    item.Image = "~/Admin/Images/LabelIco/def.ico";
                                }
                                item.UpDateTime = info2.LastWriteTime;
                                if (((type == item.Type) || string.IsNullOrEmpty(type)) || (type == "全部分类"))
                                {
                                    list.Add(item);
                                }
                            }
                        }
                        catch (XmlException exception)
                        {
                            exception.ToString();
                        }
                    }
                }
                SiteCache.Insert(key, list, new CacheDependency(str2));//add sql
                return(list);
            }
            return((List <PagerManageInfo>)SiteCache.Get(key));
        }
Пример #10
0
        /// <summary>
        /// Gets the Guid for the Site that has the specified Id
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public override Guid?GetGuid(int id)
        {
            var cacheItem = SiteCache.Get(id);

            if (cacheItem != null)
            {
                return(cacheItem.Guid);
            }

            return(null);
        }
Пример #11
0
        /// <summary>
        /// Gets the current application site.
        /// </summary>
        /// <param name="validateApiKey">if set to <c>true</c> [validate API key].</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns></returns>
        public static SiteCache GetCurrentApplicationSite(bool validateApiKey = true, RockContext rockContext = null)
        {
            var appId = HttpContext.Current?.Request?.Headers?["X-Rock-App-Id"];

            if (!appId.AsIntegerOrNull().HasValue)
            {
                return(null);
            }

            //
            // Lookup the site from the App Id.
            //
            var site = SiteCache.Get(appId.AsInteger());

            if (site == null)
            {
                return(null);
            }

            //
            // If we have been requested to validate the Api Key then do so.
            //
            if (validateApiKey)
            {
                var requestApiKey      = System.Web.HttpContext.Current?.Request?.Headers?["X-Rock-Tv-Api-Key"];
                var additionalSettings = site.AdditionalSettings.FromJsonOrNull <AppleTvApplicationSettings>();

                //
                // Ensure we have valid site configuration.
                //
                if (additionalSettings == null || !additionalSettings.ApiKeyId.HasValue)
                {
                    return(null);
                }

                rockContext = rockContext ?? new RockContext();

                // Get user login for the app and verify that it matches the request's key
                var appUserLogin = new UserLoginService(rockContext).Get(additionalSettings.ApiKeyId.Value);

                if (appUserLogin != null && appUserLogin.ApiKey == requestApiKey)
                {
                    return(site);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(site);
            }
        }
Пример #12
0
        public static ModelInfo GetModelInfoById(int id)
        {
            string    key           = "CK_CommonModel_ModelInfo_ModelId_" + id.ToString();
            ModelInfo modelInfoById = SiteCache.Get(key) as ModelInfo;

            if (modelInfoById == null)
            {
                modelInfoById = dal.GetModelInfoById(id);
                SiteCache.Insert(key, modelInfoById);
            }
            return(modelInfoById);
        }
Пример #13
0
        public static IList <ModelInfo> GetCacheModelList()
        {
            string            key       = "CK_CommonModel_ModelList_All";
            IList <ModelInfo> modelList = SiteCache.Get(key) as IList <ModelInfo>;

            if (modelList == null)
            {
                modelList = GetModelList(ModelType.None, ModelShowType.None);
                SiteCache.Insert(key, modelList, 0x4380);
            }
            return(modelList);
        }
Пример #14
0
        /// <summary>
        /// Get the current site as specified by the X-Rock-App-Id header and optionally
        /// validate the X-Rock-Mobile-Api-Key against that site.
        /// </summary>
        /// <param name="validateApiKey"><c>true</c> if the X-Rock-Mobile-Api-Key header should be validated.</param>
        /// <param name="rockContext">The Rock context to use when accessing the database.</param>
        /// <returns>A SiteCache object or null if the request was not valid.</returns>
        public static SiteCache GetCurrentApplicationSite(bool validateApiKey = true, Data.RockContext rockContext = null)
        {
            var appId = HttpContext.Current?.Request?.Headers?["X-Rock-App-Id"];

            if (!appId.AsIntegerOrNull().HasValue)
            {
                return(null);
            }

            //
            // Lookup the site from the App Id.
            //
            var site = SiteCache.Get(appId.AsInteger());

            if (site == null)
            {
                return(null);
            }

            //
            // If we have been requested to validate the Api Key then do so.
            //
            if (validateApiKey)
            {
                var appApiKey          = System.Web.HttpContext.Current?.Request?.Headers?["X-Rock-Mobile-Api-Key"];
                var additionalSettings = site.AdditionalSettings.FromJsonOrNull <AdditionalSiteSettings>();

                //
                // Ensure we have valid site configuration.
                //
                if (additionalSettings == null || !additionalSettings.ApiKeyId.HasValue)
                {
                    return(null);
                }

                rockContext = rockContext ?? new Data.RockContext();
                var userLogin = new UserLoginService(rockContext).GetByApiKey(appApiKey).FirstOrDefault();

                if (userLogin != null && userLogin.Id == additionalSettings.ApiKeyId)
                {
                    return(site);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(site);
            }
        }
        /// <summary>
        /// Build filter values/summary with user friendly data from filters
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        protected void fExceptionList_DisplayFilterValue(object sender, GridFilter.DisplayFilterValueArgs e)
        {
            switch (e.Key)
            {
            case "Site":
                int siteId;
                if (int.TryParse(e.Value, out siteId))
                {
                    var site = SiteCache.Get(siteId);
                    if (site != null)
                    {
                        e.Value = site.Name;
                    }
                }
                break;

            case "Page":
                int pageId;
                if (int.TryParse(e.Value, out pageId))
                {
                    var page = PageCache.Get(pageId);
                    if (page != null)
                    {
                        e.Value = page.InternalName;
                    }
                }
                break;

            case "User":
                int userPersonId;
                if (int.TryParse(e.Value, out userPersonId))
                {
                    PersonService personService = new PersonService(new RockContext());
                    var           user          = personService.Get(userPersonId);
                    if (user != null)
                    {
                        e.Value = user.FullName;
                    }
                }
                break;

            // ignore old filter parameters
            case "Start Date":
            case "End Date":
                e.Value = null;
                break;

            case "Date Range":
                e.Value = SlidingDateRangePicker.FormatDelimitedValues(e.Value);
                break;
            }
        }
Пример #16
0
        /// <summary>
        /// Gets the site from the site cache in the following order:
        /// 1. Get the site using the domain of the current request
        /// 2. Get the last site from the site cookie
        /// </summary>
        /// <param name="host">The host.</param>
        /// <param name="siteCookie">The site cookie.</param>
        /// <returns></returns>
        private SiteCache GetSite(string host, HttpCookie siteCookie)
        {
            // Check to see if site can be determined by domain
            SiteCache site = SiteCache.GetSiteByDomain(host);

            // Then check the last site
            if (site == null && siteCookie != null && siteCookie.Value != null)
            {
                site = SiteCache.Get(siteCookie.Value.AsInteger());
            }

            return(site);
        }
Пример #17
0
        public static IList <PagerManageInfo> GetPagerTypeList()
        {
            string key = "CK_Label_PagerLabel_Type";
            List <PagerManageInfo> list = new List <PagerManageInfo>();

            if (SiteCache.Get(key) == null)
            {
                string        str2;
                List <string> list2 = new List <string>();
                if (HttpContext.Current != null)
                {
                    str2 = HttpContext.Current.Server.MapPath("~/" + PagerLabelLibPath);
                }
                else
                {
                    str2 = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PagerLabelLibPath);
                }
                DirectoryInfo info = new DirectoryInfo(str2);
                if (info.Exists)
                {
                    foreach (FileInfo info2 in info.GetFiles())
                    {
                        XmlDocument document = new XmlDocument();
                        try
                        {
                            using (StreamReader reader = info2.OpenText())
                            {
                                document.Load(reader);
                                string innerText = document.SelectSingleNode("root/LabelType").InnerText;
                                if (!list2.Contains(innerText) && !string.IsNullOrEmpty(innerText))
                                {
                                    list2.Add(innerText);
                                }
                            }
                        }
                        catch (XmlException exception)
                        {
                            exception.ToString();
                        }
                    }
                }
                foreach (string str4 in list2)
                {
                    list.Add(new PagerManageInfo(str4));
                }
                SiteCache.Insert(key, list, new CacheDependency(str2));//add sql
                return(list);
            }
            return((List <PagerManageInfo>)SiteCache.Get(key));
        }
Пример #18
0
 /// <summary>
 /// Loads the sites.
 /// </summary>
 /// <param name="rockContext">The rock context.</param>
 private void LoadSites(RockContext rockContext)
 {
     ddlSite.Items.Clear();
     foreach (SiteCache site in new SiteService(rockContext)
              .Queryable().AsNoTracking()
              .Where(s => s.EnabledForShortening)
              .OrderBy(s => s.Name)
              .Select(a => a.Id)
              .ToList()
              .Select(a => SiteCache.Get(a)))
     {
         ddlSite.Items.Add(new ListItem(site.Name, site.Id.ToString()));
     }
 }
Пример #19
0
        /// <summary>
        /// Gets the mobile application user associated with the application identifier and api key.
        /// </summary>
        /// <param name="appId">The application (site) identifier.</param>
        /// <param name="mobileApiKey">The mobile API key.</param>
        /// <param name="rockContext">The rock context.</param>
        /// <returns>The <see cref="UserLogin"/> associated with the parameters or <c>null</c> if no match was found.</returns>
        public static UserLogin GetMobileApplicationUser(int appId, string mobileApiKey, RockContext rockContext = null)
        {
            //
            // Lookup the site from the App Id.
            //
            var site = SiteCache.Get(appId);

            if (site == null)
            {
                return(null);
            }

            return(GetMobileApplicationUser(site, mobileApiKey, rockContext));
        }
Пример #20
0
        public static string CurrentVersion()
        {
            string str = "0.0.0.0";
            string key = "CK_System_DataBaseCurrentVersion";

            if (SiteCache.Get(key) == null)
            {
                DataBaseVersionInfo info = LastVersion();
                str = info.Major.ToString(CultureInfo.CurrentCulture) + "." + info.Minor.ToString(CultureInfo.CurrentCulture) + "." + info.Build.ToString(CultureInfo.CurrentCulture) + "." + info.Revision.ToString(CultureInfo.CurrentCulture);
                SiteCache.Insert(key, str, 0x4380);
                return(str);
            }
            return(SiteCache.Get(key).ToString());
        }
Пример #21
0
        public static string ReplaceText(string inputText)
        {
            IList <WordReplaceInfo> wordFilterList = SiteCache.Get("CK_Accessories_WordReplaceInfoList") as List <WordReplaceInfo>;
            StringBuilder           builder        = new StringBuilder(inputText);

            if (wordFilterList == null)
            {
                wordFilterList = GetWordFilterList();
                SiteCache.Insert("CK_Accessories_WordReplaceInfoList", wordFilterList);
            }
            foreach (WordReplaceInfo info in wordFilterList)
            {
                builder.Replace(info.SourceWord, info.TargetWord);
            }
            return(builder.ToString());
        }
Пример #22
0
        /// <summary>
        /// Saves the page.
        /// </summary>
        private void SavePage()
        {
            var applicationId = PageParameter(PageParameterKey.SiteId).AsInteger();
            var pageId        = PageParameter(PageParameterKey.SitePageId).AsInteger();

            var rockContext = new RockContext();
            var pageService = new PageService(rockContext);
            var page        = pageService.Get(pageId);

            var site = SiteCache.Get(applicationId);

            // Site is new so create one
            if (page == null)
            {
                page = new Rock.Model.Page();
                pageService.Add(page);
                page.ParentPageId = site.DefaultPageId;
                page.LayoutId     = site.DefaultPage.LayoutId;

                // Set the order of the new page to be the last one
                var currentMaxOrder = pageService.GetByParentPageId(site.DefaultPageId)
                                      .OrderByDescending(p => p.Order)
                                      .Select(p => p.Order)
                                      .FirstOrDefault();
                page.Order = currentMaxOrder + 1;
            }

            page.InternalName = tbPageName.Text;
            page.BrowserTitle = tbPageName.Text;
            page.PageTitle    = tbPageName.Text;

            page.Description = ceTvml.Text;

            var pageResponse = page.AdditionalSettings.IsNotNullOrWhiteSpace() ? JsonConvert.DeserializeObject <ApplePageResponse>(page.AdditionalSettings) : new ApplePageResponse();

            pageResponse.Content = ceTvml.Text;

            page.AdditionalSettings = pageResponse.ToJson();

            page.Description = tbDescription.Text;

            page.DisplayInNavWhen = cbShowInMenu.Checked ? DisplayInNavWhen.WhenAllowed : DisplayInNavWhen.Never;

            page.CacheControlHeaderSettings = cpCacheSettings.CurrentCacheability.ToJson();

            rockContext.SaveChanges();
        }
Пример #23
0
 /// <summary>
 /// Displays the text of the gfShortLink control
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The e.</param>
 protected void gfShortLink_DisplayFilterValue(object sender, GridFilter.DisplayFilterValueArgs e)
 {
     switch (e.Key)
     {
     case "Site":
         int?siteId = e.Value.AsIntegerOrNull();
         if (siteId.HasValue)
         {
             var site = SiteCache.Get(siteId.Value);
             if (site != null)
             {
                 e.Value = site.Name;
             }
         }
         break;
     }
 }
        /// <summary>
        /// Gets the user-friendly description for a filter field setting.
        /// </summary>
        /// <param name="filterName"></param>
        /// <returns></returns>
        private string OnFormatFilterValueDescription(string filterName, string value)
        {
            if (filterName == FilterSettingName.Site)
            {
                int siteId;
                if (int.TryParse(value, out siteId))
                {
                    var site = SiteCache.Get(siteId);
                    if (site != null)
                    {
                        value = site.Name;
                    }
                }
            }
            else if (filterName == FilterSettingName.Page)
            {
                int pageId;
                if (int.TryParse(value, out pageId))
                {
                    var page = PageCache.Get(pageId);
                    if (page != null)
                    {
                        value = page.InternalName;
                    }
                }
            }
            else if (filterName == FilterSettingName.User)
            {
                int userPersonId;
                if (int.TryParse(value, out userPersonId))
                {
                    var personService = new PersonService(_dataContext);
                    var user          = personService.Get(userPersonId);
                    if (user != null)
                    {
                        value = user.FullName;
                    }
                }
            }
            else if (filterName == FilterSettingName.DateRange)
            {
                value = SlidingDateRangePicker.FormatDelimitedValues(value);
            }

            return(value);
        }
Пример #25
0
        /// <summary>
        /// Gets the push notification data to be sent to FCM.
        /// </summary>
        /// <param name="openAction">The open action.</param>
        /// <param name="pushData">The push data.</param>
        /// <param name="recipient">The recipient.</param>
        /// <returns>The data to be included in the <see cref="FCM.Net.Message.Data"/> property.</returns>
        private static Dictionary <string, string> GetPushNotificationData(PushOpenAction?openAction, PushData pushData, CommunicationRecipient recipient)
        {
            var notificationData = new Dictionary <string, string>();

            if (recipient != null)
            {
                notificationData.Add(PushKeys.CommunicationId, recipient.CommunicationId.ToString());
                notificationData.Add(PushKeys.RecipientId, recipient.Id.ToString());
            }
            ;

            if (!openAction.HasValue || pushData == null)
            {
                return(notificationData);
            }

            if (openAction == PushOpenAction.ShowDetails && pushData.MobileApplicationId.HasValue && recipient != null)
            {
                var site = SiteCache.Get(pushData.MobileApplicationId.Value);
                var additionalSettings = site?.AdditionalSettings.FromJsonOrNull <AdditionalSiteSettings>();

                if (additionalSettings?.CommunicationViewPageId != null)
                {
                    var page = PageCache.Get(additionalSettings.CommunicationViewPageId.Value);

                    if (page != null)
                    {
                        notificationData.Add(PushKeys.PageGuid, page.Guid.ToString());
                        notificationData.Add(PushKeys.QueryString, $"CommunicationRecipientGuid={recipient.Guid}");
                    }
                }
            }
            else if (openAction == PushOpenAction.LinkToMobilePage && pushData.MobilePageId.HasValue)
            {
                var page = PageCache.Get(pushData.MobilePageId.Value);

                if (page != null)
                {
                    notificationData.Add(PushKeys.PageGuid, page.Guid.ToString());
                    notificationData.Add(PushKeys.QueryString, UrlEncode(pushData.MobilePageQueryString));
                }
            }

            return(notificationData);
        }
Пример #26
0
        /// <summary>
        /// Handles the Pre Send Request event of the Application control.
        /// </summary>
        protected void Application_PreSendRequestHeaders()
        {
            Response.Headers.Remove("Server");
            Response.Headers.Remove("X-AspNet-Version");

            bool   useFrameDomains = false;
            string allowedDomains  = string.Empty;

            int?siteId = (Context.Items["Rock:SiteId"] ?? string.Empty).ToString().AsIntegerOrNull();

            // We only care about protecting content served up through Rock, not the static
            // content assets on the file system. Only Rock pages would have a site.
            if (!siteId.HasValue)
            {
                return;
            }

            try
            {
                if (siteId.HasValue)
                {
                    var site = SiteCache.Get(siteId.Value);
                    if (site != null && !string.IsNullOrWhiteSpace(site.AllowedFrameDomains))
                    {
                        useFrameDomains = true;
                        allowedDomains  = site.AllowedFrameDomains;
                    }
                }
            }
            catch
            {
                // ignore any exception that might have occurred
            }

            if (useFrameDomains)
            {
                // string concat is 5x faster than String.Format in this scenario
                Response.AddHeader("Content-Security-Policy", "frame-ancestors " + allowedDomains);
            }
            else
            {
                Response.AddHeader("X-Frame-Options", "SAMEORIGIN");
                Response.AddHeader("Content-Security-Policy", "frame-ancestors 'self'");
            }
        }
Пример #27
0
        protected string GetFilePath(string fileName)
        {
            string virtualPath = fileName;

            var siteCache = SiteCache.Get(hfSiteId.ValueAsInt());

            if (siteCache != null)
            {
                virtualPath = string.Format("~/Themes/{0}/Layouts/{1}.aspx", siteCache.Theme, fileName);

                if (!File.Exists(Request.MapPath(virtualPath)))
                {
                    virtualPath = virtualPath += " <span class='label label-danger'>Missing</span>";
                }
            }

            return(virtualPath);
        }
Пример #28
0
        /// <summary>
        /// Returns the default page for the site.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private async Task DefaultPageAsync(HttpContext context)
        {
            var site = GetSite(context);

            if (site == null)
            {
                site = SiteCache.Get(Rock.SystemGuid.Site.SITE_ROCK_INTERNAL.AsGuid());
            }

            if (!site.DefaultPageId.HasValue)
            {
                throw new SystemException("Invalid Site Configuration");
            }

            context.GetRouteData().Values["PageId"] = site.DefaultPageId.Value;

            await PageRouteAsync(context);
        }
Пример #29
0
        /// <summary>
        /// Binds the group members grid.
        /// </summary>
        protected void BindLayoutsGrid()
        {
            pnlLayouts.Visible = false;

            int siteId = PageParameter(PageParameterKey.SiteId).AsInteger();

            if (siteId == 0)
            {
                // quit if the siteId can't be determined
                return;
            }

            var rockContext = new RockContext();
            var site        = SiteCache.Get(siteId, rockContext);

            if (site == null)
            {
                return;
            }

            hfSiteId.SetValue(siteId);

            pnlLayouts.Visible = true;

            // Add any missing layouts
            LayoutService.RegisterLayouts(Request.MapPath("~"), site);

            LayoutService layoutService = new LayoutService(new RockContext());
            var           qry           = layoutService.Queryable().Where(a => a.SiteId.Equals(siteId));

            SortProperty sortProperty = gLayouts.SortProperty;

            if (sortProperty != null)
            {
                gLayouts.DataSource = qry.Sort(sortProperty).ToList();
            }
            else
            {
                gLayouts.DataSource = qry.OrderBy(l => l.Name).ToList();
            }

            gLayouts.DataBind();
        }
Пример #30
0
        /// <summary>
        /// Binds the filter.
        /// </summary>
        private void BindFilter()
        {
            int siteId = PageParameter(PageParameterKey.SiteId).AsInteger();

            if (siteId == 0)
            {
                // quit if the siteId can't be determined
                return;
            }
            LayoutService.RegisterLayouts(Request.MapPath("~"), SiteCache.Get(siteId));
            LayoutService layoutService = new LayoutService(new RockContext());
            var           layouts       = layoutService.Queryable().Where(a => a.SiteId.Equals(siteId)).ToList();

            ddlLayoutFilter.DataSource = layouts;
            ddlLayoutFilter.DataBind();
            ddlLayoutFilter.Items.Insert(0, Rock.Constants.All.ListItem);
            ddlLayoutFilter.Visible = layouts.Any();
            ddlLayoutFilter.SetValue(gPagesFilter.GetUserPreference("Layout"));
        }