Пример #1
0
        private void BackgroundWorker_GetUpdate_DoWork(object sender, DoWorkEventArgs e)
        {
            while (true)
            {
                if (BackgroundWorker_GetUpdate.CancellationPending)
                {
                    e.Cancel = true;
                    BotStart_Botton.Invoke((Action)(() => BotStart_Botton.BackColor = Color.Orange));
                    BotStart_Botton.Invoke((Action)(() => BotStart_Botton.Text = "اتصال "));
                    BotStart_Botton.Invoke((Action)(() => BotStart_Botton.Enabled = true));
                    break;
                }

                try
                {
                    string   last_index  = ctrl.read_index();
                    T_result new_massage = ctrl.get_update(last_index);
                    BotStart_Botton.Invoke((Action)(() => BotStart_Botton.BackColor = Color.Green));
                    BotStart_Botton.Invoke((Action)(() => BotStart_Botton.Text = "متصل شد "));
                    if (new_massage.result.Count > 0)
                    {
                        Bot_Log(new_massage);
                        ctrl.responce(new_massage);
                        ctrl.save_index(ctrl.get_update());
                    }
                }
                catch (Exception ex)
                {
                    BotStart_Botton.Invoke((Action)(() => BotStart_Botton.Enabled = true));
                    BotStart_Botton.Invoke((Action)(() => BotStart_Botton.BackColor = Color.Tomato));
                    BotStart_Botton.Invoke((Action)(() => BotStart_Botton.Text = "... عدم اتصال ، تلاش برای اتصال مجدد"));
                    warning_log(ex.Message);
                }
            }
        }
Пример #2
0
 private void Bot_Log(T_result NewUpdates)
 {
     foreach (var item in NewUpdates.result)
     {
         Data_log(item);
     }
 }
Пример #3
0
 private void UpdateChecker_Timer_Tick(object sender, EventArgs e)
 {
     try
     {
         string   last_index  = ctrl.read_index();
         T_result new_massage = ctrl.get_update(last_index);
         BotStart_Botton.BackColor = Color.Green;
         BotStart_Botton.Text      = "متصل شد ";
         if (new_massage.result.Count > 0)
         {
             Bot_Log(new_massage);
             ctrl.responce(new_massage);
             ctrl.save_index(ctrl.get_update());
         }
     }
     catch (Exception ex)
     {
         UpdateChecker_Timer.Stop();
         ReStartBot_timer.Start();
         BotStart_Botton.BackColor = Color.Orange;
         BotStart_Botton.Enabled   = true;
         BotStart_Botton.Text      = "عدم اتصال";
         warning_log(ex.Message);
     }
 }
Пример #4
0
        //save latest index of array
        public void save_index(T_result UpdateList)
        {
            int           index     = UpdateList.result.Count;
            List <Update> _update   = UpdateList.result;
            string        update_id = (_update[index - 1].update_id + 1).ToString();

            File.WriteAllText("index", update_id);
        }
Пример #5
0
        public T_result get_update(string offset)
        {
            string   url         = string.Format(this.BaseUrl + "getupdates?offset={0}", offset);
            string   responce    = create_requst(url);
            T_result update_list = JsonConvert.DeserializeObject <T_result>(responce);

            return(update_list);
        }
Пример #6
0
        public T_result get_update()
        {
            string   url         = this.BaseUrl + "getupdates";
            string   responce    = create_requst(url);
            T_result update_list = JsonConvert.DeserializeObject <T_result>(responce);

            return(update_list);
        }
Пример #7
0
 public void responce(T_result t_Result)
 {
     foreach (var item in t_Result.result)
     {
         message msg     = item.message;
         User    from    = msg.from;
         string  msgtext = msg.text;
         int     user_id = from.id;
         Decision(msgtext, user_id);
     }
 }
Пример #8
0
        static void Main(string[] args)
        {
            Controlls.SSL();
            Controlls ctrl = new Controlls();//bot controller

            Console.WriteLine("Server Started ");
            while (true)
            {
                string   last_index  = ctrl.read_index();
                T_result new_massage = ctrl.get_update(last_index);
                if (new_massage.result.Count > 0)
                {
                    ctrl.responce(new_massage);
                    ctrl.save_index(ctrl.get_update());
                }
            }
        }