Exemple #1
0
        public static ImageOptimizationResponse ConvertToResponse(this SmushItResponse smushItResponse)
        {
            if (smushItResponse == null)
             {
                 return new ImageOptimizationResponse();
             }

             var webClient = new WebClient();

             var imageOptimizationResponse = new ImageOptimizationResponse
                                                 {
                                                     OriginalImageUrl = smushItResponse.Src,
                                                     OriginalImageSize = smushItResponse.Src_Size,
                                                     PercentSaved = smushItResponse.Percent,
                                                     OptimizedImageSize = smushItResponse.Dest_Size,
                                                     ErrorMessage = smushItResponse.Error
                                                 };

             if (!string.IsNullOrEmpty(smushItResponse.Dest))
             {
                 imageOptimizationResponse.OptimizedImage = webClient.DownloadData(smushItResponse.Dest);
                 imageOptimizationResponse.Successful = true;
             }

             return imageOptimizationResponse;
        }
        private Identity AddLogEntry(ImageOptimizationResponse imageOptimizationResponse, ImageData imageData)
        {
            ImageLogEntry logEntry = this._imageLogRepository.GetLogEntry(imageOptimizationResponse.OriginalImageUrl) ?? new ImageLogEntry();

            logEntry.ContentGuid = imageData.ContentGuid;
            logEntry.OriginalSize = imageOptimizationResponse.OriginalImageSize;
            logEntry.OptimizedSize = imageOptimizationResponse.OptimizedImageSize;
            logEntry.PercentSaved = imageOptimizationResponse.PercentSaved;
            logEntry.ImageUrl = imageOptimizationResponse.OriginalImageUrl;

            return this._imageLogRepository.Save(logEntry);
        }
        private Identity AddLogEntry(ImageOptimizationResponse imageOptimizationResponse, string virtualPath)
        {
            ImageLogEntry logEntry = this._imageLogRepository.GetLogEntry(imageOptimizationResponse.OriginalImageUrl) ?? new ImageLogEntry();

            logEntry.VirtualPath = virtualPath;
            logEntry.OriginalSize = imageOptimizationResponse.OriginalImageSize;
            logEntry.OptimizedSize = imageOptimizationResponse.OptimizedImageSize;
            logEntry.PercentSaved = imageOptimizationResponse.PercentSaved;
            logEntry.ImageUrl = imageOptimizationResponse.OriginalImageUrl;

            return this._imageLogRepository.Save(logEntry);
        }