static IContentAccessor <T> CreateContentAccessor <T>(IUnityContainer container, T item) { // get registered accessors IEnumerable <IContentAccessor <T> > contentAccessors = container.ResolveAll <IContentAccessor <T> >(); // look for a match IContentAccessor <T> matchedAccessor = null; if (contentAccessors != null) { matchedAccessor = contentAccessors.FirstOrDefault(contentAccessor => { // check valid content if (contentAccessor.HasValidContent(item)) { return(true); } return(false); }); } // return a match if found return(matchedAccessor); }
static IContent CreateContent(IContentAccessor accessor) { // match content to accessors with the content type attribute Assembly contentAssembly = Assembly.GetAssembly(typeof(IContent)); List <Type> contentObjTypes = contentAssembly.GetTypes() .Where(type => typeof(IContent).IsAssignableFrom(type)) .Where(contentObjType => contentObjType.GetCustomAttributes(typeof(ContentTypeAttribute), true) .Where(attribute => string.Compare(((ContentTypeAttribute)attribute).ContentType, accessor.ContentType, true) == 0).Count() > 0) .ToList(); if (contentObjTypes.Count != 0) { throw new NoContentHandlerFoundException(); } IContent contentObj = (IContent)Activator.CreateInstance(contentObjTypes[0]); try { contentObj.Load(accessor.RawContent); } catch (Exception ex) { contentObj.IsLoaded = false; ServiceLocator.Current.GetInstance <IComboLog>().Error(string.Format("Failed to load content for content type {0}.", accessor.ContentType), ex); throw new InvalidContentException(); } return(contentObj); }
public virtual IContentAccessor GetAccessorForType(IContent content, IList <IOptionValue> options = null) { IContentAccessor contentAccessor = null; Type contentType; if (content is IProxy) { content = (IContent)unitOfWork.Session.GetSessionImplementation().PersistenceContext.Unproxy(content); contentType = content.GetType(); } else { contentType = content.GetType(); } string key = "CONTENTRENDERER-" + contentType.Name.ToUpperInvariant(); if (containerProvider.CurrentScope.IsRegisteredWithKey <IContentAccessor>(key)) { contentAccessor = containerProvider.CurrentScope .ResolveKeyed <IContentAccessor>(key, new Parameter[] { new PositionalParameter(0, content), new PositionalParameter(1, options) }); } return(contentAccessor); }
public SetupController( IContentAccessor contentAccessor, IOptions <JsonSerializerOptions> jsonSerializerOptionsAccessor) { ContentAccessor = contentAccessor; JsonSerializerOptions = jsonSerializerOptionsAccessor.Value; }
public PageContentProjection(IPageContent pageContent, IContent content, IContentAccessor contentAccessor, IEnumerable <ChildContentProjection> childProjections = null) { this.pageContent = pageContent; this.content = content; this.contentAccessor = contentAccessor; this.childProjections = childProjections; }
public PageContentProjection(IPageContent pageContent, IContent content, IContentAccessor contentAccessor, IEnumerable<ChildContentProjection> childProjections = null, IEnumerable<PageContentProjection> childRegionContentProjections = null) { this.pageContent = pageContent; this.content = content; this.contentAccessor = contentAccessor; this.childProjections = childProjections; this.childRegionContentProjections = childRegionContentProjections; }
public static IContent GetContent <T>(IUnityContainer container, T item) { IContentAccessor <T> contentAccessor = CreateContentAccessor <T>(container, item); if (contentAccessor != null) { contentAccessor.Load(item); return(CreateContent(contentAccessor)); } else { return(null); } }
public static TextContent GetTextContent <T>(IUnityContainer container, T item) { IContentAccessor <T> contentAccessor = CreateContentAccessor <T>(container, item); if (contentAccessor != null && contentAccessor.RawContentIsPlainText) { contentAccessor.Load(item); TextContent textContent = new TextContent(); textContent.Load(contentAccessor.RawContent as string); return(textContent); } else { return(null); } }
public virtual TProjection Create <TProjection>(IPageContent pageContent, IContent content, IList <IOptionValue> options, IEnumerable <ChildContentProjection> childContentProjections, IEnumerable <PageContentProjection> childRegionContentProjections, Func <IPageContent, IContent, IContentAccessor, IEnumerable <ChildContentProjection>, IEnumerable <PageContentProjection>, TProjection> createProjectionDelegate) where TProjection : PageContentProjection { IContentAccessor contentAccessor = GetAccessorForType(content, options); if (contentAccessor == null) { Log.Error(string.Format("A content accessor was not found for the content type {0} with id={1}.", content.GetType().FullName, content.Id)); contentAccessor = new EmptyContentAccessor(string.Format("<i style=\"color:red;\">{0}</i>", RootGlobalization.Message_FailedToRenderContent)); } TProjection pageContentProjection = createProjectionDelegate.Invoke(pageContent, content, contentAccessor, childContentProjections, childRegionContentProjections); return(pageContentProjection); }
public TProjection Create <TProjection>(IPageContent pageContent, IContent content, IList <IOptionValue> options, IEnumerable <ChildContentProjection> childContentProjections, Func <IPageContent, IContent, IContentAccessor, IEnumerable <ChildContentProjection>, TProjection> createProjectionDelegate) where TProjection : PageContentProjection { IContentAccessor contentAccessor = null; Type contentType; if (content is IProxy) { contentType = content.GetType().BaseType; } else { contentType = content.GetType(); } string key = "CONTENTRENDERER-" + contentType.Name.ToUpperInvariant(); if (containerProvider.CurrentScope.IsRegisteredWithKey <IContentAccessor>(key)) { contentAccessor = containerProvider.CurrentScope .ResolveKeyed <IContentAccessor>(key, new Parameter[] { new PositionalParameter(0, content), new PositionalParameter(1, options) }); } if (contentAccessor == null) { Log.Error(string.Format("A content accessor was not found for the content type {0} with id={1}.", content.GetType().FullName, content.Id)); contentAccessor = new EmptyContentAccessor(string.Format("<i style=\"color:red;\">{0}</i>", RootGlobalization.Message_FailedToRenderContent)); } TProjection pageContentProjection = createProjectionDelegate.Invoke(pageContent, content, contentAccessor, childContentProjections); return(pageContentProjection); }
public PageContentProjection(SerializationInfo info, StreamingContext context) { pageContent = (IPageContent)info.GetValue("pageContent", typeof(IPageContent)); content = (IContent)info.GetValue("content", typeof(IContent)); contentAccessor = (IContentAccessor)info.GetValue("contentAccessor", typeof(IContentAccessor)); }
public ContentController( IContentAccessor contentAccessor) { ContentAccessor = contentAccessor; }
public PageContentProjection(IPageContent pageContent, IContent content, IContentAccessor contentAccessor) { this.pageContent = pageContent; this.content = content; this.contentAccessor = contentAccessor; }
public ChildContentProjection(IPageContent pageContent, IChildContent content, IContentAccessor contentAccessor, IEnumerable<ChildContentProjection> childProjections = null, IEnumerable<PageContentProjection> childRegionContentProjections = null) : base(pageContent, content.ChildContent, contentAccessor, childProjections, childRegionContentProjections) { assignmentIdentifier = content.AssignmentIdentifier; }
public ChildContentProjection(IPageContent pageContent, IChildContent content, IContentAccessor contentAccessor, IEnumerable <ChildContentProjection> childProjections = null, IEnumerable <PageContentProjection> childRegionContentProjections = null) : base(pageContent, content.ChildContent, contentAccessor, childProjections, childRegionContentProjections) { assignmentIdentifier = content.AssignmentIdentifier; }