void IHttpHandler.ProcessRequest(HttpContext context)
        {
            int bookId = -1;

            if (context.Request["id"] != null)
            {
                int.TryParse(context.Request["id"], out bookId);
            }

            NDrawingDocument document = CreateDocument(bookId);
            NCanvas          canvas   = CreateCanvas(document);

            document.RefreshAllViews();
            canvas.DoLayout();

            MemoryStream ms = new MemoryStream();

            NPngImageFormat imageFormet = new NPngImageFormat();

            using (INImage image = CreateImage(document, canvas, canvas.Size, imageFormet))
            {
                image.SaveToStream(ms, imageFormet);
            }

            byte[] bytes = ms.GetBuffer();
            context.Response.ContentType = "image/png";
            context.Response.OutputStream.Write(bytes, 0, bytes.Length);
            context.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
        }
Exemple #2
0
        void IHttpHandler.ProcessRequest(HttpContext context)
        {
            int populationDataId;
            int dataPointId;

            if (context.Request["id"] == null)
            {
                return;
            }

            string[] tokens = context.Request["id"].Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
            if (tokens.Length != 2)
            {
                return;
            }

            if (!int.TryParse(tokens[0], out populationDataId))
            {
                return;
            }
            if (!int.TryParse(tokens[1], out dataPointId))
            {
                return;
            }

            NCustomToolsData.NData data = NCustomToolsData.Read();

            MemoryStream    ms          = new MemoryStream();
            NSize           chartSize   = new NSize(500, 200);
            NDocument       document    = CreateDocument(chartSize, data, populationDataId, dataPointId);
            NPngImageFormat imageFormat = new NPngImageFormat();

            using (INImage image = CreateImage(document, chartSize, imageFormat))
            {
                document.Refresh();
                image.SaveToStream(ms, imageFormat);
            }

            byte[] bytes = ms.GetBuffer();
            context.Response.ContentType = "image/png";
            context.Response.OutputStream.Write(bytes, 0, bytes.Length);
            context.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
        }