Beispiel #1
0
 public static string getRrdFileImgPath(CoCEnum.EventNotify id, CoCEnum.RrdGrapPeriod pr, string path, string assetspath)
 {
     return(Path.Combine(
                path,
                assetspath,
                "images",
                "rrd",
                id.ToString() + "-" + pr.ToString() + ".png"
                ));
 }
Beispiel #2
0
            private void UpdateImageOne(CoCEnum.EventNotify id, CoCEnum.RrdGrapPeriod pr, CultureInfo ci)
            {
                string path1Db = String.Empty,
                       path2Db = String.Empty,
                       pathImg = String.Empty;

                switch (id)
                {
                case CoCEnum.EventNotify.MemberChangeDonationReceive:
                {
                    return;
                }

                case CoCEnum.EventNotify.ClanChangeWarWin:
                {
                    if (pr == CoCEnum.RrdGrapPeriod.Day)
                    {
                        return;
                    }
                    break;
                }

                case CoCEnum.EventNotify.MemberChangeDonationSend:
                {
                    path2Db = CoCRrdUtil.getRrdDbPath(CoCEnum.EventNotify.MemberChangeDonationReceive, this._parent._rootpath);
                    if ((string.IsNullOrWhiteSpace(path2Db)) || (!File.Exists(path2Db)))
                    {
                        return;
                    }
                    break;
                }
                }

                path1Db = CoCRrdUtil.getRrdDbPath(id, this._parent._rootpath);
                if ((string.IsNullOrWhiteSpace(path1Db)) || (!File.Exists(path1Db)))
                {
                    return;
                }
                pathImg = CoCRrdUtil.getRrdFileImgPath(id, pr, this._parent._rootpath, this._parent._assetspath);
                if (string.IsNullOrWhiteSpace(pathImg))
                {
                    return;
                }

                long     dtstart, dtend;
                TimeSpan tsoffset = TimeSpan.MinValue;

                switch (pr)
                {
                case CoCEnum.RrdGrapPeriod.Day:
                {
                    tsoffset = new TimeSpan(1, 0, 0, 0, 0);
                    break;
                }

                case CoCEnum.RrdGrapPeriod.Week:
                {
                    tsoffset = new TimeSpan(7, 0, 0, 0, 0);
                    break;
                }

                case CoCEnum.RrdGrapPeriod.Month:
                {
                    tsoffset = new TimeSpan(30, 0, 0, 0, 0);
                    break;
                }

                case CoCEnum.RrdGrapPeriod.Year:
                {
                    tsoffset = new TimeSpan(365, 0, 0, 0, 0);
                    break;
                }
                }

                dtstart = CoCRrdUtil.getUnixTimeStamp(DateTime.Now.Subtract(tsoffset));
                dtend   = CoCRrdUtil.getUnixTimeStamp(DateTime.Now);

                RrdGraphDef graphDef = null;

                try
                {
                    graphDef = new RrdGraphDef();
                    graphDef.SetTimePeriod(dtstart, dtend);
                    graphDef.ShowSignature = false;
                    graphDef.AntiAliasing  = true;
                    graphDef.SetImageBorder(Color.White, 0);
                    graphDef.VerticalLabel = (string)Properties.Resources.ResourceManager.GetString("fmtRrd" + id.ToString() + "Vlabel", ci);

                    switch (id)
                    {
                    case CoCEnum.EventNotify.MemberChangeDonationSend:
                    {
                        graphDef.Title = string.Format(
                            "{0} / {1} ({2})",
                            (string)Properties.Resources.ResourceManager.GetString("fmtRrdMemberChangeDonationSendTitle", ci),
                            (string)Properties.Resources.ResourceManager.GetString("fmtRrdMemberChangeDonationReceiveTitle", ci),
                            (string)Properties.Resources.ResourceManager.GetString("RrdPeriodName" + pr.ToString(), ci)
                            );
                        graphDef.BackgroundResource = Properties.Resources.RrdBgMemberChangeDonationSend;
                        graphDef.Datasource("ida", path1Db, "a", "AVERAGE");
                        graphDef.Datasource("idb", path2Db, "a", "AVERAGE");
                        graphDef.Line("ida", SysDraw.Color.Lime, (string)Properties.Resources.ResourceManager.GetString("fmtRrdMemberChangeDonationSendTitle", ci), 4);
                        graphDef.Line("idb", SysDraw.Color.Red, (string)Properties.Resources.ResourceManager.GetString("fmtRrdMemberChangeDonationReceiveTitle", ci), 2);
                        graphDef.Gprint("ida", "MAX", (string)Properties.Resources.ResourceManager.GetString("fmtRrdMemberChangeDonationSendMax", ci));
                        //graphDef.Gprint("ida", "MIN", (string)Properties.Resources.ResourceManager.GetString("fmtRrdMemberChangeDonationSendMin", ci));
                        graphDef.Gprint("idb", "MAX", (string)Properties.Resources.ResourceManager.GetString("fmtRrdMemberChangeDonationReceiveMax", ci));
                        //graphDef.Gprint("idb", "MIN", (string)Properties.Resources.ResourceManager.GetString("fmtRrdMemberChangeDonationReceiveMin, ci"));
                        break;
                    }

                    case CoCEnum.EventNotify.ClanChangePoints:
                    {
                        graphDef.Title = string.Format(
                            "{0} ({1})",
                            (string)Properties.Resources.ResourceManager.GetString("fmtRrd" + id.ToString() + "Title", ci),
                            (string)Properties.Resources.ResourceManager.GetString("RrdPeriodName" + pr.ToString(), ci)
                            );
                        graphDef.BackgroundResource = Properties.Resources.RrdBgClanChangePoints;
                        graphDef.Datasource("ida", path1Db, "a", "AVERAGE");
                        graphDef.Line("ida", SysDraw.Color.Red, (string)Properties.Resources.ResourceManager.GetString("fmtRrd" + id.ToString() + "Title", ci), 2);
                        graphDef.Gprint("ida", "MAX", (string)Properties.Resources.ResourceManager.GetString("fmtRrd" + id.ToString() + "Max", ci));
                        graphDef.Gprint("ida", "MIN", (string)Properties.Resources.ResourceManager.GetString("fmtRrd" + id.ToString() + "Min", ci));
                        break;
                    }

                    case CoCEnum.EventNotify.ClanChangeWarWin:
                    {
                        graphDef.Title = string.Format(
                            "{0} ({1})",
                            (string)Properties.Resources.ResourceManager.GetString("fmtRrd" + id.ToString() + "Title", ci),
                            (string)Properties.Resources.ResourceManager.GetString("RrdPeriodName" + pr.ToString(), ci)
                            );
                        graphDef.BackgroundResource = Properties.Resources.RrdBgClanChangeWarWin;
                        graphDef.Datasource("ida", path1Db, "a", "AVERAGE");
                        graphDef.Line("ida", SysDraw.Color.Red, (string)Properties.Resources.ResourceManager.GetString("fmtRrd" + id.ToString() + "Title", ci), 2);
                        graphDef.Gprint("ida", "MAX", (string)Properties.Resources.ResourceManager.GetString("fmtRrd" + id.ToString() + "Max", ci));
                        graphDef.Gprint("ida", "MIN", (string)Properties.Resources.ResourceManager.GetString("fmtRrd" + id.ToString() + "Min", ci));
                        break;
                    }

                    default:
                    {
                        return;
                    }
                    }

                    RrdGraph graph = new RrdGraph(graphDef);
                    graph.SaveAsPNG(pathImg, 760, 200);
                }
                catch (Exception e)
                {
                    if (this._parent.isLogEnable)
                    {
                        this._parent._ilog.LogError(e.Message);
                    }
                }
            }