Exemplo n.º 1
0
        /// <summary>
        /// Sets up server/client connection information</summary>
        /// <returns>True iff information set up</returns>
        public bool ConfigureConnection()
        {
            bool result;
            var dlg = new Connections(this);
            if ((MainForm != null) && (MainForm.Icon != null))
                dlg.Icon = MainForm.Icon;
            DialogResult dr = dlg.ShowDialog(MainForm);
            if (dr == DialogResult.OK)
            {
                string oldConnection = CurrentConnection;

                lock (m_lock)
                {
                    if (m_repository != null)
                    {
                        m_repository.Dispose();
                        m_repository = null;
                    }
                }
                m_connectionInitialized = false;
                m_configuring = true; // nullify InitializeConnection() 

                string[] connectionConfig = ExtractConnectionParts(dlg.ConnectionSelected);
                if (connectionConfig != null && connectionConfig.Length == 3)
                {
                    var server = new Server(new ServerAddress(connectionConfig[0]));
                    lock (m_lock)
                    {
                        m_repository = new Repository(server);
                        m_repository.Connection.UserName = connectionConfig[1];
                        m_repository.Connection.Client = new Client {Name = connectionConfig[2]};
                    }
                }

                if (ValidateConnection(true))// a valid connection
                {
                    m_connectionInitialized = true;

                    if (dlg.UseAsDefaultConnection)
                        DefaultConnection = CurrentConnection;

                    int index = RecentConnections.IndexOf(CurrentConnection);
                    if (index != -1)
                        RecentConnections.RemoveAt(index);
                    RecentConnections.Insert(0, CurrentConnection);
                    if (CurrentConnection != oldConnection)
                        OnConnectionChanged(EventArgs.Empty);
                }
                result = true;
            }
            else //if (dr == DialogResult.Cancel)
            {
                result = false;
            }
            m_configuring = false;
            return result;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets up server/client connection information</summary>
        /// <returns>True iff information set up</returns>
        public bool ConfigureConnection()
        {
            bool result = false;
            var  dlg    = new Connections(this);

            if ((MainForm != null) && (MainForm.Icon != null))
            {
                dlg.Icon = MainForm.Icon;
            }
            DialogResult dr = dlg.ShowDialog(MainForm);

            if (dr == DialogResult.OK)
            {
                string oldConnection = CurrentConnection;

                lock (m_lock)
                {
                    if (m_connection != null)
                    {
                        m_connection.Dispose();
                        m_connection = null;
                    }
                }
                m_connectionInitialized = false;
                m_configuring           = true; // nullify InitializeConnection()

                string[] connectionConfig = ExtractConnectionParts(dlg.ConnectionSelected);
                if (connectionConfig != null && connectionConfig.Length == 3)
                {
                    Server server = new Server(new ServerAddress(connectionConfig[0]));
                    lock (m_lock)
                    {
                        m_repository             = new Repository(server);
                        m_connection             = m_repository.Connection;
                        m_connection.UserName    = connectionConfig[1];
                        m_connection.Client      = new Client();
                        m_connection.Client.Name = connectionConfig[2];
                    }
                }

                if (ValidateConnection(true))// a valid connection
                {
                    m_connectionInitialized = true;

                    if (dlg.UseAsDefaultConnection)
                    {
                        DefaultConnection = CurrentConnection;
                    }

                    int index = RecentConnections.IndexOf(CurrentConnection);
                    if (index != -1)
                    {
                        RecentConnections.RemoveAt(index);
                    }
                    RecentConnections.Insert(0, CurrentConnection);
                    if (CurrentConnection != oldConnection)
                    {
                        OnConnectionChanged(EventArgs.Empty);
                    }
                }
            }
            else if (dr == DialogResult.Cancel)
            {
            }
            m_configuring = false;
            return(result);
        }