コード例 #1
0
        private IList<IContentData> GetAllContentAreaContents(IContentData contentData)
        {
            PropertyInfo[] props = contentData.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            var blocks = new List<IContentData>();

            foreach (PropertyInfo prop in props)
            {
                if (prop.PropertyType != typeof(ContentArea))
                    continue;

                object value = prop.GetValue(contentData, null);

                var contentArea = value as ContentArea;

                if (contentArea == null || !contentArea.FilteredItems.Any())
                    continue;

                var blockLinks = contentArea.FilteredItems.Select(i => i.ContentLink);

                blocks.AddRange(blockLinks.Select(b => _contentRepository.Get<IContentData>(b)));
            }

            return blocks;
        }
コード例 #2
0
        private static bool IsSitemapPropertyEnabled(IContentData content)
        {
            var property = content.Property[PropertySEOSitemaps.PropertyName] as PropertySEOSitemaps;
            if (property==null) //not set on the page, check if there are default values for a page type perhaps 
            { 
                var page = content as PageData;
                if (page == null)
                    return false;

                var seoProperty = page.GetType().GetProperty(PropertySEOSitemaps.PropertyName);
                if (seoProperty?.GetValue(page) is PropertySEOSitemaps) //check unlikely situation when the property name is the same as defined for SEOSiteMaps
                {
                    var isEnabled= ((PropertySEOSitemaps)seoProperty.GetValue(page)).Enabled;
                    return isEnabled;
                }

            }

            if (null != property && !property.Enabled)
            {
                return false;
            }

            return true;
        }
コード例 #3
0
        public virtual object GetValue(IContentData contentData, PropertyInfo property)
        {
            var annotation = property.GetAnnotation<CmsPagePredicateAttribute>();

            var predicate = (IPagePredicate) ServiceLocator.Current.GetService(annotation.Predicate);

            return predicate.Test((PageData) contentData);
        }
コード例 #4
0
        public object GetValue(IContentData contentData, PropertyInfo property)
        {
            var page = (PageData) contentData;

            var result = GetFriendlyUrl(page);

            return result;
        }
        public virtual bool CanIntercept(IContentData contentData, PropertyInfo property)
        {
            var content = contentData as IContent;
            // extract collection item type from it (i.e. for property type IEnumerable<ArticlePage> we'll extract ArticlePage type)
            var collectionItemType = property.PropertyType.TryGetCollectionItemType();

            return content != null && collectionItemType != null && CanIntercept(content, property, collectionItemType);
        }
コード例 #6
0
        public virtual object GetValue(IContentData contentData, PropertyInfo property)
        {
            var content = (IContent) contentData;
            var annotation = property.GetAnnotation<CmsPublishedStatusAttribute>();

            var result = FilterPublished.CheckPublishedStatus(content, annotation.Status);

            return result;
        }
コード例 #7
0
        private string Execute(IContentData contentData, ContentSerializerSettings settings)
        {
            var result = this._propertyManager.GetStructuredData(contentData, settings);

            return(JsonConvert.SerializeObject(result, new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            }));
        }
