Esempio n. 1
0
        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            int port;
            if (!int.TryParse(txtPort.Text, out port))
            {
                ModernDialog.ShowMessage("Port must be an integer", "Error", MessageBoxButton.OK);
                return;
            }

            string serverName = txtName.Text;
            string password = txtPassword.Password;
            Bll.JudgeNode.Password = password;
            var host = new JudgeNodeHost(port, serverName);
            host.Open();

            var frame = NavigationHelper.FindFrame(null, this);
            if (frame != null)
            {
                frame.Source = new Uri("/JudgeNode/Status.xaml", UriKind.Relative);
            }
        }
Esempio n. 2
0
        private void btnStartLocal_Click(object sender, RoutedEventArgs e)
        {
            ConfigHelper.ServerName = txtServerName.Text;
            ConfigHelper.ServerPort = Convert.ToInt32(txtLocalPort.Text);

            string serverName = txtServerName.Text;

            int localPort;
            if (!int.TryParse(txtLocalPort.Text, out localPort))
            {
                ModernDialog.ShowMessage("Local port must be an integer", "Error", MessageBoxButton.OK);
                return;
            }

            if (lstMySqlMode.SelectedIndex == -1)
            {
                ModernDialog.ShowMessage("Please select mysql mode", "Error", MessageBoxButton.OK);
                return;
            }

            string connectionString;
            if (lstMySqlMode.SelectedIndex == 0)
            {
                StartEmbeddedMySQL();
                connectionString = "Server = localhost; Port = 3311; Database = cenaplus; Uid = root; Charset=utf8";
            }
            else
            {
                connectionString = String.Format(ConnectionStr,
                    txtMySQLPort.Text,
                    txtMySQLDBName.Text,
                    txtMySQLUsername.Text,
                    txtMySQLPassword.Password);
            }
            App.ConnectionString = connectionString;

            App.contestmanager.ScheduleAll();

            App.judger.RecordJudgeComplete += App.pushingmanager.JudgeFinished;
            App.judger.HackJudgeComplete += App.pushingmanager.HackFinished;
            App.judger.StartJudgeAllPending();

            LocalCenaServer.ContestModified += App.contestmanager.Reschedule;
            LocalCenaServer.ContestDeleted += App.contestmanager.RemoveSchedule;
            LocalCenaServer.NewRecord += App.pushingmanager.NewRecord;
            LocalCenaServer.NewRecord += App.judger.JudgeRecord;
            LocalCenaServer.NewHack += App.judger.JudgeHack;
            LocalCenaServer.RecordRejudged += App.judger.JudgeRecord;

            host = new CenaPlusServerHost(localPort, serverName);
            host.Open();

            App.Server = new LocalCenaServer { CurrentUser = new FakeSystemUser() };

            if (chkStartJudgeNode.IsChecked == true)
            {
                Random rnd = new Random();
                int port = rnd.Next(2000, 10000);
                Bll.JudgeNode.Password = rnd.NextDouble().ToString();
                var judgeNodeHost = new JudgeNodeHost(port, serverName + " Local");
                judgeNodeHost.Open();

                App.judgenodes.Add(new JudgeNodeInfo
                {
                    Location = new IPEndPoint(IPAddress.Loopback, port),
                    Name = serverName + " Local",
                    Password = Bll.JudgeNode.Password
                });
            }

            var frame = NavigationHelper.FindFrame(null, this);
            if (frame != null)
            {
                frame.Source = new Uri("/ServerMode/Online.xaml", UriKind.Relative);
            }
        }