Пример #1
0
        private void ClearCache()
        {
            RockMemoryCache cache = RockMemoryCache.Default;

            SyndicationFeedHelper.ClearCachedFeed(GetAttributeValue("RSSFeedUrl"));
            cache.Remove(TemplateCacheKey);
        }
Пример #2
0
        private void LoadFeed()
        {
            string feedUrl = GetAttributeValue("RSSFeedUrl");

            Dictionary <string, string> messages = new Dictionary <string, string>();
            bool isError = false;

            try
            {
                Dictionary <string, object> feedDictionary = SyndicationFeedHelper.GetFeed(feedUrl, GetAttributeValue("DetailPage"), (int)GetAttributeValue("CacheDuration").AsInteger(true), ref messages, ref isError);

                if (feedDictionary != null)
                {
                    string content = GetTemplate().Render(Hash.FromDictionary(feedDictionary));

                    if (content.Contains("No such template"))
                    {
                        System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(GetAttributeValue("Template"), @"'([^']*)");
                        if (match.Success)
                        {
                            messages.Add("Warning", string.Format("Could not find the template _{0}.liquid in {1}.", match.Groups[1].Value, ResolveRockUrl("~~/Assets/Liquid")));
                            isError = true;
                        }
                        else
                        {
                            messages.Add("Warning", "Unable to parse the template name from settings.");
                            isError = true;
                        }
                    }
                    else
                    {
                        phRSSFeed.Controls.Clear();
                        phRSSFeed.Controls.Add(new LiteralControl(content));
                    }

                    pnlContent.Visible = true;
                }
            }
            catch (Exception ex)
            {
                if (IsUserAuthorized("Administrate"))
                {
                    throw ex;
                }
            }

            if (messages.Count > 0)
            {
                if (IsUserAuthorized("Administrate"))
                {
                    SetNotificationBox(messages.FirstOrDefault().Key, messages.FirstOrDefault().Value, isError ? NotificationBoxType.Warning : NotificationBoxType.Info);
                }
                else
                {
                    SetNotificationBox("Content not available", "Oops. The requested content is not currently available. Please try again later.");
                }
            }
        }
Пример #3
0
        private void ClearCache()
        {
            SyndicationFeedHelper.ClearCachedFeed(GetAttributeValue(AttributeKey.RSSFeedUrl));

            if (LavaService.RockLiquidIsEnabled)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                LavaTemplateCache.Remove(this.TemplateCacheKey);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            LavaService.RemoveTemplateCacheEntry(this.TemplateCacheKey);
        }
Пример #4
0
        private void LoadFeed()
        {
            string feedUrl = GetAttributeValue("RSSFeedUrl");

            Dictionary <string, string> messages = new Dictionary <string, string>();
            bool isError = false;

            try
            {
                Dictionary <string, object> feedDictionary = SyndicationFeedHelper.GetFeed(feedUrl, GetAttributeValue("DetailPage"), GetAttributeValue("CacheDuration").AsInteger(), ref messages, ref isError);

                if (feedDictionary != null)
                {
                    int    articlesPerPage = GetAttributeValue("Resultsperpage").AsInteger();
                    int    currentPage     = 0;
                    string baseUrl         = new PageReference(RockPage.PageId).BuildUrl();

                    int.TryParse(PageParameter("articlepage"), out currentPage);

                    if (feedDictionary.ContainsKey("ResultsPerPage"))
                    {
                        feedDictionary["ResultsPerPage"] = articlesPerPage;
                    }
                    else
                    {
                        feedDictionary.Add("ResultsPerPage", articlesPerPage);
                    }


                    if (feedDictionary.ContainsKey("CurrentPage"))
                    {
                        feedDictionary["CurrentPage"] = currentPage;
                    }
                    else
                    {
                        feedDictionary.Add("CurrentPage", currentPage);
                    }

                    if (feedDictionary.ContainsKey("BaseUrl"))
                    {
                        feedDictionary["BaseUrl"] = baseUrl;
                    }
                    else
                    {
                        feedDictionary.Add("BaseUrl", baseUrl);
                    }


                    if (!String.IsNullOrWhiteSpace(GetAttributeValue("RSSFeedUrl")) && GetAttributeValue("IncludeRSSLink").AsBoolean())
                    {
                        string rssLink = string.Format("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"{0}\" href=\"{1}\" />",
                                                       feedDictionary.ContainsKey("title") ? feedDictionary["title"].ToString() : "RSS",
                                                       GetAttributeValue("RSSFeedUrl"));

                        Page.Header.Controls.Add(new LiteralControl(rssLink));
                    }


                    // rearrange the dictionary for cleaning purposes
                    if (feedDictionary.ContainsKey("entry"))
                    {
                        var item = feedDictionary["entry"];

                        if (item != null)
                        {
                            feedDictionary.Remove("entry");
                            feedDictionary["Entries"] = item;
                        }
                    }


                    // remove the link item
                    if (feedDictionary.ContainsKey("link"))
                    {
                        var item = feedDictionary["link"];

                        if (item != null)
                        {
                            feedDictionary.Remove("link");
                        }
                    }

                    string content = String.Empty;
                    if (GetAttributeValue("EnableDebug").AsBoolean() && IsUserAuthorized(Authorization.EDIT))
                    {
                        content = feedDictionary.lavaDebugInfo();
                    }
                    else
                    {
                        content = GetTemplate().Render(Hash.FromDictionary(feedDictionary));
                    }


                    if (content.Contains("No such template"))
                    {
                        System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(GetAttributeValue("Template"), @"'([^']*)");
                        if (match.Success)
                        {
                            messages.Add("Warning", string.Format("Could not find the template _{0}.liquid in {1}.", match.Groups[1].Value, ResolveRockUrl("~~/Assets/Liquid")));
                            isError = true;
                        }
                        else
                        {
                            messages.Add("Warning", "Unable to parse the template name from settings.");
                            isError = true;
                        }
                    }
                    else
                    {
                        phRSSFeed.Controls.Clear();
                        phRSSFeed.Controls.Add(new LiteralControl(content));
                    }

                    pnlContent.Visible = true;
                }
            }
            catch (Exception ex)
            {
                if (IsUserAuthorized(Authorization.ADMINISTRATE))
                {
                    throw ex;
                }
                else
                {
                    messages.Add("exception", "An exception has occurred.");
                }
            }

            if (messages.Count > 0)
            {
                if (IsUserAuthorized(Authorization.ADMINISTRATE))
                {
                    SetNotificationBox(messages.FirstOrDefault().Key, messages.FirstOrDefault().Value, isError ? NotificationBoxType.Warning : NotificationBoxType.Info);
                }
                else
                {
                    SetNotificationBox("Content not available", "Oops. The requested content is not currently available. Please try again later.");
                }
            }
        }
