コード例 #1
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);
     }
 }
コード例 #2
0
        /// <summary>
        /// Creates Batch, creates messages assigned to this batch, puts messages to send queque.
        /// returns entities NOT WRITTEN to db.
        /// 'sendPriority': int.min - lowest priory, int.max - highest.
        /// </summary>
        public BatchCreationResult CreateBatch(tblMessageSchedule schedule, int sendPriority)
        {
            var result = new BatchCreationResult();
            var batch  = Manager.Logic.Create <tblMessageBatch>();

            batch.CreatedOn          = DateTime.Now;
            batch.tblMessageSchedule = schedule;
            batch.IsSms = schedule.IsSms;

            var dataCollector = new MessageDataCollector(Manager);
            var msgData       = dataCollector.Collect(schedule);

            var markSpecs = new DefaultMarkUpSpecification {
                NewLineSymbol = "\n"
            };
            var msgProducer = new MessageProducer(schedule, null, markSpecs);

            var messages   = new List <tblMessage>();
            var sendQueues = new List <tblPendingMessagesQueue>();

            foreach (var data in msgData)
            {
                msgProducer.ChangeWildCards(data.wildCards);
                foreach (var textData in data.TextProductionData)
                {
                    var msgRaw = msgProducer.Produce(textData, schedule.IsSms ? MessageType.Sms : MessageType.Sms);
                    var msg    = Manager.Logic.Create <tblMessage>();
                    msg.Adress          = msgRaw.Adress;
                    msg.Body            = msgRaw.Body;
                    msg.Header          = msgRaw.Header;
                    msg.IsSms           = schedule.IsSms;
                    msg.tblMessageBatch = batch;
                    messages.Add(msg);
                    var pmq = Manager.Logic.Create <tblPendingMessagesQueue>();
                    pmq.tblMessage = msg;
                    pmq.Priority   = sendPriority;
                    sendQueues.Add(pmq);
                }
            }
            result.Batch     = batch;
            result.Messages  = messages;
            result.SendQueue = sendQueues;
            return(result);
        }