public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <DynamicValidationEntity>() .WithSave(DynamicValidationOperation.Save) .WithQuery(dqm, () => e => new { Entity = e, e.Id, e.Name, e.EntityType, e.PropertyRoute, e.Eval, }); DynamicValidations = sb.GlobalLazy(() => Database.Query <DynamicValidationEntity>() .Select(dv => new DynamicValidationPair { Validation = dv, PropertyRoute = dv.PropertyRoute.ToPropertyRoute() }) .GroupToDictionary(a => a.PropertyRoute.PropertyInfo), new InvalidateWith(typeof(DynamicValidationEntity))); DynamicValidationEntity.GetMainType = dve => dve.PropertyRoute?.ToPropertyRoute().Parent.Type; sb.Schema.Initializing += () => { initialized = true; }; Validator.GlobalValidation += DynamicValidation; sb.Schema.Table <TypeEntity>().PreDeleteSqlSync += type => Administrator.UnsafeDeletePreCommand(Database.Query <DynamicValidationEntity>().Where(dv => dv.EntityType == type)); } }
internal static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <ChartScriptEntity>() .WithSave(ChartScriptOperation.Save) .WithQuery(dqm, () => uq => new { Entity = uq, uq.Id, uq.Name, uq.GroupBy, uq.Columns.Count, uq.Icon, }); Scripts = sb.GlobalLazy(() => { var result = Database.Query <ChartScriptEntity>().ToDictionary(a => a.Name); foreach (var e in result.Values) { if (e.Icon != null) { e.Icon.Retrieve(); } } return(result); }, new InvalidateWith(typeof(ChartScriptEntity))); RegisterOperations(); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include<SmtpConfigurationEntity>(); dqm.RegisterQuery(typeof(SmtpConfigurationEntity), () => from s in Database.Query<SmtpConfigurationEntity>() select new { Entity = s, s.Id, s.DeliveryMethod, s.Network.Host, s.Network.Username, s.PickupDirectoryLocation }); SmtpConfigCache = sb.GlobalLazy(() => Database.Query<SmtpConfigurationEntity>().ToDictionary(a => a.ToLite()), new InvalidateWith(typeof(SmtpConfigurationEntity))); new Graph<SmtpConfigurationEntity>.Execute(SmtpConfigurationOperation.Save) { AllowsNew = true, Lite = false, Execute = (sc, _) => { }, }.Register(); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <IsolationEntity>() .WithSave(IsolationOperation.Save) .WithQuery(dqm, () => iso => new { Entity = iso, iso.Id, iso.Name }); sb.Schema.EntityEventsGlobal.PreSaving += EntityEventsGlobal_PreSaving; sb.Schema.SchemaCompleted += AssertIsolationStrategies; OperationLogic.SurroundOperation += OperationLogic_SurroundOperation; Isolations = sb.GlobalLazy(() => Database.RetrieveAllLite <IsolationEntity>(), new InvalidateWith(typeof(IsolationEntity))); ProcessLogic.ApplySession += ProcessLogic_ApplySession; Validator.OverridePropertyValidator((IsolationMixin m) => m.Isolation).StaticPropertyValidation += (mi, pi) => { if (strategies.GetOrThrow(mi.MainEntity.GetType()) == IsolationStrategy.Isolated && mi.Isolation == null) { return(ValidationMessage._0IsNotSet.NiceToString(pi.NiceName())); } return(null); }; IsStarted = true; } }
internal static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include<ChartScriptEntity>(); dqm.RegisterQuery(typeof(ChartScriptEntity), () => from uq in Database.Query<ChartScriptEntity>() select new { Entity = uq, uq.Id, uq.Name, uq.GroupBy, uq.Columns.Count, uq.Icon, }); Scripts = sb.GlobalLazy(() => { var result = Database.Query<ChartScriptEntity>().ToDictionary(a => a.Name); foreach (var e in result.Values) if (e.Icon != null) e.Icon.Retrieve(); return result; }, new InvalidateWith(typeof(ChartScriptEntity))); RegisterOperations(); } }
public static void Start(SchemaBuilder sb, Func <IEnumerable <T> > getSemiSymbols) { if (sb.NotDefined(typeof(SemiSymbolLogic <T>).GetMethod("Start"))) { sb.Include <T>(); sb.Schema.Initializing += () => lazy.Load(); sb.Schema.Synchronizing += Schema_Synchronizing; sb.Schema.Generating += Schema_Generating; SemiSymbolLogic <T> .getSemiSymbols = getSemiSymbols; lazy = sb.GlobalLazy(() => { using (AvoidCache()) { var current = Database.RetrieveAll <T>().Where(a => a.Key.HasText()); var result = EnumerableExtensions.JoinRelaxed( current, getSemiSymbols(), c => c.Key !, s => s.Key !, (c, s) => { s.SetIdAndProps(c); return(s); }, "caching " + typeof(T).Name); SemiSymbol.SetFromDatabase <T>(current.ToDictionary(a => a.Key !)); return(result.ToDictionary(a => a.Key !)); } }, new InvalidateWith(typeof(T)), Schema.Current.InvalidateMetadata); sb.Schema.EntityEvents <T>().Retrieved += SymbolLogic_Retrieved; } }
private static void StartSouthwindConfiguration(SchemaBuilder sb, DynamicQueryManager dqm) { sb.Include <ApplicationConfigurationEntity>(); Configuration = sb.GlobalLazy <ApplicationConfigurationEntity>( () => Database.Query <ApplicationConfigurationEntity>().Single(a => a.Environment == Settings.Default.Environment), new InvalidateWith(typeof(ApplicationConfigurationEntity))); new Graph <ApplicationConfigurationEntity> .Execute(ApplicationConfigurationOperation.Save) { AllowsNew = true, Lite = false, Execute = (e, _) => { }, } .Register(); dqm.RegisterQuery(typeof(ApplicationConfigurationEntity), () => from s in Database.Query <ApplicationConfigurationEntity>() select new { Entity = s, s.Id, s.Environment, s.Email.SendEmails, s.Email.OverrideEmailAddress, s.Email.DefaultCulture, s.Email.UrlLeft }); }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <RestApiKeyEntity>() .WithDelete(RestApiKeyOperation.Delete) .WithQuery(() => e => new { Entity = e, e.Id, e.User, e.ApiKey }); new Graph <RestApiKeyEntity> .Execute(RestApiKeyOperation.Save) { CanBeNew = true, CanBeModified = true, Execute = (e, _) => { }, } .Register(); RestApiKeyCache = sb.GlobalLazy(() => { return(Database.Query <RestApiKeyEntity>().ToDictionaryEx(rak => rak.ApiKey)); }, new InvalidateWith(typeof(RestApiKeyEntity))); } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <DynamicClientEntity>() .WithSave(DynamicClientOperation.Save) .WithDelete(DynamicClientOperation.Delete) .WithQuery(() => e => new { Entity = e, e.Id, e.Name, Code = e.Code.Etc(50), }); new Graph <DynamicClientEntity> .ConstructFrom <DynamicClientEntity>(DynamicClientOperation.Clone) { Construct = (e, _) => { return(new DynamicClientEntity { Name = e.Name + "_2", Code = e.Code, }); } } .Register(); Clients = sb.GlobalLazy(() => Database.Query <DynamicClientEntity>().Where(a => !a.Mixin <DisabledMixin>().IsDisabled).ToList(), new InvalidateWith(typeof(DynamicClientEntity))); IsStarted = true; } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include<DynamicValidationEntity>() .WithSave(DynamicValidationOperation.Save) .WithQuery(dqm, e => new { Entity = e, e.Id, e.Name, e.EntityType, e.PropertyRoute, e.Eval, }); DynamicValidations = sb.GlobalLazy(() => Database.Query<DynamicValidationEntity>() .Select(dv => new DynamicValidationPair { Validation = dv, PropertyRoute = dv.PropertyRoute.ToPropertyRoute() }) .GroupToDictionary(a => a.PropertyRoute.PropertyInfo), new InvalidateWith(typeof(DynamicValidationEntity))); sb.Schema.Initializing += () => { initialized = true; }; Validator.GlobalValidation += DynamicValidation; } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <SmtpConfigurationEntity>() .WithQuery(dqm, () => s => new { Entity = s, s.Id, s.DeliveryMethod, s.Network.Host, s.Network.Username, s.PickupDirectoryLocation }); SmtpConfigCache = sb.GlobalLazy(() => Database.Query <SmtpConfigurationEntity>().ToDictionary(a => a.ToLite()), new InvalidateWith(typeof(SmtpConfigurationEntity))); new Graph <SmtpConfigurationEntity> .Execute(SmtpConfigurationOperation.Save) { AllowsNew = true, Lite = false, Execute = (sc, _) => { }, } .Register(); } }
public void GenerateColumns() { var errorSuffix = "columns in table " + this.Name.Name; var columns = new Dictionary <string, IColumn>(); void AddColumns(IEnumerable <IColumn> newColumns) { try { columns.AddRange(newColumns, c => c.Name, c => c, errorSuffix); }catch (RepeatedElementsException ex) when(StartParameters.IgnoredCodeErrors != null) { StartParameters.IgnoredCodeErrors.Add(ex); } } AddColumns(Fields.Values.SelectMany(c => c.Field.Columns())); if (Mixins != null) { AddColumns(Mixins.Values.SelectMany(m => m.Fields.Values).SelectMany(f => f.Field.Columns())); } if (this.SystemVersioned != null) { AddColumns(this.SystemVersioned.Columns()); } Columns = columns; inserterDisableIdentity = new ResetLazy <InsertCacheDisableIdentity>(() => InsertCacheDisableIdentity.InitializeInsertDisableIdentity(this)); inserterIdentity = new ResetLazy <InsertCacheIdentity>(() => InsertCacheIdentity.InitializeInsertIdentity(this)); updater = new ResetLazy <UpdateCache>(() => UpdateCache.InitializeUpdate(this)); saveCollections = new ResetLazy <CollectionsCache?>(() => CollectionsCache.InitializeCollections(this)); }
public static ResetLazy <T> WithoutInvalidations <T>(Func <T> func, LazyThreadSafetyMode mode = LazyThreadSafetyMode.ExecutionAndPublication) where T : class { ResetLazy <T> result = new ResetLazy <T>(() => { using (ExecutionMode.Global()) using (HeavyProfiler.Log("ResetLazy", () => typeof(T).TypeName())) using (Transaction tr = Transaction.InTestTransaction ? null : Transaction.ForceNew()) using (new EntityCache(EntityCacheType.ForceNewSealed)) { var value = func(); if (tr != null) { tr.Commit(); } return(value); } }, mode, declaringType: func.Method.DeclaringType); registeredLazyList.Add(result); return(result); }
public ExtensionDictionaryInfo <T, KVP, K, V> RegisterDictionary <T, KVP, K, V>( Expression <Func <T, IEnumerable <KVP> > > collectionSelector, Expression <Func <KVP, K> > keySelector, Expression <Func <KVP, V> > valueSelector, Expression <Func <T, EmbeddedEntity> > forEmbedded = null, ResetLazy <HashSet <K> > allKeys = null) where T : Entity { var mei = new ExtensionDictionaryInfo <T, KVP, K, V> { CollectionSelector = collectionSelector, KeySelector = keySelector, ValueSelector = valueSelector, AllKeys = allKeys ?? GetAllKeysLazy <T, KVP, K>(collectionSelector, keySelector) }; var route = forEmbedded == null? PropertyRoute.Root(typeof(T)) : PropertyRoute.Construct(forEmbedded); RegisteredExtensionsDictionaries.Add(route, mei); return(mei); }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { // QueryManagers = queryManagers; sb.Schema.Initializing += () => { queryNamesLazy.Load(); queryNameToEntityLazy.Load(); }; sb.Include<QueryEntity>(); sb.Schema.Synchronizing += SynchronizeQueries; sb.Schema.Generating += Schema_Generating; queryNamesLazy = sb.GlobalLazy(()=>CreateQueryNames(), new InvalidateWith(typeof(QueryEntity))); queryNameToEntityLazy = sb.GlobalLazy(() => EnumerableExtensions.JoinStrict( Database.Query<QueryEntity>().ToList(), QueryNames, q => q.Key, kvp => kvp.Key, (q, kvp) => KVP.Create(kvp.Value, q), "caching QueryEntity. Consider synchronize").ToDictionary(), new InvalidateWith(typeof(QueryEntity))); } }
public static void Start(SchemaBuilder sb, Func <IEnumerable <T> > getSemiSymbols) { if (sb.NotDefined(typeof(SemiSymbolLogic <T>).GetMethod("Start"))) { sb.Include <T>(); sb.Schema.Initializing += () => lazy.Load(); sb.Schema.Synchronizing += Schema_Synchronizing; sb.Schema.Generating += Schema_Generating; SemiSymbolLogic <T> .getSemiSymbols = getSemiSymbols; lazy = sb.GlobalLazy(() => { using (AvoidCache()) { var current = Database.RetrieveAll <T>().Where(a => a.Key.HasText()); var result = EnumerableExtensions.JoinRelaxed( current, getSemiSymbols(), c => c.Key, s => s.Key, (c, s) => { s.SetIdAndName((c.Id, c.Name)); return(s); }, "caching " + typeof(T).Name); SemiSymbol.SetSemiSymbolIdsAndNames <T>(current.ToDictionary(a => a.Key, a => (a.Id, a.Name))); return(result.ToDictionary(a => a.Key)); } },
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <DynamicTypeEntity>() .WithQuery(dqm, () => e => new { Entity = e, e.Id, e.TypeName, e.BaseType, }); AvailableEmbeddedEntities = sb.GlobalLazy(() => { var namespaces = DynamicCode.GetNamespaces().ToHashSet(); return(DynamicCode.GetAssemblies() .SelectMany(a => Assembly.LoadFile(a).GetTypes()) .Where(t => typeof(EmbeddedEntity).IsAssignableFrom(t) && namespaces.Contains(t.Namespace)) .ToHashSet()); }, new InvalidateWith(typeof(TypeEntity))); DynamicTypeGraph.Register(); DynamicLogic.GetCodeFiles += GetCodeFiles; DynamicLogic.OnWriteDynamicStarter += WriteDynamicStarter; } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <CultureInfoEntity>() .WithSave(CultureInfoOperation.Save) .WithDelete(CultureInfoOperation.Delete) .WithQuery(() => c => new { Entity = c, c.Id, c.Name, c.EnglishName, c.NativeName, }); CultureInfoToEntity = sb.GlobalLazy(() => Database.Query <CultureInfoEntity>().ToDictionary(ci => ci.Name, ci => ci), invalidateWith: new InvalidateWith(typeof(CultureInfoEntity))); EntityToCultureInfo = sb.GlobalLazy(() => Database.Query <CultureInfoEntity>().ToDictionary(ci => ci, ci => CultureInfoModifier(CultureInfo.GetCultureInfo(ci.Name))), invalidateWith: new InvalidateWith(typeof(CultureInfoEntity))); sb.Schema.Synchronizing += Schema_Synchronizing; } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <TranslationReplacementEntity>() .WithSave(TranslationReplacementOperation.Save) .WithDelete(TranslationReplacementOperation.Delete) .WithQuery(() => e => new { Entity = e, e.Id, e.CultureInfo, e.WrongTranslation, e.RightTranslation, }); sb.AddUniqueIndex <TranslationReplacementEntity>(tr => new { tr.CultureInfo, tr.WrongTranslation }); ReplacementsLazy = sb.GlobalLazy(() => Database.Query <TranslationReplacementEntity>() .AgGroupToDictionary(a => a.CultureInfo.ToCultureInfo(), gr => { var dic = gr.ToDictionaryEx(a => a.WrongTranslation, a => a.RightTranslation, StringComparer.InvariantCultureIgnoreCase, "wrong translations"); var regex = new Regex(dic.Keys.ToString(Regex.Escape, "|"), RegexOptions.IgnoreCase); return(new TranslationReplacementPack(dic, regex)); }), new InvalidateWith(typeof(TranslationReplacementEntity))); } }
public UrlsRepository(string virtualPathPrefix) { if (string.IsNullOrEmpty(virtualPathPrefix)) throw new ArgumentNullException("virtualPath"); this.VirtualPathPrefix = virtualPathPrefix.ToLower(); FileLazy = GlobalLazy.WithoutInvalidations(()=>new StaticContentResult(CreateFile(), fileName)); }
public static void Start(SchemaBuilder sb, Func <CultureInfo> defaultCulture) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <TranslatedInstanceEntity>() .WithUniqueIndex(ti => new { ti.Culture, ti.PropertyRoute, ti.Instance, ti.RowId }) .WithQuery(() => e => new { Entity = e, e.Id, e.Culture, e.Instance, e.PropertyRoute, e.TranslatedText, e.OriginalText, }); TranslatedInstanceLogic.getDefaultCulture = defaultCulture ?? throw new ArgumentNullException(nameof(defaultCulture)); LocalizationCache = sb.GlobalLazy(() => Database.Query <TranslatedInstanceEntity>() .ToList() .AgGroupToDictionary(a => a.Culture.ToCultureInfo(), gr2 => gr2.GroupBy(a => a.PropertyRoute) .SelectMany(gr => { PropertyRoute pr = gr.Key.ToPropertyRoute(); PropertyRoute?mListRoute = pr.GetMListItemsRoute(); if (mListRoute == null) { return(gr.Select(ti => KeyValuePair.Create(new LocalizedInstanceKey(pr, ti.Instance, null), ti))); } Type type = ((FieldMList)Schema.Current.Field(mListRoute.Parent !)).TableMList.PrimaryKey.Type; return(gr.Select(ti => KeyValuePair.Create(new LocalizedInstanceKey(pr, ti.Instance, new PrimaryKey((IComparable)ReflectionTools.Parse(ti.RowId !, type) !)), ti))); }).ToDictionary()) , new InvalidateWith(typeof(TranslatedInstanceEntity))); sb.Schema.SchemaCompleted += () => { var s = Schema.Current; var prs = (from t in s.Tables.Keys from pr in PropertyRoute.GenerateRoutes(t) where pr.PropertyRouteType == PropertyRouteType.FieldOrProperty && pr.FieldInfo != null && pr.FieldInfo.FieldType == typeof(string) && s.Settings.FieldAttribute <TranslateFieldAttribute>(pr) != null && s.Settings.FieldAttribute <IgnoreAttribute>(pr) == null select KeyValuePair.Create(pr, s.Settings.FieldAttribute <TranslateFieldAttribute>(pr) !.TranslatableRouteType)).ToList(); foreach (var kvp in prs) { AddRoute(kvp.Key, kvp.Value); } }; } }
public ExtensionDictionaryInfo( Expression <Func <T, IEnumerable <KVP> > > collectionSelector, Expression <Func <KVP, K> > keySelector, Expression <Func <KVP, V> > valueSelector, ResetLazy <HashSet <K> > allKeys) { CollectionSelector = collectionSelector; KeySelector = keySelector; ValueSelector = valueSelector; AllKeys = allKeys; }
public UrlsRepository(string virtualPathPrefix) { if (string.IsNullOrEmpty(virtualPathPrefix)) { throw new ArgumentNullException("virtualPath"); } this.VirtualPathPrefix = virtualPathPrefix.ToLower(); FileLazy = GlobalLazy.WithoutInvalidations(() => new StaticContentResult(CreateFile(), fileName)); }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include<PropertyRouteEntity>() .WithUniqueIndex(p => new { p.Path, p.RootType }); sb.Schema.Synchronizing += SynchronizeProperties; Properties = sb.GlobalLazy(() => Database.Query<PropertyRouteEntity>().AgGroupToDictionary(a => a.RootType, gr => gr.ToDictionary(a => a.Path)), new InvalidateWith(typeof(PropertyRouteEntity)), Schema.Current.InvalidateMetadata); } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <PropertyRouteEntity>() .WithUniqueIndex(p => new { p.Path, p.RootType }); sb.Schema.Synchronizing += SynchronizeProperties; Properties = sb.GlobalLazy(() => Database.Query <PropertyRouteEntity>().AgGroupToDictionary(a => a.RootType, gr => gr.ToDictionary(a => a.Path)), new InvalidateWith(typeof(PropertyRouteEntity)), Schema.Current.InvalidateMetadata); } }
public void ResetLazy() { int i = 0; ResetLazy<string> val = new ResetLazy<string>(() => "hola" + i++); val.Reset(); //reset before initialized var str1 = val.Value; val.Reset(); //reset after initialized var str2 = val.Value; Assert.AreNotEqual(str1, str2); }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Schema.Generating += Schema_Generating; sb.Schema.Synchronizing += Schema_Synchronizing; sb.Include <SystemWordTemplateEntity>() .WithQuery(dqm, () => se => new { Entity = se, se.Id, se.FullClassName, }); RegisterSystemWordReport <MultiEntityWordTemplate>(null); RegisterSystemWordReport <QueryWordTemplate>(null); new Graph <WordTemplateEntity> .ConstructFrom <SystemWordTemplateEntity>(WordTemplateOperation.CreateWordTemplateFromSystemWordTemplate) { CanConstruct = se => HasDefaultTemplateConstructor(se) ? null : WordTemplateMessage.NoDefaultTemplateDefined.NiceToString(), Construct = (se, _) => CreateDefaultTemplate(se).Save() } .Register(); SystemWordTemplateToWordTemplates = sb.GlobalLazy(() => ( from et in Database.Query <WordTemplateEntity>() where et.SystemWordTemplate != null select new { swe = et.SystemWordTemplate, et = et.ToLite() }) .GroupToDictionary(pair => pair.swe.ToLite(), pair => pair.et), new InvalidateWith(typeof(SystemWordTemplateEntity), typeof(WordTemplateEntity))); TypeToSystemWordTemplate = sb.GlobalLazy(() => { var dbSystemWordReports = Database.RetrieveAll <SystemWordTemplateEntity>(); return(EnumerableExtensions.JoinRelaxed( dbSystemWordReports, systemWordReports.Keys, swr => swr.FullClassName, type => type.FullName, (swr, type) => KVP.Create(type, swr), "caching WordTemplates").ToDictionary()); }, new InvalidateWith(typeof(SystemWordTemplateEntity))); sb.Schema.Initializing += () => TypeToSystemWordTemplate.Load(); SystemWordTemplateToType = sb.GlobalLazy(() => TypeToSystemWordTemplate.Value.Inverse(), new InvalidateWith(typeof(SystemWordTemplateEntity))); } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Schema.Generating += Schema_Generating; sb.Schema.Synchronizing += Schema_Synchronizing; sb.Include <EmailModelEntity>() .WithQuery(() => se => new { Entity = se, se.Id, se.FullClassName, }); UserAssetsImporter.Register <EmailTemplateEntity>("EmailTemplate", EmailTemplateOperation.Save); new Graph <EmailTemplateEntity> .ConstructFrom <EmailModelEntity>(EmailTemplateOperation.CreateEmailTemplateFromModel) { Construct = (se, _) => CreateDefaultTemplateInternal(se) } .Register(); EmailModelToTemplates = sb.GlobalLazy(() => ( from et in Database.Query <EmailTemplateEntity>() where et.Model != null select new { se = et.Model, et }) .GroupToDictionary(pair => pair.se !.ToLite(), pair => pair.et !), /*CSBUG*/ new InvalidateWith(typeof(EmailModelEntity), typeof(EmailTemplateEntity))); typeToEntity = sb.GlobalLazy(() => { var dbModels = Database.RetrieveAll <EmailModelEntity>(); return(EnumerableExtensions.JoinRelaxed( dbModels, registeredModels.Keys, entity => entity.FullClassName, type => type.FullName !, (entity, type) => KeyValuePair.Create(type, entity), "caching " + nameof(EmailModelEntity)) .ToDictionary()); }, new InvalidateWith(typeof(EmailModelEntity))); sb.Schema.Initializing += () => typeToEntity.Load(); entityToType = sb.GlobalLazy(() => typeToEntity.Value.Inverse(), new InvalidateWith(typeof(EmailModelEntity))); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { if (sb.Schema.Tables.ContainsKey(typeof(UserChartEntity))) throw new InvalidOperationException("UserChart has already been registered"); UserAssetsImporter.RegisterName<UserChartEntity>("UserChart"); sb.Schema.Synchronizing += Schema_Synchronizing; sb.Include<UserChartEntity>(); dqm.RegisterQuery(typeof(UserChartEntity), () => from uq in Database.Query<UserChartEntity>() select new { Entity = uq, uq.Query, uq.EntityType, uq.Id, uq.DisplayName, uq.ChartScript, uq.GroupResults, }); sb.Schema.EntityEvents<UserChartEntity>().Retrieved += ChartLogic_Retrieved; new Graph<UserChartEntity>.Execute(UserChartOperation.Save) { AllowsNew = true, Lite = false, Execute = (uc, _) => { } }.Register(); new Graph<UserChartEntity>.Delete(UserChartOperation.Delete) { Delete = (uc, _) => { uc.Delete(); } }.Register(); UserCharts = sb.GlobalLazy(() => Database.Query<UserChartEntity>().ToDictionary(a => a.ToLite()), new InvalidateWith(typeof(UserChartEntity))); UserChartsByQuery = sb.GlobalLazy(() => UserCharts.Value.Values.Where(a => a.EntityType == null).GroupToDictionary(a => a.Query.ToQueryName(), a => a.ToLite()), new InvalidateWith(typeof(UserChartEntity))); UserChartsByType = sb.GlobalLazy(() => UserCharts.Value.Values.Where(a => a.EntityType != null).GroupToDictionary(a => TypeLogic.IdToType.GetOrThrow(a.EntityType.Id), a => a.ToLite()), new InvalidateWith(typeof(UserChartEntity))); } }
public AuthCache(SchemaBuilder sb, Func <R, K> toKey, Func <K, R> toEntity, Expression <Func <R, R, bool> > isEquals, IMerger <K, A> merger, bool invalidateWithTypes, Coercer <A, K>?coercer = null) { this.ToKey = toKey; this.ToEntity = toEntity; this.merger = merger; this.IsEquals = isEquals; this.coercer = coercer ?? Coercer <A, K> .None; runtimeRules = sb.GlobalLazy(this.NewCache, invalidateWithTypes ? new InvalidateWith(typeof(RT), typeof(RoleEntity), typeof(RuleTypeEntity)) : new InvalidateWith(typeof(RT), typeof(RoleEntity)), AuthLogic.NotifyRulesChanged); }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { QueryLogic.Start(sb); PermissionAuthLogic.RegisterPermissions(UserQueryPermission.ViewUserQuery); UserAssetsImporter.RegisterName<UserQueryEntity>("UserQuery"); sb.Schema.Synchronizing += Schema_Synchronizing; sb.Include<UserQueryEntity>(); dqm.RegisterQuery(typeof(UserQueryEntity), () => from uq in Database.Query<UserQueryEntity>() select new { Entity = uq, uq.Query, uq.Id, uq.DisplayName, uq.EntityType, }); sb.Schema.EntityEvents<UserQueryEntity>().Retrieved += UserQueryLogic_Retrieved; new Graph<UserQueryEntity>.Execute(UserQueryOperation.Save) { AllowsNew = true, Lite = false, Execute = (uq, _) => { } }.Register(); new Graph<UserQueryEntity>.Delete(UserQueryOperation.Delete) { Lite = true, Delete = (uq, _) => uq.Delete() }.Register(); UserQueries = sb.GlobalLazy(() => Database.Query<UserQueryEntity>().ToDictionary(a => a.ToLite()), new InvalidateWith(typeof(UserQueryEntity))); UserQueriesByQuery = sb.GlobalLazy(() => UserQueries.Value.Values.Where(a => a.EntityType == null).GroupToDictionary(a => a.Query.ToQueryName(), a => a.ToLite()), new InvalidateWith(typeof(UserQueryEntity))); UserQueriesByType = sb.GlobalLazy(() => UserQueries.Value.Values.Where(a => a.EntityType != null).GroupToDictionary(a => TypeLogic.IdToType.GetOrThrow(a.EntityType.Id), a => a.ToLite()), new InvalidateWith(typeof(UserQueryEntity))); } }
public void ResetLazy() { int i = 0; ResetLazy <string> val = new ResetLazy <string>(() => "hola" + i++); val.Reset(); //reset before initialized var str1 = val.Value; val.Reset(); //reset after initialized var str2 = val.Value; Assert.NotEqual(str1, str2); }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Schema.Generating += Schema_Generating; sb.Schema.Synchronizing += Schema_Synchronizing; sb.Include <SMSModelEntity>() .WithQuery(() => model => new { Entity = model, model.Id, model.FullClassName, }); new Graph <SMSTemplateEntity> .ConstructFrom <SMSModelEntity>(SMSTemplateOperation.CreateSMSTemplateFromModel) { Construct = (model, _) => CreateDefaultTemplate(model) } .Register(); SMSModelToTemplates = sb.GlobalLazy(() => ( from et in Database.Query <SMSTemplateEntity>() where et.Model != null select KeyValuePair.Create(et.Model !.ToLite(), et)) .GroupToDictionary(), new InvalidateWith(typeof(SMSTemplateEntity), typeof(SMSModelEntity))); typeToEntity = sb.GlobalLazy(() => { var dbModels = Database.RetrieveAll <SMSModelEntity>(); return(EnumerableExtensions.JoinRelaxed( dbModels, registeredModels.Keys, entity => entity.FullClassName, type => type.FullName, (entity, type) => KeyValuePair.Create(type, entity), "caching " + nameof(SMSModelEntity)) .ToDictionary()); }, new InvalidateWith(typeof(SMSModelEntity))); sb.Schema.Initializing += () => typeToEntity.Load(); entityToType = sb.GlobalLazy(() => typeToEntity.Value.Inverse(), new InvalidateWith(typeof(SMSModelEntity))); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Schema.Generating += Schema_Generating; sb.Schema.Synchronizing += Schema_Synchronizing; sb.Include <SystemEmailEntity>() .WithQuery(dqm, () => se => new { Entity = se, se.Id, se.FullClassName, }); new Graph <EmailTemplateEntity> .ConstructFrom <SystemEmailEntity>(EmailTemplateOperation.CreateEmailTemplateFromSystemEmail) { Construct = (se, _) => CreateDefaultTemplate(se) } .Register(); SystemEmailsToEmailTemplates = sb.GlobalLazy(() => ( from et in Database.Query <EmailTemplateEntity>() where et.SystemEmail != null select new { se = et.SystemEmail, et }) .GroupToDictionary(pair => pair.se.ToLite(), pair => pair.et), new InvalidateWith(typeof(SystemEmailEntity), typeof(EmailTemplateEntity))); systemEmailToEntity = sb.GlobalLazy(() => { var dbSystemEmails = Database.RetrieveAll <SystemEmailEntity>(); return(EnumerableExtensions.JoinRelaxed( dbSystemEmails, systemEmails.Keys, systemEmail => systemEmail.FullClassName, type => type.FullName, (systemEmail, type) => KVP.Create(type, systemEmail), "caching EmailTemplates") .ToDictionary()); }, new InvalidateWith(typeof(SystemEmailEntity))); sb.Schema.Initializing += () => systemEmailToEntity.Load(); systemEmailToType = sb.GlobalLazy(() => systemEmailToEntity.Value.Inverse(), new InvalidateWith(typeof(SystemEmailEntity))); } }
internal static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <ChartColorEntity>() .WithQuery(() => cc => new { Entity = cc, cc.Related, cc.Color, }); Colors = sb.GlobalLazy(() => Database.Query <ChartColorEntity>() .Select(cc => new { cc.Related.EntityType, cc.Related.Id, cc.Color !.Argb })
public ExtensionDictionaryInfo <T, KVP, K, V> RegisterDictionary <T, KVP, K, V>( Expression <Func <T, IEnumerable <KVP> > > collectionSelector, Expression <Func <KVP, K> > keySelector, Expression <Func <KVP, V> > valueSelector, ResetLazy <HashSet <K> >?allKeys = null) where T : Entity where K : notnull { var mei = new ExtensionDictionaryInfo <T, KVP, K, V>(collectionSelector, keySelector, valueSelector, allKeys ?? GetAllKeysLazy <T, KVP, K>(collectionSelector, keySelector)); RegisteredExtensionsDictionaries.Add(PropertyRoute.Root(typeof(T)), mei); return(mei); }
public TypeAuthCache(SchemaBuilder sb, IMerger <Type, TypeAllowedAndConditions> merger) { this.merger = merger; sb.Include <RuleTypeEntity>(); sb.AddUniqueIndex <RuleTypeEntity>(rt => new { rt.Resource, rt.Role }); runtimeRules = sb.GlobalLazy(NewCache, new InvalidateWith(typeof(RuleTypeEntity), typeof(RoleEntity)), AuthLogic.NotifyRulesChanged); sb.Schema.Table <TypeEntity>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand>(AuthCache_PreDeleteSqlSync); Validator.PropertyValidator((RuleTypeEntity r) => r.Conditions).StaticPropertyValidation += TypeAuthCache_StaticPropertyValidation; }
public static ChartPaletteModel?GetPalette(Type type, bool allEntities) { var dic = ChartColorLogic.Colors.Value.TryGetC(type); if (allEntities) { AssertFewEntities(type); return(new ChartPaletteModel { TypeName = TypeLogic.GetCleanName(type), Colors = Database.RetrieveAllLite(type).Select(l => new ChartColorEntity { Related = (Lite <Entity>)l, Color = dic?.TryGetC(l.Id) ! }).ToMList()
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include<DynamicViewEntity>() .WithUniqueIndex(a => new { a.ViewName, a.EntityType }) .WithSave(DynamicViewOperation.Save) .WithDelete(DynamicViewOperation.Delete) .WithQuery(dqm, e => new { Entity = e, e.Id, e.ViewName, e.EntityType, }); new Graph<DynamicViewEntity>.Construct(DynamicViewOperation.Create) { Construct = (_) => new DynamicViewEntity(), }.Register(); new Graph<DynamicViewEntity>.ConstructFrom<DynamicViewEntity>(DynamicViewOperation.Clone) { Construct = (e, _) => new DynamicViewEntity() { ViewName = "", EntityType = e.EntityType, ViewContent = e.ViewContent, }, }.Register(); DynamicViews = sb.GlobalLazy(() => Database.Query<DynamicViewEntity>().GroupToDictionary(a => a.EntityType.ToType()), new InvalidateWith(typeof(DynamicViewEntity))); sb.Include<DynamicViewSelectorEntity>() .WithSave(DynamicViewSelectorOperation.Save) .WithDelete(DynamicViewSelectorOperation.Delete) .WithQuery(dqm, e => new { Entity = e, e.Id, e.EntityType, }); } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <DynamicValidationEntity>() .WithSave(DynamicValidationOperation.Save) .WithDelete(DynamicValidationOperation.Delete) .WithQuery(() => e => new { Entity = e, e.Id, e.Name, e.EntityType, e.SubEntity, Script = e.Eval.Script.Etc(75), }); new Graph <DynamicValidationEntity> .ConstructFrom <DynamicValidationEntity>(DynamicValidationOperation.Clone) { Construct = (dv, _) => new DynamicValidationEntity() { Name = dv.Name, EntityType = dv.EntityType, SubEntity = dv.SubEntity, Eval = new DynamicValidationEval() { Script = dv.Eval.Script }, } } .Register(); DynamicValidations = sb.GlobalLazy(() => Database.Query <DynamicValidationEntity>() .SelectCatch(dv => new DynamicValidationPair(dv.SubEntity?.ToPropertyRoute() ?? PropertyRoute.Root(TypeLogic.EntityToType.GetOrThrow(dv.EntityType)), dv)) .GroupToDictionary(a => a.PropertyRoute.Type), new InvalidateWith(typeof(DynamicValidationEntity))); DynamicValidationEntity.GetMainType = dve => dve.SubEntity?.ToPropertyRoute().Type ?? TypeLogic.EntityToType.GetOrThrow(dve.EntityType); sb.Schema.Initializing += () => { initialized = true; }; Validator.GlobalValidation += DynamicValidation; sb.Schema.Table <TypeEntity>().PreDeleteSqlSync += type => Administrator.UnsafeDeletePreCommand(Database.Query <DynamicValidationEntity>().Where(dv => dv.EntityType == type)); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include<TranslationReplacementEntity>(); sb.AddUniqueIndex<TranslationReplacementEntity>(tr => new { tr.CultureInfo, tr.WrongTranslation }); dqm.RegisterQuery(typeof(TranslationReplacementEntity), () => from e in Database.Query<TranslationReplacementEntity>() select new { Entity = e, e.Id, e.CultureInfo, e.WrongTranslation, e.RightTranslation, }); new Graph<TranslationReplacementEntity>.Execute(TranslationReplacementOperation.Save) { AllowsNew = true, Lite = false, Execute = (e, _) => { }, }.Register(); new Graph<TranslationReplacementEntity>.Delete(TranslationReplacementOperation.Delete) { Delete = (e, _) => { e.Delete(); }, }.Register(); ReplacementsLazy = sb.GlobalLazy(() => Database.Query<TranslationReplacementEntity>() .AgGroupToDictionary(a => a.CultureInfo.ToCultureInfo(), gr => { var dic = gr.ToDictionary(a => a.WrongTranslation, a => a.RightTranslation, StringComparer.InvariantCultureIgnoreCase, "wrong translations"); var regex = new Regex(dic.Keys.ToString(Regex.Escape, "|"), RegexOptions.IgnoreCase); return new TranslationReplacementPack { Dictionary = dic, Regex = regex }; }), new InvalidateWith(typeof(TranslationReplacementEntity))); } }
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; } }
private static void StartSouthwindConfiguration(SchemaBuilder sb, DynamicQueryManager dqm) { sb.Include<ApplicationConfigurationEntity>(); Configuration = sb.GlobalLazy<ApplicationConfigurationEntity>( () => Database.Query<ApplicationConfigurationEntity>().Single(a => a.Environment == Settings.Default.Environment), new InvalidateWith(typeof(ApplicationConfigurationEntity))); new Graph<ApplicationConfigurationEntity>.Execute(ApplicationConfigurationOperation.Save) { AllowsNew = true, Lite = false, Execute = (e, _) => { }, }.Register(); dqm.RegisterQuery(typeof(ApplicationConfigurationEntity), () => from s in Database.Query<ApplicationConfigurationEntity>() select new { Entity = s, s.Id, s.Environment, s.Email.SendEmails, s.Email.OverrideEmailAddress, s.Email.DefaultCulture, s.Email.UrlLeft }); }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, string systemUserName, string anonymousUserName) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { SystemUserName = systemUserName; AnonymousUserName = anonymousUserName; CultureInfoLogic.AssertStarted(sb); sb.Include<UserEntity>(); sb.Include<RoleEntity>() .WithSave(RoleOperation.Save) .WithDelete(RoleOperation.Delete) .WithQuery(dqm, r => new { Entity = r, r.Id, r.Name, }); sb.Include<LastAuthRulesImportEntity>(); roles = sb.GlobalLazy(CacheRoles, new InvalidateWith(typeof(RoleEntity)), AuthLogic.NotifyRulesChanged); mergeStrategies = sb.GlobalLazy(() => { var strategies = Database.Query<RoleEntity>().Select(r => KVP.Create(r.ToLite(), r.MergeStrategy)).ToDictionary(); var graph = roles.Value; Dictionary<Lite<RoleEntity>, RoleData> result = new Dictionary<Lite<RoleEntity>, RoleData>(); foreach (var r in graph.CompilationOrder()) { var strat = strategies.GetOrThrow(r); var baseValues = graph.RelatedTo(r).Select(r2=>result[r2].DefaultAllowed); result.Add(r, new RoleData { MergeStrategy = strat, DefaultAllowed = strat == MergeStrategy.Union ? baseValues.Any(a => a) : baseValues.All(a => a) }); } return result; }, new InvalidateWith(typeof(RoleEntity)), AuthLogic.NotifyRulesChanged); sb.Schema.EntityEvents<RoleEntity>().Saving += Schema_Saving; dqm.RegisterQuery(RoleQuery.RolesReferedBy, () => from r in Database.Query<RoleEntity>() from rc in r.Roles select new { Entity = r, r.Id, r.Name, Refered = rc, }); dqm.RegisterQuery(typeof(UserEntity), () => from e in Database.Query<UserEntity>() select new { Entity = e, e.Id, e.UserName, e.Email, e.Role, e.State, }); UserGraph.Register(); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { AuthLogic.AssertStarted(sb); OperationLogic.AssertStarted(sb); Implementations imp = sb.Settings.GetImplementations((ScheduledTaskEntity st) => st.Task); Implementations imp2 = sb.Settings.GetImplementations((ScheduledTaskLogEntity st) => st.Task); if (!imp2.Equals(imp2)) throw new InvalidOperationException("Implementations of ScheduledTaskEntity.Task should be the same as in ScheduledTaskLogEntity.Task"); PermissionAuthLogic.RegisterPermissions(SchedulerPermission.ViewSchedulerPanel); ExecuteTask.Register((ITaskEntity t) => { throw new NotImplementedException("SchedulerLogic.ExecuteTask not registered for {0}".FormatWith(t.GetType().Name)); }); SimpleTaskLogic.Start(sb, dqm); sb.Include<ScheduledTaskEntity>(); sb.Include<ScheduledTaskLogEntity>(); dqm.RegisterQuery(typeof(HolidayCalendarEntity), () => from st in Database.Query<HolidayCalendarEntity>() select new { Entity = st, st.Id, st.Name, Holidays = st.Holidays.Count, }); dqm.RegisterQuery(typeof(ScheduledTaskEntity), () => from st in Database.Query<ScheduledTaskEntity>() select new { Entity = st, st.Id, st.Task, st.Rule, st.Suspended, st.MachineName, st.ApplicationName }); dqm.RegisterQuery(typeof(ScheduledTaskLogEntity), () => from cte in Database.Query<ScheduledTaskLogEntity>() select new { Entity = cte, cte.Id, cte.Task, cte.ScheduledTask, cte.StartTime, cte.EndTime, cte.ProductEntity, cte.MachineName, cte.User, cte.Exception, }); dqm.RegisterExpression((ITaskEntity ct) => ct.Executions(), () => TaskMessage.Executions.NiceToString()); dqm.RegisterExpression((ITaskEntity ct) => ct.LastExecution(), () => TaskMessage.LastExecution.NiceToString()); dqm.RegisterExpression((ScheduledTaskEntity ct) => ct.Executions(), () => TaskMessage.Executions.NiceToString()); new Graph<HolidayCalendarEntity>.Execute(HolidayCalendarOperation.Save) { AllowsNew = true, Lite = false, Execute = (c, _) => { }, }.Register(); new Graph<HolidayCalendarEntity>.Delete(HolidayCalendarOperation.Delete) { Delete = (c, _) => { c.Delete(); }, }.Register(); new Graph<ScheduledTaskEntity>.Execute(ScheduledTaskOperation.Save) { AllowsNew = true, Lite = false, Execute = (st, _) => { }, }.Register(); new Graph<ScheduledTaskEntity>.Delete(ScheduledTaskOperation.Delete) { Delete = (st, _) => { st.Executions().UnsafeUpdate().Set(l => l.ScheduledTask, l => null).Execute(); var rule = st.Rule; st.Delete(); rule.Delete(); }, }.Register(); new Graph<IEntity>.ConstructFrom<ITaskEntity>(TaskOperation.ExecuteSync) { Construct = (task, _) => ExecuteSync(task, null, UserHolder.Current)?.Retrieve() }.Register(); new Graph<ITaskEntity>.Execute(TaskOperation.ExecuteAsync) { Execute = (task, _) => ExecuteAsync(task, null, UserHolder.Current) }.Register(); ScheduledTasksLazy = sb.GlobalLazy(() => Database.Query<ScheduledTaskEntity>().Where(a => !a.Suspended && (a.MachineName == ScheduledTaskEntity.None || a.MachineName == Environment.MachineName && a.ApplicationName == Schema.Current.ApplicationName)).ToList(), new InvalidateWith(typeof(ScheduledTaskEntity))); ScheduledTasksLazy.OnReset += ScheduledTasksLazy_OnReset; ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs; } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include<ProductEntity>(); ActiveProducts = sb.GlobalLazy(() => Database.Query<ProductEntity>() .Where(a => !a.Discontinued) .Select(p => new { Category = p.Category.Entity, Product = p }) .GroupToDictionary(a => a.Category, a => a.Product), new InvalidateWith(typeof(ProductEntity))); dqm.RegisterQuery(typeof(ProductEntity), () => from p in Database.Query<ProductEntity>() select new { Entity = p.ToLite(), p.Id, p.ProductName, p.Supplier, p.Category, p.QuantityPerUnit, p.UnitPrice, p.UnitsInStock, p.Discontinued }); dqm.RegisterQuery(ProductQuery.Current, () => from p in Database.Query<ProductEntity>() where !p.Discontinued select new { Entity = p.ToLite(), p.Id, p.ProductName, p.Supplier, p.Category, p.QuantityPerUnit, p.UnitPrice, p.UnitsInStock, }); dqm.RegisterQuery(typeof(SupplierEntity), () => from s in Database.Query<SupplierEntity>() select new { Entity = s.ToLite(), s.Id, s.CompanyName, s.ContactName, s.Phone, s.Fax, s.HomePage, s.Address }); dqm.RegisterQuery(typeof(CategoryEntity), () => from s in Database.Query<CategoryEntity>() select new { Entity = s.ToLite(), s.Id, s.CategoryName, s.Description, s.Picture }); new Graph<ProductEntity>.Execute(ProductOperation.Save) { AllowsNew = true, Lite = false, Execute = (e, _) => { } }.Register(); new Graph<SupplierEntity>.Execute(SupplierOperation.Save) { AllowsNew = true, Lite = false, Execute = (e, _) => { } }.Register(); new Graph<CategoryEntity>.Execute(CategoryOperation.Save) { AllowsNew = true, Lite = false, Execute = (e, _) => { } }.Register(); } }
public void GenerateColumns() { var tableName = "columns in table " + this.Name; var columns = Fields.Values.SelectMany(c => c.Field.Columns()).ToDictionary(c => c.Name, tableName); if (Mixins != null) columns.AddRange(Mixins.Values.SelectMany(m => m.Fields.Values).SelectMany(f => f.Field.Columns()).ToDictionary(c => c.Name, tableName), tableName); Columns = columns; inserterDisableIdentity = new ResetLazy<InsertCacheDisableIdentity>(() => InsertCacheDisableIdentity.InitializeInsertDisableIdentity(this)); inserterIdentity = new ResetLazy<InsertCacheIdentity>(() => InsertCacheIdentity.InitializeInsertIdentity(this)); updater = new ResetLazy<UpdateCache>(() => UpdateCache.InitializeUpdate(this)); saveCollections = new ResetLazy<CollectionsCache>(() => CollectionsCache.InitializeCollections(this)); }