예제 #1
0
        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}"));
        }
예제 #2
0
        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));
        }
예제 #3
0
        public static Type ToType(this SystemWordTemplateEntity systemWordTemplate)
        {
            if (systemWordTemplate == null)
            {
                return(null);
            }

            return(SystemWordTemplateToType.Value.GetOrThrow(systemWordTemplate));
        }
예제 #4
0
        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);
        }
예제 #5
0
 public static IQueryable <WordTemplateEntity> WordTemplates(this SystemWordTemplateEntity e)
 {
     return(WordTemplatesExpression.Evaluate(e));
 }
예제 #6
0
 public static ISystemWordTemplate CreateDefaultSystemWordTemplate(SystemWordTemplateEntity systemWordTemplate, ModifiableEntity entity)
 {
     return((ISystemWordTemplate)SystemWordTemplateLogic.GetEntityConstructor(systemWordTemplate.ToType()).Invoke(new[] { entity }));
 }
예제 #7
0
 public static bool RequiresExtraParameters(SystemWordTemplateEntity systemWordTemplateEntity)
 {
     return(GetEntityConstructor(systemWordTemplateEntity.ToType()) == null);
 }
예제 #8
0
 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}"));
 }
예제 #9
0
        internal static bool HasDefaultTemplateConstructor(SystemWordTemplateEntity systemWordReport)
        {
            SystemWordTemplateInfo info = systemWordReports.GetOrThrow(systemWordReport.ToType());

            return(info.DefaultTemplateConstructor != null);
        }
예제 #10
0
        public string GetConstructorType(SystemWordTemplateEntity systemWordTemplate)
        {
            var type = SystemWordTemplateLogic.GetEntityType(systemWordTemplate.ToType());

            return(ReflectionServer.GetTypeName(type));
        }