Exemple #1
0
        public static void SendSMS(this ISMSModel smsModel, CultureInfo?forceCultureInfo = null)
        {
            var result = smsModel.CreateSMSMessage(forceCultureInfo);

            SMSLogic.SendSMS(result);
        }
Exemple #2
0
        public static void Register()
        {
            GetState = m => m.State;

            new ConstructFrom <SMSTemplateEntity>(SMSMessageOperation.CreateSMSFromSMSTemplate)
            {
                CanConstruct = t => !t.Active ? SMSCharactersMessage.TheTemplateMustBeActiveToConstructSMSMessages.NiceToString() : null,
                ToStates     = { SMSMessageState.Created },
                Construct    = (t, args) =>
                {
                    var defaultCulture = SMSLogic.Configuration.DefaultCulture.ToCultureInfo();
                    var ci             = args.TryGetArgC <CultureInfo>() ?? defaultCulture;

                    return(new SMSMessageEntity
                    {
                        Template = t.ToLite(),
                        Message = (t.GetCultureMessage(ci) ?? t.GetCultureMessage(defaultCulture)).Message,
                        From = t.From,
                        EditableMessage = t.EditableMessage,
                        State = SMSMessageState.Created,
                        DestinationNumber = args.TryGetArgC <string>(),
                        Certified = t.Certified
                    });
                }
            }.Register();

            new Execute(SMSMessageOperation.Send)
            {
                AllowsNew  = true,
                Lite       = false,
                FromStates = { SMSMessageState.Created },
                ToStates   = { SMSMessageState.Sent },
                Execute    = (m, _) =>
                {
                    try
                    {
                        SMSLogic.SendSMS(m);
                    }
                    catch (Exception e)
                    {
                        var ex = e.LogException();
                        using (Transaction tr = Transaction.ForceNew())
                        {
                            m.Exception = ex.ToLite();
                            m.Save();
                            tr.Commit();
                        }
                        throw;
                    }
                }
            }.Register();

            new Graph <SMSMessageEntity> .Execute(SMSMessageOperation.UpdateStatus)
            {
                CanExecute = m => m.State != SMSMessageState.Created ? null : SMSCharactersMessage.StatusCanNotBeUpdatedForNonSentMessages.NiceToString(),
                Execute    = (sms, args) =>
                {
                    var func = args.TryGetArgC <Func <SMSMessageEntity, SMSMessageState> >();
                    if (func == null)
                    {
                        func = SMSLogic.Provider.SMSUpdateStatusAction;
                    }

                    sms.State = func(sms);

                    if (sms.UpdatePackage != null)
                    {
                        sms.UpdatePackageProcessed = true;
                    }
                }
            }

            .Register();
        }
Exemple #3
0
        public static void Register()
        {
            GetState = m => m.State;

            new ConstructFrom <SMSTemplateEntity>(SMSMessageOperation.CreateSMSFromTemplate)
            {
                CanConstruct = t => !t.IsActive ? SMSCharactersMessage.TheTemplateMustBeActiveToConstructSMSMessages.NiceToString() : null,
                ToStates     = { SMSMessageState.Created },
                Construct    = (t, args) =>
                {
                    return(SMSLogic.CreateSMSMessage(t.ToLite(),
                                                     args.GetArg <Lite <Entity> >().RetrieveAndRemember(),
                                                     args.TryGetArgC <ISMSModel>(),
                                                     args.TryGetArgC <CultureInfo>()));
                }
            }.Register();

            new Execute(SMSMessageOperation.Send)
            {
                CanBeNew      = true,
                CanBeModified = true,
                FromStates    = { SMSMessageState.Created },
                ToStates      = { SMSMessageState.Sent },
                Execute       = (m, _) =>
                {
                    try
                    {
                        SMSLogic.SendSMS(m);
                    }
                    catch (Exception e)
                    {
                        var ex = e.LogException();
                        using (Transaction tr = Transaction.ForceNew())
                        {
                            m.Exception = ex.ToLite();
                            m.Save();
                            tr.Commit();
                        }
                        throw;
                    }
                }
            }.Register();


            new Graph <SMSMessageEntity> .Execute(SMSMessageOperation.UpdateStatus)
            {
                CanExecute = m => m.State != SMSMessageState.Created ? null : SMSCharactersMessage.StatusCanNotBeUpdatedForNonSentMessages.NiceToString(),
                Execute    = (sms, args) =>
                {
                    var func = args.TryGetArgC <Func <SMSMessageEntity, SMSMessageState> >();
                    if (func == null)
                    {
                        func = SMSLogic.GetProvider().SMSUpdateStatusAction;
                    }

                    sms.State = func(sms);

                    if (sms.UpdatePackage != null)
                    {
                        sms.UpdatePackageProcessed = true;
                    }
                }
            }

            .Register();
        }