Пример #1
1
        // make sure we use singleton and lazy load
        public SettingsLogic(ISitecoreContext currentContext)
        {
            _currentContext = currentContext;

            _siteSettings = new Lazy<IScripts>(() =>
            {
                return _currentContext.GetItem<IScripts>(Ids.Content.SiteSettings.Id); //this is a different way to do it compared to the social settings
            });
        }
Пример #2
0
        private IEnumerable <I___BasePage> GetAllPages(string startPath)
        {
            try
            {
                Stopwatch sw     = Stopwatch.StartNew();
                int       pageNo = Convert.ToInt32(HttpContext.Current.Request.QueryString["page"]);

                using (var context = SearchContextFactory.Create())
                {
                    var query = context.GetQueryable <GeneralContentResult>()
                                .Filter(j
                                        => (j.TemplateId == IGeneral_Content_PageConstants.TemplateId || j.TemplateId == IArticleConstants.TemplateId || j.TemplateId == ITopic_PageConstants.TemplateId) &&
                                        j.Path.StartsWith(startPath.ToLower()) &&
                                        !j.ExcludeFromGoogleSearch);

                    var results = query.GetResults();

                    var pages = results.Hits.Select(h => SitecoreContext.GetItem <I___BasePage>(h.Document.ItemId.Guid)).Where(a => a != null);

                    StringExtensions.WriteSitecoreLogs("Reached GetAllPages method at :", sw, "SitemapService");

                    return((!pages.Any())
                    ? Enumerable.Empty <I___BasePage>()
                    : pages);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #3
0
        public ActionResult EnableFacialRecognition()
        {
            if (string.IsNullOrWhiteSpace(_contextWrapper.DataSource))
            {
                return(View());
            }

            var viewModel      = new EnableFacialRecognitionViewModel();
            var dataSourceItem = _sitecoreContext.GetItem <IEnableFacialRecognition>(Guid.Parse(_contextWrapper.DataSource));

            if (dataSourceItem == null)
            {
                return(View());
            }

            viewModel.EnableFacialRecognitionLabel = _propertyBuilder.BuildHtmlString(dataSourceItem, x => x.EnableFacialRecognitionLabel);
            viewModel.InformationText = _propertyBuilder.BuildHtmlString(dataSourceItem, x => x.InformationText);
            viewModel.SaveButtonText  = _propertyBuilder.BuildHtmlString(dataSourceItem, x => x.SaveButtonText);
            viewModel.TitleText       = _propertyBuilder.BuildHtmlString(dataSourceItem, x => x.TitleText);
            viewModel.WebcamLabel     = _propertyBuilder.BuildHtmlString(dataSourceItem, x => x.WebcamLabel);
            viewModel.EnableFacialRecognitionPlaceholderText = dataSourceItem.EnableFacialRecognitionPlaceholderText;
            viewModel.WebcamAccessWarningLabel = _propertyBuilder.BuildHtmlString(dataSourceItem, x => x.WebcamAccessWarning);
            viewModel.SaveErrorLabel           = _propertyBuilder.BuildHtmlString(dataSourceItem, x => x.SaveErrorText);
            viewModel.SaveSuccessLabel         = _propertyBuilder.BuildHtmlString(dataSourceItem, x => x.SaveSuccessText);

            return(View(viewModel));
        }
        public void GetCurrentRenderingDatasource_NestingEnabled_WithDirectDatasource_WithDefaultNesting_ReturnsDatasource()
        {
            // Setup DIRECT datasource for rendering
            _rendering.DataSource.Returns(ci => _directDatasource._Id.ToString());
            _sitecoreContext.GetItem <IGlassBase>(_directDatasource._Id, inferType: true).Returns(_directDatasource);

            var datasource = _renderingService.GetCurrentRenderingDatasource <IGlassBase>();

            Assert.AreEqual(_directDatasource._Id, datasource._Id);
        }
Пример #5
0
        /// <summary>
        /// Uses the current Rendering context to setup basic fields in the model with information regarding the current rendering.
        /// Most of the processing in this method only happens if the content editor is in IsExperienceEditorEditing.
        /// </summary>
        /// <param name="model">A POCO object that will hold reference to our Rendering details</param>
        /// <param name="controller">A reference to the controller that is calling this method. This is needed for access to the HtmlHelper </param>
        public void PopulateStandardExperienceResponse(ref IComponentModelBase model, Controller controller)
        {
            if (model == null)
            {
                return;
            }

            actingController = controller;
            try
            {
                model.IsExperienceEditorEditing = Context.PageMode.IsExperienceEditorEditing;

                var currentRendering = RenderingContext.CurrentOrNull?.Rendering;

                model.IsDataSourceSet = !string.IsNullOrWhiteSpace(currentRendering.DataSource);
                model.RenderingName   = currentRendering.RenderingItem.Name;
                model.RenderingId     = currentRendering.Id.ToString();

                if (model.IsDataSourceSet && model.IsExperienceEditorEditing)
                {
                    model.DataSourceCount      = currentRendering.DataSource.Count();
                    model.DataSourceIdentifier = currentRendering.DataSource;

                    Guid datasource = Guid.Empty;
                    if (Guid.TryParse(model.DataSourceIdentifier, out datasource))
                    {
                        var dataSourceItem = _glassService.GetItem <GlassBase>(datasource);
                        model.DataSourceName = dataSourceItem.Name;
                        model.DataSourcePath = dataSourceItem.FullPath;
                        SetLinkedItems(model, datasource);
                    }

                    SetEditDatasourceEditFrame(model, controller);
                }

                if (model.IsExperienceEditorEditing)
                {
                    var conditionalRenderings = GetPersonalizedRenderings(currentRendering);
                    model.HasConditionalRenderings = conditionalRenderings.Any();
                    if (model.HasConditionalRenderings)
                    {
                        model.Rules = GetRulesForRendering(conditionalRenderings.FirstOrDefault());
                    }
                }
            }
            catch (Exception ex)
            {
                model.ErrorOccurred = true;
                model.ErrorMessage  = ex.Message;
            }
        }
Пример #6
0
        public SyndicationItem GetSyndicationItemFromSitecore(ISitecoreContext sitecoreContext, Item item)
        {
            var article = sitecoreContext.GetItem <IArticle>(item.ID.ToString());

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

            //Build the basic syndicaton item
            var searchTerm      = Sitecore.Context.Request.QueryString["q"];
            var articleUrl      = string.Format("{0}?utm_source=search&amp;utm_medium=RSS&amp;utm_term={1}&amp;utm_campaign=search_rss", article._AbsoluteUrl, searchTerm);
            var syndicationItem = new SyndicationItem(GetItemTitle(article),
                                                      GetItemSummary(article),
                                                      new Uri(articleUrl),
                                                      article._AbsoluteUrl,
                                                      article.Actual_Publish_Date);

            //Add the custom fields
            syndicationItem = AddIdToFeedItem(syndicationItem, article);
            syndicationItem = AddPubDateToFeedItem(syndicationItem, article);
            syndicationItem = AddCatgoryToFeedItem(syndicationItem, article);
            syndicationItem = AddAuthorsToFeedItem(syndicationItem, article);
            syndicationItem = AddTaxonomyToFeedItem(syndicationItem, article);
            syndicationItem = AddMediaTypeToFeedItem(syndicationItem, article);
            syndicationItem = AddEmailSortOrderField(syndicationItem, article);

            var content        = syndicationItem.Content as TextSyndicationContent;
            var descriptonText = HttpUtility.HtmlEncode(content.Text);

            syndicationItem.Content = new TextSyndicationContent(descriptonText);

            return(syndicationItem);
        }
Пример #7
0
        public bool Build(CommentViewModel viewModel)
        {
            try
            {
                var comment = Mapper.Map <Comment>(viewModel);
                var result  = _commentRepository.Create(comment);
                if (!result)
                {
                    ModelErrors.Add(_commentRepository.RepositoryErrors.LastOrDefault());
                    return(false);
                }

                using (new SecurityDisabler())
                {
                    var item = _context.GetItem <Item>(viewModel.ArticleId);
                    item.Editing.BeginEdit();
                    MultilistField comments = new MultilistField(item.Fields["Comments"]);
                    comments.Add(comment.Id.ToString());
                    item.Editing.EndEdit();
                }
                return(true);
            }
            catch (Exception ex)
            {
                ModelErrors.Add(ex);
                return(false);
            }
        }
Пример #8
0
        public static IFile GetIFile(this File file, ISitecoreContext context)
        {
            if (file == null)
            {
                throw new System.ArgumentNullException(nameof(file));
            }

            return(context.GetItem <IFile>(file.Id));
        }
Пример #9
0
        // make sure we use singleton and lazy load
        public SettingsLogic(ISitecoreContext currentContext)
        {
            _currentContext = currentContext;

            _siteSettings = new Lazy <IScripts>(() =>
            {
                return(_currentContext.GetItem <IScripts>(Ids.Content.SiteSettings.Id)); //this is a different way to do it compared to the social settings
            });
        }
        public string Create(IUserResetPassword userResetPassword)
        {
            var siteRootContext = SitecoreContext?.GetRootItem <ISite_Root>();

            var item             = SitecoreContext.GetItem <I___BasePage>(siteRootContext.Reset_Password_Page);
            var resetPasswordUrl = item?._AbsoluteUrl ?? string.Empty;

            return(string.Format("{0}?{1}={2}", resetPasswordUrl, Configuration.Parameter, userResetPassword.Token));
        }
Пример #11
0
        public void Process(HttpRequestArgs args)
        {
            Sitecore.Diagnostics.Log.Info("Started ArticleItemResolver", " ArticleItemResolver ");
            Assert.ArgumentNotNull((object)args, "args");
            if (Context.Item != null || Context.Database == null || args.Url.ItemPath.Length == 0)
            {
                return;
            }

            var match = GetArticleNumberFromRequestItemPath(args.Url.ItemPath);

            if (string.IsNullOrEmpty(match.ArticleNumber))
            {
                return;
            }

            //find the new article page
            IArticleSearchFilter filter = ArticleSearcher.CreateFilter();

            filter.PageSize       = 1;
            filter.Page           = 1;
            filter.ArticleNumbers = match.ArticleNumber.SingleToList();

            var results = ArticleSearcher.Search(filter);

            IArticle a = results.Articles.FirstOrDefault();

            if (a == null)
            {
                return;
            }

            string urlTitle = ArticleSearch.GetCleansedArticleTitle(a); // a._Name.ToLower().Replace(" ", "-");

            if (!urlTitle.Equals(match.ArticleTitle, System.StringComparison.InvariantCultureIgnoreCase))
            {
                if (!HttpContext.Current.Response.IsRequestBeingRedirected)
                {
                    HttpContext.Current.Response.RedirectPermanent(ArticleSearch.GetArticleCustomPath(a), true);
                }
            }

            Item i = SitecoreContext.GetItem <Item>(a._Id);

            if (i == null)
            {
                return;
            }

            Context.Item             = i;
            args.Url.ItemPath        = i.Paths.FullPath;
            Context.Request.ItemPath = i.Paths.FullPath;
            Sitecore.Diagnostics.Log.Info("Ended ArticleItemResolver", " ArticleItemResolver");
        }
Пример #12
0
        public static Expression <Func <T, bool> > GetPredicate <T>(ISearchParameter parameters, ISitecoreContext context) where T : IFacetableContent
        {
            var predicate = PredicateBuilder.True <T>();

            predicate = parameters.FilterOnTemplates.Aggregate(predicate, (current, temp) => current.Or(p => p.TemplateId == temp));
            if (parameters.FilterOnFields == null || !parameters.FilterOnFields.Any())
            {
                return(predicate);
            }
            IEnumerable <Guid> facetOns = parameters.FilterOnFields;
            IEnumerable <Models.Glass.Reboot.Facet> facets =
                facetOns.Select(i => context.GetItem <Models.Glass.Reboot.Facet>(i)).Reverse();

            foreach (var filter in facets)
            {
                string s = HttpContext.Current.Request.QueryString.Get(filter.Name);
                switch (filter.FacetName)
                {
                case "Genres":
                    if (!string.IsNullOrEmpty(s) && ShortID.IsShortID(s))
                    {
                        //w = w.Where(a => a.Genres.Contains(Guid.Parse(s)));
                        predicate = predicate.And(o => o.Genres.Contains(Guid.Parse(s)));
                    }
                    break;

                case "Production Company":
                    if (!string.IsNullOrEmpty(s) && ShortID.IsShortID(s))
                    {
                        //w = w.Where(a => a.ProductionCompanies.Contains(Guid.Parse(s)));
                        predicate = predicate.And(a => a.ProductionCompanies.Contains(Guid.Parse(s)));
                    }
                    break;

                case "Status":
                    if (!string.IsNullOrEmpty(s))
                    {
                        //w = w.Where(a => a.Status.Equals(s));
                        predicate = predicate.And(a => a.Status.Equals(s));
                    }
                    break;

                case "Spoken Language":
                    if (!string.IsNullOrEmpty(s))
                    {
                        //w = w.Where(a => a.Status.Equals(s));
                        predicate = predicate.And(a => a.SpokenLanguages.Contains(Guid.Parse(s)));
                    }
                    break;
                }
            }
            return(predicate);
        }
Пример #13
0
        public SearchPageParser(string pageId, ISitecoreContext context, ISearchRuleParser ruleParser)
        {
            IGlassBase page = null;

            if (!string.IsNullOrEmpty(pageId))
            {
                page = context.GetItem <IGlassBase>(pageId, inferType: true);
            }

            if (page == null)
            {
                page = context.GetCurrentItem <IGlassBase>(inferType: true);
            }

            if (!(page is I_Listing_Configuration) && RenderingContext.CurrentOrNull != null)
            {
                page = context.GetItem <IGlassBase>(RenderingContext.Current.Rendering.DataSource, inferType: true);
            }

            Initialize(page, ruleParser);
        }
        public IHttpActionResult SaveItem(SavedDocumentSaveRequest request)
        {
            Sitecore.Data.ID itemID = ID.Null;
            if (!Sitecore.Data.ID.TryParse(request.DocumentID, out itemID))
            {
                return(Ok(new
                {
                    success = false,
                    message = BadIDKey
                }));
            }

            var page            = SitecoreContext.GetItem <I___BasePage>(itemID.Guid);
            var article         = SitecoreContext.GetItem <IArticle>(itemID.Guid);
            var publicationName = ArticleService.GetArticlePublicationName(article);
            var result          = SaveDocumentContext.Save(page.Title, publicationName, request.DocumentID);

            return(Ok(new
            {
                success = result.Success,
                message = result.Message
            }));
        }
        public override IRenderingModelBase GetModel()
        {
            var model = new ContactUsRenderings();

            FillBaseProperties(model);
            var item = RenderingContext.Current?.Rendering?.Item;

            if (item != null && item.IsDerived(ContactUsConstants.TemplateId))
            {
                model.DataSource     = _sitecoreContext.GetItem <ContactUsDataModel>(item.ID.Guid);
                model.ReactViewModel = CreateReactModel(model.DataSource);
                return(model);
            }
            return(null);
        }
Пример #16
0
        public SyndicationItem GetSyndicationItemFromSitecore(ISitecoreContext sitecoreContext, Item item)
        {
            var    article         = sitecoreContext.GetItem <IArticle>(item.ID.ToString());
            string publicationName = "None";

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

            if (article.Publication != null)
            {
                var publication = sitecoreContext.GetItem <Item>(article.Publication);
                publicationName = publication?.Name;
            }
            var articleUrl = string.Format("{0}?utm_source={1}&amp;utm_medium=RSS&amp;utm_campaign={2}_RSS_Feed", article._AbsoluteUrl, publicationName, publicationName);
            //Build the basic syndicaton item
            var syndicationItem = new SyndicationItem(GetItemTitle(article),
                                                      GetItemSummary(article),
                                                      new Uri(articleUrl),
                                                      article._AbsoluteUrl,
                                                      article.Actual_Publish_Date);

            string siteLink = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);

            syndicationItem = AddImageToFeedItem(syndicationItem, article, siteLink);
            syndicationItem = AddAuthorsToFeedItem(syndicationItem, article);
            syndicationItem = AddPubDateToFeedItem(syndicationItem, article);

            var content        = syndicationItem.Content as TextSyndicationContent;
            var descriptonText = HttpUtility.HtmlEncode(content.Text);

            syndicationItem.Content = new TextSyndicationContent(descriptonText);

            return(syndicationItem);
        }
Пример #17
0
        /// <summary>
        ///     Add the copyright text to the rss channel, this is pulled from Sitecore global config.  The value
        /// can be overridden per feed if this field is filled
        /// </summary>
        /// <param name="feed"></param>
        /// <returns></returns>
        public SyndicationFeed AddCopyrightTextToFeed(SyndicationFeed feed, ISitecoreContext sitecoreContext, string siteConfigItemId, I_Base_Rss_Feed rssFeed)
        {
            if (string.IsNullOrEmpty(rssFeed.Copyright))
            {
                var siteConfig = sitecoreContext.GetItem <ISite_Root>(siteConfigItemId);
                feed.Copyright = new TextSyndicationContent(siteConfig.Copyright_Text);
            }
            else
            {
                feed.Copyright = new TextSyndicationContent(rssFeed.Copyright);
            }


            return(feed);
        }
        public ActionResult PageHeaderCarousel()
        {
            var pageData = _scContext.GetItem <ICarousel>(_context.DataSource);

            var viewModel = new CarouselViewModel
            {
                CarouselId = CreateShortId(),
                Slides     = pageData.MediaSelector.Select(slide => new CarouselSlideViewModel
                {
                    Title       = _builder.BuildHtmlString(slide, item => item.MediaTitle).ToString(),
                    Description = _builder.BuildHtmlString(slide, item => item.MediaDescription).ToString(),
                    ImageUrl    = slide.MediaImage.Src,
                    Active      = ""
                })
            };

            return(this.React("PageHeaderCarousel", viewModel));
        }
Пример #19
0
        private IEnumerable <IGeneral_Content_Page> GetPages()
        {
            var home      = SitecoreContext.GetHomeItem <IHome_Page>();
            var startPath = home._Path;

            using (var context = SearchContextFactory.Create())
            {
                var query = context.GetQueryable <GeneralContentResult>()
                            .Filter(j => j.TemplateId == IGeneral_Content_PageConstants.TemplateId && j.Path.StartsWith(startPath.ToLower()) && j.ExcludeFromGoogleSearch);

                var results = query.GetResults();

                var pages = results.Hits.Select(h => SitecoreContext.GetItem <IGeneral_Content_Page>(h.Document.ItemId.Guid)).Where(a => a != null);
                return((!pages.Any())
                ? Enumerable.Empty <IGeneral_Content_Page>()
                : pages);
            }
        }
Пример #20
0
 public override DisclaimerModel GetModel()
 {
     _context = new SitecoreContext();
     return(_context.GetItem <DisclaimerModel>(new Guid("{045D641A-1DAD-4C7F-91F2-DBD0DFDB0360}")));
 }
Пример #21
0
 public T GetContentItem <T>(string contentItem, bool isLazy = false, bool inferType = false) where T : class
 {
     return(_sitecoreContext.GetItem <T>(contentItem, isLazy, inferType));
 }
Пример #22
0
 public IBikeCardClass GetBikeCardContent(string contentGuid)
 {
     Assert.ArgumentNotNullOrEmpty(contentGuid, "contentGuid");
     return(_sitecoreContext.GetItem <IBikeCardClass>(Guid.Parse(contentGuid)));
 }
Пример #23
0
 public T GetItemById<T>(ID itemId) where T : class
 {
     return _sitecoreContext.GetItem<T>(itemId.Guid);
 }
 public IListableViewModel Create(Guid articleId)
 {
     return(Create(SitecoreContext.GetItem <IArticle>(articleId)));
 }
        public virtual T GetContentItem <T>(string contentGuid) where T : class, ICmsEntity
        {
            Assert.ArgumentNotNullOrEmpty(contentGuid, "contentGuid");

            return(_sitecoreContext.GetItem <T>(Guid.Parse(contentGuid)));
        }
 private void Load(object sender, EventArgs e)
 {
     View.Model = sitecoreContext.GetItem <BasePage>(View.SitecoreItemPath);
 }
Пример #27
0
 public CommentRepository(ISitecoreContext context)
 {
     _context         = context;
     _folder          = _context.GetItem <CommentsFolder>(Folders.Content.Global.Comments);
     RepositoryErrors = new List <Exception>();
 }
Пример #28
0
 public T GetContentItem <T>(string contentItem) where T : class
 {
     return(_sitecoreContext.GetItem <T>(contentItem));
 }
        public T GetCurrentRenderingDatasource <T>(DatasourceNestingOptions options = DatasourceNestingOptions.Default) where T : class, IGlassBase
        {
            var rendering = GetCurrentRendering();

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

            Guid dataSourceGuid;

            if (!string.IsNullOrEmpty(rendering.DataSource))
            {
                // Depending on if the datasource is a GUID vs Path, use the correct overload
                return(Guid.TryParse(rendering.DataSource, out dataSourceGuid)
                    ? _context.GetItem <T>(dataSourceGuid, inferType: true)
                    : _context.GetItem <T>(rendering.DataSource, inferType: true));
            }

            // Try to get from the Rendering StaticItem (without getting the ContextItem)
            var propertyItemId = rendering[RenderingItemIdPropertyName];
            T   propertyItem   = null;

            if (!string.IsNullOrEmpty(propertyItemId))
            {
                propertyItem = Guid.TryParse(propertyItemId, out dataSourceGuid)
                        ? _context.GetItem <T>(dataSourceGuid, inferType: true)
                        : _context.GetItem <T>(propertyItemId, inferType: true);
            }

            // Vary the fall-back logic (Always and Never recreate the behavior of Default, but with/without their respective fallback logic)
            switch (options)
            {
            case DatasourceNestingOptions.Default:
                var staticItem = rendering.Item;
                if (staticItem != null)
                {
                    return(_context.GetItem <T>(staticItem.ID.Guid, inferType: true));
                }
                break;

            case DatasourceNestingOptions.Always:
                if (propertyItem != null)
                {
                    return(propertyItem);
                }

                var nestedItem = RenderingContext.CurrentOrNull?.ContextItem;
                if (nestedItem != null)
                {
                    return(_context.GetItem <T>(nestedItem.ID.Guid, inferType: true));
                }
                break;

            case DatasourceNestingOptions.Never:
                if (propertyItem != null)
                {
                    return(propertyItem);
                }
                break;
            }

            // Finally just fall back to the context item
            return(_context.GetCurrentItem <T>(inferType: true));
        }
Пример #30
0
 public T GetDatasourceItem <T>() where T : class, IGlassBase
 {
     return(_sitecoreContext.GetItem <T>(RenderingContext.Current.Rendering.DataSource));
 }
Пример #31
0
 public static IEnumerable <T> GetChildrenOf <T>(this ISitecoreContext sitecoreContext, [NotNull] Item item) where T : class
 {
     return(item.Children.Select(x => sitecoreContext.GetItem <T>(x.ID.ToGuid())));
 }