public static Wing FactoryWing(this WingModule module) { var attr = module.GetType().GetCustomAttribute <WingModuleAttribute>(); if (attr == null) { throw new InvalidWingModuleException(string.Format("{0} does not have proper metadata attribute", module.Description)); } return(attr.FactoryWing()); }
public static Wing LoadTargets(this Wing wing, WingModule module, ISession session = null) { //&& typeof(ContentPartRecord).IsAssignableFrom(t) var assy = module.GetType().Assembly; if (session == null) { assy.GetTypes() .Where(t => t.Namespace == module.GetType().Namespace&& t.GetCustomAttribute <WingTargetAttribute>() != null) .Select(t => new { Type = t, Attribute = t.GetCustomAttribute <WingTargetAttribute>() }) .ToList() .ForEach(v => v.Attribute .CreateTarget(wing, v.Attribute.Guid, v.Type, v.Attribute.IsTrendingEnabled, v.Attribute.DisplayOrder) .LoadElements(v.Type)); } else { var targetTypeAttributes = assy .GetTypes() .Where(t => t.GetCustomAttribute <WingTargetAttribute>() != null) .Select(t => new { Type = t, Attribute = t.GetCustomAttribute <WingTargetAttribute>() }) .ToList(); foreach (var attribute in targetTypeAttributes) { if (session.Query <Target>().Any(t1 => t1.Guid != attribute.Attribute.Guid)) { continue; } attribute.Attribute .CreateTarget(wing, attribute.Attribute.Guid, attribute.Type, attribute.Attribute.IsTrendingEnabled, attribute.Attribute.DisplayOrder) .LoadElements(attribute.Type); } } return(wing); }