コード例 #1
0
ファイル: GraphParser.cs プロジェクト: jlkjxyshangli/rrd4net
        public RrdGraphDef CreateGraphDef()
        {
            // OPTIONS

            // START, END
            string startTimeValue = getOptionValue("s", "start", DEFAULT_START);
            string endTimeValue   = getOptionValue("e", "end", DEFAULT_END);

            long[] times = Util.getTimestamps(startTimeValue, endTimeValue);// GetTime("s", "start");
            long   t1    = Util.getTimestamp();
            long   t2    = Util.getTimestamp(DateTime.Now.AddSeconds(-10));

//         long endTime = GetTime("e", "end");

            gdef.setTimeSpan(times[0], times[1]);
            parseXGrid(getOptionValue("x", "x-grid"));
            parseYGrid(getOptionValue("y", "y-grid"));
            gdef.setAltYGrid(getBooleanOption("Y", "alt-y-grid"));
            gdef.setNoMinorGrid(getBooleanOption(null, "no-minor"));
            gdef.setAltYMrtg(getBooleanOption("R", "alt-y-mrtg"));
            gdef.setAltAutoscale(getBooleanOption("A", "alt-autoscale"));
            gdef.setAltAutoscaleMax(getBooleanOption("M", "alt-autoscale-max"));
            String opt = getOptionValue("X", "units-exponent");

            if (opt != null)
            {
                gdef.setUnitsExponent(int.Parse(opt));
            }

            opt = getOptionValue("L", "units-length");
            if (opt != null)
            {
                gdef.setUnitsLength(int.Parse(opt));
            }

            opt = getOptionValue("v", "vertical-label");
            if (opt != null)
            {
                gdef.setVerticalLabel(opt);
            }

            opt = getOptionValue("w", "width");
            if (opt != null)
            {
                gdef.setWidth(int.Parse(opt));
            }
            opt = getOptionValue("h", "height");
            if (opt != null)
            {
                gdef.setHeight(int.Parse(opt));
            }
            gdef.setInterlaced(getBooleanOption("i", "interlaced"));
            opt = getOptionValue("f", "imginfo");
            if (opt != null)
            {
                gdef.setImageInfo(opt);
            }
            opt = getOptionValue("a", "imgformat");
            if (opt != null)
            {
                gdef.setImageFormat(opt);
            }
            opt = getOptionValue("B", "background");
            if (opt != null)
            {
                gdef.setBackgroundImage(opt);
            }
            opt = getOptionValue("O", "overlay");
            if (opt != null)
            {
                gdef.setOverlayImage(opt);
            }
            opt = getOptionValue("U", "unit");
            if (opt != null)
            {
                gdef.setUnit(opt);
            }
            gdef.setLazy(getBooleanOption("z", "lazy"));
            opt = getOptionValue("u", "upper-limit");
            if (opt != null)
            {
                gdef.setMaxValue(double.Parse(opt));
            }
            opt = getOptionValue("l", "lower-limit");
            if (opt != null)
            {
                gdef.setMinValue(double.Parse(opt));
            }
            gdef.setRigid(getBooleanOption("r", "rigid"));
            opt = getOptionValue("b", "base");
            if (opt != null)
            {
                gdef.setBase(double.Parse(opt));
            }

            gdef.setLogarithmic(getBooleanOption("o", "logarithmic"));
            parseColors(getMultipleOptionValues("c", "color"));
            gdef.setNoLegend(getBooleanOption("g", "no-legend"));
            gdef.setOnlyGraph(getBooleanOption("j", "only-graph"));
            gdef.setForceRulesLegend(getBooleanOption("F", "force-rules-legend"));
            opt = getOptionValue("t", "title");
            if (opt != null)
            {
                gdef.setTitle(opt);
            }

            opt = getOptionValue("S", "step");
            if (opt != null)
            {
                gdef.setStep(long.Parse(opt));
            }

            // NON-OPTIONS

            String[] words = getRemainingWords();
            // the first word must be a filename
            if (words.Length < 1)
            {
                throw new ArgumentException("Image filename must be specified");
            }
            gdef.setFilename(words[0]);
            // parse remaining words, in no particular order
            for (int i = 1; i < words.Length; i++)
            {
                if (words[i].StartsWith("DEF:"))
                {
                    parseDef(words[i]);
                }
                else if (words[i].StartsWith("CDEF:"))
                {
                    parseCDef(words[i]);
                }
                else if (words[i].StartsWith("SDEF:") ||
                         words[i].StartsWith("VDEF:"))
                {
                    parseSDef(words[i]);
                }
                else if (words[i].StartsWith("PRINT:"))
                {
                    parsePrint(words[i]);
                }
                else if (words[i].StartsWith("GPRINT:"))
                {
                    parseGPrint(words[i]);
                }
                else if (words[i].StartsWith("COMMENT:"))
                {
                    parseComment(words[i]);
                }
                else if (words[i].StartsWith("HRULE:"))
                {
                    parseHRule(words[i]);
                }
                else if (words[i].StartsWith("VRULE:"))
                {
                    parseVRule(words[i]);
                }
                else if (words[i].StartsWith("LINE1:") || words[i].StartsWith("LINE2:") || words[i].StartsWith("LINE3:"))
                {
                    parseLine(words[i]);
                }
                else if (words[i].StartsWith("AREA:"))
                {
                    parseArea(words[i]);
                }
                else if (words[i].StartsWith("STACK:"))
                {
                    parseStack(words[i]);
                }
                else if (words[i].StartsWith("SHIFT:"))
                {
                    ParseShift(words[i]);
                }
                else
                {
                    throw new ArgumentException("Unexpected GRAPH token encountered: " + words[i]);
                }
            }
            // create diagram finally
            return(gdef);

            //RrdGraphInfo info = new RrdGraph(gdef).getRrdGraphInfo();
            //if (info.getFilename().CompareTo(RrdGraphConstants.IN_MEMORY_IMAGE) == 0)
            //{
            //   //println(new String(info.getBytes()));
            //}
            //else
            //{
            //   //println(info.getWidth() + "x" + info.getHeight());
            //   //String[] plines = info.getPrintLines();
            //   //   foreach (String pline in plines) {
            //   //       println(pline);
            //   //   }
            //   //if(info.getImgInfo() != null && info.getImgInfo().Length() > 0) {
            //   //   println(info.getImgInfo());
            //}
            //return info;
        }