コード例 #8
0
        public Uri Save(IContentData contentData)
        {
            IContentTypeProvider contentTypeProvider = new ContentTypeProvider();
            IContentSerializer   contentSerializer   = new FrontMatterContentSerializer(contentTypeProvider);

            if (string.IsNullOrEmpty(contentData.Layout))
            {
                contentData.Layout = contentData.GetType().Name;
            }

            var fileContent = contentSerializer.Serialize(contentData);

            string contentPath;

            if (contentData.ContentUri != null)
            {
                // if the slug has been updated, rename the file
                if (!contentData.ContentUri.Segments.Last().Equals(contentData.Slug, StringComparison.InvariantCultureIgnoreCase))
                {
                    contentData.ContentUri = RenameContentAssets(contentData.ContentUri, contentData.Slug);
                }

                contentPath = ContentUri.GetAbsolutePath(contentData.ContentUri, true);
            }
            else if (contentData.ParentUri != null)
            {
                var parentPath = ContentUri.GetAbsolutePath(contentData.ParentUri);

                if (string.IsNullOrEmpty(contentData.Slug) && string.IsNullOrEmpty(contentData.Title))
                {
                    throw new InvalidOperationException("Could not create a URL slug for content. Please supply either Title or Slug to save the content.");
                }

                if (string.IsNullOrEmpty(contentData.Slug))
                {
                    contentData.Slug = contentData.Title.ToUrlSlug();
                }

                contentPath = Path.Combine(parentPath, Path.ChangeExtension(contentData.Slug, _fileExtension));
            }
            else
            {
                throw new InvalidOperationException("Cannot save content when both ParentUri and ContentUri is missing.");
            }

            var directoryPath = Path.GetDirectoryName(contentPath);

            if (!Directory.Exists(directoryPath))
            {
                Directory.CreateDirectory(directoryPath);
            }

            File.WriteAllText(contentPath, fileContent);

            return(NormalizeContentUri(new Uri(contentPath)));
        }
コード例 #9
0
        public object GetValue(IContentData contentData, PropertyInfo property)
        {
            var content = (IContent)contentData;
            // the type from the property declaration
            var resultType = property.PropertyType;
            // load parent page and cast it to the declaration type
            var result = ContentLoader.Get <IContent>(content.ParentLink).Cast(resultType);

            return(result);
        }
コード例 #10
0
        public object GetValue(IContentData contentData, PropertyInfo property)
        {
            var value = property.GetValue(contentData);

            if (value == null)
            {
                return((string[])Enumerable.Empty <string>());
            }
            return((string[])value);
        }
コード例 #11
0
        public object GetValue(IContentData contentData, PropertyInfo property)
        {
            var content = (IContent) contentData;
            // the type from the property declaration
            var resultType = property.PropertyType;
            // load parent page and cast it to the declaration type
            var result = ContentLoader.Get<IContent>(content.ParentLink).Cast(resultType);

            return result;
        }
コード例 #12
0
        public ContentRenderingErrorModel(IContentData contentData, Exception exception)
        {
            var content = contentData as IContent;

            ContentName = content != null ? content.Name : string.Empty;

            ContentTypeName = contentData.GetOriginalType().Name;

            Exception = exception;
        }
コード例 #13
0
        private static bool IsSitemapPropertyEnabled(IContentData content)
        {
            var property = content.Property[PropertySEOSitemaps.PropertyName] as PropertySEOSitemaps;

            if (null != property && !property.Enabled)
            {
                return(false);
            }

            return(true);
        }
コード例 #14
0
        public static bool HasTemplate(this IContentData contentData)
        {
            if (contentData == null)
            {
                return(false);
            }

            var templateRepository = ServiceLocator.Current.GetInstance <ITemplateRepository>();

            return(templateRepository.List(contentData.GetOriginalType()).Any(x => x.TemplateTypeCategory.IsCategory(TemplateTypeCategories.Page)));
        }
コード例 #15
0
        /// <summary>
        /// Will look for the first long string property, ignoring link collections, that has a value.
        /// </summary>
        /// <param name="content">The page that we want to get a preview for.</param>
        /// <returns>
        /// The value from the first non empty long string.
        /// </returns>
        protected virtual string GetPreviewTextFromFirstLongString(IContentData content)
        {
            foreach (var propertyData in content.Property)
            {
                if (propertyData is PropertyLongString && !(propertyData is PropertyLinkCollection) && !string.IsNullOrEmpty(propertyData.Value as string))
                {
                    return(propertyData.ToWebString());
                }
            }

            return(string.Empty);
        }
コード例 #16
0
        public static string ToJson(this IContentData contentData)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var contentSerializer = GetContentJsonSerializer();
            var result            = contentSerializer.Serialize(contentData);

            stopwatch.Stop();
            Trace.WriteLine($".ToJson took {stopwatch.ElapsedMilliseconds}ms");
            return(result);
        }
