[smuxi] Engine: introduce official Session.Shutdown() method



commit 10669ff4aefb0ef21f76f852dbd15ac57712fd9a
Author: Mirco Bauer <meebey meebey net>
Date:   Sun Feb 23 18:37:30 2014 +0100

    Engine: introduce official Session.Shutdown() method

 src/Engine/Session.cs        |   51 +++++++++++++++++++++++++++--------------
 src/Engine/SessionManager.cs |    2 +-
 2 files changed, 34 insertions(+), 19 deletions(-)
---
diff --git a/src/Engine/Session.cs b/src/Engine/Session.cs
index b30e788..44fce40 100644
--- a/src/Engine/Session.cs
+++ b/src/Engine/Session.cs
@@ -825,27 +825,12 @@ namespace Smuxi.Engine
         {
             Trace.Call(cmd);
 
-            FrontendManager frontendMgr = cmd != null ? cmd.FrontendManager : null;
 #if LOG4NET
             f_Logger.Info("Shutting down...");
 #endif
-            lock (_ProtocolManagers) {
-                foreach (var protocolManager in _ProtocolManagers) {
-                    try {
-                        protocolManager.Disconnect(frontendMgr);
-                        protocolManager.Dispose();
-                    } catch (Exception ex) {
-#if LOG4NET
-                        f_Logger.ErrorFormat(
-                            "CommandShutdown(): {0}.Disconnect/Dispose() " +
-                            "failed, continuing with shutdown...",
-                            protocolManager.ToString()
-                        );
-                        f_Logger.Error("CommandShutdown(): Exception", ex);
-#endif
-                    }
-                }
-            }
+
+            var frontendMgr = cmd != null ? cmd.FrontendManager : null;
+            Shutdown(true, frontendMgr);
 
             if (IsLocal) {
                 // allow the frontend to cleanly terminate
@@ -1722,6 +1707,36 @@ namespace Smuxi.Engine
             UpdatePresenceStatus(newStatus, newMessage);
         }
 
+        public void Shutdown()
+        {
+            Shutdown(false, null);
+        }
+
+        public void Shutdown(bool clean, FrontendManager frontendManager)
+        {
+            Trace.Call(clean, frontendManager);
+
+            lock (_ProtocolManagers) {
+                foreach (var protocolManager in _ProtocolManagers) {
+                    try {
+                        if (clean) {
+                            protocolManager.Disconnect(frontendManager);
+                        }
+                        protocolManager.Dispose();
+                    } catch (Exception ex) {
+#if LOG4NET
+                        f_Logger.ErrorFormat(
+                            "Shutdown(): {0}.Disconnect/Dispose() " +
+                            "failed, continuing with shutdown...",
+                            protocolManager.ToString()
+                        );
+                        f_Logger.Error("Shutdown(): Exception", ex);
+#endif
+                    }
+                }
+            }
+        }
+
         void UpdatePresenceStatus(PresenceStatus status, string message)
         {
             lock (_ProtocolManagers) {
diff --git a/src/Engine/SessionManager.cs b/src/Engine/SessionManager.cs
index fc50cf2..a6c38f1 100644
--- a/src/Engine/SessionManager.cs
+++ b/src/Engine/SessionManager.cs
@@ -118,7 +118,7 @@ namespace Smuxi.Engine
         {
             lock (_Sessions) {
                 foreach (Session session in _Sessions.Values) {
-                    session.CommandShutdown(null);
+                    session.Shutdown();
                 }
             }
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]