示例#1
0
        void ProcessUpdateTimer()
        {
            m_updateTimer.Stop();
            System.Diagnostics.Debug.WriteLine("Processing update timer...");

            try
            {
                LogEngin.PushFlash("Recherche des mises à jour de données...");

                try
                {
                    if (AutoUpdater.UpdateData())
                    {
                        LogEngin.PushFlash("Vos données sont à jour.");
                    }

                    System.Diagnostics.Debug.WriteLine("Update done!");
                }
                catch (Exception ex)
                {
                    LogEngin.PushFlash(ex.Message);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                m_updateTimer.Start();
            }
        }
示例#2
0
        void ProcessDialogTimer()
        {
            if (!m_dialogTimer.IsDisposed)
            {
                m_dialogTimer.Stop();
            }

            Dbg.Log("Processing dialog timer...");

            string srvDlgURI = SettingsManager.GetServerDialogURL(m_clInfo.ClientID);
            string tmpFile   = Path.GetTempFileName();

            LogEngin.PushFlash("Interrogation du serveur...");

            try
            {
                new NetEngin(Program.NetworkSettings).Download(tmpFile, srvDlgURI, true);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);

                LogEngin.PushFlash(ex.Message);
                m_dialogTimer.Start();

                return;
            }


            try
            {
                ClientDialog clDlg = DialogEngin.ReadSrvDialog(tmpFile);

                if (m_clStatus != clDlg.ClientStatus)
                {
                    switch (clDlg.ClientStatus)
                    {
                    case ClientStatus_t.Enabled:
                        m_updateTimer.Start(true);
                        break;

                    case ClientStatus_t.Disabled:
                        if (m_clStatus == ClientStatus_t.Enabled)
                        {
                            m_updateTimer.Stop();
                        }
                        return;

                    case ClientStatus_t.Banned:
                        m_updateTimer.Stop();

                        foreach (IDBTable tbl in Program.TablesManager.Tables)
                        {
                            tbl.Clear();
                        }

                        System.Windows.Forms.MessageBox.Show(AppText.ERR_BANNED, AppText.APP_NAME,
                                                             System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        Exit();
                        return;

                    case ClientStatus_t.Reseted:
                        ResetRegistration();
                        return;

                    default:
                        Dbg.Assert(false);
                        break;
                    }

                    m_clStatus = clDlg.ClientStatus;
                }



                Dbg.Assert(m_clStatus == ClientStatus_t.Enabled);

                uint id = m_srvLastMsgID;

                var msgs = from msg in clDlg.Messages
                           where msg.ID > id
                           select msg;

                if (msgs.Any())
                {
                    m_srvLastMsgID = msgs.Max(m => m.ID);

                    Action <Message> msgHandler;

                    foreach (Message msg in msgs)
                    {
                        if (m_msgHandlersTable.TryGetValue(msg.MessageCode, out msgHandler))
                        {
                            msgHandler.Invoke(msg);
                        }
                    }


                    m_timeToLive = TTL_MAX;
                }

                if (m_needUpload)
                {
                    string clFilePath = SettingsManager.GetClientDialogFilePath(m_clInfo.ClientID);
                    new NetEngin(Program.NetworkSettings).Upload(SettingsManager.GetClientDialogURL(m_clInfo.ClientID), clFilePath, true);
                    m_needUpload = false;
                }

                if (--m_timeToLive <= 0)
                {
                    PostSyncMessage();
                }

                if (!m_dialogTimer.IsDisposed)
                {
                    m_dialogTimer.Start();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);

                if (!m_dialogTimer.IsDisposed)
                {
                    m_dialogTimer.Start();
                }
            }
        }