/// <summary>
        /// Disconnect existing connections to the server
        /// </summary>
        void Disconnect(ServerConnectionStatus css)
        {
            //stop reading and writing
            if (css.nclient != null)
            {
                //update the context menu of each extension to allow call forwarding clicking
                Globals.ExtensionManager.OnConnectionChanged(css.GetServerIPAndPort(), false);

                Globals.Logger.LogString(LogManager.LogLevels.LogFlagInfo, "Disconnected from server " + css.IP);
                css.nclient.Disconnect();
                css.nclient = null;
            }
            //notify user that we no longer get updates from the server
            ShowNoConnectionWindow();
        }
        /// <summary>
        /// When connection settings change, this function should be called to create a new connection
        /// </summary>
        public void CreateNewConnection(ServerConnectionStatus css)
        {
            //make sure we ditch old data
            Disconnect(css);

            if (Globals.IsAppRunning == false)
            {
                return;
            }

            //need connection details in order to create a new connection
            if (css.IP == null || css.IP.Length == 0 || css.PendingRemove == true)
            {
                return;
            }

            //create a client connection that should persist while the UI is alive
            NetworkClient TClient = new NetworkClient(css.IP, css.Port);

            TClient.ConnectToServer(css.IP, css.Port);
            if (TClient.IsConnected() == false)
            {
                Globals.Logger.LogString(LogManager.LogLevels.LogFlagInfo, "Failed to created new server connection to " + css.IP + ":" + css.Port.ToString());
                TClient = null;
                return; //failed to create a connection
            }

            //no more need to show user that there is no connection
            HideNoConnectionWindow();

            //if it is good to use, we use it
            css.nclient            = TClient;
            css.LastHeartBeatStamp = Environment.TickCount;

            if (PacketParserThread == null)
            {
                PacketParserThread = new Thread(new ThreadStart(AsyncParsePackets));
                PacketParserThread.Start();
            }

            //update the context menu of each extension to allow call forwarding clicking
            Globals.ExtensionManager.OnConnectionChanged(css.GetServerIPAndPort(), true);

            Globals.Logger.LogString(LogManager.LogLevels.LogFlagInfo, "Created new server connection to " + css.IP.ToString() + ":" + css.Port.ToString());
        }
        public void UpdateConnectionsDetails(ObservableCollection <ServerConnectionRow> NewConnectionList)
        {
            //check whick connections we should remove from existing list
            foreach (ServerConnectionStatus sc in ServerConnections)
            {
                if (sc.PendingRemove == true)
                {
                    continue;
                }
                ServerConnectionRow scrExisting = null;
                foreach (ServerConnectionRow scr in NewConnectionList)
                {
                    if (scr.IP == sc.IP && scr.Port == sc.Port)
                    {
                        scrExisting = scr;
                        break;
                    }
                }
                //should remove from our connection list
                if (scrExisting == null)
                {
                    sc.PendingRemove = true;
                }
                //if connection is disabled, we will try to break an existing connection on next update
                if (scrExisting != null)
                {
                    if (scrExisting.Delete_ != 0)
                    {
                        sc.PendingRemove = true;
                    }
                    sc.Enabled = scrExisting.Enabled;
                    if (scrExisting.Name != null)
                    {
                        sc.ServerName = scrExisting.Name;
                    }
                    else
                    {
                        sc.ServerName = " ";
                    }
                }
            }

            //check for connections we should add
            bool RefreshPersports = false;

            foreach (ServerConnectionRow scr in NewConnectionList)
            {
                //no need to save invalid rows
                if (scr.IP == null || scr.IP == "" || scr.Port <= 0)
                {
                    continue;
                }
                ServerConnectionStatus Existingsc = null;
                foreach (ServerConnectionStatus sc in ServerConnections)
                {
                    if (scr.IP == sc.IP && scr.Port == sc.Port && sc.PendingRemove == false)
                    {
                        Existingsc = sc;
                        break;
                    }
                }
                if (Existingsc != null)
                {
                    continue;
                }
                //create a new connection
                ServerConnections.Add(new ServerConnectionStatus(scr.IP, scr.Port, -1, scr.Enabled, scr.Name));
                //make sure we will refresh the persport for this server as soon as possible
                RefreshPersports = true;
            }
            if (RefreshPersports == true && Globals.persPortManager != null)
            {
                Globals.persPortManager.ForceStatusUpdate();
            }
        }