public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { QueryEntity.GetEntityImplementations = query => dqm.GetEntityImplementations(query.ToQueryName()); // QueryManagers = queryManagers; sb.Schema.Initializing += () => { queryNamesLazy.Load(); queryNameToEntityLazy.Load(); }; sb.Include <QueryEntity>() .WithQuery(dqm, () => q => new { Entity = q, q.Key, }); sb.Schema.Synchronizing += SynchronizeQueries; sb.Schema.Generating += Schema_Generating; queryNamesLazy = sb.GlobalLazy(() => CreateQueryNames(), new InvalidateWith(typeof(QueryEntity)), Schema.Current.InvalidateMetadata); queryNameToEntityLazy = sb.GlobalLazy(() => EnumerableExtensions.JoinRelaxed( Database.Query <QueryEntity>().ToList(), QueryNames, q => q.Key, kvp => kvp.Key, (q, kvp) => KVP.Create(kvp.Value, q), "caching QueryEntity").ToDictionary(), new InvalidateWith(typeof(QueryEntity)), Schema.Current.InvalidateMetadata); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include<WordTemplateEntity>(); SystemWordTemplateLogic.Start(sb, dqm); SymbolLogic<WordTransformerSymbol>.Start(sb, () => Transformers.Keys.ToHashSet()); SymbolLogic<WordConverterSymbol>.Start(sb, () => Converters.Keys.ToHashSet()); dqm.RegisterQuery(typeof(WordTemplateEntity), ()=> from e in Database.Query<WordTemplateEntity>() select new { Entity = e, e.Id, e.Query, e.Template.Entity.FileName }); dqm.RegisterQuery(typeof(WordTransformerSymbol), () => from f in Database.Query<WordTransformerSymbol>() select new { Entity = f, f.Key }); dqm.RegisterQuery(typeof(WordConverterSymbol), () => from f in Database.Query<WordConverterSymbol>() select new { Entity = f, f.Key }); dqm.RegisterExpression((SystemWordTemplateEntity e) => e.WordTemplates(), () => typeof(WordTemplateEntity).NiceName()); new Graph<WordTemplateEntity>.Execute(WordTemplateOperation.Save) { AllowsNew = true, Lite = false, Execute = (e, _) => { } }.Register(); new Graph<WordTemplateEntity>.Execute(WordTemplateOperation.CreateWordReport) { CanExecute = et => { if (et.SystemWordTemplate != null && SystemWordTemplateLogic.RequiresExtraParameters(et.SystemWordTemplate)) return "SystemWordTemplate ({1}) requires extra parameters".FormatWith(et.SystemWordTemplate); return null; }, Execute = (et, args) => { throw new InvalidOperationException("UI-only operation"); } }.Register(); TemplatesByType = sb.GlobalLazy(() => { var list = Database.Query<WordTemplateEntity>().Select(r => KVP.Create(r.Query, r.ToLite())).ToList(); return (from kvp in list let imp = dqm.GetEntityImplementations(kvp.Key.ToQueryName()) where !imp.IsByAll from t in imp.Types group kvp.Value by t into g select KVP.Create(g.Key.ToTypeEntity(), g.ToList())).ToDictionary(); }, new InvalidateWith(typeof(WordTemplateEntity))); WordTemplatesLazy = sb.GlobalLazy(() => Database.Query<WordTemplateEntity>() .ToDictionary(et => et.ToLite()), new InvalidateWith(typeof(WordTemplateEntity))); Schema.Current.Synchronizing += Schema_Synchronize_Tokens; Validator.PropertyValidator((WordTemplateEntity e) => e.Template).StaticPropertyValidation += ValidateTemplate; } }