Example #1
0
        private void btnGetUpdates_Click(object sender, EventArgs e)
        {
            if (tbUrl.Text == null || tbUrl.Text == "")
            {
                return;
            }
            try
            {
                //String sUrlAddress = String.Format("{0}getUpdates", sUrlHead);

                //string strTmp = DataTransfer.send_request("GET", sUrlAddress, null);
                //rtbTest.AppendText(sUrlAddress);
                //rbVingcard.AppendText("\r\n");
                //rtbTest.AppendText(strTmp);
                //rbVingcard.AppendText("\r\n");

                //2017 test
                String               strTmp = rtbTest.Text;
                receivedMessages     otmp   = new receivedMessages();
                JavaScriptSerializer js     = new JavaScriptSerializer();
                otmp = js.Deserialize <receivedMessages>(strTmp);
                //if (myresult == null) myresult = new List<messagesList>();
                CompareCallbackIfNewAdd(otmp);
                //myresult = js.Deserialize<List<messagesList>>(strTmp);
            }
            catch
            { }
        }
Example #2
0
 private void CallInformationFromServer()
 {
     if (tbUrl.Text == null || tbUrl.Text == "")
     {
         return;
     }
     try
     {
         String sUrlAddress = String.Format("{0}getUpdates", sUrlHead);
         string strTmp      = DataTransfer.send_request("GET", sUrlAddress, null);
         //String strTmp = rtbTest.Text;
         receivedMessages     otmp = new receivedMessages();
         JavaScriptSerializer js   = new JavaScriptSerializer();
         otmp = js.Deserialize <receivedMessages>(strTmp);
         CompareCallbackIfNewAdd(otmp);
     }
     catch
     { }
 }
Example #3
0
        private void CompareCallbackIfNewAdd(receivedMessages otmp)
        {
            if (otmp == null)
            {
                return;
            }
            try
            {
                List <messagesList> NewAddedMessages = new List <messagesList>();
                //copy new message list to public struct
                #region
                if (myReceivedUpdateIds == null)
                {
                    myReceivedUpdateIds = new List <int>();
                }
                if (myMessages == null) //全部添加
                {
                    myReceivedUpdateIds = new List <int>();
                    myMessages          = otmp;
                    NewAddedMessages    = otmp.result;
                }
                else
                {
                    List <messagesList> tmpMessageList = otmp.result;
                    if (tmpMessageList == null)
                    {
                        return;
                    }
                    if (myMessages.result == null)
                    {
                        myMessages.result = new List <messagesList>();
                    }
                    foreach (messagesList tmpMessage in tmpMessageList)
                    {
                        #region
                        if (myReceivedUpdateIds.Contains(tmpMessage.update_id) == false)
                        {
                            myMessages.result.Add(tmpMessage);
                            NewAddedMessages.Add(tmpMessage);
                        }
                        #endregion
                    }
                }

                //add update id to public buffer

                #endregion

                string sNewAddedMessages = "";
                foreach (messagesList tmpMessage in NewAddedMessages)
                {
                    myReceivedUpdateIds.Add(tmpMessage.update_id);
                    sNewAddedMessages += tmpMessage.message.text + " ;";
                    ConvertorMessageToLocalControlCommand(tmpMessage.message.text);
                }

                String strHead = DateTime.Now.Hour.ToString("D2") + ":" +
                                 DateTime.Now.Minute.ToString("D2") + ":" +
                                 DateTime.Now.Second.ToString("D2") + ":" +
                                 DateTime.Now.Millisecond.ToString("D3") + " : " +
                                 "Receive from Telegram server :" + sNewAddedMessages;

                SetTextCallback d = new SetTextCallback(SetText);
                this.Invoke(d, new object[] { strHead });
            }
            catch
            { }
        }