コード例 #17
0
        /// <summary>
        /// Creates a preview text from a PageData. Will first look for the property MainIntro, and if that's missing, a property called MainBody.
        /// </summary>
        /// <param name="content">The page to extract the preview from.</param>
        protected virtual string CreatePreviewText(IContentData content)
        {
            var str = string.Empty;

            if (content == null)
            {
                return(str);
            }

            return(TextIndexer.StripHtml(content.Property["MainIntro"] == null ?
                                         (content.Property["MainBody"] == null ?
                                          GetPreviewTextFromFirstLongString(content) : content.Property["MainBody"].ToWebString()) : content.Property["MainIntro"].ToWebString(), 200));
        }
コード例 #18
0
        public static bool HasTemplate(this IContent content)
        {
            ObjectExtensions.ValidateNotNullArgument((object)content, "content");
            IContentData contentData = (IContentData)content;

            if (contentData != null)
            {
                return(Enumerable.Any <TemplateModel>(ServiceLocator.Current.GetInstance <TemplateModelRepository>().List(RuntimeModelExtensions.GetOriginalType((object)contentData)), (Func <TemplateModel, bool>)(x => TemplateTypeCategoriesExtensions.IsCategory(x.TemplateTypeCategory, TemplateTypeCategories.Page))));
            }
            else
            {
                return(false);
            }
        }
コード例 #19
0
        public IEnumerable <PropertyInfo> GetProperties(IContentData contentData)
        {
            var type = contentData.GetOriginalType();

            if (_cachedContentTypes.ContainsKey(type))
            {
                return(_cachedContentTypes[type]);
            }

            var properties = type.GetProperties().Where(ShouldBeIncluded).ToList();

            _cachedContentTypes[type] = properties;
            return(properties);
        }
コード例 #20
0
 private static string GetFirstMatchingProperty(this IContentData data, string[] names)
 {
     foreach (string name in names)
     {
         if (data.Property[name] != null)
         {
             if (data.Property[name].Value != null)
             {
                 return(data.Property[name].Value.ToString());
             }
         }
     }
     return(null);
 }
コード例 #21
0
        public ContentRenderingErrorModel(IContentData contentData, Exception exception)
        {
            if (contentData is IContent content)
            {
                ContentName = content.Name;
            }
            else
            {
                ContentName = string.Empty;
            }

            ContentTypeName = contentData.GetOriginalType().Name;

            Exception = exception;
        }
コード例 #22
0
        private string CreateCacheKey(IContentData contentData, TemplateModel templateModel)
        {
            var content          = contentData as IContent;
            var hashCodeCombiner = new HashCodeCombiner();

            if (content != null)
            {
                hashCodeCombiner.Add(content.ContentLink.ToString());
            }

            hashCodeCombiner.Add(templateModel.Name);
            hashCodeCombiner.Add(templateModel.ModelType);
            hashCodeCombiner.Add(templateModel.TemplateType);
            hashCodeCombiner.Add(templateModel.Tags);
            return($"{CachePrefix}{hashCodeCombiner.CombinedHash}");
        }
コード例 #23
0
        private void AddDependecies(IRenderingContext context, IContentData contentData)
        {
            var routedContent = _contentRouteHelperAccessor().ContentLink;

            if (!ContentReference.IsNullOrEmpty(routedContent))
            {
                context.AddDependency(routedContent);
            }

            var currentContent = contentData as IContent;

            if (currentContent != null && !currentContent.ContentLink.CompareToIgnoreWorkID(routedContent))
            {
                context.AddDependency(currentContent.ContentLink);
            }
        }
コード例 #24
0
        public ContentRenderingErrorModel(IContentData contentData, Exception exception)
        {
            var content = contentData as IContent;
            if(content != null)
            {
                ContentName = content.Name;
            }
            else
            {
                ContentName = string.Empty;
            }

            ContentTypeName = contentData.GetOriginalType().Name;

            Exception = exception;
        }
