Esempio n. 1
0
        public string ToHtml(string player1Name, string player2Name, string battleOutput)
        {
            Logger.Trace("Viewing output as Animation");

            string[] splitters = { "=~=" };
            string[] frames    = battleOutput.Split(splitters, StringSplitOptions.None);
            frames = RemoveEmptyFrames(frames);

            StringBuilder scriptFramesVar = new StringBuilder("var frames{0} = [");

            for (int i = 0; i < frames.Length; ++i)
            {
                string htmlFrame = JarvisEncoding.ToHtmlEncoding(frames[i].TrimEnd(' '));
                scriptFramesVar.AppendFormat("\"{0}\"", htmlFrame);

                if (i < frames.Length - 1)
                {
                    scriptFramesVar.Append(",");
                }
            }

            scriptFramesVar.Append("]; ");

            StringBuilder builder = new StringBuilder();

            builder.AppendFormat(script1, 0);
            builder.AppendFormat(scriptFramesVar.ToString(), 0);
            builder.AppendFormat(script2, 0);
            builder.AppendFormat("<h3>{0} vs. {1}</h3> ", player1Name, player2Name);
            builder.AppendFormat(script3, 0);

            return(builder.ToString());
        }
Esempio n. 2
0
        public string ToHtml(TestCase data)
        {
            Logger.Trace("Viewing output as Animation");

            string[] splitters = { "=~=" };
            string[] frames    = data.StdOutText.Split(splitters, StringSplitOptions.None);
            frames = RemoveEmptyFrames(frames);

            StringBuilder scriptFramesVar = new StringBuilder("var frames{0} = [");

            for (int i = 0; i < frames.Length; ++i)
            {
                foreach (Keyword keyword in keywords)
                {
                    if (frames[i].Contains(keyword.Word))
                    {
                        keyword.Found = true;
                    }
                }

                string htmlFrame = JarvisEncoding.ToHtmlEncoding(frames[i].TrimEnd(' '));
                scriptFramesVar.AppendFormat("\"{0}\"", htmlFrame);

                if (i < frames.Length - 1)
                {
                    scriptFramesVar.Append(",");
                }
            }

            scriptFramesVar.Append("]; ");

            bool foundAllKeywords = true;

            foreach (Keyword keyword in keywords)
            {
                if (!keyword.Found)
                {
                    foundAllKeywords = false;
                    break; // Once we've missed one, then we don't need to keep looking
                }
            }

            data.Passed = foundAllKeywords;

            StringBuilder builder = new StringBuilder();

            builder.AppendFormat(script1, data.Id);
            builder.AppendFormat(scriptFramesVar.ToString(), data.Id);
            builder.AppendFormat(script2, data.Id);
            builder.AppendFormat("<p>Searched for: \"{0}\"</p> ", keywordList);
            builder.AppendFormat(script3, data.Id);

            return(Utilities.BuildDiffBlock("Animation:", builder.ToString(), "", ""));
        }
Esempio n. 3
0
        private string Get5xx(NancyContext context)
        {
            StringBuilder responseText = new StringBuilder();

            responseText.AppendFormat("<img style='display: block; margin: auto;' src='data:image/png;base64,{0}' /><br />", JarvisEncoding.ConvertToBase64(rootPath + "/Content/error.png", false));
            responseText.Append("<p>I'm sorry sir, it appears I have malfunctioned... an email has been sent to my creator.<br /><br />");
            responseText.Append("Error message:<br />" + JarvisEncoding.ToHtmlEncoding(context.Items["ERROR_TRACE"].ToString()));
            responseText.Append("</p>");

            Utilities.SendEmail("*****@*****.**", "Jarvis Internal Server Error!!", context.Items["ERROR_TRACE"].ToString(), "");

            return(responseText.ToString());
        }
Esempio n. 4
0
        private string StyleCheck(Assignment homework)
        {
            StringBuilder result   = new StringBuilder();
            StyleExecutor executor = new StyleExecutor();

            foreach (string file in homework.FileNames)
            {
                string errors = executor.Run(homework.Path + file);

                result.AppendFormat("File: {0}\n", file);
                result.AppendFormat("{0}\n", errors);
            }

            return(JarvisEncoding.ToHtmlEncoding(result.ToString()));
        }
Esempio n. 5
0
        public static string CompileCpp(string outputName, string path, List <string> includeDirs, List <string> sourceFiles)
        {
            string result = "";

            using (Process p = new Process())
            {
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError  = true;
                p.StartInfo.FileName  = "g++";
                p.StartInfo.Arguments = "-DJARVIS -g -std=c++11 -Werror -o" + outputName;

                foreach (string include in includeDirs)
                {
                    p.StartInfo.Arguments += " -I" + include;
                }

                // Expects the source to be full name
                foreach (string source in sourceFiles)
                {
                    p.StartInfo.Arguments += " " + source;
                }

                p.Start();

                Logger.Trace("Compilation string: {0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments);

                Jarvis.StudentProcesses.Add(p.Id);

                result = p.StandardError.ReadToEnd();
                result = result.Replace(path, "");
                result = JarvisEncoding.ToHtmlEncoding(result);

                p.WaitForExit();

                p.Close();
            }
            Logger.Trace("Compile result: {0}", result);

            return((!string.IsNullOrEmpty(result)) ? result : "Success!!");
        }
Esempio n. 6
0
        private string Compile(Assignment homework, List <string> providedFiles)
        {
            // Find all C++ source files
            List <string> sourceFiles = new List <string>();

            foreach (string file in homework.FileNames)
            {
                if (file.EndsWith(".cpp") || file.EndsWith(".cxx") || file.EndsWith(".cc"))
                {
                    sourceFiles.Add(file);
                }
            }

            // Add in provided files
            string testsPath = string.Format("{0}/courses/{1}/tests/hw{2}/", Jarvis.Config.AppSettings.Settings["workingDir"].Value, homework.Course, homework.HomeworkId);

            foreach (string file in providedFiles)
            {
                // Copy all provided files (headers and source)
                Logger.Trace("Copying {0} to {1}", testsPath + file, homework.Path);
                File.Copy(testsPath + file, homework.Path + file, true);

                // Only build source files
                if (file.EndsWith(".cpp") || file.EndsWith(".cxx") || file.EndsWith(".cc"))
                {
                    sourceFiles.Add(file);
                }
            }

            string result = "";

            using (Process p = new Process())
            {
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError  = true;
                p.StartInfo.FileName  = "g++";
                p.StartInfo.Arguments = "-DJARVIS -std=c++11 -Werror -o" + homework.Path + homework.StudentId + " -I" + homework.Path;
                foreach (string source in sourceFiles)
                {
                    //string temp = source.Replace("_", "\_");
                    p.StartInfo.Arguments += string.Format(" \"{0}{1}\"", homework.Path, source);
                }

                p.Start();

                Logger.Trace("Compilation string: {0} {1}", p.StartInfo.FileName, p.StartInfo.Arguments);

                Jarvis.StudentProcesses.Add(p.Id);

                result = p.StandardError.ReadToEnd();
                result = result.Replace(homework.Path, "");
                result = JarvisEncoding.ToHtmlEncoding(result);

                p.WaitForExit();

                p.Close();
            }
            Logger.Trace("Compile result: {0}", result);

            return((!string.IsNullOrEmpty(result)) ? result : "Success!!");
        }