Пример #1
0
        public static ServerConnection ChangeDefaultConnection(Control parent)
        {
            SelectSrcpServer selectSrcpServer = new SelectSrcpServer(GetDefaultConnectionName(), true);

            if (DialogResult.Cancel == selectSrcpServer.ShowDialog(parent))
            {
                return(null);
            }
            selectSrcpServer.Connection.SetDefault();
            return(selectSrcpServer.Connection);
        }
Пример #2
0
        public static ServerConnection GetConnection(Control parent, bool start, string connectionName, bool throwExceptionIfCanceled)
        {
            ServerConnection connection = null;

            if (connectionName != null)
            {
                connection = ServerConnections[connectionName];
            }
            while (true)
            {
                if (connection == null)
                {
                    SelectSrcpServer selectServer = new SelectSrcpServer(connectionName, start);
                    selectServer.ShowDialog(parent);
                    connection = selectServer.Connection;
                }
                if (start && connection != null && !connection.Started)
                {
                    try
                    {
                        connection.Start();
                    }
                    catch (Exception ex)
                    {
                        connection = null;
                        MessageBox.Show(parent, LocalizedString.Format("ConnectionToSRCPServerFailed", LocalizedException.GetFullMessage(ex)), null, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        continue;
                    }
                }
                break;
            }
            if (connection == null && throwExceptionIfCanceled)
            {
                throw new LocalizedException("OperationCanceled");
            }
            return(connection);
        }