Jibbr.ViewModels.AccountViewModel.InitializeConnection C# (CSharp) Method

InitializeConnection() private method

Initialize the connection for this account
private InitializeConnection ( ) : System.Boolean
return System.Boolean
        private Boolean InitializeConnection()
        {
            if (String.IsNullOrEmpty(serverName) || String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
                return false;

            if (clientConnection != null)
            {
                clientConnection.Close();
                clientConnection = null;
                presenceManager = null;
            }

            //TODO: If the server's jid winds up not being the same as our ServerName, disconnect the connection, set the ConnectServer = ServerName, set Server = jid, set AutoResolveConnectServer = false
            //and then try to reconnect.
            clientConnection = new XmppClientConnection()
            {
                Server = serverName,
                AutoResolveConnectServer = autoResolveConnectServer,
                ConnectServer = connectServer,
                Username = username,
                Password = password,
                Port = port,
                SocketConnectionType = agsXMPP.net.SocketConnectionType.Direct,
                KeepAlive = true,
                UseSSL = useSSL,
                UseStartTLS = useTLS,
                Resource = "Jabber/XMPP",
                UseCompression = true,
                AutoAgents = true,
                AutoPresence = true,
                AutoRoster = true
            };

            clientConnection.OnXmppConnectionStateChanged += OnXmppConnectionStateChanged;
            clientConnection.OnLogin += OnLogin;
            clientConnection.OnError += OnError;
            clientConnection.OnMessage += OnMessage;
            clientConnection.OnRosterStart += OnRosterStart;
            clientConnection.OnRosterItem += OnRosterItem;
            clientConnection.OnRosterEnd += OnRosterEnd;
            clientConnection.OnAuthError += OnAuthError;
            clientConnection.OnPresence += OnPresence;

            clientConnection.OnAgentStart += clientConnection_OnAgentStart;
            clientConnection.OnAgentItem += clientConnection_OnAgentItem;
            clientConnection.OnAgentEnd += clientConnection_OnAgentEnd;
            clientConnection.OnBinded += clientConnection_OnBinded;
            clientConnection.OnClose += clientConnection_OnClose;
            clientConnection.OnIq += clientConnection_OnIq;
            clientConnection.OnSaslStart += clientConnection_OnSaslStart;
            clientConnection.OnSaslEnd += clientConnection_OnSaslEnd;
            clientConnection.OnSocketError += clientConnection_OnSocketError;
            clientConnection.OnStreamError += clientConnection_OnStreamError;
            clientConnection.OnReadSocketData += clientConnection_OnReadSocketData;
            clientConnection.OnReadXml += clientConnection_OnReadXml;
            clientConnection.OnWriteSocketData += clientConnection_OnWriteSocketData;
            clientConnection.OnWriteXml += clientConnection_OnWriteXml;
            clientConnection.ClientSocket.OnValidateCertificate += ClientSocket_OnValidateCertificate;

            presenceManager = new PresenceManager(clientConnection);

            return true;
        }