private void _updateClan(stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq type, string jsonIn) { DataTable dt1 = null, dt2 = null; CoCAPI.CoCMediaDownload md = null; int[] intSeason = stCoCAPI.CoCAPI.CoCSeason.GetSeasonDateInt(); try { dt1 = stSqlite.SqliteConvertExtension.JsonToDataTable <ClanInfo>(jsonIn, true, false); if ((dt1 == null) || (dt1.Rows.Count == 0)) { stCore.LogException.Error( string.Format( Properties.Resources.DataTableEmptyIn, typeof(ClanInfo).Name ), this._parent._ilog ); return; } dt2 = this._parent.dbMgr.Query(Properties.Settings.Default.DBSysUpdateClanInfo); if (dt2 == null) { dt2 = SqliteConvertExtension.MapToDataTable <ClanInfo>(); } #if DEBUG_CLAN else { if (dt2.Rows.Count > 0) { dt2.DataTableToPrint(); } } #endif foreach (DataRow row in dt1.Rows) { DataRow dr = dt2.AsEnumerable() .Where(r => r.Field <string>("tag") .Equals(row.Field <string>("tag"))) .FirstOrDefault(); if (dr == null) { dr = dt2.NewRow(); this._setDataTableRow(ref dr, row, dt1.Columns); dr["dtup"] = DateTime.Now; dt2.Rows.Add(dr); } else { this._setDataTableRow(ref dr, row, dt1.Columns, "tag"); dr["dtup"] = DateTime.Now; } } dt1.Clear(); if (this._parent._cocNotifier != null) { this._parent.NotifyEvent(type, dt2); } if (!this._parent.dbMgr.Update(Properties.Settings.Default.DBSysUpdateClanInfo, dt2)) { throw new ArgumentException(typeof(ClanMember).Name); } md = new CoCAPI.CoCMediaDownload(this._ccl, this._parent.RootPath, this._parent); md.Download(CoCEnum.CoCFmtReq.Clan, dt2); #if DEBUG_CLAN dt2.DataTableToPrint(); #endif dt2.Clear(); } catch (Exception e) { #if DEBUG_CLAN stConsole.WriteHeader(e.ToString()); throw e; #else stCore.LogException.Error(e, this._parent._ilog); return; #endif } finally { if (md != null) { md.Dispose(); } } }
private void _updateWarlog(stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq type, string jsonIn) { DataTable dt1 = null, dt2 = null; string query = string.Format( Properties.Settings.Default.DBSysUpdateSelect, typeof(WarLog).Name ); CoCAPI.CoCMediaDownload md = null; try { dt1 = stSqlite.SqliteConvertExtension.JsonToDataTable <WarLog>(jsonIn, true, false); if ((dt1 == null) || (dt1.Rows.Count == 0)) { stCore.LogException.Error( string.Format( Properties.Resources.DataTableEmptyIn, typeof(WarLog).Name ), this._parent._ilog ); return; } dt2 = this._parent.dbMgr.Query(query); if (dt2 == null) { dt2 = SqliteConvertExtension.MapToDataTable <WarLog>(); } #if DEBUG_WARLOG else { if (dt2.Rows.Count > 0) { dt2.DataTableToPrint(); } } #endif foreach (DataRow row in dt1.Rows) { DataRow dr = dt2.AsEnumerable() .Where(r => r.Field <DateTime>("dtend").ToString() .Equals(row.Field <string>("dtend"))) .FirstOrDefault(); if (dr == null) { dr = dt2.NewRow(); this._setDataTableRow(ref dr, row, dt1.Columns, "dtend"); dr["dtend"] = stCoCAPI.CoCAPI.CoCDataUtils.FieldConvertDateTime((string)row["dtend"]); dr["cdestruct"] = CoCDataUtils.DestructionWar((double)row["cdestruct"]); dr["opdestruct"] = CoCDataUtils.DestructionWar((double)row["opdestruct"]); dt2.Rows.Add(dr); } } dt1.Clear(); if (this._parent._cocNotifier != null) { this._parent.NotifyEvent(type, dt2); } if (!this._parent.dbMgr.Update(query, dt2)) { throw new ArgumentException(typeof(WarLog).Name); } md = new CoCAPI.CoCMediaDownload(this._ccl, this._parent.RootPath, this._parent); md.Download(CoCEnum.CoCFmtReq.Warlog, dt2); #if DEBUG_WARLOG dt2.DataTableToPrint(); #endif dt2.Clear(); } catch (Exception e) { #if DEBUG_WARLOG stConsole.WriteHeader(e.ToString()); throw e; #else stCore.LogException.Error(e, this._parent._ilog); return; #endif } finally { if (md != null) { md.Dispose(); } } }
private void _updateMember(stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq type, string jsonIn) { DataTable dt1 = null, dt2 = null; int[] intSeason = stCoCAPI.CoCAPI.CoCSeason.GetSeasonDateInt(); try { dt1 = stSqlite.SqliteConvertExtension.JsonToDataTable <ClanMember>(jsonIn, true, false); if ((dt1 == null) || (dt1.Rows.Count == 0)) { stCore.LogException.Error( string.Format( Properties.Resources.DataTableEmptyIn, typeof(ClanMember).Name ), this._parent._ilog ); return; } dt2 = this._parent.dbMgr.Query(Properties.Settings.Default.DBSysUpdateMembers); if (dt2 == null) { dt2 = SqliteConvertExtension.MapToDataTable <ClanMember>(); } #if DEBUG_MEMBERS else { if (dt2.Rows.Count > 0) { dt2.DataTableToPrint(); } } #endif bool isNewTable = ((dt2.Rows.Count > 0) ? false : true); if (!isNewTable) { dt2.AsEnumerable().Where(dr => Convert.ToInt32(dr["status"]) > 0) .Select(dri => dri["status"] = 2) .ToList(); } foreach (DataRow row in dt1.Rows) { DataRow dr = dt2.AsEnumerable() .Where(r => r.Field <string>("tag") .Equals(row.Field <string>("tag"))) .FirstOrDefault(); double ratio = CoCDataUtils.DonationsRatio((int)row["send"], (int)row["receive"]); if (dr == null) { dr = dt2.NewRow(); this._setDataTableRow(ref dr, row, dt1.Columns); dr["status"] = 1; dr["ratio"] = ratio; dr["season"] = intSeason[1]; dr["year"] = intSeason[0]; dr["dtin"] = DateTime.Now; dr["note"] = ""; dt2.Rows.Add(dr); } else { this._setDataTableRow(ref dr, row, dt1.Columns, "tag"); dr["status"] = 1; dr["ratio"] = ratio; } } dt1.Clear(); if (!isNewTable) { dt2.AsEnumerable().Where(r => Convert.ToInt32(r["status"]) == 2) .Select(dr => { dr["status"] = 0; dr["dtout"] = DateTime.Now; return(dr); }).ToList(); } if (this._parent._cocNotifier != null) { this._parent.NotifyEvent(type, dt2); } if (!this._parent.dbMgr.Update(Properties.Settings.Default.DBSysUpdateMembers, dt2)) { throw new ArgumentException(typeof(ClanMember).Name); } #if DEBUG_MEMBERS dt2.DataTableToPrint(); #endif dt2.Clear(); } catch (Exception e) { #if DEBUG_MEMBERS stConsole.WriteHeader(e.ToString()); throw e; #else stCore.LogException.Error(e, this._parent._ilog); return; #endif } }