Ejemplo n.º 1
0
        public void GetQueue()
        {
            QueueProcess queue = new QueueProcess();
            Queue queues = queue.GetQueue();

            Assert.IsTrue(queues != null);
        }
Ejemplo n.º 2
0
        public void BuildQueue()
        {
            TicketTest ticketTest = new TicketTest();
            ticketTest.MakeTicket();

            //TicketInfo.GetTickets();
            TicketProcess ticketProcess = new TicketProcess();

            QueueProcess queueProcess = new QueueProcess();
            queueProcess.BuildQueueFromTicket(ticketProcess, 100);
        }
Ejemplo n.º 3
0
        public void Process()
        {
            if (processing) { return; }
            lock (lockObj)
            {
                processing = true;
            }

            TicketProcess ticketProcess = new TicketProcess();
            QueueProcess queueProcess = new QueueProcess();

            queueProcess.BuildQueueFromTicket(
                ticketProcess,
                Convert.ToInt32(ConfigurationManager.AppSettings["BlockCount"])
                );

            processing = false;
        }
Ejemplo n.º 4
0
        public void SendMail()
        {
            QueueTest queueTest = new QueueTest();
            queueTest.BuildQueue();

            ILog log = new LogCounter();

            SendMailProcess sendMailProcess = new SendMailProcess(log);

            sendMailProcess.SetHostAndPort("smtp.hostname.com", 25);

            QueueProcess queueProcess = new QueueProcess();
            Queue queue = queueProcess.GetQueue();

            foreach(Recipient recipient in queue.RecipientData)
            {
                sendMailProcess.Send(
                    new MailAddress(queue.TicketData.SenderAddress, queue.TicketData.SenderName),
                    new MailAddress[] { new MailAddress(recipient.Address, recipient.Name) },
                    queue.TicketData.Subject,
                    queue.TicketData.Body
                    );
            }
        }
Ejemplo n.º 5
0
        public void BuildQueueFromTicket(TicketProcess ticketProcess, int blobkCount)
        {
            if (blobkCount <= 0)
            {
                blobkCount = BLOCKCOUNT;
            }
            List <Ticket> tickets = ticketProcess.GetTickets();

            if (tickets.Count() == 0)
            {
                return;
            }


            Ticket ticket = tickets[0];
            Source source = ticket.Source;

            try
            {
                source = source.DecryptedSource;
                string value            = source.Value;
                string connectionString = source.ConnectionString;

                if (source.Provider == "System.Data.SqlClient")
                {
                    Database db = new SqlDatabase(source.ConnectionString);
                    DataSet  ds = db.ExecuteDataSet(CommandType.Text, source.Value);
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        QueueProcess     queueProcess = new QueueProcess();
                        List <Recipient> recipients   = new List <Recipient>();

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            string address = dr["address"].ToString();
                            string name    = dr["name"].ToString();

                            try
                            {
                                recipients.Add(new Recipient(name, address));
                            }
                            catch (Exception e)
                            {
                                LogProcess.Error(e, address + ", " + name);
                                continue;
                            }

                            if (recipients.Count >= blobkCount)
                            {
                                queueProcess.SaveQueue(new Queue()
                                {
                                    RecipientData = recipients.ToArray(),
                                    TicketData    = ticket
                                });
                                recipients = new List <Recipient>();
                            }
                        }


                        if (recipients.Count() > 0)
                        {
                            queueProcess.SaveQueue(new Queue()
                            {
                                RecipientData = recipients.ToArray(),
                                TicketData    = ticket
                            });

                            recipients = new List <Recipient>();
                        }
                    }
                }
                else if (source.Provider == "System.String[]")
                {
                    QueueProcess     queueProcess = new QueueProcess();
                    List <Recipient> recipients   = new List <Recipient>();

                    foreach (string recipient in source.Value.Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        string address = recipient.Trim();
                        recipients.Add(new Recipient(address, address));

                        if (recipients.Count >= blobkCount)
                        {
                            queueProcess.SaveQueue(new Queue()
                            {
                                RecipientData = recipients.ToArray(),
                                TicketData    = ticket
                            });
                            recipients = new List <Recipient>();
                        }
                    }

                    queueProcess.SaveQueue(new Queue()
                    {
                        RecipientData = recipients.ToArray(),
                        TicketData    = ticket
                    });
                    recipients = new List <Recipient>();
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            catch (Exception e)
            {
                LogProcess.Error(e);
            }

            ticketProcess.RemoveTicket(ticket);
        }
