public void Send(AuditableProperty property, object entity, string to)
        {
            try {
                MonorailMailer mailer;
                if (Sender != null)
                {
                    mailer = new MonorailMailer(Sender);
                }
                else
                {
                    mailer = new MonorailMailer();
                }
                mailer.UnderTest = UnderTest;

                mailer.NotifyAboutChanges(property, entity, to);
            }
            catch (Exception ex) {
                _log.Error("Ошибка отправки уведомлений об изменении наблюдаемых полей", ex);
            }
        }
Esempio n. 2
0
        protected override void Process()
        {
            var timeToSendMail = ConfigurationManager.AppSettings["SendPremoderatedPomotionListAt"]
                                 .Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

            var timeToSendMailHour    = int.Parse(timeToSendMail[0]);
            var timeToSendMailMinutes = timeToSendMail.Length > 1 ? int.Parse(timeToSendMail[1]) : 0;
            var mailTime = SystemTime.Now().Date.AddHours(timeToSendMailHour).AddMinutes(timeToSendMailMinutes);

            if (SystemTime.Now() >= mailTime && SystemTime.Now() < mailTime.AddMinutes(30))
            {
                using (new SessionScope(FlushAction.Never)) {
                    var promotions = ActiveRecordLinq.AsQueryable <SupplierPromotion>()
                                     .Where(p => !p.Moderated && p.Enabled && p.Moderator == null).OrderBy(s => s.Begin).ToList();
                    if (promotions.Count > 0)
                    {
                        _mailer = (_mailer ?? new MonorailMailer()).PremoderatedPromotions(promotions);
                        _mailer.Send();
                    }
                }
            }
        }
Esempio n. 3
0
        public virtual void CheckCommentChangesAndLog(ISession session, MonorailMailer mailer)
        {
            if (!this.IsChanged(p => p.Comment))
            {
                return;
            }

            var oldValue     = this.OldValue(p => p.Comment);
            var propertyInfo = typeof(Payer).GetProperty("Comment");
            var property     = new DiffAuditableProperty(session, propertyInfo, BindingHelper.GetDescription(propertyInfo), Comment, oldValue);

            mailer.NotifyAboutChanges(property, this, "*****@*****.**");
            foreach (var client in Clients)
            {
                var log = new AuditRecord(client)
                {
                    Message     = property.Message,
                    IsHtml      = property.IsHtml,
                    MessageType = LogMessageType.Stat
                };
                log.Save();
            }
        }
Esempio n. 4
0
        public void Setup()
        {
            message    = null;
            controller = new RegisterController();

            PrepareController(controller, "Registered");
            ((StubRequest)Request).Uri             = new Uri("https://stat.analit.net/adm/Register/Register");
            ((StubRequest)Request).ApplicationPath = "/Adm";

            ForTest.InitializeMailer();
            mailer = ForTest.TestMailer(m => message = m);

            payer = new Payer("Тестовый плательщик")
            {
                Id = 10, JuridicalName = "FullTestPayerName"
            };
            client = new Client(payer, Data.DefaultRegion)
            {
                Id         = 58,
                Name       = "Тестовый клиент",
                HomeRegion = new Region {
                    Name = "test"
                },
                Settings = new DrugstoreSettings()
            };
            supplier = new Supplier {
                Name       = "Тестовый поставщик",
                HomeRegion = new Region {
                    Name = "testSupplierRegion"
                }
            };
            payer.Clients.Add(client);
            payer.Suppliers.Add(supplier);
            user = new User(payer, client);
            client.Users.Add(user);
        }
Esempio n. 5
0
 public void Setup()
 {
     ForTest.InitializeMailer();
     mailer  = ForTest.TestMailer(m => { });
     _client = DataMother.CreateTestClientWithUser();
 }
 public SendInvoiceTask(MonorailMailer mailer)
 {
     _mailer = mailer;
 }
Esempio n. 7
0
 public SendPremoderatedPomotionList(MonorailMailer mailer)
 {
     _mailer = mailer;
 }
Esempio n. 8
0
        public static int Main(string[] args)
        {
            try {
                var    help    = false;
                string task    = null;
                var    options = new OptionSet {
                    { "help", x => help = x != null },
                    { "task=", "Выполнить указанную задачу и выйти", x => task = x },
                };
                try {
                    options.Parse(args);
                } catch (Exception e) {
                    Console.WriteLine(e.Message);
                    options.WriteOptionDescriptions(Console.Out);
                }
                if (help)
                {
                    options.WriteOptionDescriptions(Console.Out);
                    return(0);
                }
                XmlConfigurator.Configure();
                var assembly = typeof(Program).Assembly;
                StandaloneInitializer.Init(assembly);

                var jobs = new List <ActiveRecordJob>();
                using (new SessionScope()) {
                    var job = new ActiveRecordJob(new SendPaymentNotification());
                    jobs.Add(job);
                }
                var mailer = new MonorailMailer {
                    SiteRoot = ConfigurationManager.AppSettings["SiteRoot"]
                };

                var tasks = new List <Task> {
                    new SendInvoiceTask(mailer)
                };
                tasks = tasks.Concat(assembly.GetTypes().Except(tasks.Select(x => x.GetType()).ToArray())
                                     .Where(t => t.IsClass && !t.IsAbstract && !t.IsInterface && typeof(Task).IsAssignableFrom(t))
                                     .Select(t => Activator.CreateInstance(t))
                                     .OfType <Task>())
                        .ToList();

                if (!String.IsNullOrEmpty(task))
                {
                    var toRun = tasks.Where(x => x.GetType().Name.Match(task)).ToList();
                    if (toRun.Count == 0)
                    {
                        Console.WriteLine($"Не удалось найти задачу {task}, доступные задачи {tasks.Implode(x => x.GetType().Name)}");
                        return(1);
                    }
                    toRun.Each(x => x.Execute());
                    return(0);
                }

                var actions = tasks.Select(x => new Action(x.Execute))
                              .Concat(jobs.Select(x => {
                    return(new Action(() => {
                        using (new SessionScope())
                            x.Run();
                    }));
                })).ToList();
                var runner = new RepeatableCommand(30.Minute(), () => actions.Each(t => {
                    try {
                        t();
                    }
                    catch (Exception e) {
                        log.Error($"Выполнение задачи {t} завершилось ошибкой", e);
                    }
                }));
                tasks.Each(t => t.Cancellation   = runner.Cancellation);
                jobs.Each(x => x.Job.Cacellation = runner.Cancellation);
                return(CommandService.Start(args, runner));
            }
            catch (Exception e) {
                log.Error("Ошибка при запуске приложения", e);
                return(1);
            }
        }