Example #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);
            }
        }
Example #2
0
        private void ImageCompressAndThumbnail(String pathImage)
        {
            Image image = Image.FromFile(pathImage);

            foreach (ImageFormat format in ImagesFormats)
            {
                if (image.Height > format.Height || image.Width > format.Width)
                {
                    using (Image newQualityImage = DocumentUtils.ResizeImage(image, format.Width, format.Height))
                        newQualityImage.Save(DocumentUtils.GetNewPathFileName(pathImage, format.Name));
                }
            }
            image.Dispose();
        }
Example #3
0
 private void EncryptFileOnUpload(String pathFile, String encryptionKey, Boolean isImage)
 {
     AES256.EncryptFile(pathFile, encryptionKey);
     if (isImage)
     {
         foreach (ImageFormat format in ImagesFormats)
         {
             String pathFileWithExtension = DocumentUtils.GetNewPathFileName(pathFile, format.Name);
             if (File.Exists(pathFileWithExtension))
             {
                 AES256.EncryptFile(pathFileWithExtension, encryptionKey);
             }
         }
     }
 }