Beispiel #1
0
        void UpdateStatusButtons(ClientStatus_t status)
        {
            Dbg.Assert(!InvokeRequired);


            m_tsbBanishClient.Checked = m_tsbDisableClient.Checked = m_tsbEnableClient.Checked = false;

            m_tsbReset.Enabled            = m_tsbBanishClient.Enabled = m_tsbDisableClient.Enabled =
                m_tsbEnableClient.Enabled = status != ClientStatus_t.Unknown;

            if (status != ClientStatus_t.Unknown)
            {
                switch (status)
                {
                case ClientStatus_t.Enabled:
                    m_tsbEnableClient.Checked = true;
                    break;

                case ClientStatus_t.Disabled:
                    m_tsbDisableClient.Checked = true;
                    break;

                case ClientStatus_t.Banned:
                    m_tsbBanishClient.Checked = true;
                    break;
                }
            }
        }
Beispiel #2
0
        void ProcessClientStatus(ClientStatus_t status)
        {
            Dbg.Assert(!InvokeRequired);

            var client = m_tvClients.SelectedNode.Tag as HubClient;
            ManagementMode_t prfMgmnt = AppContext.ClientsManager.GetProfileManagementMode(client.ProfileID);
            var prf = m_ndxerProfiles.Get(client.ProfileID) as UserProfile;

            if (prfMgmnt == ManagementMode_t.Auto)
            {
                if (MessageBox.Show(this,
                                    $"La gestion du profil {prf.Name} sera changée en mode 'manuel'. Poursuivre ?",
                                    Text, MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    return;
                }
            }

            AppContext.LogManager.LogUserActivity($"Action utilisateur:  Changement du statut du client {ClientsManager.ClientStrID(client.ID)} en {ClientStatuses.GetStatusName(status)}");

            AppContext.ClientsManager.SetProfileManagementMode(client.ProfileID, ManagementMode_t.Manual);

            //maj le status
            AppContext.ClientsManager.SetClientStatus(client, status);
        }
Beispiel #3
0
        public void SetClientStatus(HubClient client, ClientStatus_t status)
        {
            //basculer le mode de gestion des profil vers manuel
            //SetProfileManagementMode(client.ProfileID , ManagementMode_t.Manual);

            //desactiver le client
            HubClient oldClient = GetProfileEnabledClient(client.ProfileID);

            if (status == ClientStatus_t.Enabled && oldClient != null && oldClient.ID != client.ID)
            {
                AppContext.LogManager.LogSysActivity($"Désactivation du client {ClientStrID(oldClient.ID)}", true);

                //maj la table des status clients
                var oldClStatus = m_ndxerClientsStatus.Get(oldClient.ID) as ClientStatus;
                int ndx         = m_ndxerClientsStatus.IndexOf(oldClient.ID);

                oldClStatus.Status = ClientStatus_t.Disabled;
                m_ndxerClientsStatus.Source.Replace(ndx, oldClStatus);

                string oldClFilePath = AppPaths.GetSrvDialogFilePath(oldClient.ID);

                try
                {
                    ClientDialog oldClDlg = DialogEngin.ReadSrvDialog(oldClFilePath);
                    oldClDlg.ClientStatus = ClientStatus_t.Disabled;
                    DialogEngin.WriteSrvDialog(oldClFilePath, oldClDlg);
                }
                catch (Exception ex)
                {
                    AppContext.LogManager.LogSysError($"Lecture du fichier dialogue du client {ClientStrID(oldClient.ID)}" +
                                                      ex.Message);

                    DialogEngin.WriteSrvDialog(oldClFilePath,
                                               new ClientDialog(oldClient.ID, ClientStatus_t.Disabled, Enumerable.Empty <Message>()));
                }
                finally
                {
                    AddUpload(Names.GetSrvDialogFile(oldClient.ID));
                }
            }


            //maj la table des statuts clients
            int ndxStatus = m_ndxerClientsStatus.IndexOf(client.ID);
            var clStatus  = m_ndxerClientsStatus.Get(client.ID) as ClientStatus;

            clStatus.Status = status;
            m_ndxerClientsStatus.Source.Replace(ndxStatus, clStatus);

            string filePath = AppPaths.GetSrvDialogFilePath(client.ID);

            try
            {
                ClientDialog clDlg = DialogEngin.ReadSrvDialog(filePath);
                clDlg.ClientStatus = status;
                DialogEngin.WriteSrvDialog(filePath, clDlg);
            }
            catch (Exception ex)
            {
                AppContext.LogManager.LogSysError($"Lecture du fichier dialogue du client {ClientStrID(client.ID)}" +
                                                  ex.Message);

                DialogEngin.WriteSrvDialog(filePath,
                                           new ClientDialog(client.ID, status, Enumerable.Empty <Message>()));
            }
            finally
            {
                AddUpload(Names.GetSrvDialogFile(client.ID));
            }
        }
Beispiel #4
0
 public ClientDialog(uint idClient, ClientStatus_t status, IEnumerable <Message> messages)
 {
     ClientID     = idClient;
     ClientStatus = status;
     Messages     = messages;
 }
Beispiel #5
0
        public void Start()
        {
            Dbg.Assert(IsRunning == false);

            IsRunning = true;

            Opts.SettingsView.ClientInfoChanged += SettingsView_ClientInfoChaned;

            //client enregistre?
            m_clInfo = Program.Settings.ClientInfo;

            if (m_clInfo == null)
            {
                if (RegisterClient())
                {
                    m_clStatus = ClientStatus_t.Enabled;
                    m_dialogTimer.Start();
                    m_updateTimer.Start();
                    m_dialogRunning = true;

                    var updateTask = new Task(AutoUpdater.Update, TaskCreationOptions.LongRunning);
                    updateTask.Start();
                }

                return;
            }


            DialogEngin.WriteHubDialog(SettingsManager.GetClientDialogFilePath(m_clInfo.ClientID),
                                       m_clInfo.ClientID, Enumerable.Empty <Message>());


            //process only status part of the g file
            string tmpFile = Path.GetTempFileName();

            Action start = () =>
            {
                var netEngin = new NetEngin(Program.NetworkSettings);
                netEngin.Download(tmpFile, SettingsManager.GetServerDialogURL(m_clInfo.ClientID), true);
            };

            Action onSuccess = () =>
            {
                ClientDialog clDlg = DialogEngin.ReadSrvDialog(tmpFile);

                m_clStatus = clDlg.ClientStatus;

                if (m_clStatus == ClientStatus_t.Enabled)
                {
                    new StartHandler(m_clInfo.ClientID, StartResp).Start();
                }
                else if (m_clStatus == ClientStatus_t.Banned)
                {
                    foreach (IDBTable tbl in Program.TablesManager.CriticalTables)
                    {
                        tbl.Clear();
                        Program.Settings.DataGeneration = 0;
                    }

                    System.Windows.Forms.MessageBox.Show(AppText.ERR_BANNED, AppText.APP_NAME,
                                                         System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    Exit();
                    return;
                }
                else if (m_clStatus == ClientStatus_t.Disabled)
                {
                    new ResumeHandler(ResumeResp, m_clInfo.ClientID).Start();
                }
                else
                {
                    ResetRegistration();
                }

                File.Delete(tmpFile);
            };

            Action <Task> onErr = t =>
            {
                Dbg.Log(t.Exception.InnerException.Message);

                //assume client enabled
                m_clStatus = ClientStatus_t.Enabled;
                new StartHandler(m_clInfo.ClientID, StartResp).Start();
            };

            var task = new Task(start, TaskCreationOptions.LongRunning);

            task.OnSuccess(onSuccess);
            task.OnError(onErr);

            task.Start();
        }
Beispiel #6
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();
                }
            }
        }
Beispiel #7
0
 public static string GetStatusName(ClientStatus_t status) => m_statusNames[(byte)status];
Beispiel #8
0
 public ClientStatus(uint idClient, ClientStatus_t status, DateTime seen) :
     base(idClient)
 {
     Status   = status;
     LastSeen = seen;
 }
Beispiel #9
0
 public ClientStatus(uint idClient, ClientStatus_t status) :
     this(idClient, status, DateTime.Now)
 {
 }