public bool mysql_init() { string guid = Guid.NewGuid().ToString(); lblLabelStatus.Text = "Service connecting..."; st = new Settings(); mysqlClient = new MySqlClient( st.db_host, st.db_port, st.db_username, st.db_password, st.db_database ); bool is_true = mysqlClient.Test_Connection(); if (!is_true) { Console.WriteLine("Service connection is incorrect."); lblLabelStatus.Text = "Service connection is incorrect."; return(false); } Console.WriteLine("Service connection is good."); lblLabelStatus.Text = "Service Looks Good."; mysqlQuery = new MySqlQuery(mysqlClient); myRequest = new Request(mysqlClient, st.api_webhook, st.api_access_token); myRequest.Status_Event += new Request.StatusEventHandler(Status_Logs); myRequest.Start(); return(true); }
public bool mysql_init() { st = new Settings(); mysqlClient = new MySqlClient( st.db_host, st.db_port, st.db_username, st.db_password, st.db_database ); bool is_true = mysqlClient.Test_Connection(); if (!is_true) { Console.WriteLine("MySQL connection is incorrect."); return(false); } Console.WriteLine("MySQL connection is good."); mysqlQuery = new MySqlQuery(mysqlClient); myRequest = new Request(mysqlClient, st.api_webhook, st.api_access_token); myRequest.Start(); return(true); }
public void ShouldGenerateMySqlLimitWithOffset() { var query = new MySqlQuery <User>() .Limit(19, 20); string actual = query.ToString(); Assert.Equal("LIMIT 19 OFFSET 20", actual); }
public void ShouldGenerateMySqlLimit() { var query = new MySqlQuery <User>() .Limit(75); string actual = query.ToString(); Assert.Equal("LIMIT 75", actual); }
public void ExecuteNonQuery(Sql sql, Connection db, Action<int> callback = null) { var query = new MySqlQuery { Sql = sql, Connection = db, CallbackNonQuery = callback, NonQuery = true }; lock (_syncroot) _queue.Enqueue(query); _workevent.Set(); }
public void Query(Sql sql, Connection db, Action <List <Dictionary <string, object> > > callback) { var query = new MySqlQuery { Sql = sql, Connection = db, Callback = callback }; lock (_syncroot) _queue.Enqueue(query); _workevent.Set(); }
public void ExecuteNonQuery(Sql sql, Connection db, Action <int> callback = null) { var query = new MySqlQuery { Sql = sql, Connection = db, CallbackNonQuery = callback, NonQuery = true }; lock (_syncroot) _queue.Enqueue(query); _workevent.Set(); }
public static bool Send(Queued queued) { string dt = date_time_format(date_time_now()); string message = Encryption.Do(queued.message); string sql_string = "INSERT INTO ptxt_queued (Company_uid, UserId, UserIp, ToNumber, ToMessage, Status, updated_at, created_at) VALUES " + "(" + queued.company_uid + ", '" + queued.mobile + "', 'N/A', '" + queued.mobile + "', '" + message + "', " + queued.status + ", DATE_FORMAT('" + dt + "','%Y-%m-%d %H:%i:%s'), " + "DATE_FORMAT('" + dt + "','%Y-%m-%d %H:%i:%s'));"; bool r = MySqlQuery.execute(sql_string); return(r); }
protected void Page_Load(object sender, EventArgs e) { //if (!IsPostBack) //{ if (Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")) >= Convert.ToDateTime("2015-11-6 17:00:00")) { Label1.Text = "投票已经结束"; } else { if (!string.IsNullOrEmpty(Request.QueryString["Id"])) { string userid = Request.QueryString["Id"]; string userIp = System.Web.HttpContext.Current.Request.UserHostAddress; string user_agent = MySqlQuery.getMd5Hash(Request.UserAgent); string session = Guid.NewGuid().ToString(); //Session.SessionID; DateTime time = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); if (!ValidateVote.VaildateVote(userid, userIp, session, Request.UserAgent)) { Label1.Text = "您的IP已经投过票了,或违反了其他投票规则"; } else { TabVoteItems vote = new TabVoteItems(); vote.user_agent = user_agent; vote.session = session; vote.Ip = userIp; vote.TabCanId = Convert.ToInt32(userid); vote.Votetime = time; if (query.Addvote(vote) > 0) { Label1.Text = "投票成功,计数和排名将在5分钟内更新"; query.Getcount(Convert.ToInt32(Request.QueryString["Id"])); } else { Label1.Text = "您的IP已经投过票了,或违反了其他投票规则"; } } } } }
private void sms_queue_command_init() { var sw = Stopwatch.StartNew(); List <Cache> requests = get_request(); foreach (Cache cache in requests) { CMDTransaction cmd = Json.Send(cache.from, cache.command); if (EnableReceiverOnly) { Logs(200, string.Format("Response: {0} -> {1}", cmd.account, cmd.message)); bool delete_cache = MySqlQuery.execute("DELETE FROM ptxt_cache WHERE Id = " + cache.Id + ";"); } else { Queued queue = new Queued() { company_uid = cache.company_uid, mobile = cmd.account, message = cmd.message, status = 1 }; bool save_notification = Notification.Send(queue); bool delete_cache = MySqlQuery.execute("DELETE FROM ptxt_cache WHERE Id = " + cache.Id + ";"); total_process++; sw.Stop(); decimal total_time_in_seconds = sw.ElapsedMilliseconds / 60; Console.WriteLine("Batch: {0} and Time Executed {1} seconds", total_process, total_time_in_seconds); Logs(200, string.Format("Batch: {0} and Time Executed {1} seconds", total_process, total_time_in_seconds)); } } //Logs(200, "Running...."); }
public Request(MySqlClient mysqlClient, string api_webhook, string api_access_token) { mysqlQuery = new MySqlQuery(mysqlClient); notification = new Notification(mysqlClient); thread_command = new Thread(process_sms_commmand); thread_sms = new Thread(process_sms); //thread_wallet = new Thread(monitor_wallet); Json.ApiUrl = api_webhook; Json.AccessToken = api_access_token; Die = false; KeepAlive = false; }
/// <summary> /// The worker thread method /// </summary> private void Worker() { while (_running || _queue.Count > 0) { MySqlQuery query = null; lock (_syncroot) { if (_queue.Count > 0) { query = _queue.Dequeue(); } else { foreach (Connection connection in _runningConnections) { if (connection != null && !connection.ConnectionPersistent) { CloseDb(connection); } } _runningConnections.Clear(); } } if (query != null) { query.Handle(); //if (!query.Handle()) continue; if (query.Connection != null) { _runningConnections.Add(query.Connection); } //lock (_syncroot) _queue.Dequeue(); } else if (_running) { _workevent.WaitOne(); } } }
public override void Initialize() { if (Enabled) { var config = Session.Config; var sql = new MySqlConnectionStringBuilder(); foreach (var pair in config[ConfigBlock]) { sql[pair.KeyName] = pair.Value; } var queries = MySqlQuery.Load(config["SqlQueries"]["queries"]); var mysqlDatabase = new MySqlDatabase(sql.ConnectionString); foreach (var query in queries) { mysqlDatabase.Queries[query.Name] = query; } Session.Database = mysqlDatabase; } }
private List <Cache> get_request() { List <Cache> caches = new List <Cache>(); try { DataTable dt = MySqlQuery.select_dt("SELECT * FROM ptxt_cache WHERE status_ = 1;"); if (dt != null) { DataRow[] datarows = dt.Select(); foreach (DataRow dr in datarows) { Cache cache = new Cache() { Id = Convert.ToInt64(dr["Id"]), company_uid = Convert.ToInt64(dr["company_uid_"]), from = dr["from_"].ToString(), command = dr["message_"].ToString(), status = Convert.ToInt16(dr["status_"]), updated_at = Convert.ToDateTime(dr["updated_at"]), created_at = Convert.ToDateTime(dr["created_at"]) }; caches.Add(cache); } } } catch (Exception ex) { error_message = "**Forced Stopped - Error**\r\n" + ex.Message; Logs(500, ex.Message); } return(caches); }
public Notification(MySqlClient mysqlClient) { mysqlQuery = new MySqlQuery(mysqlClient); }
public void Test_IamTooLazy() { MySqlQuery sqlite = new MySqlQuery(); Assert.Fail("I'm too lazy to write unit tests. I'll do it later. Really!"); }
public void Query(Sql sql, Connection db, Action<List<Dictionary<string, object>>> callback) { var query = new MySqlQuery { Sql = sql, Connection = db, Callback = callback }; lock (_syncroot) _queue.Enqueue(query); _workevent.Set(); }