Ejemplo n.º 1
0
        public string Run(RundotnetData data)
        {
            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            if (!string.IsNullOrEmpty(data.Program) && data.Program.Length > 200000)
            {
                return(json.Serialize(new JsonData()
                {
                    Errors = "Program is too long (max is 200000 characters).\n"
                }));
            }

            data.Warnings = new List <string>();
            data.Errors   = new List <string>();
            data          = RundotnetLogic.RunProgram(data);
            string warnings = null, errors = null;

            if (data.Warnings.Count() != 0 && data.ShowWarnings)
            {
                warnings = data.Warnings.Aggregate((a, b) => a + "\n" + b);
            }
            if (data.Errors.Count() != 0)
            {
                errors = data.Errors.Aggregate((a, b) => a + "\n" + b);
            }
            return(json.Serialize(new JsonData()
            {
                Warnings = warnings, Errors = errors, Result = data.Output, Stats = data.RunStats
            }));
        }
        public string Run(RundotnetData data)
        {
            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            if (!string.IsNullOrEmpty(data.Program) && data.Program.Length > maxChars)
            {
                return(json.Serialize(new JsonDataSubset()
                {
                    Errors = string.Format("Program is too long (max is {0} characters).\n", maxChars)
                }));
            }
            if (!string.IsNullOrEmpty(data.Input) && data.Input.Length > maxChars)
            {
                return(json.Serialize(new JsonDataSubset()
                {
                    Errors = string.Format("Input is too long (max is {0} characters).\n", maxChars)
                }));
            }

            data.Warnings = new List <string>();
            data.Errors   = new List <string>();

            //var cache = Model.GetRundotnetDataFromRedis(data);
            //if (cache != null)
            //{
            //    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, data.Output, (int)data.LanguageChoice, data.IsApi);
            //    return json.Serialize(new JsonDataSubset() { Warnings = data.ShowWarnings || data.IsApi ? cache.WholeWarning : null, Errors = cache.WholeError, Result = cache.WholeOutput, Stats = cache.RunStatus + " (cached)" });
            //}
            //else
            //{
            data = RundotnetLogic.RunProgram(data);
            string warnings = null, errors = null;

            if (data.Warnings.Count() != 0)
            {
                warnings = data.Warnings.Aggregate((a, b) => a + "\n" + b);
            }
            if (data.Errors.Count() != 0)
            {
                errors = data.Errors.Aggregate((a, b) => a + "\n" + b);
            }
            //ThreadPool.QueueUserWorkItem(f =>
            //    {
            //        data.WholeWarning = warnings;
            //        data.WholeError = errors;
            //        Model.InsertRundotnetDataToRedis(data);
            //    });
            return(json.Serialize(new JsonDataSubset()
            {
                Warnings = data.ShowWarnings || data.IsApi ? warnings : null, Errors = errors, Result = data.Output, Stats = data.RunStats, Files = data.Files
            }));
            //}
        }