Example #1
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:
                    string fname = _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);
        }
Example #2
0
        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();
            }
        }
        List<EmbeddedImage> _Items; // list of EmbeddedImage

        #endregion Fields

        #region Constructors

        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();
        }