예제 #1
0
        internal WebImage Save(HttpContextBase context, Action <string, byte[]> saveAction, string filePath, string imageFormat, bool forceWellKnownExtension)
        {
            filePath = filePath ?? FileName;
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath", CommonResources.Argument_Cannot_Be_Null_Or_Empty);
            }

            // GetBytes takes care of executing pending transformations.
            // todo: this could be made more efficient by avoiding cloning array
            // when format is same
            byte[] content = GetBytes(imageFormat);
            if (forceWellKnownExtension)
            {
                ImageFormat saveImageFormat;
                ImageFormat requestedImageFormat = String.IsNullOrEmpty(imageFormat) ? _initialFormat : GetImageFormat(imageFormat);
                var         extension            = Path.GetExtension(filePath).TrimStart('.');
                // TryFromStringToImageFormat accepts mime types and image names. For images supported by System.Drawing.Imaging, the image name maps to the extension.
                // Replace the extension with the current format in the following two events:
                //  * The extension format cannot be converted to a known format
                //  * The format does not match.
                if (!ConversionUtil.TryFromStringToImageFormat(extension, out saveImageFormat) || !saveImageFormat.Equals(requestedImageFormat))
                {
                    extension = requestedImageFormat.ToString().ToLowerInvariant();
                    filePath  = filePath + "." + extension;
                }
            }
            saveAction(VirtualPathUtil.MapPath(context, filePath), content);
            // Update the FileName since it may have changed whilst saving.
            FileName = filePath;
            return(this);
        }
예제 #2
0
        /// <summary>
        /// Saves the chart to the specified template file.
        /// </summary>
        /// <param name="path">XML template file path.</param>
        internal Chart SaveXml(HttpContextBase httpContext, string path)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "path");
            }

            ExecuteChartAction(c => {
                c.SaveXml(VirtualPathUtil.MapPath(httpContext, path));
            });
            return(this);
        }
예제 #3
0
        internal WebImage(HttpContextBase httpContext, Func <string, byte[]> readAction, string filePath)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "filePath");
            }

            _fileName      = filePath;
            _content       = readAction(VirtualPathUtil.MapPath(httpContext, filePath));
            _initialFormat = ValidateImageContent(_content, "filePath");
            _currentFormat = _initialFormat;
        }
예제 #4
0
        internal Chart Save(HttpContextBase httpContext, string path, string format)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentException(CommonResources.Argument_Cannot_Be_Null_Or_Empty, "path");
            }
            var imageFormat = ConvertStringToChartImageFormat(format);

            _path = VirtualPathUtil.MapPath(httpContext, path);
            ExecuteChartAction(c => {
                c.RenderType = DV.RenderType.ImageTag;
                c.SaveImage(FileName, imageFormat);
            });
            return(this);
        }