Пример #5
0
        private void LoadFeedItem(string feedItemId)
        {
            string feedUrl = GetAttributeValue(AttributeKey.RSSFeedUrl);
            Dictionary <string, string> messages = new Dictionary <string, string>();
            bool isError = false;

            try
            {
                Dictionary <string, object> feedDictionary = SyndicationFeedHelper.GetFeed(feedUrl, RockPage.Guid.ToString(), GetAttributeValue(AttributeKey.CacheDuration).AsInteger(), ref messages, ref isError);

                if (feedDictionary != null && feedDictionary.Count > 0)
                {
                    if (!String.IsNullOrWhiteSpace(GetAttributeValue(AttributeKey.RSSFeedUrl)) && GetAttributeValue(AttributeKey.IncludeRSSLink).AsBoolean())
                    {
                        string rssLink = string.Format("<link rel=\"alternate\" type=\"application/rss+xml\" title=\"{0}\" href=\"{1}\" />",
                                                       feedDictionary.ContainsKey("title") ? feedDictionary["title"].ToString() : "RSS",
                                                       GetAttributeValue(AttributeKey.RSSFeedUrl));

                        Page.Header.Controls.Add(new LiteralControl(rssLink));
                    }

                    Dictionary <string, object> previousItem = null;
                    Dictionary <string, object> selectedItem = null;
                    Dictionary <string, object> nextItem     = null;
                    if (feedDictionary.ContainsKey("item") || feedDictionary.ContainsKey("entry"))
                    {
                        List <Dictionary <string, object> > items = ((List <Dictionary <string, object> >)feedDictionary.Where(i => i.Key == "item" || i.Key == "entry").FirstOrDefault().Value);
                        for (int i = 0; i < items.Count; i++)
                        {
                            if (items[i]["articleHash"].ToString() == feedItemId)
                            {
                                selectedItem = items[i];


                                if (i > 0)
                                {
                                    nextItem = items[i - 1];
                                }

                                if (i < (items.Count - 1))
                                {
                                    previousItem = items[i + 1];
                                }
                                break;
                            }
                        }
                    }

                    Dictionary <string, object> feedFinal = new Dictionary <string, object>();
                    feedFinal.Add("Feed", feedDictionary);
                    feedFinal.Add("SelectedItem", selectedItem);
                    feedFinal.Add("PreviousItem", previousItem);
                    feedFinal.Add("NextItem", nextItem);

                    if (selectedItem == null)
                    {
                        messages.Add("Requested item not available", "The item that you requested is currently not available.");
                    }
                    else
                    {
                        string content = GetTemplate().Render(Hash.FromDictionary(feedFinal));

                        if (content.Contains("No such template"))
                        {
                            System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(GetAttributeValue(AttributeKey.Template), @"'([^']*)");
                            if (match.Success)
                            {
                                messages.Add("Warning", string.Format("Could not find the template _{0}.liquid in {1}.", match.Groups[1].Value, ResolveRockUrl("~~/Assets/Liquid")));
                                isError = true;
                            }
                            else
                            {
                                messages.Add("Warning", "Unable to parse the template name from settings.");
                                isError = true;
                            }
                        }
                        else
                        {
                            phFeedItem.Controls.Clear();
                            phFeedItem.Controls.Add(new LiteralControl(content));
                            pnlContent.Visible = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (IsUserAuthorized(Rock.Security.Authorization.ADMINISTRATE))
                {
                    throw ex;
                }
                else
                {
                    messages.Add("Content not available.", "Oops. The requested content is not currently available. Please try again later.");
                    isError = true;
                }
            }


            if (messages.Count > 0)
            {
                if (IsUserAuthorized(Rock.Security.Authorization.ADMINISTRATE))
                {
                    SetNotificationBox(messages.FirstOrDefault().Key, messages.FirstOrDefault().Value, isError ? NotificationBoxType.Warning : NotificationBoxType.Info);
                }
                else
                {
                    SetNotificationBox("Content not available", "Oops. The requested content is not currently available. Please try again later.");
                }
            }
        }
Пример #6
0
 private void ClearCache()
 {
     SyndicationFeedHelper.ClearCachedFeed(GetAttributeValue(AttributeKey.RSSFeedUrl));
     RockCache.Remove(TemplateCacheKey);
 }
Пример #7
0
        private void LoadFeedItem(string feedItemId)
        {
            string feedUrl = GetAttributeValue("RSSFeedUrl");
            Dictionary <string, string> messages = new Dictionary <string, string>();
            bool isError = false;

            try
            {
                Dictionary <string, object> feedDictionary = SyndicationFeedHelper.GetFeed(feedUrl, RockPage.Guid.ToString(), (int)GetAttributeValue("CacheDuration").AsInteger(true), ref messages, ref isError);

                if (feedDictionary != null && feedDictionary.Count > 0)
                {
                    Dictionary <string, object>         previousItem = null;
                    Dictionary <string, object>         selectedItem = null;
                    Dictionary <string, object>         nextItem     = null;
                    List <Dictionary <string, object> > items        = ((List <Dictionary <string, object> >)feedDictionary["Items"]);
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (items[i]["Id"].ToString() == feedItemId)
                        {
                            selectedItem = items[i];


                            //items are in descending order so the previous item will be the next indexed item
                            if (i > 0)
                            {
                                nextItem = items[i - 1];
                            }

                            if (i < (items.Count - 1))
                            {
                                previousItem = items[i + 1];
                            }
                            break;
                        }
                    }

                    if (selectedItem == null)
                    {
                        messages.Add("Requested item not available", "The item that you requested is currently not available.");
                    }
                    else
                    {
                        Dictionary <string, object> feedFinal = new Dictionary <string, object>();
                        feedFinal.Add("Feed", feedDictionary);
                        feedFinal.Add("SelectedItem", selectedItem);
                        feedFinal.Add("PreviousItem", previousItem);
                        feedFinal.Add("NextItem", nextItem);

                        string content = GetTemplate().Render(Hash.FromDictionary(feedFinal));

                        if (content.Contains("No such template"))
                        {
                            System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(GetAttributeValue("Template"), @"'([^']*)");
                            if (match.Success)
                            {
                                messages.Add("Warning", string.Format("Could not find the template _{0}.liquid in {1}.", match.Groups[1].Value, ResolveRockUrl("~~/Assets/Liquid")));
                                isError = true;
                            }
                            else
                            {
                                messages.Add("Warning", "Unable to parse the template name from settings.");
                                isError = true;
                            }
                        }
                        else
                        {
                            phFeedItem.Controls.Clear();
                            phFeedItem.Controls.Add(new LiteralControl(content));
                            pnlContent.Visible = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (IsUserAuthorized("Administrate"))
                {
                    throw ex;
                }
                else
                {
                    messages.Add("Content not available.", "Oops. The requested content is not currently available. Please try again later.");
                    isError = true;
                }
            }


            if (messages.Count > 0)
            {
                if (IsUserAuthorized("Administrate"))
                {
                    SetNotificationBox(messages.FirstOrDefault().Key, messages.FirstOrDefault().Value, isError ? NotificationBoxType.Warning : NotificationBoxType.Info);
                }
                else
                {
                    SetNotificationBox("Content not available", "Oops. The requested content is not currently available. Please try again later.");
                }
            }
        }
Пример #8
0
 private void ClearCache()
 {
     SyndicationFeedHelper.ClearCachedFeed(GetAttributeValue("RSSFeedUrl"));
     LavaTemplateCache.Remove(TemplateCacheKey);
 }