Exemple #1
0
        private void updateTwitterBackgroundWorker_DoWork(object sender, OpenNETCF.ComponentModel.DoWorkEventArgs e)
        {
            string message = e.Argument as string;

            if (message != null)
            {
                twitterAccount.Update(message);
            }
        }
Exemple #2
0
        private void fetchTimelineTwitterBackgroundWorker_DoWork(object sender, OpenNETCF.ComponentModel.DoWorkEventArgs e)
        {
            this.Invoke(new MethodInvokeDelegate(delegate
            {
                updateMenuItem.Enabled = false;
            }));

            CheckTimelineUpdate();
        }
Exemple #3
0
 private void fetchDirectMessageBackgroundWorker_DoWork(object sender, OpenNETCF.ComponentModel.DoWorkEventArgs e)
 {
     CheckDirectMessageUpdate();
 }
        public void mBW_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = (BackgroundWorker) sender;
            Database_Connection.Open();
            string[] str = null;
            string timeStringServer = null;
            string ScanariID = null;
            DateTime WsDateTime=DateTime.MinValue;  
            int indexWsNoReply = 0;

            while (!_shuttingDown)
            {
                try
                {   
                    nrScanariNesinc = TabelScanari.CountUnsynchronizedBackroudWorker(Database_Connection);
                    bw.ReportProgress(0, new WorkerArgs(nrScanariNesinc, false,null));  //update UI nrScanari 
                }
                catch (Exception ex)
                {
                    AfisareMainThread(bw, 2, nrScanariNesinc, false, "Eroare BD");
                    return; //ies dc eroare BD
                }


                while (!_shuttingDown && (nrScanariNesinc > 0))
                {

                    try
                    {   // dc fails raportam la UI;
                        str = TabelScanari.SelectTop(Database_Connection);
                    }
                    catch (Exception ex)
                    {
                        //  are try/ catch intern ; neesential afisare UI; dc fails thred continua
                        AfisareMainThread(bw, 2, nrScanariNesinc, false, "Eroare BD");
                        return;

                    }
                    // 0 - SefID
                    // 1 - CodMuncitor
                    // 2 - HalaID
                    // 3 - CelulaID
                    // 4 - AmbalajID
                    // 5 - DataScanare
                    // 6 - Cantitate
                    // 7 - Greutate
                    // 8 - ScanariID
                    ScanariID = str[8];

                    string sStream = (str[0] + "#" + str[1] + "#" + str[2] + "#" + str[3] + "#" +
                                      str[4] + "#" + str[5] + "#" + str[6] + "#" + str[7]);

                    indexWsNoReply = 0;   //Conection succes; reset indexWsNoReply  
                    while (!_shuttingDown)  //While incearca transmitere WS pana reuseste
                    {
                        try
                        {   
                            Debug.WriteLine("WsSend nrScanariNesinc: " + nrScanariNesinc);

                            timeStringServer = WS_PreluareDate.SendScanare(sStream);
                            if (timeStringServer == "Error!")
                            {// UI msg show eroare grava WebService; nu corespund datele locale cu ale Serverului
                                AfisareMainThread(bw, 2, nrScanariNesinc, false, "Eroare grava WebService! Sunati");
                                return;
                            }
                            break; // trece la UpdateTabel
                             
                        }
                        catch (Exception ex)    //WebService
                        {
                            indexWsNoReply++; // 5 max
                            bw.ReportProgress(1, new WorkerArgs(nrScanariNesinc, false, null));//TODO parametru  // update UI nrScanari + deconectat!!
                            if (indexWsNoReply > 5)
                            {   // 5 WsNoReply
                                indexWsNoReply = 0;
                                Debug.WriteLine("WaitAutoRstEvnt 10 min");
                                WaitAutoRstEvnt.WaitOne(60000 * 10, false); // wait 10 min
                            }
                            else
                            {   //  WsNoReply<5
                                Debug.WriteLine("WaitAutoRstEvnt 10 secunde");
                                WaitAutoRstEvnt.WaitOne(1000 * 10, false); //wait 10 sec 
                            }

                        }

                    }   //while (!_shuttingDown)

                    try
                    {
                        Debug.WriteLine("UpdateTabelScanari ID: " + ScanariID);
                        TabelScanari.UpdateTabelScanari(ScanariID, Database_Connection);
                        nrScanariNesinc = TabelScanari.CountUnsynchronizedBackroudWorker(Database_Connection);
                    }
                    catch (Exception ex)
                    {
                        AfisareMainThread(bw, 2, nrScanariNesinc, false, "Eroare BD");
                        return;
                    }
                    AfisareMainThread(bw, 1, nrScanariNesinc, true, null);  // Afisare UI nrScanari + conectat

                    try
                    {
                        WsDateTime = GetDateTimeFormat(timeStringServer);
                        Debug.WriteLine(WsDateTime.ToString());
                        if ((WsDateTime != DateTime.MinValue) && (IsTimeDifference(WsDateTime)))  //if GetDateTimeFormat success
                        {
                            Debug.WriteLine("DateTimeHelper.SystemTime= "+DateTimeHelper.SystemTime);
                            Debug.WriteLine("WsDateTime= "+WsDateTime);

                            DateTimeHelper.SystemTime = WsDateTime;
                        }
                    }
                    catch (Exception)
                    {   
                    }
                }   //while (!_shuttingDown && (nrScanariNesinc > 0))
                Debug.WriteLine("WaitAutoRstEvnt indefinite");
                autoResetEvnt.WaitOne(); //wait 10 sec //3 sec TEST
            }   //primul While(!_shuttingDown) !!!inainte de el pun wait!!
        }