public static string getRrdDbPath(CoCEnum.EventNotify id, string path) { return(Path.Combine( path, id.ToString() + ".rrd" )); }
public static void setData(CoCEnum.EventNotify id, DataRow dr, stCoCRrdData data) { switch (id) { case CoCEnum.EventNotify.MemberChangeDonationSend: { data.a += ( dr.Field <Int64>("send", DataRowVersion.Current) - dr.Field <Int64>("send", DataRowVersion.Original) ); break; } case CoCEnum.EventNotify.MemberChangeDonationReceive: { data.a += ( dr.Field <Int64>("receive", DataRowVersion.Current) - dr.Field <Int64>("receive", DataRowVersion.Original) ); break; } case CoCEnum.EventNotify.ClanChangePoints: { data.a = dr.Field <Int64>("points", DataRowVersion.Current); break; } case CoCEnum.EventNotify.ClanChangeWarWin: { data.a = dr.Field <Int64>("warwin", DataRowVersion.Current); break; } } }
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(); }
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" )); }
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(); }
private void _EventToTable(CoCEnum.EventNotify evtype, string name, string field, DataRow row, bool isnew = false) { try { DataRow nrow = this._data.NewRow(); nrow[this.fieldName[0]] = evtype.ToString(); nrow[this.fieldName[1]] = Convert.ToString(row[name, DataRowVersion.Current], CultureInfo.InvariantCulture); nrow[this.fieldName[2]] = Convert.ToString(row["tag", DataRowVersion.Current], CultureInfo.InvariantCulture); nrow[this.fieldName[3]] = ((!isnew) ? Convert.ToString(row[field, DataRowVersion.Original], CultureInfo.InvariantCulture) : String.Empty ); nrow[this.fieldName[4]] = ((!isnew) ? Convert.ToString(row[field, DataRowVersion.Current], CultureInfo.InvariantCulture) : String.Empty ); nrow[this.fieldName[5]] = String.Empty; nrow[this.fieldName[6]] = String.Empty; nrow[this.fieldName[7]] = this._EventCalculateField(field, row, isnew); this._data.Rows.Add(nrow); if (!isnew) { this._parent._cocRrd.UpdateValue(evtype, row); } } #if DEBUG catch (Exception e) { if (this._parent.isLogEnable) { this._parent._ilog.LogError( string.Format( Properties.Resources.CoCNotifyProcessError, Properties.Resources.CoCNotifyAddDataTable, evtype.ToString(), e.Message ) ); } #else catch (Exception) { #endif } }
private void _EventToTable(CoCEnum.EventNotify evtype, string[] fields, DataRow row) { if (fields.Length == 0) { return; } try { DataRow nrow = this._data.NewRow(); nrow[this.fieldName[0]] = evtype.ToString(); for (int i = 0; ((i < fields.Length) && (i < (this.fieldName.Length - 1))); i++) { nrow[this.fieldName[(i + 1)]] = Convert.ToString(row[fields[i]], CultureInfo.InvariantCulture); } nrow[this.fieldName[7]] = ""; this._data.Rows.Add(nrow); } #if DEBUG catch (Exception e) { if (this._parent.isLogEnable) { this._parent._ilog.LogError( string.Format( Properties.Resources.CoCNotifyProcessError, Properties.Resources.CoCNotifyAddDataTable, evtype.ToString(), e.Message ) ); } #else catch (Exception) { #endif } }
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); } } }
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(); } } }