예제 #1
0
        /// <summary>
        /// 初始化报文格式模板
        /// </summary>
        private static void InitTempLate()
        {
            if (Template.Instance != null)
            {
                return;
            }
            IMessageTemplate msgTemplate = null;

            switch (Settings.PaymentPlatForm)
            {
            case PaymentPlatFormMapping.CHINA_UNION_PAY:
                msgTemplate = new ChinaUnionPay.MessageTemplate();
                break;

            case PaymentPlatFormMapping.ALL_IN_PAY:
                msgTemplate = new AllInPay.MessageTemplate();
                break;

            case PaymentPlatFormMapping.BANK_OF_CANGZHOU:
                msgTemplate = new BankOfCangzhou.MessageTemplate();
                break;

            default:
                throw new ArgumentException(string.Format("未配置支付平台或配置的支付平台无效 Platform:{0}", Settings.PaymentPlatForm));
            }
            Template.Instance = msgTemplate.GetTemplate();
        }
예제 #2
0
        /// <summary>
        /// Returns MessageProductionData for each Recepient in template.
        /// </summary>
        public IEnumerable <MessageProductionData> Collect(IMessageTemplate templ)
        {
            var output = new List <MessageProductionData>();
            //Migrate all needed data to memory, because it will be intensive processed
            var filters = templ.Filters != null?templ.Filters.ToArray() : new tblFilter[]
            {
            };
            var wildcards = templ.Wildcards != null?templ.Wildcards.ToArray() : new tblWildcard[]
            {
            };
            var recepients = templ.Recepients != null?templ.Recepients.ToArray() : new tblRecepientCard[]
            {
            };
            var userInputedValues = templ.FilterValueContainers != null?templ.FilterValueContainers.ToArray() : new FilterValueContainer[]
            {
            };

            Dictionary <int, ValueOperatorPair[]> filtsToValOps = GetFiltersActualSettings(filters, userInputedValues);

            var Condition = SqlPredicate.BuildAndNode();

            if (filters.Length > 0)
            {
                foreach (var f in filters)
                {
                    var orNode = SqlPredicate.BuildOrNode();
                    var valops = filtsToValOps[f.Id];
                    foreach (var valop in valops)
                    {
                        orNode.Append(SqlPredicate.BuildEndNode(f.Key, valop.Operator, valop.Value, f.Type));
                    }
                    Condition.Append(orNode);
                }
            }

            //Build list of needed colomns
            var colomns = wildcards.Select(x => x.Key)
                          .Concat(recepients.Select(x => x.EmailKey))
                          .Concat(recepients.Select(x => x.NameKey))
                          .Concat(recepients.Select(x => x.PhoneKey)).Distinct();

            var sqlData = Manager.SqlLogic.FetchData(colomns, templ.TableWithKeysName, "dbo", Condition);

            var wildcardsSummed = wildcards.SelectMany(x => x.ToKeyValues());

            bool IsSms = templ.IsSms;

            foreach (var rec in recepients)
            {
                var prodData = new MessageProductionData();
                var GroupKey = IsSms ? rec.PhoneKey : rec.EmailKey;
                prodData.TextProductionData = sqlData
                                              .Where(x => !string.IsNullOrWhiteSpace(x[GroupKey].ToString()))
                                              .GroupBy(x => x[GroupKey].ToString());
                prodData.wildCards = wildcardsSummed.Concat(rec.ToKeyValues());
                output.Add(prodData);
            }

            return(output);
        }
예제 #3
0
 public static List <Message> GetDemoMessages(MessagesModuleLogic logic, IMessageTemplate tmpl, ISqlLogic sqlLogic, bool isSms, int MaxCount = 0)
 {
     using (var mng = BatchCreationManager.NewInstance(sqlLogic, logic)) {
         var cltr     = new MessageDataCollector(mng);
         var msgData  = cltr.Collect(tmpl);
         var producer = new MessageProducer(tmpl, null, new DefaultMarkUpSpecification {
             NewLineSymbol = "\n"
         });
         List <Message> result  = new List <Message>();
         int            counter = 0;
         foreach (var data in msgData)
         {
             producer.ChangeWildCards(data.wildCards);
             foreach (var textData in data.TextProductionData)
             {
                 result.Add(producer.Produce(textData, isSms ? MessageType.Sms : MessageType.Sms));
                 counter++;
                 if (counter == MaxCount)
                 {
                     return(result);
                 }
             }
         }
         return(result);
     }
 }
