コード例 #1
0
        public TopicAlertButtonModel(
            IGlassBase model,
            IRenderingContextService renderingService,
            IAuthenticatedUserContext userContext,
            IUserContentService <ISavedSearchSaveable, ISavedSearchDisplayable> savedSearchService,
            ITextTranslator textTranslator)
        {
            var parameters = renderingService.GetCurrentRenderingParameters <ITopic_Alert_Options>();

            if (IsAuthorPage(model))
            {
                parameters = SetupAuthorParameters(parameters);
            }

            IsAuthenticated = userContext.IsAuthenticated;
            SetAlertText    = textTranslator.Translate(DictionaryKeys.TopicSetAlertText);
            RemoveAlertText = textTranslator.Translate(DictionaryKeys.TopicRemoveAlertText);
            DisplayButton   = model != null && (!string.IsNullOrEmpty(parameters?.Related_Search) || Sitecore.Context.PageMode.IsExperienceEditor);
            if (DisplayButton)
            {
                AlertIsSet = savedSearchService.Exists(new SavedSearchDisplayModel
                {
                    Url          = parameters?.Related_Search ?? string.Empty,
                    AlertEnabled = true
                });
                TopicName  = GetTopicTitle(model);
                AlertTitle = !string.IsNullOrEmpty(parameters?.Search_Name) ? parameters.Search_Name : TopicName;
                AlertUrl   = parameters?.Related_Search;
            }
        }
コード例 #2
0
        public void Setup()
        {
            _resolver = Substitute.For <IComponentContext>();
            _renderingContextService = Substitute.For <IRenderingContextService>();

            IComponentRegistration retVal;

            _resolver.ComponentRegistry.TryGetRegistration(null, out retVal).ReturnsForAnyArgs(true);

            _sut = new AutofacViewModelFactory(_resolver, _renderingContextService);
        }
コード例 #3
0
 public AutofacViewModelFactory(IComponentContext resolver, IRenderingContextService renderingContextService)
 {
     if (resolver == null)
     {
         throw new ArgumentNullException(nameof(resolver));
     }
     if (renderingContextService == null)
     {
         throw new ArgumentNullException(nameof(renderingContextService));
     }
     _resolver = resolver;
     _renderingContextService = renderingContextService;
 }
コード例 #4
0
        public LatestNewsViewModel(IGlassBase datasource,
                                   IRenderingContextService renderingParametersService,
                                   IArticleSearch articleSearch,
                                   IItemManuallyCuratedContent itemManuallyCuratedContent,
                                   IArticleListItemModelFactory articleListableFactory,
                                   ISiteRootContext rootContext,
                                   ITextTranslator textTranslator,
                                   IAuthorService authorService,
                                   IDCDReader dcdReader)
        {
            Datasource    = datasource;
            ArticleSearch = articleSearch;
            ItemManuallyCuratedContent = itemManuallyCuratedContent;
            ArticleListableFactory     = articleListableFactory;
            TextTranslator             = textTranslator;
            AuthorService = authorService;
            DcdReader     = dcdReader;

            Stopwatch sw = Stopwatch.StartNew();

            StringExtensions.WriteSitecoreLogs("Reading rendering parameters at:", sw, "Latest News");

            Authors    = new List <string>();
            Parameters = renderingParametersService.GetCurrentRenderingParameters <ILatest_News_Options>();

            StringExtensions.WriteSitecoreLogs("Reading rendering parameters ends at:", sw, "Latest News");

            if (Parameters == null)
            {
                return;
            }

            DisplayTitle   = Parameters.Display_Title;
            ItemsToDisplay = Parameters.Number_To_Display?.Value ?? 6;
            SeeAllLink     = Parameters.Show_See_All ? new Link
            {
                Text = TextTranslator.Translate("Article.LatestFrom.SeeAllLink")
            } : null;

            StringExtensions.WriteSitecoreLogs("Reading publicationNames at:", sw, "Latest News");

            var publicationNames = Parameters.Publications.Any()
                ? Parameters.Publications.Select(p => p.Publication_Name)
                : new[] { rootContext.Item.Publication_Name };

            StringExtensions.WriteSitecoreLogs("Reading publicationNames ends at:", sw, "Latest News");

            StringExtensions.WriteSitecoreLogs("Reading Authers at:", sw, "Latest News");

            Authors = Parameters.Authors?.Select(p => RemoveSpecialCharactersFromGuid(p._Id.ToString())).ToArray();
            CompanyRecordNumbers = string.IsNullOrEmpty(Parameters.CompanyID)
                ? (IList <string>) new List <string>()
                : Parameters.CompanyID.Split(',');

            StringExtensions.WriteSitecoreLogs("Reading Authers ends at:", sw, "Latest News");

            if (IsAuthorPage)
            {
                Author_Page();
                if (!Parameters.Publications.Any()) // authors page shouldn't filter on the current publication
                {
                    publicationNames = Enumerable.Empty <string>();
                }
            }
            else if (datasource._TemplateId.ToString() == ICompany_PageConstants.TemplateIdString)
            {
                Company_Page();
                if (!Parameters.Publications.Any()) // authors page shouldn't filter on the current publication
                {
                    publicationNames = Enumerable.Empty <string>();
                }
            }
            else
            {
                Other_Page();
            }

            News = GetLatestNews(datasource._Id, Parameters.Subjects.Select(s => s._Id), publicationNames, Authors, CompanyRecordNumbers, ItemsToDisplay);
        }