Exemple #1
0
 public void UpdateValue(CoCEnum.EventNotify id, DataRow dr)
 {
     this._data.Where(o => (o.Key == id)).Select(o =>
     {
         CoCRrdUtil.setData(id, dr, (stCoCRrdData)o.Value);
         return(o.Value);
     }).FirstOrDefault();
 }
Exemple #2
0
            private void UpdateRrdOne(CoCEnum.EventNotify id, stCoCRrdData data, long start)
            {
                string path1Db = CoCRrdUtil.getRrdDbPath(id, this._parent._rootpath);

                if ((string.IsNullOrWhiteSpace(path1Db)) || (!File.Exists(path1Db)))
                {
                    return;
                }
                RrdDb  rrdDb  = new RrdDb(path1Db);
                Sample sample = rrdDb.CreateSample(start);

                sample.SetValue("a", data.a);
                sample.Update();
                rrdDb.Close();
            }
Exemple #3
0
            public void UpdateRrd()
            {
                long start = CoCRrdUtil.getUnixTimeStamp(DateTime.Now);

                CoCEnum.RrdGrapPeriod[] enumGrapPeriod =
                    (CoCEnum.RrdGrapPeriod[])Enum.GetValues(typeof(CoCEnum.RrdGrapPeriod)).Cast <CoCEnum.RrdGrapPeriod>();

                foreach (var d in this._data)
                {
                    stCoCRrdData data = d.Value as stCoCRrdData;
                    this.UpdateRrdOne((CoCEnum.EventNotify)d.Key, data, start);

                    foreach (CoCEnum.RrdGrapPeriod pr in enumGrapPeriod)
                    {
                        this.UpdateImageOne((CoCEnum.EventNotify)d.Key, pr, this._parent._ci);
                    }
                    data.a = 0;
                }
            }
Exemple #4
0
            public CoCRrd(CoCAPI parent, int period = 0)
            {
                this._parent     = parent;
                this._startTime  = CoCRrdUtil.getUnixTimeStamp(DateTime.Now);
                this._periodTime = period;

                if (!Directory.Exists(CoCRrdUtil.getRrdDirImgPath(this._parent._rootpath, this._parent._assetspath)))
                {
                    try
                    {
                        Directory.CreateDirectory(CoCRrdUtil.getRrdDirImgPath(this._parent._rootpath, this._parent._assetspath));
                    }
                    catch (Exception e)
                    {
                        if (this._parent.isLogEnable)
                        {
                            this._parent._ilog.LogError(e.Message);
                        }
                        throw e;
                    }
                }
            }
Exemple #5
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);
                    }
                }
            }
Exemple #6
0
            private void CreateOne(CoCEnum.EventNotify id)
            {
                string path = CoCRrdUtil.getRrdDbPath(id, this._parent._rootpath);

                if ((string.IsNullOrWhiteSpace(path)) || (File.Exists(path)))
                {
                    return;
                }
                stCoCRrdData data = this._data.Where(o => (o.Key == id)).Select(o =>
                {
                    return((stCoCRrdData)o.Value);
                }).FirstOrDefault();

                if (data == null)
                {
                    return;
                }

                RrdDef rrdDef = null;
                RrdDb  rrdDb  = null;

                try
                {
                    rrdDef           = new RrdDef(path);
                    rrdDef.StartTime = this._startTime;
                    rrdDef.Step      = (this._periodTime * 60);

                    rrdDef.AddDatasource("a", data.type, (rrdDef.Step * 2), Double.NaN, Double.NaN);

                    rrdDef.AddArchive("AVERAGE", 0, 1, 1);
                    rrdDef.AddArchive("AVERAGE", 0, 1, RrdPeriod.Week(this._periodTime));
                    rrdDef.AddArchive("AVERAGE", 0, 1, RrdPeriod.Month(this._periodTime));
                    rrdDef.AddArchive("AVERAGE", 0, 1, RrdPeriod.Year(this._periodTime));

                    rrdDef.AddArchive("MIN", 0, 1, RrdPeriod.Day(this._periodTime));
                    rrdDef.AddArchive("MIN", 0, 1, RrdPeriod.Week(this._periodTime));
                    rrdDef.AddArchive("MIN", 0, 1, RrdPeriod.Month(this._periodTime));
                    rrdDef.AddArchive("MIN", 0, 1, RrdPeriod.Year(this._periodTime));

                    rrdDef.AddArchive("MAX", 0, 1, RrdPeriod.Day(this._periodTime));
                    rrdDef.AddArchive("MAX", 0, 1, RrdPeriod.Week(this._periodTime));
                    rrdDef.AddArchive("MAX", 0, 1, RrdPeriod.Month(this._periodTime));
                    rrdDef.AddArchive("MAX", 0, 1, RrdPeriod.Year(this._periodTime));

                    rrdDb = new RrdDb(rrdDef);
                }
                catch (Exception e)
                {
                    if (this._parent.isLogEnable)
                    {
                        this._parent._ilog.LogError(e.Message);
                    }
                }
                finally
                {
                    if (rrdDb != null)
                    {
                        rrdDb.Close();
                    }
                }
            }