示例#1
0
        public byte[] GetImage(Size size)
        {
            //TODO: Externalize the count
            Dictionary <string, string> data = _accountDao.GetMostActiveUsers(5);


            List <string> dataArray  = new List <string>();
            List <string> labelArray = new List <string>();

            dataArray.AddRange(data.Values);
            labelArray.AddRange(data.Keys);

            BarGraph c = new BarGraph(Color.White);

            c.VerticalTickCount = 2;
            c.ShowLegend        = false;
            c.ShowData          = false;
            c.Height            = size.Height;
            c.Width             = size.Width;
            c.TopBuffer         = 10;
            c.BottomBuffer      = 20;
            c.FontColor         = Color.Black;
            c.CollectDataPoints(labelArray.ToArray(), dataArray.ToArray());

            Bitmap image = c.Draw();
            //TODO: Externalize the temp filepath or do it in memory
            string tempFileName = Path.GetTempFileName();

            image.Save(tempFileName);

            return(File.ReadAllBytes(tempFileName));
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // Set return type to png image format
            Response.ContentType = "image/png";

            string xValues, yValues;

            // Get input parameters from query string
            xValues = Request.QueryString["xValues"];
            yValues = Request.QueryString["yValues"];

            if (xValues != null && yValues != null)
            {
                Bitmap       bmp;
                MemoryStream memStream = new MemoryStream();
                BarGraph     bar       = new BarGraph(Color.White);

                // Set bar color for 7 days
                for (int i = 0; i < 7; i++)
                {
                    bar.SetColor(i, Color.Sienna);
                }

                // Graph settings
                bar.VerticalTickCount = 2;
                bar.ShowLegend        = false;
                bar.ShowData          = true;
                bar.Height            = 119;
                bar.Width             = 195;
                bar.TopBuffer         = 5;
                bar.BottomBuffer      = 15;
                bar.FontColor         = Color.Gray;

                bar.CollectDataPoints(xValues.Split("|".ToCharArray()), yValues.Split("|".ToCharArray()));
                bmp = bar.Draw();

                // Render BitMap Stream Back To Client
                bmp.Save(memStream, ImageFormat.Png);
                memStream.WriteTo(Response.OutputStream);
            }
        }
