Ejemplo n.º 1
0
        /// <summary>
        /// Deliver the required arguments to solver
        /// </summary>
        /// <param name="problemID">ID of problem</param>
        /// <param name="inputs">Input, only support 1 file now</param>
        /// <param name="outputs">Output, only support 1 file now</param>
        /// <param name="isInputFilePath">If is file mode</param>
        /// <param name="isOutputFilePath">If is file mode</param>
        /// <returns>Text content result</returns>
        public UITextContent GetResult(string problemID, List<string> inputs, List<string> outputs, bool isInputFilePath, bool isOutputFilePath)
        {
            Machine machine = new Machine();
            machine.ProblemID = problemID;
            machine.Inputs = inputs;
            machine.Outputs = outputs;
            machine.IsInputFilePath = isInputFilePath;
            machine.IsOuputFilePath = isOutputFilePath;

            UITextContent content = new UITextContent();

            if (isInputFilePath)
            {
                content.Input = System.IO.File.ReadAllLines(inputs.First()).ToList();
            }
            else
            {
                content.Input = inputs;
            }

            content.Output = machine.AwakeMachine();

            return content;
        }
Ejemplo n.º 2
0
        // Run with inputs, output to outputBox
        private void runBtn_Click(object sender, EventArgs e)
        {
            // Prepare arguments
            List<string> input = new List<string>(1);
            List<string> output = new List<string>(1) { outputPathBox.Text };
            string problemID = "";

            if (problemSelector.SelectedIndex > -1 && problemSelector.Items.Count > 0)
            {
                problemID = problemSelector.Items[problemSelector.SelectedIndex].ToString();
            }

            if (isInputFilePath.Checked)
            {
                input.Add(inputPathBox.Text);
            }
            else
            {
                input = inputBox.Lines.ToList();
                for (int i = 0; i < input.Count; i++)
                {
                    input[i] = input[i].Replace("\\", "\\\\").Replace("\"", "\\\"");
                }
            }

            // Run
            ContentDeliverer deliverer = new ContentDeliverer();
            UITextContent content = new UITextContent();
            try
            {
                content = deliverer.GetResult(problemID, input, output, isInputFilePath.Checked, isOutputFilePath.Checked);
            }
            catch(Exception ex)
            {
                content.Output.Add(ex.Message);
            }

            // Update UI
            inputBox.Text = "";
            outputBox.Text = "";

            string tempStr = "";

            tempStr = String.Join("\n", content.Input.ToArray());
            tempStr = (tempStr.Length > 2147483647) ? tempStr.Substring(0, 2147483647) : tempStr;
            inputBox.Text = tempStr.Replace("\\\"", "\"");

            tempStr = String.Join("\n", content.Output.ToArray());
            tempStr = (tempStr.Length > 2147483647) ? tempStr.Substring(0, 2147483647) : tempStr;
            outputBox.Text = tempStr;
        }