Example #1
0
 private void Details_Click(object sender, RoutedEventArgs e)
 {
     if (cmbTasks.SelectedIndex != -1)
     {
         MessageBoxCenterer.MessageBoxCentered(this, tasks[cmbTasks.SelectedIndex].Description, tasks[cmbTasks.SelectedIndex].Title);
     }
 }
Example #2
0
        private void PopulateTasks()
        {
            HttpResponseMessage responseMessage = HttpRequest(hostUrl + "api/tasks", HttpMethod.Get);

            SetLabelInfo("");

            if (responseMessage.StatusCode == HttpStatusCode.OK)
            {
                string responseText = responseMessage.Content.ReadAsStringAsync().Result;

                tasks = JsonConvert.DeserializeObject <List <ProgrammingTask> >(responseText);

                Dispatcher.Invoke(new Action(() =>
                {
                    cmbTasks.Items.Clear();
                }));

                for (int i = 0; i < tasks.Count; ++i)
                {
                    try
                    {
                        // force WPF to render UI elemnts
                        Dispatcher.Invoke(new Action(() =>
                        {
                            cmbTasks.Items.Add(tasks[i].Title);
                        }));
                    }
                    catch (TaskCanceledException)
                    {
                        break;
                    }
                }

                Dispatcher.Invoke(new Action(() =>
                {
                    if (cmbTasks.Items.Count > 0)
                    {
                        cmbTasks.SelectedItem = cmbTasks.Items[0];
                    }
                }));

                UpdateServerStatus(true);
            }
            else
            {
                if (responseMessage.StatusCode == HttpStatusCode.ServiceUnavailable)
                {
                    UpdateServerStatus(false);
                }

                MessageBoxCenterer.MessageBoxCentered(this, "Failed to obtain tasks", responseMessage.StatusCode.ToString());
            }
        }
        private void Ok_Click(object sender, RoutedEventArgs e)
        {
            txtBoxPort.Text = txtBoxPort.Text.Trim();

            if (new Regex("[^\\d]").IsMatch(txtBoxPort.Text)) // if contains any non digit character
            {
                MessageBoxCenterer.MessageBoxCentered(this, "Port number format is invalid", "Error");
                return;
            }

            this.DialogResult = true;
            this.Close();
        }
Example #4
0
        private bool UnsavedChanges()
        {
            if (this.Title.Contains("*"))
            {
                MessageBoxResult messageBoxResult =
                    MessageBoxCenterer.MessageBoxCentered(this, "Do you want to save changes?", "Alert", MessageBoxButton.YesNoCancel);

                if ((messageBoxResult == MessageBoxResult.Yes && !Save())
                    ||
                    messageBoxResult == MessageBoxResult.Cancel)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #5
0
        private void Send_Click(object sender, RoutedEventArgs e)
        {
            if (username == null || password == null)
            {
                if (!ShowLoginWindow())
                {
                    return;
                }
            }

            if (cmbTasks.SelectedIndex == -1)
            {
                MessageBoxCenterer.MessageBoxCentered(this, "Please select task", "Warning");
                return;
            }

            if (cmbProgrammingLanguage.SelectedIndex == -1)
            {
                MessageBoxCenterer.MessageBoxCentered(this, "Please select programming language", "Warning");
                return;
            }

            Dictionary <string, string> body = new Dictionary <string, string>();

            body.Add("ProgrammingLanguage", cmbProgrammingLanguage.SelectedItem.ToString());
            body.Add("Code", avalonEdit.Text);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add(HttpRequestHeader.ContentType.ToString(), "application/json");
            headers.Add(HttpRequestHeader.Authorization.ToString(), "User " + username + ":" + password);

            int selectedIndex = cmbTasks.SelectedIndex + 1;

            ucSpinner.Visibility      = System.Windows.Visibility.Visible;
            btnSendSolution.IsEnabled = false;
            SetLabelInfo("Sending solution...");

            //don't block current thread
            Thread thread = new Thread(() =>
            {
                HttpResponseMessage responseMessage = HttpRequest(hostUrl + "/api/tasks/" + selectedIndex, HttpMethod.Post, body,
                                                                  headers);

                string responseText = responseMessage.Content.ReadAsStringAsync().Result;

                Dispatcher.Invoke(new Action(() => { ucSpinner.Visibility = System.Windows.Visibility.Hidden; }));
                Dispatcher.Invoke(new Action(() => { btnSendSolution.IsEnabled = true; }));
                SetLabelInfo("");

                if (responseMessage.StatusCode == HttpStatusCode.ServiceUnavailable)
                {
                    UpdateServerStatus(false);
                }
                else
                {
                    UpdateServerStatus(true);
                }

                if (responseMessage.StatusCode == HttpStatusCode.OK)
                {
                    RunResult runResult = JsonConvert.DeserializeObject <RunResult>(responseText);

                    Dispatcher.Invoke(new Action(() =>
                    {
                        ResultWindow resultWindow = new ResultWindow();

                        //center
                        resultWindow.Top  = this.Top + (this.Height - resultWindow.Height) / 2;
                        resultWindow.Left = this.Left + (this.Width - resultWindow.Width) / 2;

                        resultWindow.PopulateWindow(runResult);

                        resultWindow.Show();
                    }));
                }
                else
                {
                    if (responseMessage.StatusCode == HttpStatusCode.Unauthorized)
                    {
                        Dispatcher.Invoke(new Action(() =>
                        {
                            Logout();
                        }));
                    }

                    MessageBoxCenterer.MessageBoxCentered(this, JsonConvert.DeserializeObject <Dictionary <string, string> >(responseText)["Message"],
                                                          responseMessage.StatusCode.ToString());
                }
            });

            thread.IsBackground = true;
            thread.Start();
        }