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 static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include<PropertyRouteEntity>(); sb.AddUniqueIndex<PropertyRouteEntity>(p => new { p.Path, p.RootType }); sb.Schema.Synchronizing += SyncronizeProperties; } }
public static void Start(SchemaBuilder sb, Func <NewsletterEntity, EmailSenderConfigurationEntity> getEmailSenderConfiguration) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <NewsletterEntity>(); sb.Include <NewsletterDeliveryEntity>(); NewsletterLogic.GetEmailSenderConfiguration = getEmailSenderConfiguration; ProcessLogic.AssertStarted(sb); ProcessLogic.Register(NewsletterProcess.SendNewsletter, new NewsletterProcessAlgorithm()); QueryLogic.Queries.Register(typeof(NewsletterEntity), () => from n in Database.Query <NewsletterEntity>() let p = n.LastProcess() select new { Entity = n, n.Id, n.Name, n.Subject, Text = n.Text.Try(a => a.Etc(100)), n.State, NumDeliveries = n.Deliveries().Count(), LastProcess = p, NumErrors = n.Deliveries().Count(d => d.Exception(p) != null) }); QueryLogic.Queries.Register(typeof(NewsletterDeliveryEntity), () => from e in Database.Query <NewsletterDeliveryEntity>() let p = e.Newsletter.Entity.LastProcess() select new { Entity = e, e.Id, e.Newsletter, e.Recipient, e.Sent, e.SendDate, LastProcess = p, Exception = e.Exception(p) }); NewsletterGraph.Register(); sb.AddUniqueIndex <NewsletterDeliveryEntity>(nd => new { nd.Newsletter, nd.Recipient }); Validator.PropertyValidator((NewsletterEntity news) => news.Text).StaticPropertyValidation += (sender, pi) => ValidateTokens(sender, sender.Text); Validator.PropertyValidator((NewsletterEntity news) => news.Subject).StaticPropertyValidation += (sender, pi) => ValidateTokens(sender, sender.Subject); sb.Schema.EntityEvents <NewsletterEntity>().PreSaving += Newsletter_PreSaving; } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { FileTypeLogic.Start(sb); sb.Include <FilePathEntity>() .WithQuery(() => p => new { Entity = p, p.Id, p.FileName, p.FileType, p.Suffix }); FilePathEntity.CalculatePrefixPair = CalculatePrefixPair; sb.Schema.EntityEvents <FilePathEntity>().PreSaving += FilePath_PreSaving; sb.Schema.EntityEvents <FilePathEntity>().PreUnsafeDelete += new PreUnsafeDeleteHandler <FilePathEntity>(FilePathLogic_PreUnsafeDelete); new Graph <FilePathEntity> .Execute(FilePathOperation.Save) { CanBeNew = true, CanBeModified = true, Execute = (fp, _) => { if (!fp.IsNew) { var ofp = fp.ToLite().RetrieveAndRemember(); if (fp.FileName != ofp.FileName || fp.Suffix != ofp.Suffix) { using (Transaction tr = new Transaction()) { var preSufix = ofp.Suffix.Substring(0, ofp.Suffix.Length - ofp.FileName.Length); fp.Suffix = Path.Combine(preSufix, fp.FileName); fp.Save(); fp.FileType.GetAlgorithm().MoveFile(ofp, fp); tr.Commit(); } } } } } .Register(); sb.AddUniqueIndex <FilePathEntity>(f => new { f.Suffix, f.FileType }); //With mixins, add AttachToUniqueIndexes to field QueryLogic.Expressions.Register((FilePathEntity fp) => fp.WebImage(), () => typeof(WebImage).NiceName(), "Image"); QueryLogic.Expressions.Register((FilePathEntity fp) => fp.WebDownload(), () => typeof(WebDownload).NiceName(), "Download"); } }
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 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.EntityEvents <RoleEntity>().PreUnsafeDelete += query => { Database.Query <RuleTypeEntity>().Where(r => query.Contains(r.Role.Entity)).UnsafeDelete(); return(null); }; sb.Schema.Table <TypeEntity>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand?>(AuthCache_PreDeleteSqlSync_Type); sb.Schema.Table <TypeConditionSymbol>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand?>(AuthCache_PreDeleteSqlSync_Condition); Validator.PropertyValidator((RuleTypeEntity r) => r.Conditions).StaticPropertyValidation += TypeAuthCache_StaticPropertyValidation; }
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 AuthCache(SchemaBuilder sb, Func <R, K> toKey, Func <K, R> toEntity, IMerger <K, A> merger, bool invalidateWithTypes, Coercer <A, K> coercer = null) { this.ToKey = toKey; this.ToEntity = toEntity; this.merger = merger; this.coercer = coercer ?? Coercer <A, K> .None; sb.Include <RT>(); runtimeRules = sb.GlobalLazy(this.NewCache, invalidateWithTypes ? new InvalidateWith(typeof(RT), typeof(RoleEntity), typeof(RuleTypeEntity)) : new InvalidateWith(typeof(RT), typeof(RoleEntity)), AuthLogic.NotifyRulesChanged); sb.AddUniqueIndex <RT>(rt => new { rt.Resource, rt.Role }); sb.Schema.Table <R>().PreDeleteSqlSync += new Func <Entity, SqlPreCommand>(AuthCache_PreDeleteSqlSync); }
public static void Start(SchemaBuilder sb, ISMSProvider?provider, Func <SMSConfigurationEmbedded> getConfiguration) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { CultureInfoLogic.AssertStarted(sb); sb.Schema.SchemaCompleted += () => Schema_SchemaCompleted(sb); SMSLogic.getConfiguration = getConfiguration; SMSLogic.Provider = provider; sb.Include <SMSMessageEntity>() .WithQuery(() => m => new { Entity = m, m.Id, m.From, m.DestinationNumber, m.State, m.SendDate, m.Template, m.Referred, m.Exception, }); sb.Include <SMSTemplateEntity>() .WithQuery(() => t => new { Entity = t, t.Id, t.Name, t.IsActive, t.From, t.Query, t.Model, }); sb.Schema.EntityEvents <SMSTemplateEntity>().PreSaving += new PreSavingEventHandler <SMSTemplateEntity>(EmailTemplate_PreSaving); sb.Schema.EntityEvents <SMSTemplateEntity>().Retrieved += SMSTemplateLogic_Retrieved; sb.Schema.Table <SMSModelEntity>().PreDeleteSqlSync += e => Administrator.UnsafeDeletePreCommand(Database.Query <SMSTemplateEntity>() .Where(a => a.Model.Is(e))); SMSTemplatesLazy = sb.GlobalLazy(() => Database.Query <SMSTemplateEntity>().ToDictionary(et => et.ToLite()) , new InvalidateWith(typeof(SMSTemplateEntity))); SMSTemplatesByQueryName = sb.GlobalLazy(() => { return(SMSTemplatesLazy.Value.Values.Where(q => q.Query != null).SelectCatch(et => KeyValuePair.Create(et.Query !.ToQueryName(), et)).GroupToDictionary()); }, new InvalidateWith(typeof(SMSTemplateEntity))); SMSMessageGraph.Register(); SMSTemplateGraph.Register(); Validator.PropertyValidator <SMSTemplateEntity>(et => et.Messages).StaticPropertyValidation += (t, pi) => { var dc = SMSLogic.Configuration?.DefaultCulture; if (dc != null && !t.Messages.Any(m => m.CultureInfo.Is(dc))) { return(SMSTemplateMessage.ThereMustBeAMessageFor0.NiceToString().FormatWith(dc.EnglishName)); } return(null); }; sb.AddUniqueIndex((SMSTemplateEntity t) => new { t.Model }, where : t => t.Model != null && t.IsActive == true); ExceptionLogic.DeleteLogs += ExceptionLogic_DeleteLogs; ExceptionLogic.DeleteLogs += ExceptionLogic_DeletePackages; } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { FileTypeLogic.Start(sb, dqm); sb.Include<FilePathEntity>(); sb.Schema.EntityEvents<FilePathEntity>().Retrieved += FilePathLogic_Retrieved; sb.Schema.EntityEvents<FilePathEntity>().PreSaving += FilePath_PreSaving; sb.Schema.EntityEvents<FilePathEntity>().PreUnsafeDelete += new PreUnsafeDeleteHandler<FilePathEntity>(FilePathLogic_PreUnsafeDelete); dqm.RegisterQuery(typeof(FilePathEntity), () => from p in Database.Query<FilePathEntity>() select new { Entity = p, p.Id, p.FileName, p.FileType, p.Sufix }); new Graph<FilePathEntity>.Execute(FilePathOperation.Save) { AllowsNew = true, Lite = false, Execute = (fp, _) => { if (!fp.IsNew) { var ofp = fp.ToLite().Retrieve(); if (fp.FileName != ofp.FileName || fp.Sufix != ofp.Sufix || fp.FullPhysicalPath != ofp.FullPhysicalPath) { using (Transaction tr = new Transaction()) { var preSufix = ofp.Sufix.Substring(0, ofp.Sufix.Length - ofp.FileName.Length); fp.Sufix = Path.Combine(preSufix, fp.FileName); fp.Save(); System.IO.File.Move(ofp.FullPhysicalPath, fp.FullPhysicalPath); tr.Commit(); } } } } }.Register(); sb.AddUniqueIndex<FilePathEntity>(f => new { f.Sufix, f.FileType }); //With mixins, add AttachToUniqueIndexes to field dqm.RegisterExpression((FilePathEntity fp) => fp.WebImage(), () => typeof(WebImage).NiceName(), "Image"); dqm.RegisterExpression((FilePathEntity fp) => fp.WebDownload(), () => typeof(WebDownload).NiceName(), "Download"); } }
public static void Start(SchemaBuilder sb, DynamicQueryManager dqm) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <EntityHelpEntity>(); sb.Include <NamespaceHelpEntity>(); sb.Include <AppendixHelpEntity>(); sb.Include <QueryHelpEntity>(); sb.Include <OperationHelpEntity>(); sb.AddUniqueIndex((EntityHelpEntity e) => new { e.Type, e.Culture }); sb.AddUniqueIndexMList((EntityHelpEntity e) => e.Properties, mle => new { mle.Parent, mle.Element.Property }); sb.AddUniqueIndex((NamespaceHelpEntity e) => new { e.Name, e.Culture }); sb.AddUniqueIndex((AppendixHelpEntity e) => new { Name = e.UniqueName, e.Culture }); sb.AddUniqueIndex((QueryHelpEntity e) => new { e.Query, e.Culture }); sb.AddUniqueIndexMList((QueryHelpEntity e) => e.Columns, mle => new { mle.Parent, mle.Element.ColumnName }); sb.AddUniqueIndex((OperationHelpEntity e) => new { e.Operation, e.Culture }); Types = sb.GlobalLazy <ConcurrentDictionary <CultureInfo, Dictionary <Type, EntityHelp> > >(() => new ConcurrentDictionary <CultureInfo, Dictionary <Type, EntityHelp> >(), invalidateWith: new InvalidateWith(typeof(EntityHelpEntity))); Namespaces = sb.GlobalLazy <ConcurrentDictionary <CultureInfo, Dictionary <string, NamespaceHelp> > >(() => new ConcurrentDictionary <CultureInfo, Dictionary <string, NamespaceHelp> >(), invalidateWith: new InvalidateWith(typeof(NamespaceHelpEntity))); Appendices = sb.GlobalLazy <ConcurrentDictionary <CultureInfo, Dictionary <string, AppendixHelp> > >(() => new ConcurrentDictionary <CultureInfo, Dictionary <string, AppendixHelp> >(), invalidateWith: new InvalidateWith(typeof(AppendixHelpEntity))); Queries = sb.GlobalLazy <ConcurrentDictionary <CultureInfo, Dictionary <object, QueryHelp> > >(() => new ConcurrentDictionary <CultureInfo, Dictionary <object, QueryHelp> >(), invalidateWith: new InvalidateWith(typeof(QueryHelpEntity))); Operations = sb.GlobalLazy <ConcurrentDictionary <CultureInfo, Dictionary <OperationSymbol, OperationHelp> > >(() => new ConcurrentDictionary <CultureInfo, Dictionary <OperationSymbol, OperationHelp> >(), invalidateWith: new InvalidateWith(typeof(OperationHelpEntity))); sb.Include <EntityHelpEntity>() .WithSave(EntityHelpOperation.Save) .WithQuery(dqm, () => e => new { Entity = e, e.Id, e.Type, Description = e.Description.Etc(100) }); sb.Include <NamespaceHelpEntity>() .WithSave(NamespaceHelpOperation.Save) .WithQuery(dqm, () => n => new { Entity = n, n.Id, n.Name, n.Culture, Description = n.Description.Etc(100) }); sb.Include <AppendixHelpEntity>() .WithSave(AppendixHelpOperation.Save) .WithQuery(dqm, () => a => new { Entity = a, a.Id, a.UniqueName, a.Culture, a.Title, Description = a.Description.Etc(100) }); sb.Include <QueryHelpEntity>() .WithSave(QueryHelpOperation.Save) .WithQuery(dqm, () => q => new { Entity = q, q.Id, q.Query, q.Culture, Description = q.Description.Etc(100) }); sb.Include <OperationHelpEntity>() .WithSave(OperationHelpOperation.Save) .WithQuery(dqm, () => o => new { Entity = o, o.Id, o.Operation, o.Culture, Description = o.Description.Etc(100) }); sb.Schema.Synchronizing += Schema_Synchronizing; sb.Schema.Table <OperationSymbol>().PreDeleteSqlSync += operation => Administrator.UnsafeDeletePreCommand(Database.Query <OperationHelpEntity>().Where(e => e.Operation == (OperationSymbol)operation)); sb.Schema.Table <TypeEntity>().PreDeleteSqlSync += type => Administrator.UnsafeDeletePreCommand(Database.Query <EntityHelpEntity>().Where(e => e.Type == (TypeEntity)type)); sb.Schema.Table <QueryEntity>().PreDeleteSqlSync += query => Administrator.UnsafeDeletePreCommand(Database.Query <QueryHelpEntity>().Where(e => e.Query == (QueryEntity)query)); PermissionAuthLogic.RegisterPermissions(HelpPermissions.ViewHelp); } }
public static void Start(SchemaBuilder sb) { if (sb.NotDefined(MethodInfo.GetCurrentMethod())) { sb.Include <DynamicTypeConditionSymbolEntity>() .WithQuery(() => e => new { Entity = e, e.Id, e.Name, }); sb.Include <DynamicTypeConditionEntity>() .WithSave(DynamicTypeConditionOperation.Save) .WithQuery(() => e => new { Entity = e, e.Id, e.SymbolName, e.EntityType, e.Eval.Script, }); new Graph <DynamicTypeConditionEntity> .ConstructFrom <DynamicTypeConditionEntity>(DynamicTypeConditionOperation.Clone) { Construct = (e, args) => new DynamicTypeConditionEntity() { SymbolName = e.SymbolName, EntityType = e.EntityType, Eval = new DynamicTypeConditionEval() { Script = e.Eval.Script }, } } .Register(); new Graph <DynamicTypeConditionSymbolEntity> .Execute(DynamicTypeConditionSymbolOperation.Save) { CanBeModified = true, CanBeNew = true, Execute = (e, _) => { if (!e.IsNew) { var old = e.ToLite().RetrieveAndRemember(); if (old.Name != e.Name) { DynamicSqlMigrationLogic.AddDynamicRename(typeof(TypeConditionSymbol).Name, $"CodeGenTypeCondition.{old.Name}", $"CodeGenTypeCondition.{e.Name}"); } } } } .Register(); DynamicLogic.GetCodeFiles += GetCodeFiles; DynamicLogic.OnWriteDynamicStarter += WriteDynamicStarter; DynamicCode.RegisteredDynamicTypes.Add(typeof(DynamicTypeConditionEntity)); sb.Schema.Table <TypeEntity>().PreDeleteSqlSync += type => Administrator.UnsafeDeletePreCommand(Database.Query <DynamicTypeConditionEntity>().Where(dtc => dtc.EntityType == type)); sb.AddUniqueIndex((DynamicTypeConditionEntity e) => new { e.SymbolName, e.EntityType }); } }