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); }
//protected: protected override void DoRead(IReader reader) { byte mode = reader.ReadByte(); if (!Enum.IsDefined(typeof(ManagementMode_t), mode)) { throw new CorruptedStreamException(); } ManagementMode = (ManagementMode_t)mode; }
private void AutoManagement_Click(object sender, EventArgs e) { ListViewItem lvi = m_lvData.SelectedItems[0]; var prf = lvi.Tag as UserProfile; var prfMgmntMode = m_ndxerMgmntMode.Get(prf.ID) as ProfileManagementMode; ManagementMode_t mode = m_tsbAutoManagement.Checked ? ManagementMode_t.Manual : ManagementMode_t.Auto; m_tsbAutoManagement.Checked = !m_tsbAutoManagement.Checked; prfMgmntMode.ManagementMode = mode; m_ndxerMgmntMode.Source.Replace(m_ndxerMgmntMode.IndexOf(prf.ID), prfMgmntMode); }
public void SetProfileManagementMode(uint idProfile, ManagementMode_t mode) { var mgmntMode = m_ndxerProfilesMgmnt.Get(idProfile) as ProfileManagementMode; Dbg.Assert(mgmntMode != null); if (mgmntMode.ManagementMode != mode) { AppContext.LogManager.LogSysActivity($"Mode de gestion du profil {idProfile} changé vers " + $"{ProfileManagementMode.GetManagementModeName(mode)}", true); mgmntMode.ManagementMode = mode; int ndx = m_ndxerProfilesMgmnt.IndexOf(idProfile); m_ndxerProfilesMgmnt.Source.Replace(ndx, mgmntMode); } }
private void ManagementMode_DatumReplaced(IDataRow row) { if (InvokeRequired) { Invoke(new Action <IDataRow>(ManagementMode_DatumReplaced), row); } else { var lvi = (from item in m_lvData.Items.AsEnumerable <ListViewItem>() where (item.Tag as UserProfile).ID == row.ID select item).Single(); ManagementMode_t mode = (m_ndxerMgmntMode.Get(row.ID) as ProfileManagementMode).ManagementMode; if (lvi.Selected) { m_tsbAutoManagement.Checked = mode == ManagementMode_t.Auto; } lvi.SubItems[m_colMgmntMode.Index].Text = ProfileManagementMode.GetManagementModeName(mode); } }
Message ProcessNewConnectionReq(Message msg) { Dbg.Assert(msg.MessageCode == Message_t.NewConnection); //TextLogger.Info("Réception d’une nouvelle requête d’inscription."); var ms = new MemoryStream(msg.Data); var reader = new RawDataReader(ms, Encoding.UTF8); ClientInfo clInfo = ClientInfo.LoadClientInfo(reader); ClientEnvironment clEnv = ClientEnvironment.Load(reader); byte[] data = BitConverter.GetBytes(clInfo.ClientID); var profile = m_ndxerProfiles.Get(clInfo.ProfileID) as UserProfile; string reqLog = $"Réception d'une demande d’inscription émanant de {clInfo.ContactName}" + $"(ID = {ClientStrID(clInfo.ClientID)}) pour " + (profile == null ? "un profil inexistant." : $"le profil {profile.Name}."); AppContext.LogManager.LogSysActivity(reqLog, true); //verifier que le profil existe if (profile == null) { AppContext.LogManager.LogSysActivity("Lancement de la procédure d’actualisation " + "de la liste des profils sur le serveur", true); ProcessProfilesChange(); return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.InvalidProfile, data)); } //verifier que ClientID n'existe pas var clSameID = m_ndxerClients.Get(clInfo.ClientID) as HubClient; if (clSameID != null) { AppContext.LogManager.LogSysActivity("Collision d’identifiants: " + $"un client portant le même ID est déjà enregistré ({clSameID.ContactName}). " + "Exiger au client de reformuler son inscription avec un nouvel ID", true); return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.InvalidID, data)); } //verifier que le profile est en mode auto ManagementMode_t prfMgmntMode = GetProfileManagementMode(clInfo.ProfileID); if (prfMgmntMode == ManagementMode_t.Manual) { AppContext.LogManager.LogSysActivity("Profil en gestion manuelle, inscription rejetée.", true); return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.Rejected, data)); } TextLogger.Info("Profil en gestion automatique."); TextLogger.Info("Enregistrement du client..."); //desactiver l'ancien client actif si il existe var oldClient = GetProfileEnabledClient(clInfo.ProfileID); if (oldClient != null) { if (IsClientRunning(oldClient.ID)) { //rejeter l'inscription AppContext.LogManager.LogSysActivity($"Un client pour le profil {profile.Name} est déjà en cours d’exécution. " + "Inscription rejetée", true); return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.Rejected, data)); } 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; oldClStatus.Status = ClientStatus_t.Disabled; int ndx = m_ndxerClientsStatus.IndexOf(oldClStatus.ID); m_ndxerClientsStatus.Source.Replace(ndx, oldClStatus); //maj des fichiers de dialogue de old client string filePath = AppPaths.GetSrvDialogFilePath(oldClient.ID); ClientDialog clDlg = new ClientDialog(oldClient.ID, ClientStatus_t.Disabled, Enumerable.Empty <Message>()); DialogEngin.WriteSrvDialog(filePath, clDlg); AddUpload(Names.GetSrvDialogFile(oldClient.ID)); } //creer le fichier dialogue string srvDlgPath = AppPaths.GetSrvDialogFilePath(clInfo.ClientID); DialogEngin.WriteSrvDialog(srvDlgPath, new ClientDialog(clInfo.ClientID, ClientStatus_t.Enabled, Enumerable.Empty <Message>())); DialogEngin.WriteHubDialog(AppPaths.GetClientDilogFilePath(clInfo.ClientID), clInfo.ClientID, Enumerable.Empty <Message>()); try { new NetEngin(AppContext.Settings.NetworkSettings).Upload(Urls.DialogDirURL, new string[] { AppPaths.GetClientDilogFilePath(clInfo.ClientID), AppPaths.GetSrvDialogFilePath(clInfo.ClientID) }); } catch (Exception ex) { AppContext.LogManager.LogSysError($"Traitement de la requête d'inscription du client {ClientStrID(clInfo.ClientID)}: " + $"{ ex.Message}. demande ignorée, laisser le client reformuler la requête", true); return(null); // let the cleint retry req. } //maj la table des clients var hClient = new HubClient(clInfo.ClientID, clInfo.ProfileID) { ContaclEMail = clInfo.ContaclEMail, ContactName = clInfo.ContactName, ContactPhone = clInfo.ContactPhone, }; m_ndxerClients.Source.Insert(hClient); //maj du status client var clStatus = new ClientStatus(clInfo.ClientID, ClientStatus_t.Enabled); m_ndxerClientsStatus.Source.Insert(clStatus); //maj du client env UpdateClientEnvironment(clInfo.ClientID, clEnv); //maj du dict des clients actifs m_onlineClients.Add(clInfo.ClientID); AppContext.LogManager.StartLogger(clInfo.ClientID); AppContext.LogManager.LogClientActivity(clInfo.ClientID, "Inscription"); ClientStarted?.Invoke(clInfo.ClientID); AppContext.LogManager.LogSysActivity($"Inscription du client {clInfo.ClientID} terminée", true); TextLogger.Info("Inscription réussie. :-)"); return(msg.CreateResponse(++m_lastCnxRespMsgID, Message_t.Ok, data)); }
public static string GetManagementModeName(ManagementMode_t mode) => m_modesName[(byte)mode];
public ProfileManagementMode(uint idProfile, ManagementMode_t mode = ManagementMode_t.Auto) : base(idProfile) { ManagementMode = mode; }