public virtual IPublishedContent GetByRoute(UmbracoContext umbracoContext, bool preview, string route, bool? hideTopLevelNode = null) { if (route == null) throw new ArgumentNullException("route"); // try to get from cache if not previewing var contentId = preview ? 0 : _routesCache.GetNodeId(route); // if found id in cache then get corresponding content // and clear cache if not found - for whatever reason IPublishedContent content = null; if (contentId > 0) { content = GetById(umbracoContext, preview, contentId); if (content == null) _routesCache.ClearNode(contentId); } // still have nothing? actually determine the id hideTopLevelNode = hideTopLevelNode ?? GlobalSettings.HideTopLevelNodeFromPath; // default = settings content = content ?? DetermineIdByRoute(umbracoContext, preview, route, hideTopLevelNode.Value); // cache if we have a content and not previewing if (content != null && !preview) { var domainRootNodeId = route.StartsWith("/") ? -1 : int.Parse(route.Substring(0, route.IndexOf('/'))); var iscanon = !UnitTesting && !DomainHelper.ExistsDomainInPath(DomainHelper.GetAllDomains(false), content.Path, domainRootNodeId); // and only if this is the canonical url (the one GetUrl would return) if (iscanon) _routesCache.Store(contentId, route); } return content; }
public TemplateRenderer(UmbracoContext umbracoContext, int pageId, int? altTemplateId) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); PageId = pageId; AltTemplate = altTemplateId; _umbracoContext = umbracoContext; }
public PublishedContentRequestBuilder(PublishedContentRequest publishedContentRequest) { if (publishedContentRequest == null) throw new ArgumentNullException("publishedContentRequest"); _publishedContentRequest = publishedContentRequest; _umbracoContext = publishedContentRequest.RoutingContext.UmbracoContext; _routingContext = publishedContentRequest.RoutingContext; }
/// <summary> /// Gets the other urls of a published content. /// </summary> /// <param name="umbracoContext">The Umbraco context.</param> /// <param name="id">The published content id.</param> /// <param name="current">The current absolute url.</param> /// <returns>The other urls for the published content.</returns> /// <remarks> /// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para> /// </remarks> public IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current) { if (!FindByUrlAliasEnabled) return Enumerable.Empty<string>(); // we have nothing to say var node = umbracoContext.ContentCache.GetById(id); string umbracoUrlName = null; if (node.HasProperty(Constants.Conventions.Content.UrlAlias)) umbracoUrlName = node.GetPropertyValue<string>(Constants.Conventions.Content.UrlAlias); if (string.IsNullOrWhiteSpace(umbracoUrlName)) return Enumerable.Empty<string>(); var n = node; var domainUris = DomainHelper.DomainsForNode(n.Id, current, false); while (domainUris == null && n != null) // n is null at root { // move to parent node n = n.Parent; domainUris = n == null ? null : DomainHelper.DomainsForNode(n.Id, current, false); } var path = "/" + umbracoUrlName; if (domainUris == null) { var uri = new Uri(path, UriKind.Relative); return new[] { UriUtility.UriFromUmbraco(uri).ToString() }; } return domainUris .Select(domainUri => new Uri(CombinePaths(domainUri.Uri.GetLeftPart(UriPartial.Path), path))) .Select(uri => UriUtility.UriFromUmbraco(uri).ToString()); }
/// <summary> /// Contructor generally used for unit testing /// </summary> /// <param name="controllerFactory"></param> /// <param name="umbracoContext"></param> internal RenderRouteHandler(IControllerFactory controllerFactory, UmbracoContext umbracoContext) { if (controllerFactory == null) throw new ArgumentNullException("controllerFactory"); if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); _controllerFactory = controllerFactory; _umbracoContext = umbracoContext; }
/// <summary> /// Constructor - can be used for testing /// </summary> /// <param name="umbracoContext"></param> /// <param name="contentId"></param> /// <param name="culture"></param> public EnsurePublishedContentRequestAttribute(UmbracoContext umbracoContext, int contentId, string culture = null) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); _umbracoContext = umbracoContext; _contentId = contentId; _culture = culture; }
/// <summary> /// Constructor - can be used for testing /// </summary> /// <param name="umbracoContext"></param> /// <param name="dataTokenName"></param> /// <param name="culture"></param> public EnsurePublishedContentRequestAttribute(UmbracoContext umbracoContext, string dataTokenName, string culture = null) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); _umbracoContext = umbracoContext; _dataTokenName = dataTokenName; _culture = culture; }
protected UmbracoApiController(UmbracoContext umbracoContext) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); UmbracoContext = umbracoContext; InstanceId = Guid.NewGuid(); Umbraco = new UmbracoHelper(umbracoContext); }
/// <summary> /// Gets the nice url of a published content. /// </summary> /// <param name="umbracoContext">The Umbraco context.</param> /// <param name="id">The published content id.</param> /// <param name="current">The current absolute url.</param> /// <param name="mode">The url mode.</param> /// <returns>The url for the published content.</returns> /// <remarks> /// <para>The url is absolute or relative depending on <c>mode</c> and on <c>current</c>.</para> /// <para>If the provider is unable to provide a url, it should return <c>null</c>.</para> /// </remarks> public virtual string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode) { if (!current.IsAbsoluteUri) throw new ArgumentException("Current url must be absolute.", "current"); // will not use cache if previewing var route = umbracoContext.ContentCache.GetRouteById(id); if (string.IsNullOrWhiteSpace(route)) { LogHelper.Warn<DefaultUrlProvider>( "Couldn't find any page with nodeId={0}. This is most likely caused by the page not being published.", () => id); return null; } // extract domainUri and path // route is /<path> or <domainRootId>/<path> var pos = route.IndexOf('/'); var path = pos == 0 ? route : route.Substring(pos); var domainUri = pos == 0 ? null : DomainHelper.DomainForNode(int.Parse(route.Substring(0, pos)), current); // assemble the url from domainUri (maybe null) and path return AssembleUrl(domainUri, path, current, mode).ToString(); }
IPublishedContent DetermineIdByRoute(UmbracoContext umbracoContext, bool preview, string route, bool hideTopLevelNode) { if (route == null) throw new ArgumentNullException("route"); //the route always needs to be lower case because we only store the urlName attribute in lower case route = route.ToLowerInvariant(); var pos = route.IndexOf('/'); var path = pos == 0 ? route : route.Substring(pos); var startNodeId = pos == 0 ? 0 : int.Parse(route.Substring(0, pos)); IEnumerable<XPathVariable> vars; var xpath = CreateXpathQuery(startNodeId, path, hideTopLevelNode, out vars); //check if we can find the node in our xml cache var content = GetSingleByXPath(umbracoContext, preview, xpath, vars == null ? null : vars.ToArray()); // if hideTopLevelNodePath is true then for url /foo we looked for /*/foo // but maybe that was the url of a non-default top-level node, so we also // have to look for /foo (see note in ApplyHideTopLevelNodeFromPath). if (content == null && hideTopLevelNode && path.Length > 1 && path.IndexOf('/', 1) < 0) { xpath = CreateXpathQuery(startNodeId, path, false, out vars); content = GetSingleByXPath(umbracoContext, preview, xpath, vars == null ? null : vars.ToArray()); } return content; }
/// <summary> /// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers. /// </summary> /// <param name="umbracoContext">The Umbraco context.</param> /// <param name="urlProviders">The list of url providers.</param> /// <param name="provider"></param> public UrlProvider(UmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders, UrlProviderMode provider = UrlProviderMode.Auto) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); _umbracoContext = umbracoContext; _urlProviders = urlProviders; Mode = provider; }
internal RoutingContext( UmbracoContext umbracoContext, Lazy<IEnumerable<IContentFinder>> contentFinders, Lazy<IContentFinder> contentLastChanceFinder, Lazy<UrlProvider> urlProvider) { _publishedContentFinders = contentFinders; _publishedContentLastChanceFinder = contentLastChanceFinder; _urlProvider = urlProvider; }
/// <summary> /// Initializes a new instance of the <see cref="RoutingContext"/> class. /// </summary> /// <param name="umbracoContext"> </param> /// <param name="contentFinders">The document lookups resolver.</param> /// <param name="contentLastChanceFinder"> </param> /// <param name="urlProvider">The nice urls provider.</param> internal RoutingContext( UmbracoContext umbracoContext, IEnumerable<IContentFinder> contentFinders, IContentFinder contentLastChanceFinder, UrlProvider urlProvider) { UmbracoContext = umbracoContext; PublishedContentFinders = contentFinders; PublishedContentLastChanceFinder = contentLastChanceFinder; UrlProvider = urlProvider; }
/// <summary> /// Initializes a new instance of the <see cref="RoutingContext"/> class. /// </summary> /// <param name="umbracoContext"> </param> /// <param name="documentLookups">The document lookups resolver.</param> /// <param name="documentLastChanceLookup"> </param> /// <param name="publishedContentStore">The content store.</param> /// <param name="niceUrlResolver">The nice urls resolver.</param> internal RoutingContext( UmbracoContext umbracoContext, IEnumerable<IPublishedContentLookup> documentLookups, IDocumentLastChanceLookup documentLastChanceLookup, IPublishedContentStore publishedContentStore, NiceUrlProvider niceUrlResolver) { this.UmbracoContext = umbracoContext; this.DocumentLookups = documentLookups; DocumentLastChanceLookup = documentLastChanceLookup; this.PublishedContentStore = publishedContentStore; this.NiceUrlProvider = niceUrlResolver; }
/// <summary> /// Initializes a new instance of the <see cref="UrlProvider"/> class with an Umbraco context and a list of url providers. /// </summary> /// <param name="umbracoContext">The Umbraco context.</param> /// <param name="urlProviders">The list of url providers.</param> internal UrlProvider(UmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders) { _umbracoContext = umbracoContext; _urlProviders = urlProviders; var provider = UrlProviderMode.Auto; Mode = provider; if (Enum<UrlProviderMode>.TryParse(UmbracoConfig.For.UmbracoSettings().WebRouting.UrlProviderMode, out provider)) { Mode = provider; } }
public virtual IEnumerable<IPublishedContent> GetAtRoot(UmbracoContext umbracoContext, bool preview) { var rootMedia = global::umbraco.cms.businesslogic.media.Media.GetRootMedias(); var result = new List<IPublishedContent>(); //TODO: need to get a ConvertFromMedia method but we'll just use this for now. foreach (var media in rootMedia .Select(m => global::umbraco.library.GetMedia(m.Id, true)) .Where(media => media != null && media.Current != null)) { media.MoveNext(); result.Add(ConvertFromXPathNavigator(media.Current)); } return result; }
internal async Task<bool> RouteUmbracoContentAsync(UmbracoContext umbCtx, PublishedContentRequest pcr, RouteData routeData) { //Initialize the context, this will be called a few times but the initialize logic // only executes once. There might be a nicer way to do this but the RouteContext and // other request scoped instances are not available yet. umbCtx.Initialize(pcr); //Prepare the request if it hasn't already been done if (pcr.IsPrepared == false) { if (await pcr.PrepareAsync(routeData)) { if (umbCtx.HasContent == false) return false; } } return umbCtx.HasContent; }
public virtual string GetRouteById(UmbracoContext umbracoContext, bool preview, int contentId) { // try to get from cache if not previewing var route = preview ? null : _routesCache.GetRoute(contentId); // if found in cache then return if (route != null) return route; // else actually determine the route route = DetermineRouteById(umbracoContext, preview, contentId); // cache if we have a route and not previewing if (route != null && !preview) _routesCache.Store(contentId, route); return route; }
/// <summary> /// Gets the other urls of a published content. /// </summary> /// <param name="umbracoContext">The Umbraco context.</param> /// <param name="id">The published content id.</param> /// <param name="current">The current absolute url.</param> /// <returns>The other urls for the published content.</returns> /// <remarks> /// <para>Other urls are those that <c>GetUrl</c> would not return in the current context, but would be valid /// urls for the node in other contexts (different domain for current request, umbracoUrlAlias...).</para> /// </remarks> public virtual IEnumerable<string> GetOtherUrls(UmbracoContext umbracoContext, int id, Uri current) { // will not use cache if previewing var route = umbracoContext.ContentCache.GetRouteById(id); if (string.IsNullOrWhiteSpace(route)) { LogHelper.Warn<DefaultUrlProvider>( "Couldn't find any page with nodeId={0}. This is most likely caused by the page not being published.", () => id); return null; } // extract domainUri and path // route is /<path> or <domainRootId>/<path> var pos = route.IndexOf('/'); var path = pos == 0 ? route : route.Substring(pos); var domainUris = pos == 0 ? null : DomainHelper.DomainsForNode(int.Parse(route.Substring(0, pos)), current); // assemble the alternate urls from domainUris (maybe empty) and path return AssembleUrls(domainUris, path).Select(uri => uri.ToString()); }
/// <summary> /// Constructor generally used for unit testing /// </summary> /// <param name="httpContext"></param> /// <param name="umbracoContext"> </param> internal PartialViewMacroEngine(HttpContextBase httpContext, UmbracoContext umbracoContext) { _getHttpContext = () => httpContext; _getUmbracoContext = () => umbracoContext; }
/// <summary> /// Assigns the request to the http context and proceeds to process the request. If everything is successful, invoke the callback. /// </summary> /// <param name="httpContext"></param> /// <param name="umbracoContext"></param> /// <param name="onSuccess"></param> internal void ProcessRequest(HttpContextBase httpContext, UmbracoContext umbracoContext, Action<PublishedContentRequest> onSuccess) { if (umbracoContext == null) throw new NullReferenceException("The UmbracoContext.Current is null, ProcessRequest cannot proceed unless there is a current UmbracoContext"); if (umbracoContext.RoutingContext == null) throw new NullReferenceException("The UmbracoContext.RoutingContext has not been assigned, ProcessRequest cannot proceed unless there is a RoutingContext assigned to the UmbracoContext"); //assign back since this is a front-end request umbracoContext.PublishedContentRequest = this; // note - at that point the original legacy module did something do handle IIS custom 404 errors // ie pages looking like /anything.aspx?404;/path/to/document - I guess the reason was to support // "directory urls" without having to do wildcard mapping to ASP.NET on old IIS. This is a pain // to maintain and probably not used anymore - removed as of 06/2012. @zpqrtbnk. // // to trigger Umbraco's not-found, one should configure IIS and/or ASP.NET custom 404 errors // so that they point to a non-existing page eg /redirect-404.aspx // TODO: SD: We need more information on this for when we release 4.10.0 as I'm not sure what this means. //find domain _builder.LookupDomain(); // redirect if it has been flagged if (this.IsRedirect) httpContext.Response.Redirect(this.RedirectUrl, true); //set the culture on the thread - once, so it's set when running document lookups Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = this.Culture; //find the document, found will be true if the doc request has found BOTH a node and a template // though currently we don't use this value. var found = _builder.LookupDocument(); //set the culture on the thread -- again, 'cos it might have changed due to a wildcard domain Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture = this.Culture; //this could be called in the LookupDocument method, but I've just put it here for clarity. _builder.DetermineRenderingEngine(); //TODO: here we should launch an event so that people can modify the doc request to do whatever they want. // redirect if it has been flagged if (this.IsRedirect) httpContext.Response.Redirect(this.RedirectUrl, true); // handle 404 if (this.Is404) { httpContext.Response.StatusCode = 404; httpContext.Response.TrySkipIisCustomErrors = Umbraco.Core.Configuration.UmbracoSettings.TrySkipIisCustomErrors; if (!this.HasNode) { httpContext.RemapHandler(new PublishedContentNotFoundHandler()); return; } // else we have a document to render // not having a template is ok here, MVC will take care of it } // just be safe - should never ever happen if (!this.HasNode) throw new Exception("No document to render."); // trigger PublishedContentRequest.Rendering event? // with complete access to the content request? // render even though we might have no template // to give MVC a chance to hijack routes // pass off to our handlers (mvc or webforms) // assign the legacy page back to the docrequest // handlers like default.aspx will want it and most macros currently need it this.UmbracoPage = new page(this); // these two are used by many legacy objects httpContext.Items["pageID"] = this.DocumentId; httpContext.Items["pageElements"] = this.UmbracoPage.Elements; if (onSuccess != null) onSuccess(this); }
/// <summary> /// Primary constructor. /// </summary> /// <param name="context">Umbraco context.</param> public ConfiguredFormsController(UmbracoContext context) : base(context) { Persistence = ConfiguredFormPersistence.Current.Manager; Entities = EntityPersistence.Current.Manager; }
/// <summary> /// Initializes a new instance of the <see cref="CustomerContext"/> class. /// </summary> /// <param name="umbracoContext"> /// The umbraco context. /// </param> public CustomerContext(UmbracoContext umbracoContext) : base(MerchelloContext.Current, umbracoContext) { }
public InstallController(UmbracoContext umbracoContext) { _umbracoContext = umbracoContext; }
protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext, IPublishedContent baseContent) { var urlNames = _urlNames.Single(x => x.NodeId == baseContent.Id); var controllerName = requestContext.RouteData.GetRequiredString("controller"); var rootUrl = baseContent.Url; return(new ArticulateVirtualPage( baseContent, urlNames.SearchPageName, controllerName, urlNames.SearchUrlName)); }
protected IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext) { var umbracoHelper = new UmbracoHelper(umbracoContext); return(umbracoHelper.TypedContent(_sitemapNodeId)); }
protected UmbracoController(UmbracoContext umbracoContext) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); UmbracoContext = umbracoContext; }
/// <summary> /// Primary constructor. /// </summary> public SetupController( UmbracoContext umbracoContext) : base(umbracoContext) { }
public UmbracoController(UmbracoContext umbracoContext, PublishedContentService headlessService) : base(umbracoContext, headlessService) { }
protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext) { IPublishedContent rootNode = base.FindContent(requestContext, umbracoContext); string courseUrl = (string)requestContext.RouteData.Values["courseNiceUrl"]; IPublishedContent courseNode = rootNode.DescendantsOrSelf(nameof(Course)).FirstOrDefault(x => x.UrlName == courseUrl); return(courseNode); }
protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext) { umbracoContext = umbracoContext ?? AcademyPlatform.Web.Umbraco.UmbracoConfiguration.Extensions.UmbracoContextExtensions.GetOrCreateContext(); IPublishedContent rootNode = umbracoContext.ContentCache.GetAtRoot().FirstOrDefault(); if (rootNode == null) { throw new ApplicationException("No root content found in Umbraco database"); } return(rootNode); }
public SearchHelper(UmbracoContext context) { umbracoHelper = new UmbracoHelper(context); }
/// <summary> /// Primary constructor. /// </summary> /// <param name="context">Umbraco context.</param> public EntitiesController(UmbracoContext context) : base(context) { Entities = EntityPersistence.Current.Manager; }
public UmbracoIdentityAccountController(UmbracoContext umbracoContext, UmbracoHelper umbracoHelper, UmbracoMembersUserManager <UmbracoApplicationMember> userManager, UmbracoMembersRoleManager <UmbracoApplicationRole> roleManager) : base(umbracoContext, umbracoHelper) { _userManager = userManager; _roleManager = roleManager; }
/// <summary> /// Initializes a new instance of the <see cref="InvoiceApiController"/> class. /// </summary> /// <param name="merchelloContext"> /// The merchello context. /// </param> /// <param name="umbracoContext"> /// The umbraco context. /// </param> internal InvoiceApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext) : base((MerchelloContext)merchelloContext, umbracoContext) { _invoiceService = merchelloContext.Services.InvoiceService; }
protected override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext, IPublishedContent baseContent) { var urlAndPageName = _urlsAndPageNames.Single(x => x.NodeId == baseContent.Id); var tag = requestContext.RouteData.Values["tag"] == null ? null : requestContext.RouteData.Values["tag"].ToString(); var actionName = requestContext.RouteData.GetRequiredString("action"); var rootUrl = baseContent.Url; var urlName = actionName.InvariantEquals("tags") ? urlAndPageName.TagsUrlName : urlAndPageName.CategoriesUrlName; var pageName = actionName.InvariantEquals("tags") ? urlAndPageName.TagsPageName : urlAndPageName.CategoriesPageName; return(new ArticulateVirtualPage( baseContent, tag.IsNullOrWhiteSpace() ? pageName : tag, requestContext.RouteData.GetRequiredString("controller"), tag.IsNullOrWhiteSpace() ? urlName : urlName.EnsureEndsWith('/') + tag)); }
public ArticleContentIndexService(IElasticClient client, UmbracoContext umbracoContext) : base(client, umbracoContext) { }
public UmbracoControl(UmbracoContext umbracoContext) { _umbracoContext = umbracoContext; }
/// <summary> /// Constructor /// </summary> /// <param name="umbracoContext"></param> public MemberTypeController(UmbracoContext umbracoContext) : base(umbracoContext) { _provider = Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider(); }
public SimpleController() { _umbracoContext = UmbracoContext.Current; }
/// <summary> /// Constructor /// </summary> /// <param name="umbracoContext"></param> public ContentController(UmbracoContext umbracoContext) : base(umbracoContext) { }
/// <summary> /// Constructor /// </summary> /// <param name="umbracoContext"></param> protected ContentControllerBase(UmbracoContext umbracoContext) : base(umbracoContext) { }
/// <summary> /// Initializes a new instance of the <see cref="ContextualPublishedCache"/> with a context. /// </summary> /// <param name="umbracoContext">The context.</param> protected ContextualPublishedCache(UmbracoContext umbracoContext) { UmbracoContext = umbracoContext; }
public PartialViewMacroController(UmbracoContext umbracoContext, MacroModel macro, INode currentPage) { _umbracoContext = umbracoContext; _macro = macro; _currentPage = currentPage; }
/// <summary> /// Initializes a new instance of the <see cref="PaymentApiController"/> class. /// This is a helper contructor for unit testing /// </summary> /// <param name="merchelloContext"> /// The merchello Context. /// </param> /// <param name="umbracoContext"> /// The umbraco Context. /// </param> public PaymentApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext) : base(merchelloContext, umbracoContext) { _paymentService = merchelloContext.Services.PaymentService; _invoiceService = merchelloContext.Services.InvoiceService; }
/// <summary> /// THIS SHOULD BE ONLY USED FOR UNIT TESTS /// </summary> /// <param name="umbracoContext"></param> public UmbracoAuthorizeAttribute(UmbracoContext umbracoContext) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); _umbracoContext = umbracoContext; _applicationContext = _umbracoContext.Application; }
protected sealed override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext) { var byId = umbracoContext.Content.GetById(_realNodeId); return(byId == null ? null : FindContent(requestContext, umbracoContext, byId)); }
protected UmbracoAuthorizedHttpHandler(UmbracoContext umbracoContext) : base(umbracoContext) { }
internal InstallHelper(UmbracoContext umbContext) { _umbContext = umbContext; }
/// <summary> /// Default constructor /// </summary> /// <param name="umbracoContext"></param> protected UmbracoControl(UmbracoContext umbracoContext) { if (umbracoContext == null) throw new ArgumentNullException("umbracoContext"); UmbracoContext = umbracoContext; Umbraco = new UmbracoHelper(umbracoContext); }
protected UmbracoAuthorizedWebService(UmbracoContext umbracoContext) : base(umbracoContext) { }
/// <summary> /// Initializes a new instance of the <see cref="NiceUrlProvider"/> class. /// </summary> /// <param name="publishedContentStore">The content store.</param> /// <param name="umbracoContext">The Umbraco context.</param> public NiceUrlProvider(IPublishedContentStore publishedContentStore, UmbracoContext umbracoContext) { _umbracoContext = umbracoContext; _publishedContentStore = publishedContentStore; this.EnforceAbsoluteUrls = false; }
/// <summary> /// Creates a new RedirectToUmbracoResult /// </summary> /// <param name="publishedContent"></param> /// <param name="umbracoContext"></param> public RedirectToUmbracoPageResult(IPublishedContent publishedContent, UmbracoContext umbracoContext) { _publishedContent = publishedContent; _pageId = publishedContent.Id; _umbracoContext = umbracoContext; }
/// <summary> /// Default constructor /// </summary> /// <param name="umbracoContext"></param> protected SurfaceController(UmbracoContext umbracoContext) : base(umbracoContext) { }
/// <summary> /// Creates a new RedirectToUmbracoResult /// </summary> /// <param name="pageId"></param> /// <param name="umbracoContext"></param> public RedirectToUmbracoPageResult(int pageId, UmbracoContext umbracoContext) { _pageId = pageId; _umbracoContext = umbracoContext; }
protected sealed override IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext) { var byId = umbracoContext.ContentCache.GetById(_realNodeId); if (byId == null) { return(null); } return(FindContent(requestContext, umbracoContext, byId)); }
protected virtual IPublishedContent FindContent(RequestContext requestContext, UmbracoContext umbracoContext, IPublishedContent baseContent) { return(baseContent); }
public YuzuFormViewModelFactory(UmbracoContext umbracoContext, IMapper mapper) { this.umbracoContext = umbracoContext; this.mapper = mapper; }
/// <inheritdoc/> public override string GetUrl(UmbracoContext umbracoContext, int id, Uri current, UrlProviderMode mode) { var content = umbracoContext.ContentCache.GetById(id); if (content?.Parent == null) { return(null); } if (!current.IsAbsoluteUri) { throw new ArgumentException("Current url must be absolute.", "current"); } if (content.DocumentTypeAlias == nameof(ErrorPageModel)) { var parts = current.GetAbsolutePathDecoded().Split( new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); var tmpUrl = "/"; // Lets try to get the content by using parts of the url until we find it. for (var index = 0; index < parts.Length; index++) { tmpUrl += parts[index] + "/"; try { // Try to resolve it as a route. content = UmbracoContext.Current.ContentCache.GetByRoute(tmpUrl); if (content != null) { break; } } catch (Exception) { // ignored } } if (content?.Parent == null) { return(null); } } if (content.DocumentTypeAlias == nameof(ProfilePageModel)) { using (var container = DependencyResolver.Current.GetService <IContainer>().GetNestedContainer()) { var membershipService = container.GetInstance <IMembershipService>(); var helper = new UmbracoHelper(umbracoContext); // This will add the selected date before the node name. For example /news/item1/ // becomes /news/28-07-2014/item1/. var url = content.Parent.Url; if (!url.EndsWith("/")) { url += "/"; } var currentUrl = current.AbsolutePath; currentUrl = currentUrl.TrimStart('/'); var segments = currentUrl.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (!segments.Skip(1).Any()) { var currentMember = helper.MembershipHelper.GetCurrentMember() as MemberPublishedContent; if (currentMember != null) { var member = membershipService.MapMember(currentMember); var u = string.Format( "{0}/{1}/", url + content.UrlName, member.UserName.ToLower().ToUrlSegment()); return(u); } } else { var username = segments.Skip(1).First(); var memberByUsername = helper.MembershipHelper.GetByUsername(username) as MemberPublishedContent; if (memberByUsername == null) { memberByUsername = ApplicationContext.Current.Services.MemberService .GetMembersByGroup(nameof(MemberTypes.SiteMember)) .Select(x => helper.MembershipHelper.GetById(x.Id)).OfType <MemberPublishedContent>() .FirstOrDefault( x => x.UserName.ToUrlSegment().Equals( username, StringComparison.OrdinalIgnoreCase)); } if (memberByUsername != null) { var member = membershipService.MapMember(memberByUsername); var u = string.Format( "{0}/{1}/", url + content.UrlName, member.UserName.ToLower().ToUrlSegment()); return(u); } } } } return(null); }