Ejemplo n.º 6
0
        public void Process()
        {
            if (processing || this.smtpServer == null) { return; }
            lock (lockObj)
            {
                processing = true;
            }

            QueueProcess queueProcess = new QueueProcess();

            int blockSleep = Convert.ToInt32(ConfigurationManager.AppSettings["BlockSleep"]);

            ClickOnceDMLib.Structs.Queue queue = queueProcess.GetQueue();

            if (queue != null)
            {
                InitSMTPServer();

                LogProcess.Info("In-Process Start");

                ILog log = new LogCounter(); // log interface

                foreach (Recipient recipient in queue.RecipientData)
                {
                    long baseTick = DateTime.Now.Ticks;

                    var smtp = from s1 in this.smtpServer
                               orderby s1.Weight ascending
                               select s1;

                    SMTPServer serverInfo = smtp.First();

                    SendMailProcess sendMailProcess = new SendMailProcess(log);

                    sendMailProcess.SetHostAndPort(serverInfo.Host, serverInfo.Port);

                    MailAddress mailAddress = null;

                    try
                    {
                        mailAddress = new MailAddress(recipient.Address.Trim(), recipient.Name);
                    }
                    catch (Exception ex)
                    {
                        LogProcess.Error(ex);
                        continue;
                    }

                    if (mailAddress != null)
                    {
                        sendMailProcess.Send(
                            new MailAddress(queue.TicketData.SenderAddress, queue.TicketData.SenderName),
                            new MailAddress[] { mailAddress },
                            queue.TicketData.Subject,
                            queue.TicketData.Body
                            );

                        serverInfo.SetWeight(TimeSpan.FromTicks(DateTime.Now.Ticks - baseTick).Milliseconds);
                    }
                }

                log.Flush(); // write log

                LogProcess.Info("In-Process End");

                Thread.Sleep(blockSleep);
            }

            processing = false;
        }
Ejemplo n.º 7
0
        public void BuildQueueFromTicket(TicketProcess ticketProcess, int blobkCount)
        {
            if (blobkCount <= 0)
            {
                blobkCount = BLOCKCOUNT;
            }
            List<Ticket> tickets = ticketProcess.GetTickets();

            if (tickets.Count() == 0)
            {
                return;
            }

            Ticket ticket = tickets[0];
            Source source = ticket.Source;

            try
            {
                source = source.DecryptedSource;
                string value = source.Value;
                string connectionString = source.ConnectionString;

                if (source.Provider == "System.Data.SqlClient")
                {
                    Database db = new SqlDatabase(source.ConnectionString);
                    DataSet ds = db.ExecuteDataSet(CommandType.Text, source.Value);
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        QueueProcess queueProcess = new QueueProcess();
                        List<Recipient> recipients = new List<Recipient>();

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            string address = dr["address"].ToString();
                            string name = dr["name"].ToString();

                            try
                            {
                                recipients.Add(new Recipient(name, address));
                            }
                            catch (Exception e)
                            {
                                LogProcess.Error(e, address + ", " + name);
                                continue;
                            }

                            if (recipients.Count >= blobkCount)
                            {
                                queueProcess.SaveQueue(new Queue()
                                {
                                    RecipientData = recipients.ToArray(),
                                    TicketData = ticket
                                });
                                recipients = new List<Recipient>();
                            }
                        }

                        if (recipients.Count() > 0)
                        {
                            queueProcess.SaveQueue(new Queue()
                            {
                                RecipientData = recipients.ToArray(),
                                TicketData = ticket
                            });

                            recipients = new List<Recipient>();
                        }
                    }
                }
                else if (source.Provider == "System.String[]")
                {
                    QueueProcess queueProcess = new QueueProcess();
                    List<Recipient> recipients = new List<Recipient>();

                    foreach (string recipient in source.Value.Trim().Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        string address = recipient.Trim();
                        recipients.Add(new Recipient(address, address));

                        if (recipients.Count >= blobkCount)
                        {
                            queueProcess.SaveQueue(new Queue()
                            {
                                RecipientData = recipients.ToArray(),
                                TicketData = ticket
                            });
                            recipients = new List<Recipient>();
                        }
                    }

                    queueProcess.SaveQueue(new Queue()
                    {
                        RecipientData = recipients.ToArray(),
                        TicketData = ticket
                    });
                    recipients = new List<Recipient>();
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            catch (Exception e)
            {
                LogProcess.Error(e);
            }

            ticketProcess.RemoveTicket(ticket);
        }