Пример #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
        internal Chart(HttpContextBase httpContext, VirtualPathProvider virtualPathProvider, int width, int height,
                       string theme = null, string themePath = null)
        {
            Debug.Assert(httpContext != null);

            if (width < 0)
            {
                throw new ArgumentOutOfRangeException("width", String.Format(CultureInfo.CurrentCulture,
                                                                             CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
            }
            if (height < 0)
            {
                throw new ArgumentOutOfRangeException("height", String.Format(CultureInfo.CurrentCulture,
                                                                              CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
            }

            _httpContext         = httpContext;
            _virtualPathProvider = virtualPathProvider;
            _width  = width;
            _height = height;
            _theme  = theme;

            // path must be app-relative in case chart is rendered from handler in different directory
            if (!String.IsNullOrEmpty(themePath))
            {
                _themePath = VirtualPathUtil.ResolvePath(TemplateStack.GetCurrentTemplate(httpContext), httpContext, themePath);
                if (!_virtualPathProvider.FileExists(_themePath))
                {
                    throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, HelpersResources.Chart_ThemeFileNotFound, _themePath), "themePath");
                }
            }
        }
Пример #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
        /// <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);
        }
Пример #5
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);
        }
Пример #6
0
        internal Chart(HttpContextBase httpContext, Func <VirtualPathProvider> virtualPathProviderFunc,
                       int width, int height, string theme = null, string themePath = null)
        {
            Contract.Assert(httpContext != null);
            Contract.Assert(virtualPathProviderFunc != null);

            // HostingEnvironment.VirtualPathProvider never null in running host but may change at any time.
            Contract.Assert(virtualPathProviderFunc() != null);

            if (width < 0)
            {
                throw new ArgumentOutOfRangeException("width", String.Format(
                                                          CultureInfo.CurrentCulture,
                                                          CommonResources.Argument_Must_Be_GreaterThanOrEqualTo,
                                                          0));
            }
            if (height < 0)
            {
                throw new ArgumentOutOfRangeException("height", String.Format(
                                                          CultureInfo.CurrentCulture,
                                                          CommonResources.Argument_Must_Be_GreaterThanOrEqualTo,
                                                          0));
            }

            _httpContext             = httpContext;
            _virtualPathProviderFunc = virtualPathProviderFunc;
            _width  = width;
            _height = height;
            _theme  = theme;

            // path must be app-relative in case chart is rendered from handler in different directory
            if (!String.IsNullOrEmpty(themePath))
            {
                _themePath = VirtualPathUtil.ResolvePath(TemplateStack.GetCurrentTemplate(httpContext), httpContext, themePath);
                if (!virtualPathProviderFunc().FileExists(_themePath))
                {
                    throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, HelpersResources.Chart_ThemeFileNotFound, _themePath), "themePath");
                }
            }
        }