コード例 #1
0
ファイル: QueueProcess.cs プロジェクト: jongha/clickoncedm
        public void SaveQueue(Queue queue)
        {
            lock (lockObj)
            {
                if (queue.RecipientData.Count() > 0)
                {
                    string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + Guid.NewGuid().ToString("N") + ".queue";

                    using (FileStream stream = new FileStream(System.IO.Path.Combine(PathInfo.Queue, fileName), FileMode.CreateNew))
                    {
                        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Queue));
                        serializer.WriteObject(stream, queue);
                    }
                }
            }
        }
コード例 #2
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;
        }
コード例 #3
0
ファイル: QueueProcess.cs プロジェクト: jongha/clickoncedm
        public Queue GetQueue()
        {
            IOrderedEnumerable<string> files = GetQueueFiles();

            Queue queue = new Queue();

            if (files.Count() > 0)
            {
                string file = files.First();
                FileInfo fileInfo = new FileInfo(file);
                string queueName = System.IO.Path.GetFileName(file);

                if (fileInfo.Length > 0)
                {
                    using (FileStream stream = new FileStream(PathInfo.CombinePath(PathInfo.Queue, queueName), FileMode.Open))
                    {
                        try
                        {
                            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Queue));
                            queue = (Queue)serializer.ReadObject(stream);
                        }
                        catch (Exception e)
                        {
                            LogProcess.Error(e);
                        }
                    }
                }
                else
                {
                    queue = null;
                }

                RemoveQueue(queueName);
            }
            else
            {
                queue = null;
            }

            return queue;
        }