Example #1
0
        public dto.sm.AttachmentTO addAttachment(string pwd, Int32 messageId, Int32 messageOplock, string fileName, string mimeType, byte[] attachment)
        {
            AttachmentTO result = new AttachmentTO();

            if (String.IsNullOrEmpty(pwd))
            {
                result.fault = new FaultTO("Missing pwd");
            }
            else if (messageId <= 0)
            {
                result.fault = new FaultTO("Invalid message ID");
            }
            else if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(mimeType) || attachment == null || attachment.Length <= 0)
            {
                result.fault = new FaultTO("Must supply all attachment properties");
            }

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

            try
            {
                using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd }))
                {
                    AttachmentDao dao = new AttachmentDao(cxn);
                    MessageAttachment newAttachment = dao.attachToMessage(
                        new MessageAttachment() { AttachmentName = fileName, MimeType = mimeType, SmFile = attachment },
                        new Message() { Id = messageId, Oplock = messageOplock });
                    result = new AttachmentTO(newAttachment);
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return result;
        }
Example #2
0
        public dto.sm.MessageTO deleteAttachment(string pwd, Int32 messageId)
        {
            MessageTO result = new MessageTO();

            if (String.IsNullOrEmpty(pwd))
            {
                result.fault = new FaultTO("Missing pwd");
            }
            else if (messageId <= 0)
            {
                result.fault = new FaultTO("Invalid message ID");
            }

            if (result.fault != null)
            {
                return result;
            }
            try
            {
                using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd }))
                {
                    AttachmentDao dao = new AttachmentDao(cxn);
                    Message dbMsg = dao.deleteAttachmentFromMessage(messageId);
                    result = new MessageTO(dbMsg);
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return result;
        }
Example #3
0
        public dto.sm.AttachmentTO updateAttachment(string pwd, Int32 attachmentId, Int32 attachmentOplock, string fileName, string mimeType, byte[] attachment)
        {
            AttachmentTO result = new AttachmentTO();

            if (String.IsNullOrEmpty(pwd))
            {
                result.fault = new FaultTO("Missing pwd");
            }
            else if (attachmentId <= 0)
            {
                result.fault = new FaultTO("Invalid attachment ID");
            }
            else if (String.IsNullOrEmpty(fileName) || String.IsNullOrEmpty(mimeType) || attachment == null || attachment.Length <= 0)
            {
                result.fault = new FaultTO("Must supply all attachment properties");
            }

            if (result.fault != null)
            {
                return result;
            }
            try
            {
                using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd }))
                {
                    AttachmentDao dao = new AttachmentDao(cxn);
                    MessageAttachment updatedAttachment = dao.updateAttachment(new MessageAttachment()
                        { Id = attachmentId, Oplock = attachmentOplock, AttachmentName = fileName, MimeType = mimeType, SmFile = attachment });
                    updatedAttachment.SmFile = null; // don't pass back - client already has image so save the bandwidth
                    result = new AttachmentTO(updatedAttachment);
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return result;
        }
Example #4
0
        public dto.sm.AttachmentTO getAttachment(string pwd, Int32 attachmentId)
        {
            AttachmentTO result = new AttachmentTO();

            if (String.IsNullOrEmpty(pwd))
            {
                result.fault = new FaultTO("Missing pwd");
            }
            else if (attachmentId <= 0)
            {
                result.fault = new FaultTO("Invalid attachment ID");
            }

            if (result.fault != null)
            {
                return result;
            }
            try
            {
                using (MdoOracleConnection cxn = new MdoOracleConnection(new mdo.DataSource() { ConnectionString = pwd }))
                {
                    AttachmentDao dao = new AttachmentDao(cxn);
                    MessageAttachment attachment = dao.getAttachment(attachmentId);
                    result = new AttachmentTO(attachment);
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return result;
        }
Example #5
0
        public void deleteDraft(Message message)
        {
            if (message == null || message.Id <= 0)
            {
                throw new MdoException("Invalid Message");
            }
            Message dbMessage = getMessageComplete(message.Id);
            if (dbMessage == null || dbMessage.Id <= 0)
            {
                throw new MdoException("No message found with that ID");
            }
            if (dbMessage.SentDate.Year > 1900)
            {
                throw new MdoException("This message is not a valid draft - already sent");
            }
            if (dbMessage.MessageThread == null || dbMessage.MessageThread.Id <= 0 || dbMessage.Addressees == null ||
                dbMessage.Addressees.Count != 1 || dbMessage.Addressees[0] == null || dbMessage.Addressees[0].Id <= 0)
            {
                throw new MdoException("Data integrity - message thread/addressee appears malformed in database");
            }
            if (dbMessage.Addressees[0].FolderId != (int)domain.sm.enums.SystemFolderEnum.Drafts)
            {
                throw new MdoException("You can only delete messages marked as DRAFT");
            }
            try
            {
                _cxn.beginTransaction();

                AddresseeDao addrDao = new AddresseeDao(_cxn);

                // turns out there might be multiple draft messages for a thread - they should all be deleted
                domain.sm.Thread msgThread = getMessagesFromThread(dbMessage.MessageThread.Id);
                foreach (Message msg in msgThread.Messages)
                {
                    IList<domain.sm.Addressee> allAddressees = addrDao.getAddresseesForMessage(msg.Id);
                    if (allAddressees != null && allAddressees.Count != 1)
                    {
                        throw new MdoException("Data integrity: Invalid draft. This draft message has more than one addressee.");
                    }

                    if (msg.SentDate.Year > 1900 || msg.CompletedDate.Year > 1900 ||
                        allAddressees[0].Owner.Id != dbMessage.Addressees[0].Owner.Id || allAddressees[0].FolderId != (Int32)domain.sm.enums.SystemFolderEnum.Drafts)
                    {
                        throw new MdoException("Data integrity: There appears to be multiple messages associated with the thread. The data is inconsistent between them.");
                    }
                    addrDao.deleteAddressee(allAddressees[0].Id);
                    deleteMessage(msg.Id);
                }

                // see if there were any attachments for this draft message
                if (dbMessage.Attachment)
                {
                    AttachmentDao attachDao = new AttachmentDao(_cxn);
                    attachDao.deleteAttachment(Convert.ToInt32(dbMessage.AttachmentId));
                }

                deleteThread(dbMessage.MessageThread.Id);

                _cxn.commitTransaction();
            }
            catch (Exception)
            {
                _cxn.rollbackTransaction();
                throw;
            }
        }