List <EmbeddedImage> _Items;                     // list of EmbeddedImage

        internal EmbeddedImages(ReportDefn r, ReportLink p, XmlNode xNode) : base(r, p)
        {
            _Items = new List <EmbeddedImage>();
            // Loop thru all the child nodes
            foreach (XmlNode xNodeLoop in xNode.ChildNodes)
            {
                if (xNodeLoop.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                if (xNodeLoop.Name == "EmbeddedImage")
                {
                    EmbeddedImage ei = new EmbeddedImage(r, this, xNodeLoop);
                    _Items.Add(ei);
                }
                else
                {
                    this.OwnerReport.rl.LogError(4, "Unknown Report element '" + xNodeLoop.Name + "' ignored.");
                }
            }
            if (_Items.Count == 0)
            {
                OwnerReport.rl.LogError(8, "For EmbeddedImages at least one EmbeddedImage is required.");
            }
            else
            {
                _Items.TrimExcess();
            }
        }
        Stream GetImageStream(Report rpt, Row row, out string mtype)
        {
            mtype = null;
            Stream strm = null;

            try
            {
                switch (this._Source)
                {
                case StyleBackgroundImageSourceEnum.Database:
                    if (_MIMEType == null)
                    {
                        return(null);
                    }
                    mtype = _MIMEType.EvaluateString(rpt, row);
                    object o = _Value.Evaluate(rpt, row);
                    strm = new MemoryStream((byte[])o);
                    break;

                case StyleBackgroundImageSourceEnum.Embedded:
                    string        name = _Value.EvaluateString(rpt, row);
                    EmbeddedImage ei   = (EmbeddedImage)OwnerReport.LUEmbeddedImages[name];
                    mtype = ei.MIMEType;
                    byte[] ba = Convert.FromBase64String(ei.ImageData);
                    strm = new MemoryStream(ba);
                    break;

                case StyleBackgroundImageSourceEnum.External:
                    string fname = _Value.EvaluateString(rpt, row);
                    mtype = Image.GetMimeType(fname);
                    if (fname.StartsWith("http:") ||
                        fname.StartsWith("file:") ||
                        fname.StartsWith("https:"))
                    {
                        WebRequest  wreq = WebRequest.Create(fname);
                        WebResponse wres = wreq.GetResponse();
                        strm = wres.GetResponseStream();
                    }
                    else
                    {
                        strm = new FileStream(fname, System.IO.FileMode.Open, FileAccess.Read);
                    }
                    break;

                default:
                    return(null);
                }
            }
            catch
            {
                if (strm != null)
                {
                    strm.Close();
                    strm = null;
                }
            }

            return(strm);
        }
Пример #3
0
        Stream GetImageStream(Report rpt, Row row, out string mtype)
        {
            mtype = null;
            Stream strm = null;

            try
            {
                switch (this.ImageSource)
                {
                case ImageSourceEnum.Database:
                    if (_MIMEType == null)
                    {
                        return(null);
                    }
                    mtype = _MIMEType.EvaluateString(rpt, row);
                    object o = _Value.Evaluate(rpt, row);
                    strm = new MemoryStream((byte[])o);
                    break;

                case ImageSourceEnum.Embedded:
                    string        name = _Value.EvaluateString(rpt, row);
                    EmbeddedImage ei   = (EmbeddedImage)OwnerReport.LUEmbeddedImages[name];
                    mtype = ei.MIMEType;
                    byte[] ba = Convert.FromBase64String(ei.ImageData);
                    strm = new MemoryStream(ba);
                    break;

                case ImageSourceEnum.External:
                    //Added Image URL from forum, User: solidstate http://www.fyireporting.com/forum/viewtopic.php?t=905
                    string fname = this.ImageUrl = _Value.EvaluateString(rpt, row);
                    mtype = GetMimeType(fname);
                    if (fname.StartsWith("http:") ||
                        fname.StartsWith("file:") ||
                        fname.StartsWith("https:"))
                    {
                        WebRequest  wreq = WebRequest.Create(fname);
                        WebResponse wres = wreq.GetResponse();
                        strm = wres.GetResponseStream();
                    }
                    else
                    {
                        strm = new FileStream(fname, System.IO.FileMode.Open, FileAccess.Read);
                    }
                    break;

                default:
                    return(null);
                }
            }
            catch (Exception e)
            {
                if (strm != null)
                {
                    strm.Close();
                    strm = null;
                }
                rpt.rl.LogError(4, string.Format("Unable to load image. {0}", e.Message));
            }

            return(strm);
        }