Exemple #1
0
        /// <summary>
        /// Calls the StartServer method with Task.Run to not
        /// block the UI thread.
        /// </summary>

        private void ButtonStart_Click(object sender, EventArgs e)
        {
            this.serverUri = ServerUriBuilder.PrepareServerUri(this.serverUriTemplate, textBox1.Text);

            WriteToConsole("Starting server...");
            ButtonStart.Enabled = false;

            try
            {
                Task.Run(() => server.StartServer(this.serverUri));
            }
            catch (TargetInvocationException)
            {
                WriteToConsole("Server failed to start. A server is already running on " + this.serverUri);
                //Re-enable button to let user try to start server again
                this.Invoke((Action)(() => ButtonStart.Enabled = true));
                return;
            }
            this.Invoke((Action)(() => ButtonStop.Enabled = true));
            WriteToConsole("Server started at " + this.serverUri);
        }
Exemple #2
0
        public void ShouldBuildCorrectServerUri()
        {
            var serverUri = ServerUriBuilder.PrepareServerUri("http://test:{0}", "2020").ToString();

            Assert.AreEqual("http://test:2020", serverUri);
        }
Exemple #3
0
        public void ShouldReturnDefaultUriWhenPortIsntGiven()
        {
            var serverUri = ServerUriBuilder.PrepareServerUri("http://test:{0}", "").ToString();

            Assert.AreEqual("http://test:8080", serverUri);
        }