Exemple #1
0
            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();
                    }
                }
            }
Exemple #2
0
            private void _updateAllList <T>(stCoCAPI.CoCAPI.CoCEnum.CoCFmtReq type, string jsonIn) where T : class, new()
            {
                DataTable dt1 = null,
                          dt2 = null;
                string query  = string.Format(
                    @"SELECT * FROM {0}",
                    typeof(T).Name
                    );

                CoCAPI.CoCMediaDownload md = null;

                try
                {
                    dt1 = stSqlite.SqliteConvertExtension.JsonToDataTable <T>(jsonIn, true, false);
                    if ((dt1 == null) || (dt1.Rows.Count == 0))
                    {
                        stCore.LogException.Error(
                            string.Format(
                                Properties.Resources.DataTableEmptyIn,
                                typeof(T).Name
                                ),
                            this._parent._ilog
                            );
                        return;
                    }
                    dt2 = this._parent.dbMgr.Query(query);
                    if (dt2 == null)
                    {
                        dt2 = SqliteConvertExtension.MapToDataTable <T>();
                    }
                    foreach (DataRow row in dt1.Rows)
                    {
                        DataRow dr = dt2.AsEnumerable()
                                     .Where(r => (Convert.ToInt32(r["id"]) == Convert.ToInt32(row["id"])))
                                     .FirstOrDefault();

                        if (dr == null)
                        {
                            dr = dt2.NewRow();
                            this._setDataTableRow(ref dr, row, dt1.Columns);
                            dt2.Rows.Add(dr);
                        }
                        else
                        {
                            this._setDataTableRow(ref dr, row, dt1.Columns, "id");
                        }
                    }

                    dt1.Clear();

                    if (!this._parent.dbMgr.Update(query, dt2))
                    {
                        throw new ArgumentException(typeof(T).Name);
                    }

                    md = new CoCAPI.CoCMediaDownload(this._ccl, this._parent.RootPath, this._parent);
                    md.Download(type, dt2);

#if DEBUG_LIST
                    dt2.DataTableToPrint();
#endif
                    dt2.Clear();
                }
                catch (Exception e)
                {
#if DEBUG_LIST
                    stConsole.WriteHeader(e.ToString());
                    throw e;
#else
                    stCore.LogException.Error(e, this._parent._ilog);
                    return;
#endif
                }
                finally
                {
                    if (md != null)
                    {
                        md.Dispose();
                    }
                }
            }
Exemple #3
0
            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();
                    }
                }
            }