Exemplo n.º 1
0
        public void MailNotAssignable(OnlineOrder order, string bdsEmail, string reason, string[] cc)
        {
            #region check
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }

            if (string.IsNullOrEmpty(bdsEmail))
            {
                throw new ArgumentException("message", nameof(bdsEmail));
            }
            #endregion
            _composer.Reset();
            _composer.AppendText("p", $"Cant assign case from: {order.Name} CMND: {order.NatId}");
            _composer.AppendText("p", "Please assign manually.");
            if (!string.IsNullOrEmpty(reason))
            {
                _composer.AppendText("p", reason);
            }
            var mail = new MailMessage()
            {
                From       = CreateMailAddress(_options.Username),
                IsBodyHtml = true,
                Body       = _composer.ToString(),
                Subject    = "Can not assign online sale case"
            };
            //Always CC
            AddOptionsCC(mail);
            //Additional CC
            AddCC(mail, cc);

            mail.To.Add(CreateMailAddress(bdsEmail));
            _queue.Enqueue(mail);
        }
Exemplo n.º 2
0
        public void MailCancelBet(Register bet)
        {
            _composer.AppendText("p", $"Cancel bet: <b>{bet.Username}</b>");
            _composer.AppendText("p", $"<b>{bet.Game.Player1} vs {bet.Game.Player2}</b> - {bet.Game.Start.ToString("dd-MM-yyyy hh:mm")}");
            _composer.AppendText("br", string.Empty);
            _composer.AppendText("p", $"Bet more at: {_options.Ad}");
            _composer.AppendText("p", "Thanks for playing :D");

            var mail = new MailMessage()
            {
                From       = CreateMailAddress(_options.Username),
                IsBodyHtml = true,
                Body       = _composer.ToString(),
                Subject    = "Bet canceled"
            };

            //Add receivers
            foreach (var address in _options.Receivers.Select(r => CreateMailAddress(r)))
            {
                mail.To.Add(address);
            }
            //CC bet owner
            mail.CC.Add(CreateMailAddress(bet.Username));
            _queue.Enqueue(mail);
        }
Exemplo n.º 3
0
        public void Send(dynamic receiver, string templateKey, dynamic data, CultureInfo language = null)
        {
            language    = (language ?? CultureInfo.CurrentCulture);
            templateKey = (templateKey ?? string.Empty).Trim().ToLower();

            if (string.IsNullOrWhiteSpace(templateKey))
            {
                throw new ArgumentException("You must specify the template key.", "templateKey");
            }

            var decoratedData = data;

            foreach (var decorator in m_decorators)
            {
                decoratedData = decorator.Decorate(decoratedData);
            }

            var decoratedReceiver = receiver;

            foreach (var decorator in m_decorators)
            {
                decoratedReceiver = decorator.Decorate(decoratedReceiver);
            }

            decoratedData.recipient = decoratedReceiver;

            IRenderer applicableRenderer = null;

            // try full name key-en-us
            var triedKeys    = new List <string>();
            var localizedKey = Template.GenerateLocalizedKey(templateKey, language);

            triedKeys.Add(localizedKey);
            if (m_renderer.ContainsKey(localizedKey))
            {
                applicableRenderer = m_renderer[localizedKey];
            }

            // try shorter name key-en
            var shorterLocalizedKey = localizedKey.Substring(0, localizedKey.LastIndexOf('-'));

            triedKeys.Add(shorterLocalizedKey);
            if (applicableRenderer == null && m_renderer.ContainsKey(shorterLocalizedKey))
            {
                applicableRenderer = m_renderer[templateKey];
            }

            // try just key
            triedKeys.Add(templateKey);
            if (applicableRenderer == null && m_renderer.ContainsKey(templateKey))
            {
                applicableRenderer = m_renderer[templateKey];
            }

            if (applicableRenderer == null)
            {
                throw new ArgumentException(
                          string.Format("No template could be found for keys: {0}",
                                        string.Join(",", triedKeys))
                          , "templateKey");
            }

            var mail = new Models.Mail();

            m_senderConfiguration.Configure(mail);
            m_receiverMapper.Map(decoratedReceiver, mail);

            applicableRenderer.Render(mail, decoratedData);

            m_queue.Enqueue(mail, decoratedReceiver);

            if (!m_asyncActive)
            {
                m_mailSenderService.ProcessNext();
            }
        }