Example #1
0
        public static mysql_results pre_program(string id)
        {
            cmd.CommandText = "SELECT * FROM `pre_program` WHERE `masterID` = " + id;
            cmd.CommandType = CommandType.Text;
            MySqlDataReader reader = cmd.ExecuteReader();

            mysql_todo[]  list = new mysql_todo[50];
            mysql_results res = new mysql_results();
            TimeSpan      ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
            double        unixTime = ts.TotalSeconds;
            int           i = 0, j = 0;

            res.result = false;
            while (reader.Read())
            {
                if (reader.GetString(2).Length > 2)
                {
                    list[i]     = new mysql_todo();
                    list[i].sql = "INSERT `log_current_session` SET `type`='cmd', `message`='" + reader.GetString(2) + "',`when`=" + (reader.GetInt32(1) + unixTime).ToString().Replace(',', '.') + ",`who_ID`=" + reader.GetUInt32(5);
                    res.result  = true;
                    i++;
                }
            }

            reader.Close();
            for (j = 0; j < i; j++)
            {
                QueryCommand(list[j].sql);
            }
            return(res);
        }
Example #2
0
        public static void check()
        {
            TimeSpan ts       = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
            double   unixTime = ts.TotalSeconds;

            mysql_results res    = new mysql_results();
            nxt_result    result = new nxt_result();

            //check mysql conntection
            if (mysql.connection.State == ConnectionState.Open || mysql.connection.State == ConnectionState.Connecting)
            {
                res = mysql.QueryCommand("SELECT `ID`,`message`,`when` FROM `log_current_session` WHERE `status`='' AND `when`< '" + unixTime.ToString().Replace(',', '.') + "' AND `when`> '" + (unixTime - 100).ToString().Replace(',', '.') + "' AND `type`='cmd' ORDER BY `when` ASC LIMIT 0,1");
                if (res.result)
                {
                    IrcBot.log += DateTime.Now + "checking(" + res.msg + ")...";
                    result      = NXT_ROVER_CONTROL.command_translation(res.msg);
                    if (result.result)
                    {
                        //true
                        cmd.CommandText = "UPDATE `log_current_session` SET `status`='" + result.value + "', `when`='" + unixTime.ToString().Replace(',', '.') + "' WHERE `ID`=" + res.ID;
                        cmd.CommandType = CommandType.Text;
                        MySqlDataReader reader = cmd.ExecuteReader();
                        reader.Close();
                        IrcBot.log += "succed\n";
                    }
                    else
                    {
                        //false
                        cmd.CommandText = "UPDATE `log_current_session` SET `status`='" + result.value + "' WHERE `ID`=" + res.ID;
                        cmd.CommandType = CommandType.Text;
                        MySqlDataReader reader = cmd.ExecuteReader();
                        reader.Close();
                        IrcBot.log += "faild\n";
                    }
                }
            }
            else
            {
                //make connecion
                IrcBot.log += "Mysql connection faild";
                mysql.connect();
            }
        }
Example #3
0
        public static nxt_result run_program_mysql(int name)
        {
            nxt_result    result       = new nxt_result();
            mysql_results result_mysql = new mysql_results();

            result_mysql = mysql.pre_program(Convert.ToString(name));

            if (result_mysql.result == true)
            {
                result.result = true;
                result.value  = "succed";
            }
            else
            {
                result.result = false;
                result.value  = "Faild";
            }
            return(result);
        }
Example #4
0
        public static mysql_results QueryCommand(string sql)
        {
            cmd.CommandText = sql;
            cmd.CommandType = CommandType.Text;

            MySqlDataReader reader = cmd.ExecuteReader();
            mysql_results   res    = new mysql_results();

            res.result = false;
            while (reader.Read())
            {
                res.ID     = reader.GetInt32(0);
                res.msg    = reader.GetString(1);
                res.when   = reader.GetDouble(2);
                res.result = true;
            }

            reader.Close();
            return(res);
        }
Example #5
0
        public static mysql_results QueryCommand(string sql)
        {
            cmd.CommandText = sql;
            cmd.CommandType = CommandType.Text;

            MySqlDataReader reader = cmd.ExecuteReader();
            mysql_results res = new mysql_results();
            res.result = false;
            while (reader.Read())
            {
                res.ID = reader.GetInt32(0);
                res.msg = reader.GetString(1);
                res.when = reader.GetDouble(2);
                res.result = true;

            }

            reader.Close();
            return res;
        }