예제 #4
0
        private void SendRejectionNotification(User user)
        {
            messageTemplate = new RejectionEmailMesageTemplate(user);

            NotificationManager.SendNotification("Your parking slot request has been rejected!",
                                                 messageTemplate.Template,
                                                 user.Email,
                                                 NotificationMedia.Email);
        }
예제 #5
0
        private void SendSuccessNotification(User user)
        {
            messageTemplate = new SuccessEmailMesageTemplate(user);

            NotificationManager.SendNotification("Your parking slot has been confirmed!",
                                                 messageTemplate.Template,
                                                 user.Email,
                                                 NotificationMedia.Email);
        }
예제 #6
0
 public TemplateGenerator(Func <NotificationTypes, ITemplates> templateSelectors,
                          IMessageTemplate notificationtemplate,
                          Func <string, IMessageData> dataHandler,
                          OmnitureConfiguration config)
 {
     _templateSelectors    = templateSelectors;
     _notificationtemplate = notificationtemplate;
     _config      = config;
     _dataHandler = dataHandler;
 }
예제 #7
0
        protected async Task SendResponse(
            long chatId,
            IMessageTemplate messageTemplate)
        {
            var res = await _telegramBot.SendMessageAsync(
                chatId,
                messageTemplate);

            res.EnsureSuccessStatusCode();
        }
예제 #8
0
        private void SendInterestNotification(User user, User targetUsr)
        {
            string baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority) + "/api/users";

            messageTemplate = new InterestEmailMesageTemplate(user, targetUsr, baseUrl);

            NotificationManager.SendNotification("There is an empty parking slot!",
                                                 messageTemplate.Template,
                                                 targetUsr.Email,
                                                 NotificationMedia.Email);
        }
예제 #9
0
        private void SendConfirmationNotification(User user, IQueryable <User> targetUsers)
        {
            string baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority) + "/api/users";

            messageTemplate = new ConfirmationEmailMesageTemplate(user, targetUsers, baseUrl);

            NotificationManager.SendNotification("Parking slot confirmation!",
                                                 messageTemplate.Template,
                                                 user.Email,
                                                 NotificationMedia.Email);
        }
예제 #10
0
 public MessageProducer(IMessageTemplate templ, IEnumerable <KeyValuePair <string, string> > wildcards, INodeMarkUpSpecification specs)
 {
     try {
         headerTempl = TextNode.SplitTextToNodes(templ.MsgHeader + "  ", specs);
         bodyTempl   = TextNode.SplitTextToNodes(templ.MsgBody + "  ", specs);
     }
     catch (TextParseException e) {
         errorContainer.parseExceptions.Add(e);
         throw new MessageProducerException("Text parse Exception: " + e.Message);
     }
     this.wildcards = wildcards;
 }
예제 #11
0
        public Task <HttpResponseMessage> EditMessageAsync(
            long chatId,
            long messageId,
            IMessageTemplate messageTemplate,
            bool disableWebPagePreview)

        => MakeRequest("editMessageText",
                       new EditMessageRequest(chatId, messageId, messageTemplate.Text)
        {
            ParseMode             = messageTemplate.ParseMode.ToString(),
            DisableWebPagePreview = disableWebPagePreview,
            ReplyMarkup           = messageTemplate.ReplyMarkup
        });
예제 #12
0
        /// <summary>
        /// Save a message template.
        /// </summary>
        /// <param name="entity"></param>
        public void Save(IMessageTemplate entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            if (!(entity is MessageTemplate template))
            {
                throw new NotSupportedException("Cannot persist unless entity is a MessageTemplate");
            }

            Save(template, FileName(template.Name, template.CultureCode));
        }
        /// <summary>
        /// Save a message template.
        /// </summary>
        /// <param name="entity"></param>
        public void Save(IMessageTemplate entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            var template = entity as MessageTemplate;
            if (template == null)
            {
                throw new NotSupportedException("Cannot persist unless entity is a MessageTemplate");
            }

            Save(template, FileName(template.Name, template.CultureCode));
        }