示例#3
0
        public override void Draw(GameTime gameTime)
        {
            if (!Game1.displayHUD || !Game1.debugMode)
            {
                return;
            }
            if (gameTime.ElapsedGameTime.TotalSeconds > 0.0)
            {
                _fps  = 1.0 / gameTime.ElapsedGameTime.TotalSeconds;
                _mspf = gameTime.ElapsedGameTime.TotalSeconds * 1000.0;
            }
            if (gameTime.IsRunningSlowly)
            {
                _runningSlowly = true;
            }
            if (_font == null)
            {
                return;
            }
            _spriteBatch.Begin();
            _drawX = XOffset;
            _drawY = YOffset;
            StringBuilder sb = _stringBuilder;

            Utility.makeSafe(ref _drawX, ref _drawY, 0, 0);
            int   collection = GC.CollectionCount(0);
            float memory     = (float)GC.GetTotalMemory(forceFullCollection: false) / 1048576f;

            if (_lastCollection != collection)
            {
                _lastCollection = collection;
                _lastBaseMB     = memory;
            }
            float diff = memory - _lastBaseMB;

            sb.AppendFormatEx("FPS: {0,3}   GC: {1,3}   {2:0.00}MB   +{3:0.00}MB", (int)Math.Round(_fps), _lastCollection % 1000, _lastBaseMB, diff);
            Color col = Color.Yellow;

            if (_runningSlowly)
            {
                sb.Append("   [IsRunningSlowly]");
                _runningSlowly = false;
                col            = Color.Red;
            }
            DrawLine(col, sb, _drawX);
            if (Game1.IsMultiplayer)
            {
                col = Color.Yellow;
                if (Game1.IsServer)
                {
                    foreach (KeyValuePair <long, Farmer> farmer in Game1.otherFarmers)
                    {
                        sb.AppendFormat("Ping({0}): {1:0.0}ms", farmer.Value.Name, Game1.server.getPingToClient(farmer.Key));
                        DrawLine(col, sb, _drawX);
                    }
                }
                else
                {
                    sb.AppendFormat("Ping: {0:0.0}ms", Game1.client.GetPingToHost());
                    DrawLine(col, sb, _drawX);
                }
            }
            if (bandwidthMonitor != null && bandwidthMonitor.LogBandwidth)
            {
                sb.AppendFormat("Up - b/s: {0}  Avg b/s: {1}", (int)bandwidthMonitor.BandwidthLogger.BitsUpPerSecond, (int)bandwidthMonitor.BandwidthLogger.AvgBitsUpPerSecond);
                DrawLine(col, sb, _drawX);
                sb.AppendFormat("Down - b/s: {0}  Avg b/s: {1}", (int)bandwidthMonitor.BandwidthLogger.BitsDownPerSecond, (int)bandwidthMonitor.BandwidthLogger.AvgBitsDownPerSecond);
                DrawLine(col, sb, _drawX);
                sb.AppendFormat("Total MB Up: {0:0.00}  Total MB Down: {1:0.00}  Total Seconds: {2:0.00}", (float)bandwidthMonitor.BandwidthLogger.TotalBitsUp / 8f / 1000f / 1000f, (float)bandwidthMonitor.BandwidthLogger.TotalBitsDown / 8f / 1000f / 1000f, (float)bandwidthMonitor.BandwidthLogger.TotalMs / 1000f);
                DrawLine(col, sb, _drawX);
                if (bandwidthUpGraph != null && bandwidthDownGraph != null)
                {
                    bandwidthUpGraph.Draw(_spriteBatch);
                    bandwidthDownGraph.Draw(_spriteBatch);
                }
            }
            _spriteBatch.End();
        }
示例#4
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        private void Page_Load(object sender, EventArgs e)
        {
            // This is a quick check for referrer server name against host server
            // For best security practice in a deployed application, an authenticating mechanism should be in placed.
            // Image should only be rendered for authenticated users only.

            // set return type to png image format
            Response.ContentType = "image/png";

            string xValues, yValues, chartType, print;
            bool   boolPrint;

            // Get input parameters from query string
            chartType = Request.QueryString["chartType"];
            xValues   = Request.QueryString["xValues"];
            yValues   = Request.QueryString["yValues"];
            print     = Request.QueryString["Print"];

            if (chartType == null)
            {
                chartType = string.Empty;
            }

            // check for printing option
            if (print == null)
            {
                boolPrint = false;
            }
            else
            {
                try
                {
                    boolPrint = Convert.ToBoolean(print);
                }
                catch
                {
                    boolPrint = false;
                }
            }

            if (xValues != null && yValues != null)
            {
                Color bgColor;

                if (boolPrint)
                {
                    bgColor = Color.White;
                }
                else
                {
                    bgColor = Color.White;
                }

                Bitmap       StockBitMap;
                MemoryStream memStream = new MemoryStream();

                switch (chartType)
                {
                case "bar":
                    BarGraph bar = new BarGraph(bgColor);

                    bar.VerticalLabel     = string.Empty;
                    bar.VerticalTickCount = 5;
                    bar.ShowLegend        = false;
                    bar.ShowData          = false;
                    bar.Height            = 400;
                    bar.Width             = 700;

                    bar.CollectDataPoints(xValues.Split("|".ToCharArray()), yValues.Split("|".ToCharArray()));
                    StockBitMap = bar.Draw();
                    break;

                default:
                    PieChart pc = new PieChart(bgColor);

                    pc.CollectDataPoints(xValues.Split("|".ToCharArray()), yValues.Split("|".ToCharArray()));

                    StockBitMap = pc.Draw();

                    break;
                }

                // Render BitMap Stream Back To Client
                StockBitMap.Save(memStream, ImageFormat.Png);
                memStream.WriteTo(Response.OutputStream);
            }
        }