public static WordTemplateEntity GetDefaultTemplate(SystemWordTemplateEntity systemWordTemplate, Entity entity) { var templates = SystemWordTemplateToWordTemplates.Value.TryGetC(systemWordTemplate.ToLite()).EmptyIfNull().Select(a => WordTemplateLogic.WordTemplatesLazy.Value.GetOrThrow(a)); if (templates.IsNullOrEmpty() && HasDefaultTemplateConstructor(systemWordTemplate)) { using (ExecutionMode.Global()) using (OperationLogic.AllowSave <WordTemplateEntity>()) using (Transaction tr = Transaction.ForceNew()) { var template = CreateDefaultTemplate(systemWordTemplate); template.Save(); return(tr.Commit(template)); } } var isAllowed = Schema.Current.GetInMemoryFilter <WordTemplateEntity>(userInterface: false); var candidates = templates.Where(isAllowed).Where(t => t.IsApplicable(entity)); return(GetTemplate(candidates, systemWordTemplate, CultureInfo.CurrentCulture) ?? GetTemplate(candidates, systemWordTemplate, CultureInfo.CurrentCulture.Parent) ?? candidates.Only() ?? throw new InvalidProgramException($"No active template found for {systemWordReports} in {CultureInfo.CurrentCulture} or {CultureInfo.CurrentCulture.Parent}")); }
public static byte[] CreateReport(this ISystemWordTemplate systemWordTemplate, out WordTemplateEntity template, bool avoidConversion = false) { SystemWordTemplateEntity system = GetSystemWordTemplate(systemWordTemplate.GetType()); template = GetDefaultTemplate(system, systemWordTemplate.UntypedEntity as Entity); return(WordTemplateLogic.CreateReport(template.ToLite(), systemWordTemplate: systemWordTemplate, avoidConversion: avoidConversion)); }
public static Type ToType(this SystemWordTemplateEntity systemWordTemplate) { if (systemWordTemplate == null) { return(null); } return(SystemWordTemplateToType.Value.GetOrThrow(systemWordTemplate)); }
internal static WordTemplateEntity CreateDefaultTemplate(SystemWordTemplateEntity systemWordReport) { SystemWordTemplateInfo info = systemWordReports.GetOrThrow(systemWordReport.ToType()); if (info.DefaultTemplateConstructor == null) { return(null); } WordTemplateEntity template = info.DefaultTemplateConstructor(); if (template.Name == null) { template.Name = systemWordReport.FullClassName; } template.SystemWordTemplate = systemWordReport; template.Query = QueryLogic.GetQueryEntity(info.QueryName); return(template); }
public static IQueryable <WordTemplateEntity> WordTemplates(this SystemWordTemplateEntity e) { return(WordTemplatesExpression.Evaluate(e)); }
public static ISystemWordTemplate CreateDefaultSystemWordTemplate(SystemWordTemplateEntity systemWordTemplate, ModifiableEntity entity) { return((ISystemWordTemplate)SystemWordTemplateLogic.GetEntityConstructor(systemWordTemplate.ToType()).Invoke(new[] { entity })); }
public static bool RequiresExtraParameters(SystemWordTemplateEntity systemWordTemplateEntity) { return(GetEntityConstructor(systemWordTemplateEntity.ToType()) == null); }
private static WordTemplateEntity GetTemplate(IEnumerable <WordTemplateEntity> candidates, SystemWordTemplateEntity systemWordTemplate, CultureInfo culture) { return(candidates .Where(a => a.Culture.Name == culture.Name) .SingleOrDefaultEx(() => $"Active WordTemplates for SystemWordTemplate {systemWordTemplate} in {culture.Name}")); }
internal static bool HasDefaultTemplateConstructor(SystemWordTemplateEntity systemWordReport) { SystemWordTemplateInfo info = systemWordReports.GetOrThrow(systemWordReport.ToType()); return(info.DefaultTemplateConstructor != null); }
public string GetConstructorType(SystemWordTemplateEntity systemWordTemplate) { var type = SystemWordTemplateLogic.GetEntityType(systemWordTemplate.ToType()); return(ReflectionServer.GetTypeName(type)); }