public static RouteValueDictionary GetPageRoute(this RequestContext requestContext, ContentReference contentLink) { var values = new RouteValueDictionary(); values[RoutingConstants.NodeKey] = contentLink; values[RoutingConstants.LanguageKey] = ContentLanguage.PreferredCulture.Name; return values; }
public static List<SessionBlock> GetSessions(ContentReference EventPageBase) { var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); List<SessionBlock> sessions = contentRepository.GetChildren<SessionBlock>(GetOrCreateSessionFolder(EventPageBase).ContentLink, new NullLanguageSelector()).ToList<SessionBlock>(); sessions.Sort(delegate(SessionBlock s1, SessionBlock s2) { return s1.Start.CompareTo(s2.Start); }); return sessions; }
private string GetLoginUrl(ContentReference returnToContentLink) { return string.Format( "{0}?ReturnUrl={1}", FormsAuthentication.LoginUrl, _urlResolver.GetUrl(returnToContentLink)); }
public virtual LayoutModel CreateLayoutModel(ContentReference currentContentLink, RequestContext requestContext) { if (ContentReference.StartPage.ID == 0) return null; var startPage = _contentLoader.Get<StartPage>(ContentReference.StartPage); return new LayoutModel { // MenuTopPages = startPage.MenuTopPageLinks, SearchPageRouteValues = requestContext.GetPageRoute(startPage.SearchPageLink), SearchPageLink = startPage.SearchPageLink, // header SearchLabel = startPage.SearchLabel, SearchPlaceholderLabel = startPage.SearchPlaceholderLabel, LogoAlternativeText = startPage.LogoAlternativeText, // footer PhoneNumber = startPage.PhoneNumber, PhoneNumberLabel = startPage.PhoneNumberLabel, MailAddress = startPage.MailAddress, Address = startPage.Address, CvrNumber = startPage.CvrNumber }; }
public IDateContainer ConstructDateContainer(ContentReference parent, string name, DateTime startPublish) { var dateContainer = this.ConstructDateContainerPage<BlogListPage>(parent, name, startPublish); dateContainer.Heading = name; return dateContainer; }
protected string GetCourseName(ContentReference EventPageBase) { var currentEvent = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>().Get<BVNetwork.Attend.Models.Pages.EventPageBase>(EventPageBase); if (currentEvent == null) return string.Empty; return currentEvent.Name; }
/// <summary> /// Instantiates new CacheKey. /// </summary> /// <param name="type">Singleton page's type.</param> /// <param name="parentLink">A root page's content reference under which singleton page gets searched.</param> /// <exception cref="ArgumentNullException"></exception> public CacheKey(Type type, ContentReference parentLink) { if (type == null) throw new ArgumentNullException(nameof(type)); if (parentLink == null) throw new ArgumentNullException(nameof(parentLink)); Type = type; ParentLink = parentLink; }
/// <summary> /// Returns an element for each child page of the rootLink using the itemTemplate. /// </summary> /// <param name="helper">The html helper in whose context the list should be created</param> /// <param name="rootLink">A reference to the root whose children should be listed</param> /// <param name="itemTemplate"> /// A template for each page which will be used to produce the return value. Can be either a /// delegate or a Razor helper. /// </param> /// <param name="includeRoot">Whether an element for the root page should be returned</param> /// <param name="requireVisibleInMenu"> /// Wether pages that do not have the "Display in navigation" checkbox checked should be /// excluded /// </param> /// <param name="requirePageTemplate">Whether page that do not have a template (i.e. container pages) should be excluded</param> /// <remarks> /// Filter by access rights and publication status. /// </remarks> public static IHtmlString MenuList(this HtmlHelper helper, ContentReference rootLink, Func<MenuItem, HelperResult> itemTemplate = null, bool includeRoot = false, bool requireVisibleInMenu = true, bool requirePageTemplate = true) { itemTemplate = itemTemplate ?? GetDefaultItemTemplate(helper); var currentContentLink = helper.ViewContext.RequestContext.GetContentLink(); var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); Func<IEnumerable<PageData>, IEnumerable<PageData>> filter = pages => pages.FilterForDisplay(requirePageTemplate, requireVisibleInMenu); var menuItems = contentLoader.GetChildren<PageData>(rootLink) .FilterForDisplay(requirePageTemplate, requireVisibleInMenu) .Select(x => CreateMenuItem(x, currentContentLink, rootLink, contentLoader, filter)) .ToList(); if (includeRoot) { menuItems.Insert(0, CreateMenuItem(contentLoader.Get<PageData>(rootLink), currentContentLink, rootLink, contentLoader, filter)); } var buffer = new StringBuilder(); var writer = new StringWriter(buffer); foreach (var menuItem in menuItems) { itemTemplate(menuItem).WriteTo(writer); } return new MvcHtmlString(buffer.ToString()); }
public virtual LayoutModel CreateLayoutModel(ContentReference currentContentLink, RequestContext requestContext) { var startPageContentLink = SiteDefinition.Current.StartPage; // Use the content link with version information when editing the startpage, // otherwise the published version will be used when rendering the props below. if (currentContentLink.CompareToIgnoreWorkID(startPageContentLink)) { startPageContentLink = currentContentLink; } var startPage = _contentLoader.Get<StartPage>(startPageContentLink); return new LayoutModel { Logotype = startPage.SiteLogotype, LogotypeLinkUrl = new MvcHtmlString(_urlResolver.GetUrl(SiteDefinition.Current.StartPage)), ProductPages = startPage.ProductPageLinks, CompanyInformationPages = startPage.CompanyInformationPageLinks, NewsPages = startPage.NewsPageLinks, CustomerZonePages = startPage.CustomerZonePageLinks, LoggedIn = requestContext.HttpContext.User.Identity.IsAuthenticated, LoginUrl = new MvcHtmlString(GetLoginUrl(currentContentLink)), SearchActionUrl = new MvcHtmlString(EPiServer.Web.Routing.UrlResolver.Current.GetUrl(startPage.SearchPageLink)) }; }
public void Send(ContentReference mailReference, NameValueCollection nameValueCollection, string toEmail, string language) { var body = GetHtmlBodyForMail(mailReference, nameValueCollection, language); var mailPage = _contentLoader.Get<MailBasePage>(mailReference); Send(mailPage.MailTitle, body, toEmail); }
public void CompareTo_IfTheInstanceIdIsLessThanTheObjectParameterId_ShouldReturnMinusOne() { ContentReference contentReferenceToCompareWith = new ContentReference(_random.Next(1, int.MaxValue)); ContentReference contentReference = contentReferenceToCompareWith.Copy(); contentReference.ID = contentReference.ID - 1; Assert.AreEqual(-1, contentReference.CompareTo(contentReferenceToCompareWith)); }
private IOrganizeChildren GetChildrenOrganizer(ContentReference pageLink) { if (ContentReference.IsNullOrEmpty(pageLink)) return null; return GetPage(pageLink) as IOrganizeChildren; }
public void CompareTo_IfTheIdsAreEqualAndTheInstanceWorkIdIsGreaterThanTheObjectParameterWorkId_ShouldReturnMinusOne() { ContentReference contentReferenceToCompareWith = new ContentReference(_random.Next(0, int.MaxValue), _random.Next(0, int.MaxValue - 1)); ContentReference contentReference = contentReferenceToCompareWith.Copy(); contentReference.WorkID = contentReference.WorkID + 1; Assert.AreEqual(-1, contentReference.CompareTo(contentReferenceToCompareWith)); }
public IHttpActionResult Get(int id) { var reference = new ContentReference(id); if (ContentReference.IsNullOrEmpty(reference)) { var message = new HttpResponseMessage(); message.StatusCode = HttpStatusCode.NotFound; message.ReasonPhrase = String.Format("Did not find page content with id {0}", id); throw new HttpResponseException(message); } var pageData = this._contentLoader.Get<PageData>(reference) as MobilePageData; if (pageData == null) { var message = new HttpResponseMessage(); message.StatusCode = HttpStatusCode.Forbidden; message.ReasonPhrase = String.Format("Page with id {0} was not of type {1}", id, typeof(MobilePageData).Name); throw new HttpResponseException(message); } var epiTitle = pageData.Title; var epiContent = PreProcess(pageData.Content); return Ok(new { title = epiTitle, content = epiContent }); }
public static ContentFolder GetOrCreateEventFolder(ContentReference EventPageBase, string folderName) { var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); var contentAssetHelper = ServiceLocator.Current.GetInstance<ContentAssetHelper>(); ContentFolder folder = null; var assetsFolder = contentAssetHelper.GetOrCreateAssetFolder(EventPageBase); var folders = contentRepository.GetChildren<ContentFolder>(assetsFolder.ContentLink); foreach (ContentFolder cf in folders) { if (cf.Name == folderName) folder = cf; } if (folder == null) { folder = contentRepository.GetDefault<ContentFolder>(assetsFolder.ContentLink); folder.Name = folderName; contentRepository.Save(folder, EPiServer.DataAccess.SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess); } return folder; }
public string ResolveUrl(ContentReference contentReference) { if (ContentReference.IsNullOrEmpty(contentReference)) return string.Empty; var content = _lazyContentRepository.Value.Get<IContent>(contentReference); return ResolveUrl(content); }
public IDictionary<string, QuickNavigatorMenuItem> GetMenuItems(ContentReference currentContent) { string adminModeUiLink = VirtualPathUtility.Combine(Paths.ProtectedRootPath, "CMS/Admin/default.aspx"); var menuItems = new Dictionary<string, QuickNavigatorMenuItem>(); menuItems.Add("qn-admin-mode", new QuickNavigatorMenuItem("Admin Mode", adminModeUiLink, null, null, null)); return menuItems; }
public static IParticipant GenerateParticipation(ContentReference EventPageBase, string email, bool sendMail, string xform, string logText) { if (Business.Email.Validation.IsEmail(email)) return ParticipantProviderManager.Provider.GenerateParticipant(EventPageBase, email, sendMail, xform, logText); else throw new InvalidEmailException("Attend participant cannot be created without a valid e-mail address."); }
public void CompareTo_IfTheIdsAreEqualAndTheInstanceProviderNameIsLessThanTheObjectParameterProviderName_ShouldReturnMinusOne() { ContentReference contentReferenceToCompareWith = new ContentReference(_random.Next(0, int.MaxValue), _random.Next(0, int.MaxValue), "2"); ContentReference contentReference = contentReferenceToCompareWith.Copy(); contentReference.ProviderName = "1"; Assert.AreEqual(-1, 1.CompareTo(2)); Assert.AreEqual(-1, string.Compare("1", "2", StringComparison.Ordinal)); Assert.AreEqual(-1, contentReference.CompareTo(contentReferenceToCompareWith)); }
public ContentReference CreateNew(ContentReference parentNodeLink, Node node, ContentType nodeType) { //Create a new instance of CatalogContentTypeSample that will be a child to the specified parentNode. var nodeContent = _contentRepository.GetDefault<NodeContent>(parentNodeLink, nodeType.ID); // Set required properties nodeContent.Code = node.code; return Update(nodeContent, node, SaveAction.Publish); }
public static UrlBuilder ResizeImage(this HtmlHelper helper, ContentReference image, int? width = null, int? height = null) { if(image == null || image == ContentReference.EmptyReference) throw new ArgumentNullException(nameof(image)); var url = UrlResolver.Current.GetUrl(image); return helper.ResizeImage(url, width, height); }
public ActionResult Set(string marketId, ContentReference contentLink) { _currentMarket.SetCurrentMarket(new MarketId(marketId)); var currentMarket = _marketService.GetMarket(new MarketId(marketId)); _languageService.SetCurrentLanguage(currentMarket.DefaultLanguage.Name); var returnUrl = _urlResolver.GetUrl(Request, contentLink, currentMarket.DefaultLanguage.Name); return Json(new { returnUrl }); }
public static string GetUrl(this UrlResolver urlResolver, HttpRequestBase request, ContentReference contentLink, string language) { if (!ContentReference.IsNullOrEmpty(contentLink)) { return urlResolver.GetUrl(contentLink, language); } return request.UrlReferrer == null ? "/" : request.UrlReferrer.PathAndQuery; }
public void EqualityOperator_IfBothParametersAreTheSameInstance_ShouldReturnTrue() { ContentReference contentReference = new ContentReference(); #pragma warning disable 1718 // ReSharper disable EqualExpressionComparison Assert.IsTrue(contentReference == contentReference); // ReSharper restore EqualExpressionComparison #pragma warning restore 1718 }
public virtual string GetExportableLink(ContentReference contentLink) { var pageMap = PermanentLinkMapStore.Find(contentLink) as PermanentContentLinkMap; if (pageMap != null) { return GetExportableLink(pageMap.Guid, string.Empty); } return ""; }
public static ScheduledEmailBlock GenerateScheduledEmailBlock(ContentReference EventPageBase) { var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); ScheduledEmailBlock emailBlock = contentRepository.GetDefault<ScheduledEmailBlock>(GetOrCreateEmailFolder(EventPageBase).ContentLink, new CultureInfo(Localization.LanguageHelper.MasterLanguage(EventPageBase))); (emailBlock as IContent).Name = "New message"; emailBlock.EventPage = EventPageBase as PageReference; contentRepository.Save(emailBlock as IContent, SaveAction.Publish); return emailBlock; }
/// <summary> /// Creates the favicon. /// </summary> /// <param name="rootFolder">The root folder.</param> /// <param name="originalFile">The original file.</param> /// <param name="filePrefix">The file prefix.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> public override void CreateFavicon( ContentReference rootFolder, Stream originalFile, string filePrefix, int width, int height) { //Get a suitable MediaData type from extension Type mediaType = this.ContentMediaResolver.Service.GetFirstMatching(".png"); ContentType contentType = this.ContentTypeRepository.Service.Load(mediaType); try { //Get a new empty file data ImageData media = this.ContentRepository.Service.GetDefault<ImageData>(rootFolder, contentType.ID); media.Name = string.Format(CultureInfo.InvariantCulture, "{0}-{1}x{2}.png", filePrefix, width, height); //Create a blob in the binary container Blob blob = this.BlobFactory.Service.CreateBlob(media.BinaryDataContainer, ".png"); ImageJob imageJob = new ImageJob( originalFile, blob.OpenWrite(), new Instructions( string.Format( CultureInfo.InvariantCulture, "width={0}&height={1}&crop=auto&format=png", width, height))) { ResetSourceStream = true, DisposeDestinationStream = true, DisposeSourceObject = false }; imageJob.Build(); //Assign to file and publish changes media.BinaryData = blob; this.ContentRepository.Service.Save(media, SaveAction.Publish); } catch (AccessDeniedException accessDeniedException) { Logger.Error("[Favicons] Error creating icon.", accessDeniedException); } catch (ArgumentNullException argumentNullException) { Logger.Error("[Favicons] Error creating icon.", argumentNullException); } catch (FormatException formatException) { Logger.Error("[Favicons] Error creating icon.", formatException); } }
public override IEnumerable <IParticipant> GetParticipants(EPiServer.Core.ContentReference EventPageBase) { List <IParticipant> participants = new List <IParticipant>(); for (int i = 0; i < 10; i++) { participants.Add(GenerateParticipant(EventPageBase, "test" + i + "@test.com", false, null, "Created test participant")); } return(participants); }
protected void Page_Load(object sender, System.EventArgs e) { if (Request.QueryString["pid"] != null) { var repository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentRepository>(); string contentId = Request.QueryString["pid"]; var contentLink = new ContentReference(contentId); CurrentContent = repository.Get<PageData>(contentLink); } }
public IEnumerable<PageData> GetContent(ContentReference contentRef, string scope = null) { var refs = scope == null ? Store.Items<CategoryAssignment>().Where(ca => ca.CategoryPage == contentRef.ToReferenceWithoutVersion()).ToList() : Store.Items<CategoryAssignment>().Where(ca => ca.CategoryPage == contentRef.ToReferenceWithoutVersion() && ca.Scope == scope).ToList(); var repo = ServiceLocator.Current.GetInstance<IContentRepository>(); return refs.Select(ca => repo.Get<PageData>(ca.ContentPage)).Where(x => !x.IsDeleted); }
public void DeleteAssignmentsByCategory(ContentReference categoryRef) { if (Store.Items<CategoryAssignment>().Where(ca => ca.ContentPage == categoryRef.ToReferenceWithoutVersion()).Count() > 0) { foreach (var item in Store.Items<CategoryAssignment>().Where(ca => ca.CategoryPage == categoryRef.ToReferenceWithoutVersion())) { Store.Delete(item); } } }
public override IParticipant GenerateParticipant(EPiServer.Core.ContentReference EventPageBase, string email, bool sendMail, string xform, string logText) { DDSParticipant newParticipant = new DDSParticipant { AttendStatus = AttendStatus.Confirmed.ToString(), EventPage = EventPageBase as PageReference, Email = email, XForm = xform, DateSubmitted = DateTime.Now }; newParticipant.Code = newParticipant.Id.ToString(); newParticipant.EventPageID = EventPageBase.ID; ParticipantDataStore.Save(newParticipant); return(newParticipant); }
public override IParticipant GenerateParticipant(EPiServer.Core.ContentReference EventPage, string email, bool sendMail, string xform, string logText) { return(new TestParticipant { AttendStatus = AttendStatus.Confirmed.ToString(), Code = "123", EventPage = EventPage as PageReference, Email = email, XForm = xform, DateSubmitted = DateTime.Now }); }
public PermanentContentLinkMap Find(EPiServer.Core.ContentReference contentReference) { var pageMaps = _linkMaps.Where(map => map is PermanentContentLinkMap).Cast <PermanentContentLinkMap>(); return(pageMaps.SingleOrDefault(map => contentReference.CompareToIgnoreWorkID(map.ContentReference))); }
public override IEnumerable <IParticipant> GetParticipants(EPiServer.Core.ContentReference EventPage) { return (from participants in ParticipantDataStore.Items <DDSParticipant>() where participants.EventPageID == EventPage.ID select participants); }