コード例 #1
0
        public static void Start(SchemaBuilder sb, DynamicQueryManager dqm, ISMSProvider provider, Func <SMSConfigurationEmbedded> getConfiguration)
        {
            if (sb.NotDefined(MethodInfo.GetCurrentMethod()))
            {
                CultureInfoLogic.AssertStarted(sb);

                SMSLogic.getConfiguration = getConfiguration;
                SMSLogic.Provider         = provider;

                sb.Include <SMSMessageEntity>()
                .WithQuery(dqm, () => m => new
                {
                    Entity = m,
                    m.Id,
                    Source = m.From,
                    m.DestinationNumber,
                    m.State,
                    m.SendDate,
                    m.Template
                });

                sb.Include <SMSTemplateEntity>()
                .WithQuery(dqm, () => t => new
                {
                    Entity = t,
                    t.Id,
                    t.Name,
                    IsActive = t.IsActiveNow(),
                    Source   = t.From,
                    t.AssociatedType,
                    t.StartDate,
                    t.EndDate,
                });

                SMSMessageGraph.Register();
                SMSTemplateGraph.Register();

                Validator.PropertyValidator <SMSTemplateEntity>(et => et.Messages).StaticPropertyValidation += (t, pi) =>
                {
                    if (!t.Messages.Any(m => m.CultureInfo.Is(SMSLogic.Configuration.DefaultCulture)))
                    {
                        return(SMSTemplateMessage.ThereMustBeAMessageFor0.NiceToString().FormatWith(SMSLogic.Configuration.DefaultCulture.EnglishName));
                    }

                    return(null);
                };
            }
        }
コード例 #2
0
ファイル: SMSLogic.cs プロジェクト: sschoensee/extensions
        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;
            }
        }