コード例 #25
0
        public object Handle(
            ContentArea contentArea,
            PropertyInfo property,
            IContentData contentData,
            IContentSerializerSettings settings)
        {
            if (contentArea == null)
            {
                return(null);
            }
            var contentAreaItems = GetContentAreaItems(contentArea);

            if (WrapItems(contentArea, settings))
            {
                var items = new Dictionary <string, List <object> >();
                foreach (var item in contentAreaItems)
                {
                    var result   = this._propertyManager.GetStructuredData(item, settings);
                    var typeName = item.GetOriginalType().Name;
                    result.Add(settings.BlockTypePropertyName, typeName);
                    if (items.ContainsKey(typeName))
                    {
                        items[typeName].Add(result);
                    }
                    else
                    {
                        items[typeName] = new List <object> {
                            result
                        };
                    }
                }

                return(items);
            }
            else
            {
                var items = new List <object>();
                foreach (var item in contentAreaItems)
                {
                    var result = this._propertyManager.GetStructuredData(item, settings);
                    result.Add(settings.BlockTypePropertyName, item.GetOriginalType().Name);
                    items.Add(result);
                }

                return(items);
            }
        }
コード例 #26
0
        private IEnumerable <ContentExtractionResult> ExtractBlockInternal(IContentData content, IContentExtractorController extractor)
        {
            var result = new List <ContentExtractionResult>();

            var extractionResults = GetExtractionResults(_extractors, content, extractor);

            result.AddRange(extractionResults);

            var relatedContentList = extractionResults.SelectMany(r => r.ContentReferences);

            foreach (var relatedContent in relatedContentList)
            {
                result.AddRange(ExtractBlockInternal(relatedContent, extractor));
            }

            return(result);
        }
コード例 #27
0
        public ContentExtractionResult Extract(IContentData content, IContentExtractorController extractor)
        {
            var texts = new List <string>();

            var properties = content.GetIndexableProperties();

            foreach (var property in properties)
            {
                var textsFromProperty = ExtractTextFromProperty(extractor, property);
                if (string.IsNullOrEmpty(textsFromProperty) == false)
                {
                    texts.Add(textsFromProperty);
                }
            }

            return(new ContentExtractionResult(texts, null));
        }
コード例 #28
0
        public ActionResult Index(NodeContent currentContent)
        {
            SetLanguage();
            string language = Language;
            var    client   = SearchClient.Instance;

            IContentLoader     loader         = ServiceLocator.Current.GetInstance <IContentLoader>();
            ProductService     productService = ServiceLocator.Current.GetInstance <ProductService>();
            ReferenceConverter refConverter   = ServiceLocator.Current.GetInstance <ReferenceConverter>();


            try
            {
                SearchResults <FindProduct> results = client.Search <FindProduct>()
                                                      .Filter(x => x.ParentCategoryId.Match(currentContent.ContentLink.ID))
                                                      .Filter(x => x.Language.Match(language))
                                                      .StaticallyCacheFor(TimeSpan.FromMinutes(1))
                                                      .GetResult();

                List <ProductListViewModel> searchResult = new List <ProductListViewModel>();
                foreach (SearchHit <FindProduct> searchHit in results.Hits)
                {
                    ContentReference contentLink = refConverter.GetContentLink(searchHit.Document.Id, CatalogContentType.CatalogEntry, 0);

                    // The content can be deleted from the db, but still exist in the index
                    IContentData content = null;
                    if (loader.TryGet(contentLink, out content))
                    {
                        IProductListViewModelInitializer modelInitializer = content as IProductListViewModelInitializer;
                        if (modelInitializer != null)
                        {
                            searchResult.Add(productService.GetProductListViewModel(modelInitializer));
                        }
                    }
                }


                return(PartialView("Blocks/NodeContentPartial", searchResult));
            }

            catch (Exception)
            {
                return(PartialView("Blocks/NodeContentPartial", null));
            }
        }
