getMessage() public method

public getMessage ( Int32 messageId ) : domain.sm.Message
messageId System.Int32
return domain.sm.Message
コード例 #1
0
ファイル: SecureMessageLib.cs プロジェクト: OSEHRA/mdws
        public ThreadTO saveDraft(string pwd, Int32 replyingToMessageId, string threadSubject, Int32 messageCategory, 
            Int32 messageId, Int32 senderId, Int32 recipientId, string messageBody, Int32 messageOplock, Int32 threadOplock)
        {
            ThreadTO result = new ThreadTO();

            if (String.IsNullOrEmpty(pwd))
            {
                result.fault = new FaultTO("Missing pwd");
            }
            else if (messageCategory > 0 && !Enum.IsDefined(typeof(gov.va.medora.mdo.domain.sm.enums.MessageCategoryTypeEnum), messageCategory))
            {
                result.fault = new FaultTO("Invalid message category");
            }
            else if (String.IsNullOrEmpty(messageBody))
            {
                result.fault = new FaultTO("Missing message body");
            }
            else if (messageId > 0 && messageOplock < 0)
            {
                result.fault = new FaultTO("Invalid message ID/message oplock");
            }
            else if (senderId <= 0 || recipientId <= 0)
            {
                result.fault = new FaultTO("Invalid sender/recipient");
            }
            if (result.fault != null)
            {
                return result;
            }

            try
            {
                Message message = new Message()
                {
                    Body = messageBody,
                    Checksum = StringUtils.getMD5Hash(messageBody),
                    Id = messageId,
                    MessageThread = new Thread(),
                    RecipientId = recipientId,
                    SenderId = senderId,
                    Oplock = messageOplock
                };
                message.MessageThread.Subject = threadSubject;
                if (Enum.IsDefined(typeof(mdo.domain.sm.enums.MessageCategoryTypeEnum), messageCategory))
                {
                    message.MessageThread.MessageCategoryType = (mdo.domain.sm.enums.MessageCategoryTypeEnum)messageCategory;
                }
                message.MessageThread.Oplock = threadOplock;

                using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd }))
                {
                    SecureMessageDao dao = new SecureMessageDao(cxn);

                    if (replyingToMessageId > 0)
                    {
                        Message replyingToMsg = dao.getMessage(replyingToMessageId);
                        if (replyingToMsg == null || replyingToMsg.Id <= 0 || replyingToMsg.MessageThread == null || replyingToMsg.MessageThread.Id <= 0)
                        {
                            throw new Exception("Invalid reply to message ID");
                        }
                        message.MessageThread.Id = replyingToMsg.MessageThread.Id;
                    }

                    gov.va.medora.mdo.domain.sm.Message savedDraft = dao.saveDraft(message);
                    MessageTO msg = new MessageTO(savedDraft);
                    result = new ThreadTO(savedDraft.MessageThread);
                    result.messages = new MessageTO[] { msg };
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return result;
        }
コード例 #2
0
ファイル: SecureMessageLib.cs プロジェクト: OSEHRA/mdws
        public MessageTO sendReplyMessage(string pwd, Int32 replyingToMessageId, Int32 senderId, Int32 recipientId, string messageBody)
        {
            MessageTO result = new MessageTO();

            if (replyingToMessageId <= 0)
            {
                result.fault = new FaultTO("Missing reply message ID");
            }
            else if (senderId <= 0)
            {
                result.fault = new FaultTO("Missing sender ID");
            }
            //else if (recipientId <= 0)
            //{
            //    result.fault = new FaultTO("Missing recipient ID");
            //}
            else if (String.IsNullOrEmpty(messageBody))
            {
                result.fault = new FaultTO("Must supply a message body");
            }

            if (result.fault != null)
            {
                return result;
            }

            try
            {
                using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd }))
                {
                    SecureMessageDao dao = new SecureMessageDao(cxn);
                    Message replyingTo = dao.getMessage(replyingToMessageId);
                    if (replyingTo == null || replyingTo.Id <= 0)
                    {
                        throw new Exception("No message found for that ID");
                    }

                    Message newReply = new Message()
                    {
                        SentDate = DateTime.Now,
                        SenderId = senderId,
                        RecipientId = recipientId,
                        Body = messageBody,
                        Checksum = StringUtils.getMD5Hash(messageBody),
                        MessageThread = replyingTo.MessageThread
                    };

                    result = new MessageTO(dao.sendReply(replyingTo, newReply));
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return result;
        }
コード例 #3
0
        public Message deleteAttachmentFromMessage(Int32 messageId)
        {
            SecureMessageDao smDao = new SecureMessageDao(_cxn);
            Message dbMsg = smDao.getMessage(messageId);
            if (dbMsg == null || dbMsg.Id <= 0 || !dbMsg.Attachment || dbMsg.AttachmentId <= 0)
            {
                throw new MdoException("Not a valid message ID");
            }

            try
            {
                _cxn.beginTransaction();

                OracleQuery request = buildUpdateMessageQuery(dbMsg, -1);
                nonQuery qry = delegate() { return (Int32)request.Command.ExecuteNonQuery(); };
                if ((Int32)_cxn.query(request, qry) != 1)
                {
                    throw new MdoException("Failed to update secure message record for attachment");
                }
                deleteAttachment(Convert.ToInt32(dbMsg.AttachmentId));
                dbMsg.AttachmentId = 0;
                dbMsg.Attachment = false;
                dbMsg.Oplock++;
                _cxn.commitTransaction();
                return dbMsg;
            }
            catch (Exception)
            {
                _cxn.rollbackTransaction();
                throw;
            }
        }