Exemple #1
0
        /*
        **
        ** Download
        **
        */

        public virtual HttpResponseMessage Get(Document entity, HttpRequestMessage Request, object adds, String extensionName = null, Client currentClient = null, int?idHome = null)
        {
            if (!((DocumentValidation)validation).DownloadValidation(validationDictionnary, currentClient, entity))
            {
                throw new ManahostValidationException(validationDictionnary);
            }
            if (extensionName != null)
            {
                entity.Url   = DocumentUtils.GetNewPathFileName(DocumentUtils.GetFullDocumentUrl(entity.Url), extensionName, true);
                entity.Title = Path.GetFileNameWithoutExtension(entity.Title) + "_" + extensionName + Path.GetExtension(entity.Title);
            }
            try
            {
                HttpResponseMessage response = new HttpResponseMessage();
                Stream result = DocumentUtils.GetDocumentStream((Boolean)entity.IsPrivate, entity.Url, DocumentUtils.GetEncryptionPassword(HomeRepository, currentClient));

                entity.MimeType     = DocumentUtils.GetMimeType(entity.Title);
                response.StatusCode = HttpStatusCode.OK;
                response.Content    = new StreamContent(result);
                response.Content.Headers.ContentType        = new MediaTypeHeaderValue(entity.MimeType);
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = entity.Title
                };
                return(response);
            }
            catch (IOException)
            {
                validationDictionnary.AddModelError(String.Format(GenericNames.MODEL_STATE_FORMAT, TypeOfName.GetNameFromType <Document>(), "Download"), GenericError.FILE_NOT_FOUND);
                throw new ManahostValidationException(validationDictionnary);
            }
        }
Exemple #2
0
        public static List <System.Net.Mail.Attachment> GetAttachments(List <Document> attachmentList, Home currentHome)
        {
            List <System.Net.Mail.Attachment> attachments = new List <System.Net.Mail.Attachment>();

            foreach (Document cur in attachmentList)
            {
                attachments.Add(new Attachment(DocumentUtils.GetDocumentStream((bool)cur.IsPrivate, (string)cur.Url, currentHome.EncryptionPassword), (string)cur.Title));
            }
            return(attachments);
        }
Exemple #3
0
 private String GetMailBody(Document body, Home currentHome)
 {
     return(DocumentUtils.GetStringFromStream(DocumentUtils.GetDocumentStream((bool)body.IsPrivate, (string)body.Url, (string)currentHome.EncryptionPassword)));
 }