コード例 #29
0
        public object Execute(PropertyInfo property, IContentData contentData, ISelectionFactory selectionFactory)
        {
            var result = (IEnumerable <SelectOption>) this._defaultSelectManyStrategy.Execute(property, contentData, selectionFactory);
            var type   = contentData.GetOriginalType();

            if (IsCustomContentType(type, property.Name))
            {
                var onlyValue = CustomProperties[type][property.Name];
                if (onlyValue)
                {
                    return(result.Where(x => x.Selected).Select(x => x.Value));
                }

                return(result.Where(x => x.Selected));
            }

            return(result);
        }
コード例 #30
0
        private static NameValueCollection BuildFocalPointCollection(IContentData image)
        {
            var queryCollection = new NameValueCollection();

            if (image?.Property["ImageFocalPoint"]?.Value != null)
            {
                var propertyValue = image.Property["ImageFocalPoint"].ToString();
                var focalValues   = propertyValue.Split('|');
                if (focalValues.Length == 2)
                {
                    var x = focalValues[0];
                    var y = focalValues[1];
                    queryCollection.Add("center", y + "," + x);
                }
            }

            return(queryCollection);
        }
コード例 #31
0
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (bindingContext.ModelName == "currentContent")
            {
                var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);

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

                IContentData contentData = valueProviderResult.RawValue as IContentData;

                return(contentData);
            }

            return(base.BindModel(controllerContext, bindingContext));
        }
コード例 #32
0
        private string GetPropertyStringValue(IContentData content, string propertyName)
        {
            if (string.IsNullOrWhiteSpace(propertyName))
            {
                return(null);
            }

            PropertyData data = content.Property[propertyName];

            if (data == null || data.IsNull)
            {
                return(null);
            }

            return(data.Value is string stringValue
                ? stringValue
                : null);
        }