Example #6
0
        public static mysql_results pre_program(string id)
        {
            cmd.CommandText = "SELECT * FROM `pre_program` WHERE `masterID` = " + id;
            cmd.CommandType = CommandType.Text;
            MySqlDataReader reader = cmd.ExecuteReader();
            mysql_todo[] list = new mysql_todo[50];
            mysql_results res = new mysql_results();
            TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
            double unixTime = ts.TotalSeconds;
            int i=0,j=0;
            res.result = false;
            while (reader.Read())
            {
                if (reader.GetString(2).Length > 2)
                {
                    list[i] = new mysql_todo();
                    list[i].sql = "INSERT `log_current_session` SET `type`='cmd', `message`='" + reader.GetString(2) + "',`when`=" + (reader.GetInt32(1) + unixTime).ToString().Replace(',', '.') + ",`who_ID`=" + reader.GetUInt32(5);
                    res.result = true;
                    i++;
                }

            }

            reader.Close();
            for (j = 0; j < i; j++)
            {
                QueryCommand(list[j].sql);

            }
            return res;
        }
Example #7
0
        public static void check()
        {
            TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));
              double unixTime = ts.TotalSeconds;

              mysql_results res = new mysql_results();
              nxt_result result = new nxt_result();
              //check mysql conntection
              if (mysql.connection.State == ConnectionState.Open || mysql.connection.State == ConnectionState.Connecting)
              {
                  res = mysql.QueryCommand("SELECT `ID`,`message`,`when` FROM `log_current_session` WHERE `status`='' AND `when`< '" + unixTime.ToString().Replace(',', '.') + "' AND `when`> '" + (unixTime-100).ToString().Replace(',', '.') + "' AND `type`='cmd' ORDER BY `when` ASC LIMIT 0,1");
                  if (res.result)
                  {
                      IrcBot.log += DateTime.Now + "checking(" + res.msg + ")...";
                      result = NXT_ROVER_CONTROL.command_translation(res.msg);
                      if (result.result)
                      {
                          //true
                          cmd.CommandText = "UPDATE `log_current_session` SET `status`='" + result.value + "', `when`='" + unixTime.ToString().Replace(',', '.') + "' WHERE `ID`=" + res.ID;
                          cmd.CommandType = CommandType.Text;
                          MySqlDataReader reader = cmd.ExecuteReader();
                          reader.Close();
                          IrcBot.log += "succed\n";
                      }
                      else
                      {
                          //false
                          cmd.CommandText = "UPDATE `log_current_session` SET `status`='" + result.value + "' WHERE `ID`=" + res.ID;
                          cmd.CommandType = CommandType.Text;
                          MySqlDataReader reader = cmd.ExecuteReader();
                          reader.Close();
                          IrcBot.log += "faild\n";

                      }
                  }
              }
              else
              {
                  //make connecion
                  IrcBot.log += "Mysql connection faild";
                  mysql.connect();
              }
        }
Example #8
0
        public static nxt_result run_program_mysql(int name)
        {
            nxt_result result = new nxt_result();
            mysql_results result_mysql = new mysql_results();

            result_mysql = mysql.pre_program(Convert.ToString(name));

            if (result_mysql.result == true)
            {
                result.result = true;
                result.value = "succed";

            }
            else
            {
                result.result = false;
                result.value = "Faild";
            }
            return result;
        }
Example #9
0
        public static mysql_results QueryCommand(string sql)
        {
            while (in_use == true)
            {
               Thread.Sleep(1);
            }

            in_use = true;
                cmd.CommandText = sql;
                cmd.CommandType = CommandType.Text;
                cmd.CommandTimeout = 1;

                mysql_results res = new mysql_results();
                try
                {

                    
                    MySqlDataReader reader = cmd.ExecuteReader();

                    res.result = false;
                    while (reader.Read())
                    {
                        res.ID = reader.GetInt32(0);
                        res.msg = reader.GetString(1);
                        res.when = reader.GetDouble(2);
                        res.result = true;


                    }

                    reader.Close();
                }
                catch
                {
                    
                    res.ID = 0;
                    res.msg = "";
                    res.when = 0.0;
                    res.result = false;
                    in_use = false;
                    return res;
                }
                in_use = false;
                return res;
            }