public bool CloseSession() { CSessionClient session = CSessionClient.GetSessionForIdSession(IdSession); if (session != null) { try { session.CloseSession(); return(true); } catch { try { IGestionnaireSessions gestionnaire = (IGestionnaireSessions)C2iFactory.GetNewObject(typeof(IGestionnaireSessions)); ISessionClientSurServeur sessionSurServeur = gestionnaire.GetSessionClientSurServeur(IdSession); sessionSurServeur.CloseSession(); return(true); } catch (Exception) { return(false); } } } return(false); }
/////////////////////////////////////////////// public virtual void CloseSession() { if (!m_bIsOpen) { return; } DateTime dt = DateTime.Now; if (BeforeClosingSession != null) { BeforeClosingSession(this); } TimeSpan sp = DateTime.Now - dt; //Console.WriteLine("Closing " + m_nIdSession + " : 1-" + sp.TotalMilliseconds); CGestionnaireObjetsAttachesASession.OnCloseSession(IdSession); sp = DateTime.Now - dt; //Console.WriteLine("Closing " + m_nIdSession + " : 2-" + sp.TotalMilliseconds); if (OnCloseSession != null) { OnCloseSession(this, new EventArgs()); } sp = DateTime.Now - dt; //Console.WriteLine("Closing " + m_nIdSession + " : 3-" + sp.TotalMilliseconds); m_tableSessionParId.Remove(IdSession); sp = DateTime.Now - dt; //Console.WriteLine("Closing " + m_nIdSession + " : 4-" + sp.TotalMilliseconds); m_tableSessionsLocales.Remove(IdSession); sp = DateTime.Now - dt; //Console.WriteLine("Closing " + m_nIdSession + " : 5-" + sp.TotalMilliseconds); if (m_sessionSurServeur != null) { m_sessionSurServeur.CloseSession(); } sp = DateTime.Now - dt; //Console.WriteLine("Closing " + m_nIdSession + " : 6-" + sp.TotalMilliseconds); m_sessionSurServeur = null; if (m_cacheInfosUtilisateur != null) { m_cacheInfosUtilisateur.Dispose(); } sp = DateTime.Now - dt; //Console.WriteLine("Closing " + m_nIdSession + " : 7-" + sp.TotalMilliseconds); m_cacheInfosUtilisateur = null; //Nettoie les recepteurs de notification m_tableRecepteursParType.Clear(); GetDataThread(m_bUseSessionUtilisateurData).PopIdSession(); sp = DateTime.Now - dt; //Console.WriteLine("Closing " + m_nIdSession + " : 8-" + sp.TotalMilliseconds); m_bIsOpen = false; m_sponsor.Unregister(m_sessionSurServeur); sp = DateTime.Now - dt; //Console.WriteLine("Closing " + m_nIdSession + " : 9-" + sp.TotalMilliseconds); m_sessionSurServeur = null; }
private void m_lnkFermer_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { if (m_wndListeSession.CheckedItems.Count == 0) { MessageBox.Show(I.T("Check sessions to close first !|20519")); return; } if (MessageBox.Show( I.T("You will send a stop message to @1 sessions. Please confirm this action|20515", m_wndListeSession.CheckedItems.Count.ToString()), I.T("Confirmation|20516"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } ArrayList lstThreads = new ArrayList(); m_listeServicesToLaunch.Clear(); m_listeThreadsEnAttente.Clear(); ThreadStart funcStart = new ThreadStart(AskForClose); StringBuilder bl = new StringBuilder(); int nNbSessionsSysteme = 0; foreach (ListViewItem item in m_wndListeSession.CheckedItems) { CInfoSessionAsDynamicClass info = item.Tag as CInfoSessionAsDynamicClass; if (info != null && info.IsSystem) { nNbSessionsSysteme++; bl.Append(info.IdSession); bl.Append(','); } } string strMessage = ""; if (nNbSessionsSysteme > 0) { bl.Remove(bl.Length - 1, 1); if (nNbSessionsSysteme > 1) { strMessage = I.T("Sessions @1 are system sessions and will not be close|20517", bl.ToString()); } else { strMessage = I.T("@1 session is a system session and will not be closed|20518", bl.ToString()); } MessageBox.Show(strMessage); } IGestionnaireSessions gestionnaire = (IGestionnaireSessions)C2iFactory.GetNewObject(typeof(IGestionnaireSessions)); foreach (ListViewItem item in m_wndListeSession.CheckedItems) { CInfoSessionAsDynamicClass info = item.Tag as CInfoSessionAsDynamicClass; if (info != null && !info.IsSystem) { int nIdSession = info.IdSession; CSessionClient session = CSessionClient.GetSessionForIdSession(nIdSession); try { if (!info.Invalide) { CServiceSurClientFermerApplication service = (CServiceSurClientFermerApplication)session.GetServiceSurClient(CServiceSurClientFermerApplication.c_idService); if (service != null) { lock (m_listeServicesToLaunch) { m_listeServicesToLaunch.Add(service); } Thread th = new Thread(funcStart); th.Start(); } } else { ISessionClientSurServeur sessionSurServeur = gestionnaire.GetSessionClientSurServeur(info.IdSession); sessionSurServeur.CloseSession(); } } catch { } } } }