コード例 #33
0
 /// <summary>
 /// Renders the contentData using the wrapped renderer and catches common, non-critical exceptions.
 /// </summary>
 public void Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
 {
     try
     {
         _mvcRenderer.Render(helper, partialRequestHandler, contentData, templateModel);
     }
     catch (Exception) when(HttpContext.Current.IsDebuggingEnabled)
     {
         //If debug="true" we assume a developer is making the request
         throw;
     }
     catch (NullReferenceException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (ArgumentException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (ApplicationException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (InvalidOperationException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (NotImplementedException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (IOException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (EPiServerException ex)
     {
         HandlerError(helper, contentData, ex);
     }
     catch (XFormException ex)
     {
         HandlerError(helper, contentData, ex);
     }
 }
        public static void RenderContentData(HtmlHelper html,
                                             IContentData content,
                                             string tag)
        {
            var templateResolver = ServiceLocator.Current.GetInstance <TemplateResolver>();
            var templateModel    = templateResolver.Resolve(
                html.ViewContext.HttpContext,
                content.GetOriginalType(),
                content,
                TemplateTypeCategories.MvcPartial,
                tag);

            var contentRenderer = ServiceLocator.Current.GetInstance <IContentRenderer>();

            html.RenderContentData(
                content,
                true,
                templateModel,
                contentRenderer);
        }
コード例 #35
0
        public object Handle(string stringValue, PropertyInfo property, IContentData contentData)
        {
            if (HasSelectAttribute(property))
            {
                var selectOneAttribute = GetSelectOneAttribute(property);
                if (selectOneAttribute != null)
                {
                    var selectionFactory = CreateSelectionFactoryInstance(selectOneAttribute.SelectionFactoryType);
                    return(this._selectOneStrategy.Execute(property, contentData, selectionFactory));
                }
                else
                {
                    var selectManyAttribute = GetSelectManyAttribute(property);
                    var selectionFactory    = CreateSelectionFactoryInstance(selectManyAttribute.SelectionFactoryType);
                    return(this._selectManyStrategy.Execute(property, contentData, selectionFactory));
                }
            }

            return(stringValue);
        }
コード例 #36
0
        public object Handle(
            ContentReference contentReference,
            PropertyInfo property,
            IContentData contentData,
            IContentSerializerSettings settings)
        {
            if (contentReference == null || contentReference == ContentReference.EmptyReference)
            {
                return(null);
            }

            var url = new Uri(this._urlHelper.ContentUrl(contentReference, settings.UrlSettings));

            if (settings.UrlSettings.UseAbsoluteUrls && url.IsAbsoluteUri)
            {
                return(url.AbsoluteUri);
            }

            return(url.PathAndQuery);
        }
        private bool ResolveProperty(IContentData content, string propertyName)
        {
            //First try to find property on typed model
            var property = content.GetType().GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);

            if (property != null && property.CanRead && property.CanWrite)
            {
                return(true);
            }

            //Then check if property is in PropertyCollection
            var propertyData = content.Property[propertyName];

            if (propertyData != null)
            {
                return(true);
            }

            //Finally check if it is defined on an interface
            return(GetInterfaceForPropertyName(propertyName));
        }
コード例 #38
0
        public object Handle(string stringValue, PropertyInfo property, IContentData contentData)
        {
            if (HasSelectAttribute(property))
            {
                var  selectOneAttribute = GetSelectOneAttribute(property);
                Type selectionFactoryType;
                if (selectOneAttribute != null)
                {
                    selectionFactoryType = selectOneAttribute.SelectionFactoryType;
                }
                else
                {
                    var selectManyAttribute = GetSelectManyAttribute(property);
                    selectionFactoryType = selectManyAttribute.SelectionFactoryType;
                }

                var valueAsDictionary = GetStructuredData(property, contentData, selectionFactoryType);
                return(valueAsDictionary);
            }

            return(stringValue);
        }
        public virtual object GetValue(IContentData contentData, PropertyInfo property)
        {
            var collectionItemType = property.PropertyType.TryGetCollectionItemType();

            return GetValue((IContent) contentData, property, collectionItemType);
        }
コード例 #40
0
 public bool CanIntercept(IContentData contentData, PropertyInfo property)
 {
     return contentData is PageData;
 }
コード例 #41
0
 public virtual bool CanIntercept(IContentData contentData, PropertyInfo property)
 {
     return property.HasAnnotation<CmsPagePredicateAttribute>()
         && (contentData is PageData) && property.PropertyType == typeof(bool);
 }
コード例 #42
0
 private void CopyProperties(IContentData content, PropertyDataCollection properties)
 {
     foreach (var property in properties)
     {
         // continue if the property isn't languagespecific or a metadata property
         if (!content.Property[property.Name].IsLanguageSpecific || content.Property[property.Name].IsMetaData)
         {
             continue;
         }
         // if it is a block, recursively copy the property values
         if (property.Value is IContentData)
         {
             CopyProperties(content.Property[property.Name].Value as IContentData, (property.Value as IContentData).Property);
         }
         else
         {
             // copy the property value
             content.Property[property.Name].Value = property.Value;
         }
     }
 }
コード例 #43
0
 public bool CanIntercept(IContentData contentData, PropertyInfo property)
 {
     // we intercept property if it's declared in a page or shared block.
     return contentData is IContent;
 }
 /// <summary>
 /// Renders the contentData using the wrapped renderer and catches common, non-critical exceptions.
 /// </summary>
 public void Render(HtmlHelper helper, PartialRequest partialRequestHandler, IContentData contentData, TemplateModel templateModel)
 {
     try
     {
         _mvcRenderer.Render(helper, partialRequestHandler, contentData, templateModel);
     }
     catch (NullReferenceException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             //If debug="true" we assume a developer is making the request
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (ArgumentException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (ApplicationException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (InvalidOperationException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (NotImplementedException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (IOException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (EPiServerException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
     catch (XFormException ex)
     {
         if (HttpContext.Current.IsDebuggingEnabled)
         {
             throw;
         }
         HandlerError(helper, contentData, ex);
     }
 }
 private void HandlerError(HtmlHelper helper, IContentData contentData, Exception renderingException)
 {
     if (PrincipalInfo.HasEditAccess)
     {
         var errorModel = new ContentRenderingErrorModel(contentData, renderingException);
         helper.RenderPartial("TemplateError", errorModel);
     }
 }
コード例 #46
0
ファイル: MvcContextExtensions.cs プロジェクト: encel/Encel
 public static void SetCurrentContent(this ViewContext viewContext, IContentData contentData)
 {
     viewContext.RouteData.Values[CURRENT_CONTENT_KEY] = contentData;
 }
コード例 #47
0
        private IList<ContentReference> GetAllImages(IContentData contentData)
        {
            PropertyInfo[] props = contentData.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);

            IList<ContentReference> images = new List<ContentReference>();

            foreach (PropertyInfo prop in props)
            {
                if (prop.PropertyType != typeof (ContentReference) || !IsImage(prop))
                    continue;

                object value = prop.GetValue(contentData, null);

                var image = value as ContentReference;

                if (!ContentReference.IsNullOrEmpty(image))
                    images.Add(image);
            }

            return images;
        }
コード例 #48
0
 public virtual bool CanIntercept(IContentData contentData, PropertyInfo property)
 {
     return property.HasAnnotation<CmsPublishedStatusAttribute>()
         && contentData is IContent
         && property.PropertyType == typeof(bool);
 }
コード例 #49
0
 public bool CanIntercept(IContentData contentData, PropertyInfo property)
 {
     return property.HasAnnotation<CmsReferenceAttribute>();
 }
コード例 #50
0
        public object GetValue(IContentData contentData, PropertyInfo property)
        {
            // define if property is required
            var requiredAnnotation = property.GetAttribute<RequiredAttribute>();

            // get annotation attribute
            var annotation = property.GetAnnotation<CmsReferenceAttribute>();

            // get reference property name set by attribute or default
            var referencePropertyName = annotation.LinkFieldName ?? property.Name + "Link";

            // lookup reference property
            var referenceProperty = contentData.Property[referencePropertyName] as PropertyPageReference;

            if (referenceProperty != null)
            // if reference property found
            {
                // get link to a referenced page
                var link = referenceProperty.ContentLink;

                if (!ContentReference.IsNullOrEmpty(link))
                // and if it's not empty
                {
                    // load referenced page and cast it to the target property type.
                    var result = ContentLoader.Get<PageData>(link).Cast(property.PropertyType);

                    if (result != null)
                    {
                        return result;
                    }
                }
            }

            if (requiredAnnotation == null)
            // if property is not marked as required
            {
                return null;
            }

            // otherwise get error message
            string errorMessageFormat;

            if (!string.IsNullOrEmpty(requiredAnnotation.ErrorMessageResourceName))
            {
                errorMessageFormat = LocalizationService.GetString(requiredAnnotation.ErrorMessageResourceName);
            }
            else if (!string.IsNullOrEmpty(requiredAnnotation.ErrorMessage))
            {
                errorMessageFormat = requiredAnnotation.ErrorMessage;
            }
            else
            {
                errorMessageFormat = LocalizationService.GetString("EPiProperties/PropertyRequiredFormat", "Required property '{0}' is not properly set on the page #{1} of type '{2}'. ");
            }

            var content = contentData as IContent;

            if (content != null)
            {
                var contentType = ContentTypeRepository.Load(content.ContentTypeID);

                var errorMessage = string.Format(errorMessageFormat,
                    property.Name,
                    content.ContentLink.ID,
                    contentType.DisplayName);

                throw new ApplicationException(errorMessage);
            }
            else
            {
                throw new ApplicationException(string.Format(errorMessageFormat,
                    property.Name,
                    "?",
                    "?")); // TODO
            }
        }
コード例 #51
0
 private void HandlerError(HtmlHelper helper, IContentData contentData, Exception renderingException)
 {
     if (PrincipalInfo.HasEditAccess)
     {
         //var errorModel = new ContentRenderingErrorModel(contentData, renderingException);
         throw new NotImplementedException();
         // todo: roru, 2 parameters
         // helper.RenderPartial("TemplateError", errorModel);
     }
 }