예제 #14
0
        public Task <HttpResponseMessage> SendMessageAsync(
            long chatId,
            IMessageTemplate messageTemplate,
            bool disableWebPagePreview,
            bool disableNotification,
            long replyToMessageId)

        => MakeRequest("sendMessage",
                       new SendMessageRequest(chatId, messageTemplate.Text)
        {
            ParseMode             = messageTemplate.ParseMode.ToString(),
            DisableWebPagePreview = disableWebPagePreview,
            DisableNotification   = disableNotification,
            ReplyToMessageId      = replyToMessageId,
            ReplyMarkup           = messageTemplate.ReplyMarkup
        });
예제 #15
0
 /// <summary>
 /// Construtor padrão
 /// </summary><param name="encryption">Criptografia de dados</param>
 /// <param name="unitOfWork">Implementação de IUnitOfWork</param>
 /// <param name="emailSender">Envio de emails</param>
 /// <param name="messageTemplate">Templates para email</param>
 /// <param name="generalSettings">Configurações gerais</param>
 /// <param name="logger">Logger</param>
 public UserBusiness(
     IEncryption encryption,
     IUnitOfWork unitOfWork,
     IEmailSender emailSender,
     IMessageTemplate messageTemplate,
     IGeneralSettings generalSettings,
     ILogger <CRUDBusiness <User> > logger)
     : base(unitOfWork, logger)
 {
     _encryption      = encryption;
     _unitOfWork      = unitOfWork;
     _emailSender     = emailSender;
     _messageTemplate = messageTemplate;
     _general         = generalSettings;
     _logger          = logger;
 }
예제 #16
0
 /// <summary>
 /// Construtor padrão
 /// </summary>
 /// <param name="encryption">Objeto de criptografia</param>
 /// <param name="userBusiness">Negócios para usuários</param>
 /// <param name="general">Configurações gerais</param>
 /// <param name="jwt">Configurações JWT</param>
 /// <param name="emailSender">Envio de email</param>
 /// <param name="messageTemplate">Template para mensagens</param>
 /// <param name="authUser">Usuário autenticado</param>
 /// <param name="logger">Logger</param>
 public AuthBusiness(
     IEncryption encryption,
     IUserBusiness userBusiness,
     IGeneralSettings general,
     IJwtSettings jwt,
     IEmailSender emailSender,
     IMessageTemplate messageTemplate,
     IAuthUser authUser,
     ILogger <AuthBusiness> logger)
 {
     _encryption      = encryption;
     _userBusiness    = userBusiness;
     _general         = general;
     _jwt             = jwt;
     _emailSender     = emailSender;
     _messageTemplate = messageTemplate;
     _authUser        = authUser;
     _logger          = logger;
 }
예제 #17
0
        /// <summary>
        /// Merges standard details and properties into the template producing a message
        /// </summary>
        /// <param name="template"></param>
        /// <param name="toAddress"></param>
        /// <param name="properties"></param>
        /// <param name="ccAddress"></param>
        /// <param name="bccAddress"></param>
        /// <returns></returns>
        public static IMessage Merge(this IMessageTemplate template, IDictionary <string, object> properties, IEnumerable <string> toAddress, IEnumerable <string> ccAddress = null, IEnumerable <string> bccAddress = null)
        {
            var to    = toAddress ?? Enumerable.Empty <string>();
            var cc    = ccAddress ?? Enumerable.Empty <string>();
            var bcc   = bccAddress ?? Enumerable.Empty <string>();
            var props = properties ?? new Dictionary <string, object>();

            // Create a new target message and copy the base properties over
            var message = new Message();

            // Put a copy of our stuff in there
            template.CopyTo(message);

            // Set up who we are sending to
            foreach (var s in to)
            {
                message.ToAddress.Add(s);
            }

            foreach (var s in bcc)
            {
                message.Bcc.Add(s);
            }

            foreach (var s in cc)
            {
                message.Cc.Add(s);
            }

            // Ok, do the merging
            // NOTE: Do the merge twice as we might be pushing values over that contain variables
            message.Merge(props);
            message.Merge(props);

            return(message);
        }
예제 #18
0
 public SmtpMessageSenderService(IMessageTemplate template)
 {
     this.template = template;
 }