예제 #1
0
        public Message GetMessage(int id)
        {
            Message msg = null;

            using (var proxy = new SqlDataReaderProxy("[dbo].[MessageSelectById]", CommandType.StoredProcedure))
            {
                proxy.Parameters.Add(new SqlParameter("@Id", id) { DbType = DbType.Int32 });
                while (proxy.Read())
                {
                    msg = new Message
                    {
                        Id = (int) proxy["Id"],
                        From = proxy["From"] as string,
                        Sender = proxy["Sender"] as string,
                        Subject = proxy["Subject"] as string,
                        Body = proxy["Body"] as string,
                        To = GetMessageToByMessageId(id),
                        ReplyTo = GetMessageReplyToByMessageId(id),
                        Cc = GetMessageCcByMessageId(id),
                        Bcc = GetMessageBccByMessageId(id),
                        CreateDate = proxy.GetDateTime(proxy.GetOrdinal("CreateDate")),
                        Status = GetCurrentMessageStatusByMessageId(id),
                        Connection = new Connection
                        {
                            EnableSsl = proxy.GetBoolean(proxy.GetOrdinal("EnableSsl")),
                            Host = proxy["Host"] as string,
                            Port = proxy.GetInt32(proxy.GetOrdinal("Port"))
                        },
                        Credential = GetCredential(id),
                    };
                }
            }

            return msg;
        }
예제 #2
0
        public List<Message> GetMessagesByApplicationId(int id)
        {
            var list = new List<Message>();

            using (var proxy = new SqlDataReaderProxy("[dbo].[MessageSelectByApplication]", CommandType.StoredProcedure))
            {
                proxy.Parameters.Add(new SqlParameter("@ApplicationId", id) {DbType = DbType.Int32});
                while (proxy.Read())
                {
                    var msg = new Message
                    {
                        Id = (int)proxy["Id"],
                        From = proxy["From"] as string,
                        Sender = proxy["Sender"] as string,
                        Subject = proxy["Subject"] as string,
                        Body = proxy["Body"] as string,
                    };

                    list.Add(msg);
                }
            }

            // Load children
            foreach (var msg in list)
            {
                msg.To = GetMessageToByMessageId(msg.Id);
                msg.ReplyTo = GetMessageReplyToByMessageId(msg.Id);
                msg.Cc = GetMessageCcByMessageId(msg.Id);
                msg.Bcc = GetMessageBccByMessageId(msg.Id);
                msg.Status = GetCurrentMessageStatusByMessageId(msg.Id);
                msg.Credential = GetCredential(msg.Id);
            }

            return list;
        }