public async ValueTask <Tokens[]> Selecttoken(SelectTokenMode Mode) { DataTable Table; Tokens[] ret; string cmdstr = @"SELECT user_id, token, token_secret FROM token NATURAL JOIN crawlprocess "; switch (Mode) { case SelectTokenMode.CurrentProcess: cmdstr += "WHERE pid = @pid;"; break; case SelectTokenMode.RestInStreamer: cmdstr += "WHERE rest_needed IS TRUE;"; break; case SelectTokenMode.All: cmdstr += ";"; break; } using (MySqlCommand cmd = new MySqlCommand(cmdstr)) { cmd.Parameters.Add("@pid", MySqlDbType.Int32).Value = Selfpid; Table = await SelectTable(cmd, IsolationLevel.ReadUncommitted).ConfigureAwait(false); } if (Table == null) { return(new Tokens[0]); } try { ret = new Tokens[Table.Rows.Count]; for (int i = 0; i < Table.Rows.Count; i++) { ret[i] = (Tokens.Create(config.token.ConsumerKey, config.token.ConsumerSecret, Table.Rows[i].Field <string>(1), Table.Rows[i].Field <string>(2), Table.Rows[i].Field <long>(0))); } return(ret); } finally { Table.Clear(); Table.Dispose(); } }
///<summary>いろいろ条件付きでTokenを取得する ///Token.UserIdはちゃんとセットされる</summary> public async Task <IEnumerable <UserStreamerSetting> > SelectUserStreamerSetting(SelectTokenMode Mode) { string cmdstr = @"SELECT user_id, token, token_secret, rest_my_tweet, last_status_id FROM token JOIN crawlprocess USING (user_id) "; switch (Mode) { case SelectTokenMode.CurrentProcess: cmdstr += "WHERE pid = @pid;"; break; case SelectTokenMode.All: cmdstr += ";"; break; } using (var cmd = new MySqlCommand(cmdstr)) { cmd.Parameters.Add("@pid", MySqlDbType.Int32).Value = Selfpid; var ret = new List <UserStreamerSetting>(); if (await ExecuteReader(cmd, (r) => { ret.Add(new UserStreamerSetting() { Token = Tokens.Create(config.token.ConsumerKey, config.token.ConsumerSecret, r.GetString(1), r.GetString(2), r.GetInt64(0)), rest_my_tweet = r.GetBoolean(3), last_status_id = r.GetInt64(4) }); }, IsolationLevel.ReadUncommitted).ConfigureAwait(false)) { return(ret.ToArray()); } else { return(Enumerable.Empty <UserStreamerSetting>()); } //一応全取得に成功しない限り返さない } }