Exemplo n.º 1
0
        public MailAttachment AttachDocument(int id, string fileId, string version, string shareLink)
        {
            try
            {
                Thread.CurrentThread.CurrentCulture   = CurrentCulture;
                Thread.CurrentThread.CurrentUICulture = CurrentCulture;

                var attachment = MailBoxManager.AttachFileFromDocuments(TenantId, Username, id, fileId, version, shareLink);
                return(attachment);
            }
            catch (AttachmentsException e)
            {
                string errorMessage;
                switch (e.ErrorType)
                {
                case AttachmentsException.Types.BadParams:
                    errorMessage = MailApiResource.AttachmentsBadInputParamsError;
                    break;

                case AttachmentsException.Types.EmptyFile:
                    errorMessage = MailApiResource.AttachmentsEmptyFileNotSupportedError;
                    break;

                case AttachmentsException.Types.MessageNotFound:
                    errorMessage = MailApiResource.AttachmentsMessageNotFoundError;
                    break;

                case AttachmentsException.Types.TotalSizeExceeded:
                    errorMessage = MailApiResource.AttachmentsTotalLimitError;
                    break;

                case AttachmentsException.Types.DocumentNotFound:
                    errorMessage = MailApiResource.AttachmentsDocumentNotFoundError;
                    break;

                case AttachmentsException.Types.DocumentAccessDenied:
                    errorMessage = MailApiResource.AttachmentsDocumentAccessDeniedError;
                    break;

                default:
                    errorMessage = MailApiResource.AttachmentsUnknownError;
                    break;
                }
                throw new Exception(errorMessage);
            }
            catch (Exception)
            {
                throw new Exception(MailApiResource.AttachmentsUnknownError);
            }
        }
        public MailAttachment AttachDocument(int id, string fileId, string version, string shareLink, string streamId)
        {
            try
            {
                var attachment = MailBoxManager.AttachFileFromDocuments(TenantId, Username, id, fileId, version, shareLink, streamId);
                return(attachment);
            }
            //todo: rewrite to typed exceptions
            catch (AttachmentsException e)
            {
                string error_message;

                switch (e.ErrorType)
                {
                case AttachmentsException.Types.BAD_PARAMS:
                    error_message = MailApiResource.AttachmentsBadInputParamsError;
                    break;

                case AttachmentsException.Types.EMPTY_FILE:
                    error_message = MailApiResource.AttachmentsEmptyFileNotSupportedError;
                    break;

                case AttachmentsException.Types.MESSAGE_NOT_FOUND:
                    error_message = MailApiResource.AttachmentsMessageNotFoundError;
                    break;

                case AttachmentsException.Types.TOTAL_SIZE_EXCEEDED:
                    error_message = MailApiResource.AttachmentsTotalLimitError;
                    break;

                case AttachmentsException.Types.DOCUMENT_NOT_FOUND:
                    error_message = MailApiResource.AttachmentsDocumentNotFoundError;
                    break;

                case AttachmentsException.Types.DOCUMENT_ACCESS_DENIED:
                    error_message = MailApiResource.AttachmentsDocumentAccessDeniedError;
                    break;

                default:
                    error_message = MailApiResource.AttachmentsUnknownError;
                    break;
                }
                throw new Exception(error_message);
            }
            catch (Exception)
            {
                throw new Exception(MailApiResource.AttachmentsUnknownError);
            }
        }