public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (TemplateId.IsNullOrEmpty()) { yield return(new ValidationResult("TemplateId can't be null or empty.")); } if (To.IsNullOrEmpty()) { yield return(new ValidationResult("The To can't be empty.")); } else { foreach (var to in To) { var items = to.Validate(validationContext); foreach (var item in items) { yield return(item); } } } }
/// <summary> /// Configures the specified type. /// </summary> /// <param name="type">The type.</param> /// <param name="config">The config.</param> /// <exception cref="Glass.Mapper.Configuration.ConfigurationException">Type configuration is not of type {0}.Formatted(typeof (SitecoreTypeConfiguration).FullName)</exception> public override AbstractTypeConfiguration Configure(Type type) { var scConfig = new SitecoreTypeConfiguration(); if (scConfig == null) { throw new ConfigurationException( "Type configuration is not of type {0}".Formatted(typeof(SitecoreTypeConfiguration).FullName)); } try { if (BranchId.HasValue()) { scConfig.BranchId = new ID(this.BranchId); } else { scConfig.BranchId = ID.Null; } } catch (Exception ex) { throw new MapperException("Failed to convert BranchId for type {0}. Value was {1}".Formatted(type.FullName, this.TemplateId), ex); } try { if (TemplateId.HasValue()) { scConfig.TemplateId = new ID(this.TemplateId); } else { scConfig.TemplateId = ID.Null; } } catch (Exception ex) { throw new MapperException("Failed to convert TemplateId for type {0}. Value was {1}".Formatted(type.FullName, this.TemplateId), ex); } if (TemplateId.IsNullOrEmpty() && this.EnforceTemplate.IsEnabled()) { throw new ConfigurationException( "The type {0} has EnforceTemplate set to true but no TemplateId".Formatted(type.FullName)); } scConfig.EnforceTemplate = this.EnforceTemplate; scConfig.TemplateName = this.TemplateName; scConfig.Cache = this.Cache; base.Configure(type, scConfig); return(scConfig); }
/// <summary> /// Configures the specified type. /// </summary> /// <param name="type">The type.</param> /// <param name="config">The config.</param> /// <exception cref="Glass.Mapper.Configuration.ConfigurationException">Type configuration is not of type {0}.Formatted(typeof (SitecoreTypeConfiguration).FullName)</exception> public override AbstractTypeConfiguration Configure(Type type) { var scConfig = new SitecoreTypeConfiguration(); if (scConfig == null) { throw new ConfigurationException( "Type configuration is not of type {0}".Formatted(typeof(SitecoreTypeConfiguration).FullName)); } if (BranchId.IsNotNullOrEmpty()) { scConfig.BranchId = new ID(this.BranchId); } else { scConfig.BranchId = ID.Null; } if (TemplateId.IsNotNullOrEmpty()) { scConfig.TemplateId = new ID(this.TemplateId); } else { scConfig.TemplateId = ID.Null; } if (TemplateId.IsNullOrEmpty() && this.EnforceTemplate != SitecoreEnforceTemplate.No) { throw new ConfigurationException( "The type {0} has EnforceTemplate set to true but no TemplateId".Formatted(type.FullName)); } scConfig.EnforceTemplate = this.EnforceTemplate; scConfig.CodeFirst = this.CodeFirst; scConfig.TemplateName = this.TemplateName; base.Configure(type, scConfig); return(scConfig); }
public override void Apply([NotNull] T ruleContext) { if (TemplateId.IsNullOrEmpty() || DisplayName.IsNullOrEmpty()) { return; } var addedItem = ruleContext.Item; var templateId = new TemplateID(ID.Parse(TemplateId)); if (addedItem.Children.Any(i => i.TemplateID == templateId.ID)) { return; } if (addedItem.TemplateID != templateId) { addedItem.Add(DisplayName, templateId); } }