예제 #1
0
        public IEnumerable <Model.RedirectKeyword> GetKeywordRedirects(CultureInfo cultureInfo)
        {
            var result = _keywordsCache.ContainsKey(cultureInfo) ? _keywordsCache[cultureInfo] : null;

            if (result == null)
            {
                result = new List <Model.RedirectKeyword>();
                using (var connection = new DataConnection(PublicationScope.Unpublished, cultureInfo))
                {
                    foreach (var redirectKeyword in connection.Get <RedirectKeyword>())
                    {
                        var interfaceType = redirectKeyword.DataSourceId.InterfaceType;
                        var stringKey     = redirectKeyword.GetUniqueKey().ToString();
                        var locale        = redirectKeyword.DataSourceId.LocaleScope.Name;

                        var existingPublishSchedule   = PublishScheduleHelper.GetPublishSchedule(interfaceType, stringKey, locale);
                        var existingUnpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(interfaceType, stringKey, locale);

                        if (redirectKeyword.PublicationStatus == GenericPublishProcessController.Published)
                        {
                            result.Add(new Model.RedirectKeyword
                            {
                                Keyword       = redirectKeyword.Keyword,
                                LandingPage   = KeywordFacade.GetPageUrl(redirectKeyword.LandingPage, cultureInfo),
                                PublishDate   = existingPublishSchedule?.PublishDate.ToTimeZoneDateTimeString(),
                                UnpublishDate = existingUnpublishSchedule?.UnpublishDate.ToTimeZoneDateTimeString(),
                            });
                        }
                        else
                        {
                            var publishedredirectKeyword = DataFacade.GetDataFromOtherScope(redirectKeyword, DataScopeIdentifier.Public).FirstOrDefault();

                            result.Add(new Model.RedirectKeyword
                            {
                                Keyword     = publishedredirectKeyword?.Keyword,
                                LandingPage =
                                    publishedredirectKeyword != null
                                        ? KeywordFacade.GetPageUrl(publishedredirectKeyword.LandingPage, cultureInfo)
                                        : null,
                                KeywordUnpublished     = redirectKeyword.Keyword,
                                LandingPageUnpublished = KeywordFacade.GetPageUrl(redirectKeyword.LandingPage, cultureInfo),
                                PublishDate            = existingPublishSchedule?.PublishDate.ToTimeZoneDateTimeString(),
                                UnpublishDate          = existingUnpublishSchedule?.UnpublishDate.ToTimeZoneDateTimeString(),
                            });
                        }
                    }
                }
                _keywordsCache[cultureInfo] = result;
            }
            return(result);
        }
예제 #2
0
        private List <Model.RedirectKeyword> LoadKeywords(CultureInfo cultureInfo)
        {
            var result = new List <Model.RedirectKeyword>();

            using (var connection = new DataConnection(PublicationScope.Unpublished, cultureInfo))
            {
                foreach (var redirectKeyword in connection.Get <RedirectKeyword>())
                {
                    var interfaceType = redirectKeyword.DataSourceId.InterfaceType;
                    var stringKey     = redirectKeyword.GetUniqueKey().ToString();
                    var locale        = redirectKeyword.DataSourceId.LocaleScope.Name;

                    var existingPublishSchedule   = PublishScheduleHelper.GetPublishSchedule(interfaceType, stringKey, locale);
                    var existingUnpublishSchedule = PublishScheduleHelper.GetUnpublishSchedule(interfaceType, stringKey, locale);

                    Model.RedirectKeyword keyword;
                    if (redirectKeyword.PublicationStatus == GenericPublishProcessController.Published)
                    {
                        keyword = new Model.RedirectKeyword
                        {
                            Keyword       = redirectKeyword.Keyword,
                            LandingPage   = KeywordFacade.GetPageUrl(redirectKeyword.LandingPage, cultureInfo),
                            PublishDate   = existingPublishSchedule?.PublishDate.ToTimeZoneDateTimeString(),
                            UnpublishDate = existingUnpublishSchedule?.UnpublishDate.ToTimeZoneDateTimeString(),
                            HomePage      = GetHomePageTitle(redirectKeyword.HomePage.GetValueOrDefault()),
                            HomePageId    = redirectKeyword.HomePage.GetValueOrDefault(),
                        };
                    }
                    else
                    {
                        var publishedredirectKeyword = DataFacade.GetDataFromOtherScope(redirectKeyword, DataScopeIdentifier.Public).FirstOrDefault();
                        keyword = new Model.RedirectKeyword
                        {
                            Keyword     = redirectKeyword.Keyword ?? publishedredirectKeyword?.Keyword,
                            LandingPage = publishedredirectKeyword != null?KeywordFacade.GetPageUrl(publishedredirectKeyword.LandingPage, cultureInfo) : null,
                                              LandingPageUnpublished = KeywordFacade.GetPageUrl(redirectKeyword.LandingPage, cultureInfo),
                                              PublishDate            = existingPublishSchedule?.PublishDate.ToTimeZoneDateTimeString(),
                                              UnpublishDate          = existingUnpublishSchedule?.UnpublishDate.ToTimeZoneDateTimeString(),
                                              HomePage   = GetHomePageTitle((redirectKeyword.HomePage ?? publishedredirectKeyword?.HomePage).GetValueOrDefault()),
                                              HomePageId = (redirectKeyword.HomePage ?? publishedredirectKeyword?.HomePage).GetValueOrDefault(),
                        };
                    }

                    result.Add(keyword);
                }
            }

            return(result);
        }