Beispiel #1
0
        public void getData <T>()
        {
            try
            {
                int           _count = 0;
                int           _page  = 1;
                string        _columns;
                StringBuilder _sb = new StringBuilder();

                List <JSONKeyValue <T> > _list = AppConfig.GetValues <T>(string.Format("data,{0}", this._item), string.Concat(this._database, ".json"));
                string[] _JSONPath             = new string[_list.Count];
                string[] _fields = new string[_list.Count];

                foreach (JSONKeyValue <T> _obj in _list)
                {
                    _sb.Append(_obj._key).Append(",");
                    _fields[_count]   = _obj._key;
                    _JSONPath[_count] = _obj._value.ToString();
                    _count++;
                }

                _count   = 0;
                _columns = _sb.ToString();

                Console.WriteLine(string.Format("writing {0} from {1} to database.........", this._item, this._database));

                do
                {
                    cJSON getData = new cJSON(AppConfig.GetString("url_domain", "", "config", string.Concat(this._database, ".json")),
                                              String.Format(AppConfig.GetString(this._item, "", "Config,request_url", string.Concat(this._database, ".json")), _page.ToString()),
                                              AppConfig.GetString("username", "", "config", string.Concat(this._database, ".json")), AppConfig.GetString("password", "", "config", string.Concat(this._database, ".json")));
                    DataTable dtOrganizations = getData.GetDataTable(_JSONPath, _fields);
                    if (dtOrganizations == null)
                    {
                        break;
                    }
                    _count = dtOrganizations.Rows.Count;
                    if (AppConfig.GetBool("multiThreading") == true)
                    {
                        foreach (DataRow drOrganizations in dtOrganizations.Rows)
                        {
                            int          _columnIndex = HelperClass.ColumnIndex(drOrganizations, "id");
                            objSQL       _params      = new objSQL(drOrganizations, string.Format("Select {1}imported,lastupdate,s3_flag from dbo.{2} where Id = {0}", drOrganizations[_columnIndex].ToString(), _columns, this._item), _fields);
                            WaitCallback wi           = new WaitCallback(new SQL.SQL()._work);
                            _th.add2queue(ref wi, _params);
                        }
                        while (_th.activeThreads() > curThreads)
                        {
                        }
                    }
                    else
                    {
                        foreach (DataRow drOrganizations in dtOrganizations.Rows)
                        {
                            int     _columnIndex = HelperClass.ColumnIndex(drOrganizations, "id");
                            objSQL  _params      = new objSQL(drOrganizations, string.Format("Select {1}imported,lastupdate,s3_flag from dbo.{2} where Id = {0}", drOrganizations[_columnIndex].ToString(), _columns, this._item), _fields);
                            SQL.SQL wi           = new SQL.SQL();
                            wi._work(_params);
                        }
                    }
                    _page++;
                } while (_count != 0);
            }
            catch (Exception ex)
            {
                string err = string.Format("{0}: {1}", MethodBase.GetCurrentMethod().Name, ex.ToString());
                Nlogger.Error(err);
            }
        }