Beispiel #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
            }));
        }
Beispiel #2
0
        public ViewResult GetEditCode(RundotnetData data, string savedNr)
        {
            Compression.SetCompression();
            var code = Model.GetCode(savedNr, false);

            if (code == null)
            {
                throw new HttpException(404, "not found");
            }
            data.Title          = code.Title;
            data.Program        = code.Program;
            data.Input          = code.Input;
            data.Output         = code.Output;
            data.CompilerArgs   = code.CompilerArgs;
            data.LanguageChoice = (LanguagesEnum)code.Lang;
            data.EditorChoice   = (EditorsEnum)code.Editor;
            data.WholeError     = code.WholeError;
            data.WholeWarning   = code.Warnings;
            data.ShowWarnings   = code.ShowWarnings;
            data.RunStats       = code.Stats;
            data.CodeGuid       = code.Guid;
            data.IsSaved        = true;
            data.Votes          = code.Votes;

            data.IsInEditMode      = code.IsPrimaryVersion;
            data.EditVisible       = false;
            data.BackToForkVisible = code.IsPrimaryVersion;
            data.PrimaryGuid       = code.PrimaryGuid == null ? data.CodeGuid : code.PrimaryGuid;

            return(View("Index", data));
        }
        public ActionResult Index(RundotnetData data, string savedNr = null)
        {
            Compression.SetCompression();

            //retrieve saved code
            savedNr = savedNr ?? HttpContext.Request.QueryString["code"];
            if (!string.IsNullOrEmpty(savedNr))
            {
                var code = Model.GetCode(savedNr);
                data.Program = code.Program;
                data.LanguageChoice = code.Lang.ToString() == "0" ? "1" : code.Lang.ToString();
                data.EditorChoice = code.Editor.ToString() == "0" ? "1" : code.Editor.ToString();
                data.Output = code.Output;
                data.WholeError = code.WholeError;
                data.WholeWarning = code.Warnings;
                data.ShowWarnings = code.ShowWarnings;
                data.RunStats = code.Stats;
                return View(data);
            }

            if (string.IsNullOrEmpty(data.LanguageChoice))
                data.LanguageChoice = "1";
            if (string.IsNullOrEmpty(data.EditorChoice))
                data.EditorChoice = "1";
            if (data.EditorChoice == "1" && data.ShowCodeMirror == false)
                data.EditorChoice = "2";

            data.Program = data.GetInitialCode(data.LanguageChoice, data.EditorChoice);

            return View(data);
        }
Beispiel #4
0
        public string Save(RundotnetData data)
        {
            Compression.SetCompression();

            string url = null;

            if (data.Program == null)
            {
                data.Program = string.Empty;
            }
            if (!string.IsNullOrEmpty(data.WholeError))
            {
                data.Status = GlobalConst.RundotnetStatus.Error;
            }
            else
            {
                data.Status = GlobalConst.RundotnetStatus.OK;
            }
            string guid = Model.SaveCode(data);

            if (!string.IsNullOrEmpty(guid))
            {
                url = Utils.Utils.BaseUrl + guid;
            }

            JavaScriptSerializer json = new JavaScriptSerializer();

            return(json.Serialize(new JsonData()
            {
                Url = url
            }));
        }
Beispiel #5
0
 public static RundotnetData RunProgram(RundotnetData data)
 {
     if (data.LanguageChoice == LanguagesEnum.CSharp || data.LanguageChoice == LanguagesEnum.VB)
     {
         return RunDotNet(data);
     }
     else if (data.LanguageChoice == LanguagesEnum.SqlServer)
     {
         return RunSqlServer(data);
     }
     else if (data.LanguageChoice == LanguagesEnum.VCPP || data.LanguageChoice == LanguagesEnum.VC)
     {
         return RunWindows(data);
     }
     else if (data.LanguageChoice == LanguagesEnum.MySql)
     {
         return RunMySql(data);
     }
     else if (data.LanguageChoice == LanguagesEnum.Postgresql)
     {
         return RunPostgre(data);
     }
     else if (data.LanguageChoice == LanguagesEnum.Oracle)
     {
         return RunOracle(data);
     }
     else if (data.LanguageChoice == LanguagesEnum.ClientSide)
     {
         return data;
     }
     else
     {
         return RunLinux(data);
     }
 }
        public ViewResult GetLiveCode(string savedNr)
        {
            Compression.SetCompression();
            RundotnetData data = new RundotnetData();
            var           code = Model.GetLiveCode(savedNr);

            if (code == null)
            {
                throw new HttpException(404, "not found");
            }

            data.Program        = code.Program;
            data.Input          = code.Input;
            data.CompilerArgs   = code.CompilerArgs;
            data.LanguageChoice = (LanguagesEnum)code.Lang;
            data.EditorChoice   = (EditorsEnum)code.Editor;
            data.ShowWarnings   = code.ShowWarnings;
            data.CodeGuid       = savedNr;
            data.User_Id        = code.UserId;
            data.Title          = code.Title;

            data.PrimaryGuid  = data.CodeGuid;
            data.IsLive       = true;
            data.IsSaved      = true;
            data.DisplayName  = SessionManager.IsUserInSession() ? SessionManager.UserName : Utils.Utils.RandomLetter();
            data.EditorChoice = EditorsEnum.Codemirror;

            return(View("Index", data));
        }
 public static RundotnetData RunProgram(RundotnetData data)
 {
     if (data.LanguageChoice == LanguagesEnum.CSharp || data.LanguageChoice == LanguagesEnum.VB)
     {
         return(RunDotNet(data));
     }
     else if (data.LanguageChoice == LanguagesEnum.SqlServer)
     {
         return(RunSqlServer(data));
     }
     else if (data.LanguageChoice == LanguagesEnum.VCPP || data.LanguageChoice == LanguagesEnum.VC)
     {
         return(RunWindows(data));
     }
     else if (data.LanguageChoice == LanguagesEnum.MySql)
     {
         return(RunMySql(data));
     }
     else if (data.LanguageChoice == LanguagesEnum.Postgresql)
     {
         return(RunPostgre(data));
     }
     else if (data.LanguageChoice == LanguagesEnum.Oracle)
     {
         return(RunOracle(data));
     }
     else if (data.LanguageChoice == LanguagesEnum.ClientSide)
     {
         return(data);
     }
     else
     {
         return(RunLinux(data));
     }
 }
        public string Save(RundotnetData data)
        {
            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            if (!string.IsNullOrEmpty(data.Program) && data.Program.Length > maxChars)
            {
                return(json.Serialize(new JsonData()
                {
                    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 JsonData()
                {
                    Errors = string.Format("Input is too long (max is {0} characters).\n", maxChars)
                }));
            }

            string url = null;

            if (data.Program == null)
            {
                data.Program = string.Empty;
            }
            if (!string.IsNullOrEmpty(data.WholeError))
            {
                data.Status = GlobalConst.RundotnetStatus.Error;
            }
            else
            {
                data.Status = GlobalConst.RundotnetStatus.OK;
            }

            if (data.IsInEditMode || data.IsLive)
            {
                Model.UpdateCode(data);
                return(json.Serialize(new JsonData()
                {
                    Updated = true
                }));
            }
            else
            {
                string guid = Model.SaveCode(data);
                if (!string.IsNullOrEmpty(guid))
                {
                    url = Utils.Utils.BaseUrl + guid;
                }
                return(json.Serialize(new JsonData()
                {
                    Url = url
                }));
            }
        }
        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
            }));
            //}
        }
 public static RundotnetData RunProgram(RundotnetData data)
 {
     List<string> dotNet = new List<string>(){"1", "2", "3"};
     if (dotNet.Contains(data.LanguageChoice))
     {
         return RunDotNet(data);
     }
     else
     {
         return RunLinux(data);
     }
 }
        public string Api_save(string code)
        {
            Response.AppendHeader("Access-Control-Allow-Origin", "*");
            var data = new RundotnetData()
            {
                LanguageChoice = LanguagesEnum.CSharp,
                Program = code,
                EditorChoice = EditorsEnum.Codemirror,
                Title = "Rexmonitor testing code: " + DateTime.UtcNow.ToString("yyyy-MM-dd")
            };

            string guid = Model.SaveCode(data);
            return guid;
        }
        public string Api_save(string code)
        {
            Response.AppendHeader("Access-Control-Allow-Origin", "*");
            var data = new RundotnetData()
            {
                LanguageChoice = LanguagesEnum.CSharp,
                Program        = code,
                EditorChoice   = EditorsEnum.Codemirror,
                Title          = "Rexmonitor testing code: " + DateTime.UtcNow.ToString("yyyy-MM-dd")
            };

            string guid = Model.SaveCode(data);

            return(guid);
        }
        public static RundotnetData RunProgram(RundotnetData data)
        {
            List <string> dotNet = new List <string>()
            {
                "1", "2", "3"
            };

            if (dotNet.Contains(data.LanguageChoice))
            {
                return(RunDotNet(data));
            }
            else
            {
                return(RunLinux(data));
            }
        }
        public ViewResult GetEditCode(RundotnetData data, string savedNr)
        {
            Compression.SetCompression();
            var rights = Model.GetCodeRights(savedNr);

            if (rights[1] == (byte)0)
            {
                throw new HttpException(404, "not found");
            }
            var code = Model.GetCode(savedNr, false);

            if (code == null)
            {
                throw new HttpException(404, "not found");
            }
            data.Title          = code.Title;
            data.Program        = code.Program;
            data.Input          = code.Input;
            data.Output         = code.Output;
            data.CompilerArgs   = code.CompilerArgs;
            data.LanguageChoice = (LanguagesEnum)code.Lang;
            data.EditorChoice   = (EditorsEnum)code.Editor;
            data.WholeError     = code.WholeError;
            data.WholeWarning   = code.Warnings;
            data.ShowWarnings   = code.ShowWarnings;
            data.RunStats       = code.Stats;
            data.CodeGuid       = code.Guid;
            data.IsSaved        = true;
            data.Votes          = code.Votes;
            data.User_Id        = code.UserId;

            data.IsInEditMode      = code.IsPrimaryVersion;
            data.EditVisible       = false;
            data.BackToForkVisible = code.IsPrimaryVersion;
            data.PrimaryGuid       = code.PrimaryGuid == null ? data.CodeGuid : code.PrimaryGuid;

            if (SessionManager.IsDarkTheme)
            {
                data.EditorChoice = EditorsEnum.Codemirror;
            }
            if (Utils.Utils.IsMobile)
            {
                data.EditorChoice = EditorsEnum.Simple;
            }

            return(View("Index", data));
        }
        public string Save(RundotnetData data)
        {
            Compression.SetCompression();

            string url = null;
            if (data.Program == null)
                data.Program = string.Empty;
            if (!string.IsNullOrEmpty(data.WholeError))
                data.Status = GlobalConst.RundotnetStatus.Error;
            else
                data.Status = GlobalConst.RundotnetStatus.OK;
            string guid = Model.SaveCode(data);
            if (!string.IsNullOrEmpty(guid))
                url = Utils.Utils.BaseUrl + guid;

            JavaScriptSerializer json = new JavaScriptSerializer();
            return json.Serialize(new JsonData() { Url = url });
        }
 public static RundotnetData RunProgram(RundotnetData data)
 {
     if (data.LanguageChoice == LanguagesEnum.CSharp || data.LanguageChoice == LanguagesEnum.VB || data.LanguageChoice == LanguagesEnum.FSharp)
     {
         return(RunDotNet(data));
     }
     else if (data.LanguageChoice == LanguagesEnum.SqlServer)
     {
         return(RunSqlServer(data));
     }
     else if (data.LanguageChoice == LanguagesEnum.VCPP || data.LanguageChoice == LanguagesEnum.VC)
     {
         return(RunWindows(data));
     }
     else
     {
         return(RunLinux(data));
     }
 }
        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 ViewResult GetEditCode(RundotnetData data, string savedNr)
        {
            Compression.SetCompression();
            var rights = Model.GetCodeRights(savedNr);
            if (rights[1] == (byte)0)
            {
                throw new HttpException(404, "not found");
            }
            var code = Model.GetCode(savedNr, false);
            if (code == null)
            {
                throw new HttpException(404, "not found");
            }
            data.Title = code.Title;
            data.Program = code.Program;
            data.Input = code.Input;
            data.Output = code.Output;
            data.CompilerArgs = code.CompilerArgs;
            data.LanguageChoice = (LanguagesEnum)code.Lang;
            data.EditorChoice = (EditorsEnum)code.Editor;
            data.WholeError = code.WholeError;
            data.WholeWarning = code.Warnings;
            data.ShowWarnings = code.ShowWarnings;
            data.RunStats = code.Stats;
            data.CodeGuid = code.Guid;
            data.IsSaved = true;
            data.Votes = code.Votes;
            data.User_Id = code.UserId;

            data.IsInEditMode = code.IsPrimaryVersion;
            data.EditVisible = false;
            data.BackToForkVisible = code.IsPrimaryVersion;
            data.PrimaryGuid = code.PrimaryGuid == null ? data.CodeGuid : code.PrimaryGuid;

            if (Utils.Utils.IsMobile)
            {
                data.EditorChoice = EditorsEnum.Simple;
            }

            return View("Index", data);
        }
Beispiel #19
0
        public ActionResult Index(RundotnetData data, string savedNr = null)
        {
            Compression.SetCompression();

            //retrieve saved code
            savedNr = savedNr ?? HttpContext.Request.QueryString["code"];
            if (!string.IsNullOrEmpty(savedNr))
            {
                var code = Model.GetCode(savedNr);
                data.Program        = code.Program;
                data.LanguageChoice = code.Lang.ToString() == "0" ? "1" : code.Lang.ToString();
                data.EditorChoice   = code.Editor.ToString() == "0" ? "1" : code.Editor.ToString();
                data.Output         = code.Output;
                data.WholeError     = code.WholeError;
                data.WholeWarning   = code.Warnings;
                data.ShowWarnings   = code.ShowWarnings;
                data.RunStats       = code.Stats;
                return(View(data));
            }

            if (string.IsNullOrEmpty(data.LanguageChoice))
            {
                data.LanguageChoice = "1";
            }
            if (string.IsNullOrEmpty(data.EditorChoice))
            {
                data.EditorChoice = "1";
            }
            if (data.EditorChoice == "1" && data.ShowCodeMirror == false)
            {
                data.EditorChoice = "2";
            }

            data.Program = data.GetInitialCode(data.LanguageChoice, data.EditorChoice);

            return(View(data));
        }
Beispiel #20
0
 public static void UpdateCode(RundotnetData data)
 {
     var guid = Utils.Utils.GetGuid();
     try
     {
         var rights = GetCodeRights(data.CodeGuid);
         if (rights[1] == (byte)0)
         {
             return;
         }
         if (data.IsLive)
         {
             DB.DB.Live_Code_Update(guid, data.Program, data.Input, data.SavedOutput, data.CompilerArgs, data.CodeGuid, data.WholeError, data.WholeWarning, data.ShowWarnings, (int)data.Status, data.StatsToSave, data.Title);
         }
         else
         {
             DB.DB.Code_Update(guid, data.Program, data.Input, data.SavedOutput, data.CompilerArgs, data.CodeGuid, data.WholeError, data.WholeWarning, data.ShowWarnings, (int)data.Status, data.StatsToSave, data.Title);
             if (SessionManager.IsUserInSession())
             {
                 int uid = (int)SessionManager.UserId;
                 Task.Run(() =>
                 {
                     Search.PutUserItem(new UsersItem()
                     {
                         Code = data.Program,
                         Date = DateTime.Now,
                         Guid = data.CodeGuid,
                         ID = "code_" + data.CodeGuid,
                         Lang = data.LanguageChoice.ToLanguage(),
                         UserId = uid,
                         Title = data.Title
                     });
                 });
             }
         }
     }
     catch (Exception e)
     {
         Utils.Log.LogInfo(e.Message, e, "error");
     }
 }
Beispiel #21
0
        public static string SaveCode(RundotnetData data, bool wall = false, bool live = false, bool personal = false)
        {
            var guid = Utils.Utils.GetGuid();

            try
            {
                DB.DB.Code_Insert(data.Title, data.Program, data.Input, data.SavedOutput, data.CompilerArgs, Convert.ToInt32(data.LanguageChoice), Convert.ToInt32(data.EditorChoice), guid, SessionManager.UserId, data.WholeError, data.WholeWarning, data.ShowWarnings, (int)data.Status, data.StatsToSave, wall, live, personal);

                if (data.Privacy != null && data.Privacy != "2")
                {
                    if (!string.IsNullOrEmpty(data.PrivacyUsers) && data.Privacy == "3" && SessionManager.IsUserInSession())
                    {
                        data.PrivacyUsers += "," + SessionManager.UserName;
                    }
                    DB.DB.Privacy_Info_Insert(data.Privacy, data.PrivacyUsers, guid);
                }

                if (SessionManager.IsUserInSession())
                {
                    int uid = (int)SessionManager.UserId;
                    Task.Run(() =>
                        {
                            Search.PutUserItem(new UsersItem()
                            {
                                Code = data.Program,
                                Date = DateTime.Now,
                                Guid = guid,
                                ID = "code_"+guid,
                                Lang = data.LanguageChoice.ToLanguage(),
                                UserId = uid,
                                Title = data.Title,
                                IsLive = live == true ? 1 : 0
                            });
                        });
                }
            }
            catch (Exception e)
            {
                Utils.Log.LogInfo(e.Message, e, "error");
                return "";
            }
            return guid;
        }
        public string SaveOnWall(RundotnetData data)
        {
            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            if (!string.IsNullOrEmpty(data.Program) && data.Program.Length > maxChars)
            {
                return json.Serialize(new JsonData() { 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 JsonData() { Errors = string.Format("Input is too long (max is {0} characters).\n", maxChars) });
            }
            if (!string.IsNullOrEmpty(data.Title) && data.Title.Length > 100)
            {
                return json.Serialize(new JsonData() { Errors = "Title is too long (max is 100 characters).\n" });
            }
            string url = null;
            if (data.Program == null)
                data.Program = string.Empty;
            if (!string.IsNullOrEmpty(data.WholeError))
                data.Status = GlobalConst.RundotnetStatus.Error;
            else
                data.Status = GlobalConst.RundotnetStatus.OK;
            string guid = Model.SaveCode(data, true);
            if (!string.IsNullOrEmpty(guid))
                url = Utils.Utils.BaseUrl + guid;

            return json.Serialize(new JsonData() { Url = url });
        }
Beispiel #23
0
        public ActionResult Index(RundotnetData data, string savedNr = null)
        {
            Compression.SetCompression();

            //retrieve saved code
            savedNr = savedNr ?? HttpContext.Request.QueryString["code"];
            if (!string.IsNullOrEmpty(savedNr))
            {
                var code = Model.GetCode(savedNr, false);
                if (code == null)
                {
                    throw new HttpException(404, "not found");
                }
                data.Title          = code.Title;
                data.Program        = code.Program;
                data.Input          = code.Input;
                data.CompilerArgs   = code.CompilerArgs;
                data.Output         = code.Output;
                data.LanguageChoice = (LanguagesEnum)code.Lang;
                data.EditorChoice   = (EditorsEnum)code.Editor;
                data.WholeError     = code.WholeError;
                data.WholeWarning   = code.Warnings;
                data.ShowWarnings   = code.ShowWarnings;
                data.RunStats       = code.Stats;
                data.CodeGuid       = code.Guid;
                data.Votes          = code.Votes;

                data.IsInEditMode      = false;
                data.EditVisible       = code.IsPrimaryVersion;
                data.BackToForkVisible = false;
                data.PrimaryGuid       = code.PrimaryGuid == null ? data.CodeGuid : code.PrimaryGuid;
                data.IsSaved           = true;
                if (data.PrimaryGuid != data.CodeGuid)
                {
                    data.LivesVersion = Model.IsLive(data.PrimaryGuid);
                }

                return(View(data));
            }

            data.IsLive       = false;
            data.IsInEditMode = false;

            if ((int)data.LanguageChoice != (int)LanguagesEnum.Unknown && (int)data.EditorChoice != (int)EditorsEnum.Unknown)
            {
                Model.SaveUserProfile(data.LanguageChoice, data.EditorChoice);
            }

            UserProfile profile = null;

            if ((int)data.LanguageChoice == (int)LanguagesEnum.Unknown || (int)data.EditorChoice == (int)EditorsEnum.Unknown)
            {
                profile = Model.GetUserProfile();
            }

            if ((int)data.LanguageChoice == (int)LanguagesEnum.Unknown)
            {
                data.LanguageChoice = profile.LanguageChoice;
            }

            if ((int)data.EditorChoice == (int)EditorsEnum.Unknown)
            {
                data.EditorChoice = profile.EditorChoice;
            }

            data.Program      = data.GetInitialCode(data.LanguageChoice, data.EditorChoice);
            data.CompilerArgs = data.GetInitialCompilerArgs(data.LanguageChoice);
            return(View(data));
        }
        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 });
            //}
        }
        static RundotnetData RunSqlServer(RundotnetData data)
        {
            string path = reExp.Utils.Utils.RootFolder + "executables/usercode/" + Utils.Utils.RandomString() + ".sql";

            using (TextWriter tw = new StreamWriter(path))
            {
                tw.Write(data.Program);
            }

            using (Process process = new Process())
            {
                try
                {
                    double TotalMemoryInBytes = 0;
                    double TotalThreadCount   = 0;
                    int    samplesCount       = 0;

                    process.StartInfo.FileName               = reExp.Utils.Utils.RootFolder + "executables/SqlServer.exe";
                    process.StartInfo.Arguments              = path.Replace(" ", "|_|");
                    process.StartInfo.UseShellExecute        = false;
                    process.StartInfo.CreateNoWindow         = true;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError  = true;

                    DateTime start = DateTime.Now;
                    process.Start();

                    OutputReader output       = new OutputReader(process.StandardOutput, false);
                    Thread       outputReader = new Thread(new ThreadStart(output.ReadOutput));
                    outputReader.Start();
                    OutputReader error       = new OutputReader(process.StandardError);
                    Thread       errorReader = new Thread(new ThreadStart(error.ReadOutput));
                    errorReader.Start();


                    do
                    {
                        // Refresh the current process property values.
                        process.Refresh();
                        if (!process.HasExited)
                        {
                            try
                            {
                                var proc = process.TotalProcessorTime;
                                // Update the values for the overall peak memory statistics.
                                var mem1 = process.PagedMemorySize64;
                                var mem2 = process.PrivateMemorySize64;

                                //update stats
                                TotalMemoryInBytes += (mem1 + mem2);
                                TotalThreadCount   += (process.Threads.Count);
                                samplesCount++;

                                if (proc.TotalSeconds > 5 || mem1 + mem2 > 100000000 || process.Threads.Count > 100 || start + TimeSpan.FromSeconds(15) < DateTime.Now)
                                {
                                    var time = proc.TotalSeconds;
                                    var mem  = mem1 + mem2;
                                    process.Kill();
                                    var res = string.Format("Process killed because it exceeded given resources.\nCpu time used {0} sec, absolute running time {1} sec, memory used {2} Mb, nr of threads {3}", time, (int)(DateTime.Now - start).TotalSeconds, (int)(mem / 1048576), process.Threads.Count);
                                    data.Errors.Add(res);
                                    string partialResult = output.Builder.ToString();
                                    data.Output   = partialResult;
                                    data.RunStats = string.Format("Absolute service time: {0} sec", Math.Round((double)(DateTime.Now - start).TotalMilliseconds / 1000, 2));
                                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, res, (int)data.LanguageChoice, data.IsApi, false);
                                    return(data);
                                }
                            }
                            catch (InvalidOperationException)
                            {
                                break;
                            }
                        }
                    }while (!process.WaitForExit(10));
                    process.WaitForExit();

                    errorReader.Join(5000);
                    outputReader.Join(5000);

                    if (!string.IsNullOrEmpty(error.Output))
                    {
                        data.Output = output.Builder.ToString();
                        data.Errors.Add(error.Output);
                        data.RunStats = string.Format("Absolute service time: {0} sec", Math.Round((double)(DateTime.Now - start).TotalMilliseconds / 1000, 2));
                        Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, error.Output, (int)data.LanguageChoice, data.IsApi, false);
                        return(data);
                    }

                    if (File.Exists(path + ".stats"))
                    {
                        using (TextReader tr = new StreamReader(path + ".stats"))
                        {
                            data.RunStats = tr.ReadLine();
                            if (!string.IsNullOrEmpty(data.RunStats))
                            {
                                data.RunStats += ", ";
                            }
                            else
                            {
                                data.RunStats = "";
                            }
                            data.RunStats += string.Format("absolute service time: {0} sec", Math.Round((double)(DateTime.Now - start).TotalMilliseconds / 1000, 2));
                        }
                    }
                    else
                    {
                        data.RunStats = string.Format("Absolute service time: {0} sec", Math.Round((double)(DateTime.Now - start).TotalMilliseconds / 1000, 2));
                    }

                    data.Output = output.Output;
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "OK", (int)data.LanguageChoice, data.IsApi, true);
                    return(data);
                }
                catch (Exception e)
                {
                    if (!process.HasExited)
                    {
                        reExp.Utils.Log.LogInfo("Process left running " + e.Message, e, "RunSqlServer");
                    }
                    throw;
                }
                finally
                {
                    try
                    {
                        reExp.Utils.CleanUp.DeleteFile(path);
                        reExp.Utils.CleanUp.DeleteFile(path + ".stats");
                    }
                    catch (Exception)
                    { }

                    SqlServerUtils job = new SqlServerUtils();
                    Thread         t   = new Thread(job.DoShrinkJob);
                    t.Start();
                }
            }
        }
        static RundotnetData RunLinux(RundotnetData data)
        {
            LinuxService service = new LinuxService();

            Service.linux.Languages lang = Service.linux.Languages.Java;

            if (data.LanguageChoice == LanguagesEnum.Prolog)
            {
                data.Input += "\nhalt.";
            }
            switch (data.LanguageChoice)
            {
            case LanguagesEnum.Java:
                lang = Service.linux.Languages.Java;
                break;

            case LanguagesEnum.Python:
                lang = Service.linux.Languages.Python;
                break;

            case LanguagesEnum.C:
                lang = Service.linux.Languages.C;
                break;

            case LanguagesEnum.CPP:
                lang = Service.linux.Languages.CPP;
                break;

            case LanguagesEnum.Php:
                lang = Service.linux.Languages.Php;
                break;

            case LanguagesEnum.Pascal:
                lang = Service.linux.Languages.Pascal;
                break;

            case LanguagesEnum.ObjectiveC:
                lang = Service.linux.Languages.ObjectiveC;
                break;

            case LanguagesEnum.Haskell:
                lang = Service.linux.Languages.Haskell;
                break;

            case LanguagesEnum.Ruby:
                lang = Service.linux.Languages.Ruby;
                break;

            case LanguagesEnum.Perl:
                lang = Service.linux.Languages.Perl;
                break;

            case LanguagesEnum.Lua:
                lang = Service.linux.Languages.Lua;
                break;

            case LanguagesEnum.Nasm:
                lang = Service.linux.Languages.Nasm;
                break;

            case LanguagesEnum.Javascript:
                lang = Service.linux.Languages.Javascript;
                break;

            case LanguagesEnum.Lisp:
                lang = Service.linux.Languages.Lisp;
                break;

            case LanguagesEnum.Prolog:
                lang = Service.linux.Languages.Prolog;
                break;

            case LanguagesEnum.Go:
                lang = Service.linux.Languages.Go;
                break;

            case LanguagesEnum.Scala:
                lang = Service.linux.Languages.Scala;
                break;

            case LanguagesEnum.Scheme:
                lang = Service.linux.Languages.Scheme;
                break;

            case LanguagesEnum.Nodejs:
                lang = Service.linux.Languages.Nodejs;
                break;

            case LanguagesEnum.Python3:
                lang = Service.linux.Languages.Python3;
                break;

            case LanguagesEnum.Octave:
                lang = Service.linux.Languages.Octave;
                break;

            case LanguagesEnum.CClang:
                lang = Service.linux.Languages.CClang;
                break;

            case LanguagesEnum.CPPClang:
                lang = Service.linux.Languages.CppClang;
                break;

            case LanguagesEnum.D:
                lang = Service.linux.Languages.D;
                break;

            case LanguagesEnum.R:
                lang = Service.linux.Languages.R;
                break;

            case LanguagesEnum.Tcl:
                lang = Service.linux.Languages.Tcl;
                break;

            case LanguagesEnum.Swift:
                lang = Service.linux.Languages.Swift;
                break;

            case LanguagesEnum.FSharp:
                lang = Service.linux.Languages.FSharp;
                break;

            case LanguagesEnum.Bash:
                lang = Service.linux.Languages.Bash;
                break;

            case LanguagesEnum.Ada:
                lang = Service.linux.Languages.Ada;
                break;

            case LanguagesEnum.Erlang:
                lang = Service.linux.Languages.Erlang;
                break;

            case LanguagesEnum.Elixir:
                lang = Service.linux.Languages.Elixir;
                break;

            case LanguagesEnum.Ocaml:
                lang = Service.linux.Languages.Ocaml;
                break;

            default:
                break;
            }
            Stopwatch watch = new Stopwatch();

            watch.Start();
            var res = service.DoWork(data.Program, data.Input, data.CompilerArgs, lang);

            watch.Stop();
            if (res != null)
            {
                if (string.IsNullOrEmpty(res.Stats))
                {
                    res.Stats = "";
                }
                else
                {
                    res.Stats += ", ";
                }
                res.Stats    += string.Format("absolute service time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2));
                data.RunStats = res.Stats;
            }
            bool logged = false;

            if (!string.IsNullOrEmpty(res.System_Error))
            {
                reExp.Utils.Log.LogInfo("Linux " + res.System_Error, null, "RunDotNet");
                data.Errors.Add(res.System_Error);
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Linux: system error " + res.System_Error, (int)data.LanguageChoice, data.IsApi, false);
                return(data);
            }
            if (!string.IsNullOrEmpty(res.Errors))
            {
                data.Errors.Add(res.Errors);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Linux: error " + res.Errors, (int)data.LanguageChoice, data.IsApi, false);
                    logged = true;
                }
            }
            if (res.Exit_Code < 0)
            {
                data.Errors.Add(res.Exit_Status);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Linux: negative exit code " + res.Exit_Status, (int)data.LanguageChoice, data.IsApi, false);
                    logged = true;
                }
            }
            if (!string.IsNullOrEmpty(res.Warnings))
            {
                data.Warnings.Add(res.Warnings);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Linux: warnings", (int)data.LanguageChoice, data.IsApi, true);
                    logged = true;
                }
            }
            data.Output = res.Output;
            if (res.Files != null)
            {
                data.Files = new List <string>();
                foreach (var f in res.Files)
                {
                    data.Files.Add(Convert.ToBase64String(f));
                }
            }
            if (!logged)
            {
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Linux: ok", (int)data.LanguageChoice, data.IsApi, true);
                logged = true;
            }
            return(data);
        }
Beispiel #27
0
        static RundotnetData RunDotNet(RundotnetData data)
        {
            int compilationTimeInMs;
            CompilerParameters cp = new CompilerParameters();
            cp.GenerateExecutable = false;
            Random rg = Utils.Utils.GetTrulyRandom();
            string folder = reExp.Utils.Utils.RootFolder + @"\executables\usercode\";
            string assemblyName = "userAssembly_" + rg.Next(0, 10000000);

            string path = folder + assemblyName + ".dll";
            cp.OutputAssembly = path;
            // Save the assembly as a physical file.
            cp.GenerateInMemory = false;
            // Set whether to treat all warnings as errors.
            cp.TreatWarningsAsErrors = false;
            cp.WarningLevel = 4;
            cp.IncludeDebugInformation = false;

            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("System.Core.dll");

            cp.ReferencedAssemblies.Add("System.Numerics.dll");
            cp.ReferencedAssemblies.Add("System.Data.dll");
            cp.ReferencedAssemblies.Add("System.Data.DataSetExtensions.dll");
            cp.ReferencedAssemblies.Add("System.Xml.dll");
            cp.ReferencedAssemblies.Add("System.Xml.Linq.dll");
            cp.ReferencedAssemblies.Add("System.Drawing.dll");

            if (data.LanguageChoice == LanguagesEnum.CSharp)
                cp.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
            else if (data.LanguageChoice == LanguagesEnum.VB)
                cp.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll");

            cp.ReferencedAssemblies.Add(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute).Assembly.Location);
            cp.ReferencedAssemblies.Add(typeof(System.ComponentModel.Composition.ImportAttribute).Assembly.Location);
            cp.ReferencedAssemblies.Add(typeof(System.Web.HttpRequest).Assembly.Location);
            cp.ReferencedAssemblies.Add(typeof(System.Net.Http.HttpClient).Assembly.Location);
            cp.ReferencedAssemblies.Add(typeof(Newtonsoft.Json.JsonSerializer).Assembly.Location);

            //cp.ReferencedAssemblies.Add(typeof(System.Windows.Threading.DispatcherTimer).Assembly.Location);

            CompilerResults cr = null;

            using (var provider = GetProvider(data.LanguageChoice))
            {
                DateTime comp_start = DateTime.Now;
                // Invoke compilation of the source file.
                cr = provider.CompileAssemblyFromSource(cp, new string[] { data.Program });
                compilationTimeInMs = (int)(DateTime.Now - comp_start).TotalMilliseconds;
            }

            var messages = cr.Errors.Cast<CompilerError>();
            var warnings = messages.Where(f => f.IsWarning == true);
            var errors = messages.Where(f => f.IsWarning == false);

            if (warnings.Count() != 0)
            {
                foreach (var warn in warnings)
                    data.Warnings.Add(string.Format("({0}:{1}) {2}", warn.Line, warn.Column, warn.ErrorText));
            }
            if (errors.Count() != 0)
            {
                foreach (var ce in errors)
                {
                    data.Errors.Add(string.Format("({0}:{1}) {2}", ce.Line, ce.Column, ce.ErrorText));
                }
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Compilation errors", (int)data.LanguageChoice, data.IsApi, false);
                data.RunStats = string.Format("Compilation time: {0} s", Math.Round((compilationTimeInMs / (double)1000), 2));
                return data;
            }
            else
            {
                using (Process process = new Process())
                {
                    try
                    {
                        double TotalMemoryInBytes = 0;
                        double TotalThreadCount = 0;
                        int samplesCount = 0;

                        process.StartInfo.FileName = reExp.Utils.Utils.RootFolder + "executables/SpawnedProcess.exe";
                        process.StartInfo.Arguments = folder.Replace(" ", "|_|") + " " + assemblyName + " Rextester|Program|Main";
                        process.StartInfo.UseShellExecute = false;
                        process.StartInfo.CreateNoWindow = true;
                        process.StartInfo.RedirectStandardOutput = true;
                        process.StartInfo.RedirectStandardError = true;
                        process.StartInfo.RedirectStandardInput = true;

                        DateTime start = DateTime.Now;
                        process.Start();
                        //try
                        //{
                        //    process.PriorityClass = ProcessPriorityClass.BelowNormal;
                        //}
                        //catch (Exception)
                        //{ }

                        if (!string.IsNullOrEmpty(data.Input))
                        {
                            InputWriter input = new InputWriter(process.StandardInput, data.Input);
                            Thread inputWriter = new Thread(new ThreadStart(input.Writeinput));
                            inputWriter.Start();
                        }

                        OutputReader output = new OutputReader(process.StandardOutput);
                        Thread outputReader = new Thread(new ThreadStart(output.ReadOutput));
                        outputReader.Start();
                        OutputReader error = new OutputReader(process.StandardError);
                        Thread errorReader = new Thread(new ThreadStart(error.ReadOutput));
                        errorReader.Start();

                        do
                        {
                            // Refresh the current process property values.
                            process.Refresh();
                            if (!process.HasExited)
                            {
                                try
                                {
                                    var proc = process.TotalProcessorTime;
                                    // Update the values for the overall peak memory statistics.
                                    var mem1 = process.PagedMemorySize64;
                                    var mem2 = process.PrivateMemorySize64;

                                    //update stats
                                    TotalMemoryInBytes += (mem1 + mem2);
                                    TotalThreadCount += (process.Threads.Count);
                                    samplesCount++;

                                    if (proc.TotalSeconds > 5 || mem1 + mem2 > 100000000 || process.Threads.Count > 100 || start + TimeSpan.FromSeconds(10) < DateTime.Now)
                                    {
                                        var time = proc.TotalSeconds;
                                        var mem = mem1 + mem2;
                                        process.Kill();
                                        var res = string.Format("Process killed because it exceeded given resources.\nCpu time used {0} sec, absolute running time {1} sec, memory used {2} Mb, nr of threads {3}", time, (int)(DateTime.Now - start).TotalSeconds, (int)(mem / 1048576), process.Threads.Count);
                                        data.Errors.Add(res);
                                        string partialResult = output.Builder.ToString();
                                        data.Output = partialResult;
                                        Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, res, (int)data.LanguageChoice, data.IsApi, false);
                                        data.RunStats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec, cpu time: {2} sec, average memory usage: {3} Mb, average nr of threads: {4}",
                                            Math.Round((compilationTimeInMs / (double)1000), 2),
                                            Math.Round((DateTime.Now - start).TotalSeconds, 2),
                                            Math.Round(proc.TotalSeconds, 2),
                                            samplesCount != 0 ? (int?)((TotalMemoryInBytes / samplesCount) / 1048576) : null,
                                            samplesCount != 0 ? (int?)(TotalThreadCount / samplesCount) : null);
                                        return data;
                                    }
                                }
                                catch (InvalidOperationException)
                                {
                                    break;
                                }
                            }
                        }
                        while (!process.WaitForExit(10));
                        process.WaitForExit();

                        data.RunStats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec, cpu time: {2} sec, average memory usage: {3} Mb, average nr of threads: {4}",
                                            Math.Round((compilationTimeInMs / (double)1000), 2),
                                            Math.Round((process.ExitTime - process.StartTime).TotalSeconds, 2),
                                            Math.Round(process.TotalProcessorTime.TotalSeconds, 2),
                                            samplesCount != 0 ? (int?)((TotalMemoryInBytes / samplesCount) / 1048576) : null,
                                            samplesCount != 0 ? (int?)(TotalThreadCount / samplesCount) : null);

                        errorReader.Join(5000);
                        outputReader.Join(5000);
                        if (!string.IsNullOrEmpty(error.Output))
                        {
                            data.Output = output.Builder.ToString();
                            data.Errors.Add(error.Output);
                            Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, error.Output, (int)data.LanguageChoice, data.IsApi, false);
                            return data;
                        }
                        data.Output = output.Output;
                        Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "OK", (int)data.LanguageChoice, data.IsApi, true);
                        return data;
                    }
                    catch (Exception e)
                    {
                        if (!process.HasExited)
                        {
                            reExp.Utils.Log.LogInfo("Process left running " + e.Message, e, "RunDotNet");
                        }
                        throw;
                    }
                    finally
                    {
                        reExp.Utils.CleanUp.DeleteFile(path);
                    }
                }
            }
        }
Beispiel #28
0
        static RundotnetData RunWindows(RundotnetData data)
        {
            WindowsService service = new WindowsService();
            Service.win.Languages lang = Service.win.Languages.VCPP;

            switch (data.LanguageChoice)
            {
                case LanguagesEnum.VCPP:
                    lang = Service.win.Languages.VCPP;
                    break;
                case LanguagesEnum.VC:
                    lang = Service.win.Languages.VC;
                    break;
                default:
                    break;
            }
            Stopwatch watch = new Stopwatch();
            watch.Start();
            var res = service.DoWork(data.Program, data.Input, data.CompilerArgs, lang);
            watch.Stop();
            if (res != null)
            {
                if (string.IsNullOrEmpty(res.Stats))
                    res.Stats = "";
                else
                    res.Stats += ", ";
                res.Stats += string.Format("absolute service time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2));
                data.RunStats = res.Stats;
            }
            bool logged = false;
            if (!string.IsNullOrEmpty(res.System_Error))
            {
                reExp.Utils.Log.LogInfo("Windows " + res.System_Error, null, "RunDotNet");
                data.Errors.Add(res.System_Error);
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: system error", (int)data.LanguageChoice, data.IsApi, false);
                return data;
            }
            if (!string.IsNullOrEmpty(res.Errors))
            {
                data.Errors.Add(res.Errors);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: error", (int)data.LanguageChoice, data.IsApi, false);
                    logged = true;
                }
            }
            if (res.Exit_Code < 0)
            {
                data.Errors.Add(res.Exit_Status);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: negative exit code", (int)data.LanguageChoice, data.IsApi, false);
                    logged = true;
                }
            }
            if (!string.IsNullOrEmpty(res.Warnings))
            {
                data.Warnings.Add(res.Warnings);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: warnings", (int)data.LanguageChoice, data.IsApi, true);
                    logged = true;
                }
            }
            data.Output = res.Output;
            if (res.Files != null)
            {
                data.Files = new List<string>();
                foreach (var f in res.Files)
                {
                    data.Files.Add(Convert.ToBase64String(f));
                }
            }
            if (!logged)
            {
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: ok", (int)data.LanguageChoice, data.IsApi, true);
                logged = true;
            }
            return data;
        }
Beispiel #29
0
        static RundotnetData RunLinux(RundotnetData data)
        {
            LinuxService service = new LinuxService();
            Service.linux.Languages lang = Service.linux.Languages.Java;

            if (data.LanguageChoice == LanguagesEnum.Prolog)
            {
                data.Input += "\nhalt.";
            }
            switch(data.LanguageChoice)
            {
                case LanguagesEnum.Java:
                    lang = Service.linux.Languages.Java;
                    break;
                case LanguagesEnum.Python:
                    lang = Service.linux.Languages.Python;
                    break;
                case LanguagesEnum.C:
                    lang = Service.linux.Languages.C;
                    break;
                case LanguagesEnum.CPP:
                    lang = Service.linux.Languages.CPP;
                    break;
                case LanguagesEnum.Php:
                    lang = Service.linux.Languages.Php;
                    break;
                case LanguagesEnum.Pascal:
                    lang = Service.linux.Languages.Pascal;
                    break;
                case LanguagesEnum.ObjectiveC:
                    lang = Service.linux.Languages.ObjectiveC;
                    break;
                case LanguagesEnum.Haskell:
                    lang = Service.linux.Languages.Haskell;
                    break;
                case LanguagesEnum.Ruby:
                    lang = Service.linux.Languages.Ruby;
                    break;
                case LanguagesEnum.Perl:
                    lang = Service.linux.Languages.Perl;
                    break;
                case LanguagesEnum.Lua:
                    lang = Service.linux.Languages.Lua;
                    break;
                case LanguagesEnum.Nasm:
                    lang = Service.linux.Languages.Nasm;
                    break;
                case LanguagesEnum.Javascript:
                    lang = Service.linux.Languages.Javascript;
                    break;
                case LanguagesEnum.Lisp:
                    lang = Service.linux.Languages.Lisp;
                    break;
                case LanguagesEnum.Prolog:
                    lang = Service.linux.Languages.Prolog;
                    break;
                case LanguagesEnum.Go:
                    lang = Service.linux.Languages.Go;
                    break;
                case LanguagesEnum.Scala:
                    lang = Service.linux.Languages.Scala;
                    break;
                case LanguagesEnum.Scheme:
                    lang = Service.linux.Languages.Scheme;
                    break;
                case LanguagesEnum.Nodejs:
                    lang = Service.linux.Languages.Nodejs;
                    break;
                case LanguagesEnum.Python3:
                    lang = Service.linux.Languages.Python3;
                    break;
                case LanguagesEnum.Octave:
                    lang = Service.linux.Languages.Octave;
                    break;
                case LanguagesEnum.CClang:
                    lang = Service.linux.Languages.CClang;
                    break;
                case LanguagesEnum.CPPClang:
                    lang = Service.linux.Languages.CppClang;
                    break;
                case LanguagesEnum.D:
                    lang = Service.linux.Languages.D;
                    break;
                case LanguagesEnum.R:
                    lang = Service.linux.Languages.R;
                    break;
                case LanguagesEnum.Tcl:
                    lang = Service.linux.Languages.Tcl;
                    break;
                case LanguagesEnum.Swift:
                    lang = Service.linux.Languages.Swift;
                    break;
                case LanguagesEnum.FSharp:
                    lang = Service.linux.Languages.FSharp;
                    break;
                case LanguagesEnum.Bash:
                    lang = Service.linux.Languages.Bash;
                    break;
                case LanguagesEnum.Ada:
                    lang = Service.linux.Languages.Ada;
                    break;
                case LanguagesEnum.Erlang:
                    lang = Service.linux.Languages.Erlang;
                    break;
                case LanguagesEnum.Elixir:
                    lang = Service.linux.Languages.Elixir;
                    break;
                case LanguagesEnum.Ocaml:
                    lang = Service.linux.Languages.Ocaml;
                    break;

                default:
                    break;
            }
            Stopwatch watch = new Stopwatch();
            watch.Start();
            var res = service.DoWork(data.Program, data.Input, data.CompilerArgs, lang);
            watch.Stop();
            if (res != null)
            {
                if (string.IsNullOrEmpty(res.Stats))
                    res.Stats = "";
                else
                    res.Stats += ", ";
                res.Stats += string.Format("absolute service time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds/(double)1000, 2));
                data.RunStats = res.Stats;
            }
            bool logged = false;
            if (!string.IsNullOrEmpty(res.System_Error))
            {
                reExp.Utils.Log.LogInfo("Linux " + res.System_Error, null, "RunDotNet");
                data.Errors.Add(res.System_Error);
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Linux: system error " + res.System_Error, (int)data.LanguageChoice, data.IsApi, false);
                return data;
            }
            if (!string.IsNullOrEmpty(res.Errors))
            {
                data.Errors.Add(res.Errors);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Linux: error " + res.Errors, (int)data.LanguageChoice, data.IsApi, false);
                    logged = true;
                }
            }
            if (res.Exit_Code < 0)
            {
                data.Errors.Add(res.Exit_Status);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Linux: negative exit code " + res.Exit_Status, (int)data.LanguageChoice, data.IsApi, false);
                    logged = true;
                }
            }
            if (!string.IsNullOrEmpty(res.Warnings))
            {
                data.Warnings.Add(res.Warnings);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Linux: warnings", (int)data.LanguageChoice, data.IsApi, true);
                    logged = true;
                }
            }
            data.Output = res.Output;
            if (res.Files != null)
            {
                data.Files = new List<string>();
                foreach (var f in res.Files)
                {
                    data.Files.Add(Convert.ToBase64String(f));
                }
            }
            if (!logged)
            {
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Linux: ok", (int)data.LanguageChoice, data.IsApi, true);
                logged = true;
            }
            return data;
        }
Beispiel #30
0
        static RundotnetData RunSqlServer(RundotnetData data)
        {
            string path = reExp.Utils.Utils.RootFolder + "executables/usercode/" + Utils.Utils.RandomString() + ".sql";
            using (TextWriter tw = new StreamWriter(path))
            {
                tw.Write(data.Program);
            }

            using (Process process = new Process())
            {
                try
                {
                    double TotalMemoryInBytes = 0;
                    double TotalThreadCount = 0;
                    int samplesCount = 0;

                    process.StartInfo.FileName = reExp.Utils.Utils.RootFolder + "executables/SqlServer.exe";
                    process.StartInfo.Arguments = path.Replace(" ", "|_|");
                    process.StartInfo.UseShellExecute = false;
                    process.StartInfo.CreateNoWindow = true;
                    process.StartInfo.RedirectStandardOutput = true;
                    process.StartInfo.RedirectStandardError = true;

                    DateTime start = DateTime.Now;
                    process.Start();

                    OutputReader output = new OutputReader(process.StandardOutput, false);
                    Thread outputReader = new Thread(new ThreadStart(output.ReadOutput));
                    outputReader.Start();
                    OutputReader error = new OutputReader(process.StandardError);
                    Thread errorReader = new Thread(new ThreadStart(error.ReadOutput));
                    errorReader.Start();

                    do
                    {
                        // Refresh the current process property values.
                        process.Refresh();
                        if (!process.HasExited)
                        {
                            try
                            {
                                var proc = process.TotalProcessorTime;
                                // Update the values for the overall peak memory statistics.
                                var mem1 = process.PagedMemorySize64;
                                var mem2 = process.PrivateMemorySize64;

                                //update stats
                                TotalMemoryInBytes += (mem1 + mem2);
                                TotalThreadCount += (process.Threads.Count);
                                samplesCount++;

                                if (proc.TotalSeconds > 5 || mem1 + mem2 > 100000000 || process.Threads.Count > 100 || start + TimeSpan.FromSeconds(15) < DateTime.Now)
                                {
                                    var time = proc.TotalSeconds;
                                    var mem = mem1 + mem2;
                                    process.Kill();
                                    var res = string.Format("Process killed because it exceeded given resources.\nCpu time used {0} sec, absolute running time {1} sec, memory used {2} Mb, nr of threads {3}", time, (int)(DateTime.Now - start).TotalSeconds, (int)(mem / 1048576), process.Threads.Count);
                                    data.Errors.Add(res);
                                    string partialResult = output.Builder.ToString();
                                    data.Output = partialResult;
                                    data.RunStats = string.Format("Absolute service time: {0} sec", Math.Round((double)(DateTime.Now - start).TotalMilliseconds / 1000, 2));
                                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, res, (int)data.LanguageChoice, data.IsApi, false);
                                    return data;
                                }
                            }
                            catch (InvalidOperationException)
                            {
                                break;
                            }
                        }
                    }
                    while (!process.WaitForExit(10));
                    process.WaitForExit();

                    errorReader.Join(5000);
                    outputReader.Join(5000);

                    if (!string.IsNullOrEmpty(error.Output))
                    {
                        data.Output = output.Builder.ToString();
                        data.Errors.Add(error.Output);
                        data.RunStats = string.Format("Absolute service time: {0} sec", Math.Round((double)(DateTime.Now - start).TotalMilliseconds / 1000, 2));
                        Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, error.Output, (int)data.LanguageChoice, data.IsApi, false);
                        return data;
                    }

                    if (File.Exists(path + ".stats"))
                    {
                        using (TextReader tr = new StreamReader(path + ".stats"))
                        {
                            data.RunStats = tr.ReadLine();
                            if (!string.IsNullOrEmpty(data.RunStats))
                                data.RunStats += ", ";
                            else
                                data.RunStats = "";
                            data.RunStats += string.Format("absolute service time: {0} sec", Math.Round((double)(DateTime.Now - start).TotalMilliseconds / 1000, 2));
                        }
                    }
                    else
                    {
                        data.RunStats = string.Format("Absolute service time: {0} sec", Math.Round((double)(DateTime.Now - start).TotalMilliseconds / 1000, 2));
                    }

                    data.Output = output.Output;
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "OK", (int)data.LanguageChoice, data.IsApi, true);
                    return data;
                }
                catch (Exception e)
                {
                    if (!process.HasExited)
                    {
                        reExp.Utils.Log.LogInfo("Process left running " + e.Message, e, "RunSqlServer");
                    }
                    throw;
                }
                finally
                {
                    try
                    {
                        reExp.Utils.CleanUp.DeleteFile(path);
                        reExp.Utils.CleanUp.DeleteFile(path + ".stats");
                    }
                    catch (Exception)
                    { }

                    SqlServerUtils job = new SqlServerUtils();
                    Thread t = new Thread(job.DoShrinkJob);
                    t.Start();
                }
            }
        }
        public string SaveOnPersonalWall(RundotnetData data)
        {
            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            if (!SessionManager.IsUserInSession())
            {
                return(json.Serialize(new JsonData()
                {
                    NotLoggedIn = true
                }));
            }

            if (!string.IsNullOrEmpty(data.Program) && data.Program.Length > maxChars)
            {
                return(json.Serialize(new JsonData()
                {
                    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 JsonData()
                {
                    Errors = string.Format("Input is too long (max is {0} characters).\n", maxChars)
                }));
            }
            if (!string.IsNullOrEmpty(data.Title) && data.Title.Length > 100)
            {
                return(json.Serialize(new JsonData()
                {
                    Errors = "Title is too long (max is 100 characters).\n"
                }));
            }
            string url = null;

            if (data.Program == null)
            {
                data.Program = string.Empty;
            }
            if (!string.IsNullOrEmpty(data.WholeError))
            {
                data.Status = GlobalConst.RundotnetStatus.Error;
            }
            else
            {
                data.Status = GlobalConst.RundotnetStatus.OK;
            }
            string guid = Model.SaveCode(data: data, personal: true);

            if (!string.IsNullOrEmpty(guid))
            {
                url = Utils.Utils.BaseUrl + guid;
            }

            return(json.Serialize(new JsonData()
            {
                Url = url
            }));
        }
 public ContentResult Api(RundotnetData data)
 {
     Response.AppendHeader("Access-Control-Allow-Origin", "*");
     data.IsApi = true;
     return(this.Content(Run(data), "application/json"));
 }
        public ActionResult Index(RundotnetData data, string savedNr = null, string lang_title = null)
        {
            Compression.SetCompression();

            //retrieve saved code
            savedNr = savedNr ?? HttpContext.Request.QueryString["code"];
            if (!string.IsNullOrEmpty(savedNr))
            {
                var code = Model.GetCode(savedNr, false);
                if (code == null)
                {
                    throw new HttpException(404, "not found");
                }
                data.Title          = code.Title;
                data.Program        = code.Program;
                data.Input          = code.Input;
                data.CompilerArgs   = code.CompilerArgs;
                data.Output         = code.Output;
                data.LanguageChoice = (LanguagesEnum)code.Lang;
                data.EditorChoice   = (EditorsEnum)code.Editor;
                data.WholeError     = code.WholeError;
                data.WholeWarning   = code.Warnings;
                data.ShowWarnings   = code.ShowWarnings;
                data.RunStats       = code.Stats;
                data.CodeGuid       = code.Guid;
                data.Votes          = code.Votes;
                data.User_Id        = code.UserId;

                data.IsInEditMode      = false;
                data.EditVisible       = code.IsPrimaryVersion;
                data.BackToForkVisible = false;
                data.PrimaryGuid       = code.PrimaryGuid == null ? data.CodeGuid : code.PrimaryGuid;
                data.IsSaved           = true;
                if (data.PrimaryGuid != data.CodeGuid)
                {
                    data.LivesVersion = Model.IsLive(data.PrimaryGuid);
                }

                if (SessionManager.IsDarkTheme)
                {
                    data.EditorChoice = EditorsEnum.Codemirror;
                }
                if (Utils.Utils.IsMobile)
                {
                    data.EditorChoice = EditorsEnum.Simple;
                }
                return(View(data));
            }

            data.IsLive       = false;
            data.IsInEditMode = false;

            if (!string.IsNullOrEmpty(lang_title))
            {
                if (lang_title.ToLower() == "nasm_online_compiler" || lang_title.ToLower() == "nasm")
                {
                    data.LanguageChoice = LanguagesEnum.Nasm;
                }
                else if (lang_title.ToLower() == "csharp_online_compiler" || lang_title.ToLower() == "csharp")
                {
                    data.LanguageChoice = LanguagesEnum.CSharp;
                }
                else if (lang_title.ToLower() == "cpp_online_compiler_gcc" || lang_title.ToLower() == "gcc")
                {
                    data.LanguageChoice = LanguagesEnum.CPP;
                }
                else if (lang_title.ToLower() == "cpp_online_compiler_clang" || lang_title.ToLower() == "clang")
                {
                    data.LanguageChoice = LanguagesEnum.CPPClang;
                }
                else if (lang_title.ToLower() == "cpp_online_compiler_visual" || lang_title.ToLower() == "vcpp")
                {
                    data.LanguageChoice = LanguagesEnum.VCPP;
                }
                else if (lang_title.ToLower() == "c_online_compiler_gcc" || lang_title.ToLower() == "c_gcc")
                {
                    data.LanguageChoice = LanguagesEnum.C;
                }
                else if (lang_title.ToLower() == "c_online_compiler_clang" || lang_title.ToLower() == "c_clang")
                {
                    data.LanguageChoice = LanguagesEnum.CClang;
                }
                else if (lang_title.ToLower() == "c_online_compiler_visual" || lang_title.ToLower() == "c_vcpp")
                {
                    data.LanguageChoice = LanguagesEnum.VC;
                }
                else if (lang_title.ToLower() == "common_lisp_online_compiler" || lang_title.ToLower() == "clisp")
                {
                    data.LanguageChoice = LanguagesEnum.Lisp;
                }
                else if (lang_title.ToLower() == "d_online_compiler" || lang_title.ToLower() == "d")
                {
                    data.LanguageChoice = LanguagesEnum.D;
                }
                else if (lang_title.ToLower() == "fsharp_online_compiler" || lang_title.ToLower() == "fsharp")
                {
                    data.LanguageChoice = LanguagesEnum.FSharp;
                }
                else if (lang_title.ToLower() == "go_online_compiler" || lang_title.ToLower() == "go")
                {
                    data.LanguageChoice = LanguagesEnum.Go;
                }
                else if (lang_title.ToLower() == "haskell_online_compiler" || lang_title.ToLower() == "haskell")
                {
                    data.LanguageChoice = LanguagesEnum.Haskell;
                }
                else if (lang_title.ToLower() == "java_online_compiler" || lang_title.ToLower() == "java")
                {
                    data.LanguageChoice = LanguagesEnum.Java;
                }
                else if (lang_title.ToLower() == "js_online_compiler" || lang_title.ToLower() == "js")
                {
                    data.LanguageChoice = LanguagesEnum.Javascript;
                }
                else if (lang_title.ToLower() == "lua_online_compiler" || lang_title.ToLower() == "lua")
                {
                    data.LanguageChoice = LanguagesEnum.Lua;
                }
                else if (lang_title.ToLower() == "nodejs_online_compiler" || lang_title.ToLower() == "nodejs")
                {
                    data.LanguageChoice = LanguagesEnum.Nodejs;
                }
                else if (lang_title.ToLower() == "octave_online_compiler" || lang_title.ToLower() == "octave")
                {
                    data.LanguageChoice = LanguagesEnum.Octave;
                }
                else if (lang_title.ToLower() == "objectivec_online_compiler" || lang_title.ToLower() == "objectivec")
                {
                    data.LanguageChoice = LanguagesEnum.ObjectiveC;
                }
                else if (lang_title.ToLower() == "pascal_online_compiler" || lang_title.ToLower() == "pascal")
                {
                    data.LanguageChoice = LanguagesEnum.Pascal;
                }
                else if (lang_title.ToLower() == "perl_online_compiler" || lang_title.ToLower() == "perl")
                {
                    data.LanguageChoice = LanguagesEnum.Perl;
                }
                else if (lang_title.ToLower() == "php_online_compiler" || lang_title.ToLower() == "php")
                {
                    data.LanguageChoice = LanguagesEnum.Php;
                }
                else if (lang_title.ToLower() == "prolog_online_compiler" || lang_title.ToLower() == "prolog")
                {
                    data.LanguageChoice = LanguagesEnum.Prolog;
                }
                else if (lang_title.ToLower() == "python_online_compiler" || lang_title.ToLower() == "python")
                {
                    data.LanguageChoice = LanguagesEnum.Python;
                }
                else if (lang_title.ToLower() == "python3_online_compiler" || lang_title.ToLower() == "python3")
                {
                    data.LanguageChoice = LanguagesEnum.Python3;
                }
                else if (lang_title.ToLower() == "r_online_compiler" || lang_title.ToLower() == "r")
                {
                    data.LanguageChoice = LanguagesEnum.R;
                }
                else if (lang_title.ToLower() == "ruby_online_compiler" || lang_title.ToLower() == "ruby")
                {
                    data.LanguageChoice = LanguagesEnum.Ruby;
                }
                else if (lang_title.ToLower() == "scala_online_compiler" || lang_title.ToLower() == "scala")
                {
                    data.LanguageChoice = LanguagesEnum.Scala;
                }
                else if (lang_title.ToLower() == "scheme_online_compiler" || lang_title.ToLower() == "scheme")
                {
                    data.LanguageChoice = LanguagesEnum.Scheme;
                }
                else if (lang_title.ToLower() == "sql_server_online_compiler" || lang_title.ToLower() == "sql_server")
                {
                    data.LanguageChoice = LanguagesEnum.SqlServer;
                }
                else if (lang_title.ToLower() == "mysql_online_compiler" || lang_title.ToLower() == "mysql")
                {
                    data.LanguageChoice = LanguagesEnum.MySql;
                }
                else if (lang_title.ToLower() == "oracle_online_compiler" || lang_title.ToLower() == "oracle")
                {
                    data.LanguageChoice = LanguagesEnum.Oracle;
                }
                else if (lang_title.ToLower() == "postgresql_online_compiler" || lang_title.ToLower() == "postgresql")
                {
                    data.LanguageChoice = LanguagesEnum.Postgresql;
                }
                else if (lang_title.ToLower() == "tcl_online_compiler" || lang_title.ToLower() == "tcl")
                {
                    data.LanguageChoice = LanguagesEnum.Tcl;
                }
                else if (lang_title.ToLower() == "visual_basic_online_compiler" || lang_title.ToLower() == "vb")
                {
                    data.LanguageChoice = LanguagesEnum.VB;
                }
                else if (lang_title.ToLower() == "client_side" || lang_title.ToLower() == "jsfiddle")
                {
                    data.LanguageChoice = LanguagesEnum.ClientSide;
                }
                else if (lang_title.ToLower() == "swift_online_compiler" || lang_title.ToLower() == "swift")
                {
                    data.LanguageChoice = LanguagesEnum.Swift;
                }
                else if (lang_title.ToLower() == "bash_online_compiler" || lang_title.ToLower() == "bash")
                {
                    data.LanguageChoice = LanguagesEnum.Bash;
                }
                else if (lang_title.ToLower() == "ada_online_compiler" || lang_title.ToLower() == "ada")
                {
                    data.LanguageChoice = LanguagesEnum.Ada;
                }
                else if (lang_title.ToLower() == "erlang_online_compiler" || lang_title.ToLower() == "erlang")
                {
                    data.LanguageChoice = LanguagesEnum.Erlang;
                }
                else if (lang_title.ToLower() == "elixir_online_compiler" || lang_title.ToLower() == "elixir")
                {
                    data.LanguageChoice = LanguagesEnum.Elixir;
                }
                else if (lang_title.ToLower() == "ocaml_online_compiler" || lang_title.ToLower() == "ocaml")
                {
                    data.LanguageChoice = LanguagesEnum.Ocaml;
                }
                else
                {
                    data.LanguageChoice = LanguagesEnum.CSharp;
                }
            }

            if ((int)data.LanguageChoice != (int)LanguagesEnum.Unknown && (int)data.EditorChoice != (int)EditorsEnum.Unknown && !Utils.Utils.IsMobile)
            {
                Model.SaveUserProfile(data.LanguageChoice, data.EditorChoice);
            }

            UserProfile profile = null;

            if ((int)data.LanguageChoice == (int)LanguagesEnum.Unknown || (int)data.EditorChoice == (int)EditorsEnum.Unknown)
            {
                profile = Model.GetUserProfile();
            }

            if ((int)data.LanguageChoice == (int)LanguagesEnum.Unknown)
            {
                data.LanguageChoice = profile.LanguageChoice;
            }

            if ((int)data.EditorChoice == (int)EditorsEnum.Unknown)
            {
                data.EditorChoice = profile.EditorChoice;
            }

            data.Program      = data.GetInitialCode(data.LanguageChoice, data.EditorChoice);
            data.CompilerArgs = data.GetInitialCompilerArgs(data.LanguageChoice);

            if (SessionManager.IsDarkTheme)
            {
                data.EditorChoice = EditorsEnum.Codemirror;
            }
            if (Utils.Utils.IsMobile)
            {
                data.EditorChoice = EditorsEnum.Simple;
            }

            return(View(data));
        }
        static RundotnetData RunLinux(RundotnetData data)
        {
            LinuxService service = new LinuxService();

            Service.linux.Languages lang = Service.linux.Languages.Java;
            switch (data.LanguageChoice)
            {
            case "4":
                lang = Service.linux.Languages.Java;
                break;

            case "5":
                lang = Service.linux.Languages.Python;
                break;

            case "6":
                lang = Service.linux.Languages.C;
                break;

            case "7":
                lang = Service.linux.Languages.CPP;
                break;

            default:
                break;
            }
            Stopwatch watch = new Stopwatch();

            watch.Start();
            var res = service.DoWork(data.Program, lang);

            watch.Stop();
            if (res != null)
            {
                if (string.IsNullOrEmpty(res.Stats))
                {
                    res.Stats = "";
                }
                else
                {
                    res.Stats += ", ";
                }
                res.Stats    += string.Format("absolute service time: {0}", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2));
                data.RunStats = res.Stats;
            }
            bool logged = false;

            if (!string.IsNullOrEmpty(res.System_Error))
            {
                reExp.Utils.Log.LogInfo("Linux " + res.System_Error, "RunDotNet");
                data.Errors.Add(res.System_Error);
                Utils.Log.LogCodeToDB(data.Program, "Linux: system error");
                return(data);
            }
            if (!string.IsNullOrEmpty(res.Errors))
            {
                data.Errors.Add(res.Errors);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, "Linux: error");
                    logged = true;
                }
            }
            if (res.Exit_Code < 0)
            {
                data.Errors.Add(res.Exit_Status);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, "Linux: negative exit code");
                    logged = true;
                }
            }
            if (!string.IsNullOrEmpty(res.Warnings))
            {
                data.Warnings.Add(res.Warnings);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, "Linux: warnings");
                    logged = true;
                }
            }
            data.Output = res.Output;
            if (!logged)
            {
                Utils.Log.LogCodeToDB(data.Program, "Linux: ok");
                logged = true;
            }
            return(data);
        }
        public ViewResult GetLiveCode(string savedNr)
        {
            Compression.SetCompression();
            RundotnetData data = new RundotnetData();
            var code = Model.GetLiveCode(savedNr);
            if (code == null)
            {
                throw new HttpException(404, "not found");
            }

            data.Program = code.Program;
            data.Input = code.Input;
            data.CompilerArgs = code.CompilerArgs;
            data.LanguageChoice = (LanguagesEnum)code.Lang;
            data.EditorChoice = (EditorsEnum)code.Editor;
            data.ShowWarnings = code.ShowWarnings;
            data.CodeGuid = savedNr;
            data.User_Id = code.UserId;
            data.Title = code.Title;

            data.PrimaryGuid = data.CodeGuid;
            data.IsLive = true;
            data.IsSaved = true;
            data.DisplayName = SessionManager.IsUserInSession() ? SessionManager.UserName : Utils.Utils.RandomLetter();

            return View("Index", data);
        }
        static RundotnetData RunDotNet(RundotnetData data)
        {
            int compilationTimeInMs;
            CompilerParameters cp = new CompilerParameters();

            cp.GenerateExecutable = false;
            Random rg           = Utils.Utils.GetTrulyRandom();
            string folder       = reExp.Utils.Utils.RootFolder + @"\executables\usercode\";
            string assemblyName = "userAssembly_" + rg.Next(0, 10000000);

            string path = folder + assemblyName + ".dll";

            cp.OutputAssembly = path;
            // Save the assembly as a physical file.
            cp.GenerateInMemory = false;
            // Set whether to treat all warnings as errors.
            cp.TreatWarningsAsErrors   = false;
            cp.WarningLevel            = 4;
            cp.IncludeDebugInformation = false;


            cp.ReferencedAssemblies.Add("System.dll");
            cp.ReferencedAssemblies.Add("System.Core.dll");

            cp.ReferencedAssemblies.Add("System.Numerics.dll");
            cp.ReferencedAssemblies.Add("System.Data.dll");
            cp.ReferencedAssemblies.Add("System.Data.DataSetExtensions.dll");
            cp.ReferencedAssemblies.Add("System.Xml.dll");
            cp.ReferencedAssemblies.Add("System.Xml.Linq.dll");
            cp.ReferencedAssemblies.Add("System.Drawing.dll");

            if (data.LanguageChoice == LanguagesEnum.CSharp)
            {
                cp.ReferencedAssemblies.Add("Microsoft.CSharp.dll");
            }
            else if (data.LanguageChoice == LanguagesEnum.VB)
            {
                cp.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll");
            }

            cp.ReferencedAssemblies.Add(typeof(System.ComponentModel.DataAnnotations.DisplayAttribute).Assembly.Location);
            cp.ReferencedAssemblies.Add(typeof(System.ComponentModel.Composition.ImportAttribute).Assembly.Location);
            cp.ReferencedAssemblies.Add(typeof(System.Web.HttpRequest).Assembly.Location);
            cp.ReferencedAssemblies.Add(typeof(System.Net.Http.HttpClient).Assembly.Location);
            cp.ReferencedAssemblies.Add(typeof(Newtonsoft.Json.JsonSerializer).Assembly.Location);

            //cp.ReferencedAssemblies.Add(typeof(System.Windows.Threading.DispatcherTimer).Assembly.Location);

            CompilerResults cr = null;

            using (var provider = GetProvider(data.LanguageChoice))
            {
                DateTime comp_start = DateTime.Now;
                // Invoke compilation of the source file.
                cr = provider.CompileAssemblyFromSource(cp, new string[] { data.Program });
                compilationTimeInMs = (int)(DateTime.Now - comp_start).TotalMilliseconds;
            }

            var messages = cr.Errors.Cast <CompilerError>();
            var warnings = messages.Where(f => f.IsWarning == true);
            var errors   = messages.Where(f => f.IsWarning == false);

            if (warnings.Count() != 0)
            {
                foreach (var warn in warnings)
                {
                    data.Warnings.Add(string.Format("({0}:{1}) {2}", warn.Line, warn.Column, warn.ErrorText));
                }
            }
            if (errors.Count() != 0)
            {
                foreach (var ce in errors)
                {
                    data.Errors.Add(string.Format("({0}:{1}) {2}", ce.Line, ce.Column, ce.ErrorText));
                }
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Compilation errors", (int)data.LanguageChoice, data.IsApi, false);
                data.RunStats = string.Format("Compilation time: {0} s", Math.Round((compilationTimeInMs / (double)1000), 2));
                return(data);
            }
            else
            {
                using (Process process = new Process())
                {
                    try
                    {
                        double TotalMemoryInBytes = 0;
                        double TotalThreadCount   = 0;
                        int    samplesCount       = 0;

                        process.StartInfo.FileName               = reExp.Utils.Utils.RootFolder + "executables/SpawnedProcess.exe";
                        process.StartInfo.Arguments              = folder.Replace(" ", "|_|") + " " + assemblyName + " Rextester|Program|Main";
                        process.StartInfo.UseShellExecute        = false;
                        process.StartInfo.CreateNoWindow         = true;
                        process.StartInfo.RedirectStandardOutput = true;
                        process.StartInfo.RedirectStandardError  = true;
                        process.StartInfo.RedirectStandardInput  = true;

                        DateTime start = DateTime.Now;
                        process.Start();
                        //try
                        //{
                        //    process.PriorityClass = ProcessPriorityClass.BelowNormal;
                        //}
                        //catch (Exception)
                        //{ }

                        if (!string.IsNullOrEmpty(data.Input))
                        {
                            InputWriter input       = new InputWriter(process.StandardInput, data.Input);
                            Thread      inputWriter = new Thread(new ThreadStart(input.Writeinput));
                            inputWriter.Start();
                        }

                        OutputReader output       = new OutputReader(process.StandardOutput);
                        Thread       outputReader = new Thread(new ThreadStart(output.ReadOutput));
                        outputReader.Start();
                        OutputReader error       = new OutputReader(process.StandardError);
                        Thread       errorReader = new Thread(new ThreadStart(error.ReadOutput));
                        errorReader.Start();


                        do
                        {
                            // Refresh the current process property values.
                            process.Refresh();
                            if (!process.HasExited)
                            {
                                try
                                {
                                    var proc = process.TotalProcessorTime;
                                    // Update the values for the overall peak memory statistics.
                                    var mem1 = process.PagedMemorySize64;
                                    var mem2 = process.PrivateMemorySize64;

                                    //update stats
                                    TotalMemoryInBytes += (mem1 + mem2);
                                    TotalThreadCount   += (process.Threads.Count);
                                    samplesCount++;

                                    if (proc.TotalSeconds > 5 || mem1 + mem2 > 100000000 || process.Threads.Count > 100 || start + TimeSpan.FromSeconds(10) < DateTime.Now)
                                    {
                                        var time = proc.TotalSeconds;
                                        var mem  = mem1 + mem2;
                                        process.Kill();
                                        var res = string.Format("Process killed because it exceeded given resources.\nCpu time used {0} sec, absolute running time {1} sec, memory used {2} Mb, nr of threads {3}", time, (int)(DateTime.Now - start).TotalSeconds, (int)(mem / 1048576), process.Threads.Count);
                                        data.Errors.Add(res);
                                        string partialResult = output.Builder.ToString();
                                        data.Output = partialResult;
                                        Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, res, (int)data.LanguageChoice, data.IsApi, false);
                                        data.RunStats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec, cpu time: {2} sec, average memory usage: {3} Mb, average nr of threads: {4}",
                                                                      Math.Round((compilationTimeInMs / (double)1000), 2),
                                                                      Math.Round((DateTime.Now - start).TotalSeconds, 2),
                                                                      Math.Round(proc.TotalSeconds, 2),
                                                                      samplesCount != 0 ? (int?)((TotalMemoryInBytes / samplesCount) / 1048576) : null,
                                                                      samplesCount != 0 ? (int?)(TotalThreadCount / samplesCount) : null);
                                        return(data);
                                    }
                                }
                                catch (InvalidOperationException)
                                {
                                    break;
                                }
                            }
                        }while (!process.WaitForExit(10));
                        process.WaitForExit();

                        data.RunStats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec, cpu time: {2} sec, average memory usage: {3} Mb, average nr of threads: {4}",
                                                      Math.Round((compilationTimeInMs / (double)1000), 2),
                                                      Math.Round((process.ExitTime - process.StartTime).TotalSeconds, 2),
                                                      Math.Round(process.TotalProcessorTime.TotalSeconds, 2),
                                                      samplesCount != 0 ? (int?)((TotalMemoryInBytes / samplesCount) / 1048576) : null,
                                                      samplesCount != 0 ? (int?)(TotalThreadCount / samplesCount) : null);

                        errorReader.Join(5000);
                        outputReader.Join(5000);
                        if (!string.IsNullOrEmpty(error.Output))
                        {
                            data.Output = output.Builder.ToString();
                            data.Errors.Add(error.Output);
                            Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, error.Output, (int)data.LanguageChoice, data.IsApi, false);
                            return(data);
                        }
                        data.Output = output.Output;
                        Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "OK", (int)data.LanguageChoice, data.IsApi, true);
                        return(data);
                    }
                    catch (Exception e)
                    {
                        if (!process.HasExited)
                        {
                            reExp.Utils.Log.LogInfo("Process left running " + e.Message, e, "RunDotNet");
                        }
                        throw;
                    }
                    finally
                    {
                        reExp.Utils.CleanUp.DeleteFile(path);
                    }
                }
            }
        }
        public ActionResult Index(RundotnetData data, string savedNr = null, string lang_title = null)
        {
            Compression.SetCompression();

            //retrieve saved code
            savedNr = savedNr ?? HttpContext.Request.QueryString["code"];
            if (!string.IsNullOrEmpty(savedNr))
            {
                var code = Model.GetCode(savedNr, false);
                if (code == null)
                {
                    throw new HttpException(404, "not found");
                }
                data.Title = code.Title;
                data.Program = code.Program;
                data.Input = code.Input;
                data.CompilerArgs = code.CompilerArgs;
                data.Output = code.Output;
                data.LanguageChoice = (LanguagesEnum)code.Lang;
                data.EditorChoice = (EditorsEnum)code.Editor;
                data.WholeError = code.WholeError;
                data.WholeWarning = code.Warnings;
                data.ShowWarnings = code.ShowWarnings;
                data.RunStats = code.Stats;
                data.CodeGuid = code.Guid;
                data.Votes = code.Votes;
                data.User_Id = code.UserId;

                data.IsInEditMode = false;
                data.EditVisible = code.IsPrimaryVersion;
                data.BackToForkVisible = false;
                data.PrimaryGuid = code.PrimaryGuid == null ? data.CodeGuid : code.PrimaryGuid;
                data.IsSaved = true;
                if (data.PrimaryGuid != data.CodeGuid)
                {
                    data.LivesVersion = Model.IsLive(data.PrimaryGuid);
                }

                if(Utils.Utils.IsMobile)
                {
                    data.EditorChoice = EditorsEnum.Simple;
                }
                return View(data);
            }

            data.IsLive = false;
            data.IsInEditMode = false;

            if (!string.IsNullOrEmpty(lang_title))
            {
                if (lang_title.ToLower() == "nasm_online_compiler" || lang_title.ToLower() == "nasm")
                {
                    data.LanguageChoice = LanguagesEnum.Nasm;
                }
                else if (lang_title.ToLower() == "csharp_online_compiler" || lang_title.ToLower() == "csharp")
                {
                    data.LanguageChoice = LanguagesEnum.CSharp;
                }
                else if (lang_title.ToLower() == "cpp_online_compiler_gcc" || lang_title.ToLower() == "gcc")
                {
                    data.LanguageChoice = LanguagesEnum.CPP;
                }
                else if (lang_title.ToLower() == "cpp_online_compiler_clang" || lang_title.ToLower() == "clang")
                {
                    data.LanguageChoice = LanguagesEnum.CPPClang;
                }
                else if (lang_title.ToLower() == "cpp_online_compiler_visual" || lang_title.ToLower() == "vcpp")
                {
                    data.LanguageChoice = LanguagesEnum.VCPP;
                }
                else if (lang_title.ToLower() == "c_online_compiler_gcc" || lang_title.ToLower() == "c_gcc")
                {
                    data.LanguageChoice = LanguagesEnum.C;
                }
                else if (lang_title.ToLower() == "c_online_compiler_clang" || lang_title.ToLower() == "c_clang")
                {
                    data.LanguageChoice = LanguagesEnum.CClang;
                }
                else if (lang_title.ToLower() == "c_online_compiler_visual" || lang_title.ToLower() == "c_vcpp")
                {
                    data.LanguageChoice = LanguagesEnum.VC;
                }
                else if (lang_title.ToLower() == "common_lisp_online_compiler" || lang_title.ToLower() == "clisp")
                {
                    data.LanguageChoice = LanguagesEnum.Lisp;
                }
                else if (lang_title.ToLower() == "d_online_compiler" || lang_title.ToLower() == "d")
                {
                    data.LanguageChoice = LanguagesEnum.D;
                }
                else if (lang_title.ToLower() == "fsharp_online_compiler" || lang_title.ToLower() == "fsharp")
                {
                    data.LanguageChoice = LanguagesEnum.FSharp;
                }
                else if (lang_title.ToLower() == "go_online_compiler" || lang_title.ToLower() == "go")
                {
                    data.LanguageChoice = LanguagesEnum.Go;
                }
                else if (lang_title.ToLower() == "haskell_online_compiler" || lang_title.ToLower() == "haskell")
                {
                    data.LanguageChoice = LanguagesEnum.Haskell;
                }
                else if (lang_title.ToLower() == "java_online_compiler" || lang_title.ToLower() == "java")
                {
                    data.LanguageChoice = LanguagesEnum.Java;
                }
                else if (lang_title.ToLower() == "js_online_compiler" || lang_title.ToLower() == "js")
                {
                    data.LanguageChoice = LanguagesEnum.Javascript;
                }
                else if (lang_title.ToLower() == "lua_online_compiler" || lang_title.ToLower() == "lua")
                {
                    data.LanguageChoice = LanguagesEnum.Lua;
                }
                else if (lang_title.ToLower() == "nodejs_online_compiler" || lang_title.ToLower() == "nodejs")
                {
                    data.LanguageChoice = LanguagesEnum.Nodejs;
                }
                else if (lang_title.ToLower() == "octave_online_compiler" || lang_title.ToLower() == "octave")
                {
                    data.LanguageChoice = LanguagesEnum.Octave;
                }
                else if (lang_title.ToLower() == "objectivec_online_compiler" || lang_title.ToLower() == "objectivec")
                {
                    data.LanguageChoice = LanguagesEnum.ObjectiveC;
                }
                else if (lang_title.ToLower() == "pascal_online_compiler" || lang_title.ToLower() == "pascal")
                {
                    data.LanguageChoice = LanguagesEnum.Pascal;
                }
                else if (lang_title.ToLower() == "perl_online_compiler" || lang_title.ToLower() == "perl")
                {
                    data.LanguageChoice = LanguagesEnum.Perl;
                }
                else if (lang_title.ToLower() == "php_online_compiler" || lang_title.ToLower() == "php")
                {
                    data.LanguageChoice = LanguagesEnum.Php;
                }
                else if (lang_title.ToLower() == "prolog_online_compiler" || lang_title.ToLower() == "prolog")
                {
                    data.LanguageChoice = LanguagesEnum.Prolog;
                }
                else if (lang_title.ToLower() == "python_online_compiler" || lang_title.ToLower() == "python")
                {
                    data.LanguageChoice = LanguagesEnum.Python;
                }
                else if (lang_title.ToLower() == "python3_online_compiler" || lang_title.ToLower() == "python3")
                {
                    data.LanguageChoice = LanguagesEnum.Python3;
                }
                else if (lang_title.ToLower() == "r_online_compiler" || lang_title.ToLower() == "r")
                {
                    data.LanguageChoice = LanguagesEnum.R;
                }
                else if (lang_title.ToLower() == "ruby_online_compiler" || lang_title.ToLower() == "ruby")
                {
                    data.LanguageChoice = LanguagesEnum.Ruby;
                }
                else if (lang_title.ToLower() == "scala_online_compiler" || lang_title.ToLower() == "scala")
                {
                    data.LanguageChoice = LanguagesEnum.Scala;
                }
                else if (lang_title.ToLower() == "scheme_online_compiler" || lang_title.ToLower() == "scheme")
                {
                    data.LanguageChoice = LanguagesEnum.Scheme;
                }
                else if (lang_title.ToLower() == "sql_server_online_compiler" || lang_title.ToLower() == "sql_server")
                {
                    data.LanguageChoice = LanguagesEnum.SqlServer;
                }
                else if (lang_title.ToLower() == "mysql_online_compiler" || lang_title.ToLower() == "mysql")
                {
                    data.LanguageChoice = LanguagesEnum.MySql;
                }
                else if (lang_title.ToLower() == "oracle_online_compiler" || lang_title.ToLower() == "oracle")
                {
                    data.LanguageChoice = LanguagesEnum.Oracle;
                }
                else if (lang_title.ToLower() == "postgresql_online_compiler" || lang_title.ToLower() == "postgresql")
                {
                    data.LanguageChoice = LanguagesEnum.Postgresql;
                }
                else if (lang_title.ToLower() == "tcl_online_compiler" || lang_title.ToLower() == "tcl")
                {
                    data.LanguageChoice = LanguagesEnum.Tcl;
                }
                else if (lang_title.ToLower() == "visual_basic_online_compiler" || lang_title.ToLower() == "vb")
                {
                    data.LanguageChoice = LanguagesEnum.VB;
                }
                else if (lang_title.ToLower() == "client_side" || lang_title.ToLower() == "jsfiddle")
                {
                    data.LanguageChoice = LanguagesEnum.ClientSide;
                }
                else if (lang_title.ToLower() == "swift_online_compiler" || lang_title.ToLower() == "swift")
                {
                    data.LanguageChoice = LanguagesEnum.Swift;
                }
                else if (lang_title.ToLower() == "bash_online_compiler" || lang_title.ToLower() == "bash")
                {
                    data.LanguageChoice = LanguagesEnum.Bash;
                }
                else if (lang_title.ToLower() == "ada_online_compiler" || lang_title.ToLower() == "ada")
                {
                    data.LanguageChoice = LanguagesEnum.Ada;
                }
                else if (lang_title.ToLower() == "erlang_online_compiler" || lang_title.ToLower() == "erlang")
                {
                    data.LanguageChoice = LanguagesEnum.Erlang;
                }
                else if (lang_title.ToLower() == "elixir_online_compiler" || lang_title.ToLower() == "elixir")
                {
                    data.LanguageChoice = LanguagesEnum.Elixir;
                }
                else if (lang_title.ToLower() == "ocaml_online_compiler" || lang_title.ToLower() == "ocaml")
                {
                    data.LanguageChoice = LanguagesEnum.Ocaml;
                }
                else
                {
                    data.LanguageChoice = LanguagesEnum.CSharp;
                }
            }

            if ((int)data.LanguageChoice != (int)LanguagesEnum.Unknown && (int)data.EditorChoice != (int)EditorsEnum.Unknown)
                Model.SaveUserProfile(data.LanguageChoice, data.EditorChoice);

            UserProfile profile = null;
            if ((int)data.LanguageChoice == (int)LanguagesEnum.Unknown || (int)data.EditorChoice == (int)EditorsEnum.Unknown)
                profile = Model.GetUserProfile();

            if ((int)data.LanguageChoice == (int)LanguagesEnum.Unknown)
                data.LanguageChoice = profile.LanguageChoice;

            if ((int)data.EditorChoice == (int)EditorsEnum.Unknown)
                data.EditorChoice = profile.EditorChoice;

            data.Program = data.GetInitialCode(data.LanguageChoice, data.EditorChoice);
            data.CompilerArgs = data.GetInitialCompilerArgs(data.LanguageChoice);

            if (Utils.Utils.IsMobile)
            {
                data.EditorChoice = EditorsEnum.Simple;
            }

            return View(data);
        }
        static RundotnetData RunWindows(RundotnetData data)
        {
            WindowsService service = new WindowsService();

            Service.win.Languages lang = Service.win.Languages.VCPP;

            switch (data.LanguageChoice)
            {
            case LanguagesEnum.VCPP:
                lang = Service.win.Languages.VCPP;
                break;

            case LanguagesEnum.VC:
                lang = Service.win.Languages.VC;
                break;

            default:
                break;
            }
            Stopwatch watch = new Stopwatch();

            watch.Start();
            var res = service.DoWork(data.Program, data.Input, data.CompilerArgs, lang);

            watch.Stop();
            if (res != null)
            {
                if (string.IsNullOrEmpty(res.Stats))
                {
                    res.Stats = "";
                }
                else
                {
                    res.Stats += ", ";
                }
                res.Stats    += string.Format("absolute service time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2));
                data.RunStats = res.Stats;
            }
            bool logged = false;

            if (!string.IsNullOrEmpty(res.System_Error))
            {
                reExp.Utils.Log.LogInfo("Windows " + res.System_Error, null, "RunDotNet");
                data.Errors.Add(res.System_Error);
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: system error", (int)data.LanguageChoice, data.IsApi, false);
                return(data);
            }
            if (!string.IsNullOrEmpty(res.Errors))
            {
                data.Errors.Add(res.Errors);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: error", (int)data.LanguageChoice, data.IsApi, false);
                    logged = true;
                }
            }
            if (res.Exit_Code < 0)
            {
                data.Errors.Add(res.Exit_Status);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: negative exit code", (int)data.LanguageChoice, data.IsApi, false);
                    logged = true;
                }
            }
            if (!string.IsNullOrEmpty(res.Warnings))
            {
                data.Warnings.Add(res.Warnings);
                if (!logged)
                {
                    Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: warnings", (int)data.LanguageChoice, data.IsApi, true);
                    logged = true;
                }
            }
            data.Output = res.Output;
            if (res.Files != null)
            {
                data.Files = new List <string>();
                foreach (var f in res.Files)
                {
                    data.Files.Add(Convert.ToBase64String(f));
                }
            }
            if (!logged)
            {
                Utils.Log.LogCodeToDB(data.Program, data.Input, data.CompilerArgs, "Windows: ok", (int)data.LanguageChoice, data.IsApi, true);
                logged = true;
            }
            return(data);
        }
 public ContentResult Api(RundotnetData data)
 {
     Response.AppendHeader("Access-Control-Allow-Origin", "*");
     data.IsApi = true;
     return this.Content(Run(data), "application/json");
 }
Beispiel #40
0
        public static string SaveCode(RundotnetData data)
        {
            Random rg = new Random();
            var guid = Utils.Utils.RandomString() + rg.Next(1000, 100000).ToString();

            try
            {
                DB.DB.Code_Insert(data.Program, data.SavedOutput, Convert.ToInt32(data.LanguageChoice), Convert.ToInt32(data.EditorChoice), guid, SessionManager.UserId, data.WholeError, data.WholeWarning, data.ShowWarnings, (int)data.Status, data.StatsToSave);
            }
            catch (Exception)
            {
                return "";
            }
            return guid;
        }
 static RundotnetData RunLinux(RundotnetData data)
 {
     LinuxService service = new LinuxService();
     Service.linux.Languages lang = Service.linux.Languages.Java;
     switch(data.LanguageChoice)
     {
         case "4":
             lang = Service.linux.Languages.Java;
             break;
         case "5":
             lang = Service.linux.Languages.Python;
             break;
         case "6":
             lang = Service.linux.Languages.C;
             break;
         case "7":
             lang = Service.linux.Languages.CPP;
             break;
         default:
             break;
     }
     Stopwatch watch = new Stopwatch();
     watch.Start();
     var res = service.DoWork(data.Program, lang);
     watch.Stop();
     if (res != null)
     {
         if (string.IsNullOrEmpty(res.Stats))
             res.Stats = "";
         else
             res.Stats += ", ";
         res.Stats += string.Format("absolute service time: {0}", Math.Round((double)watch.ElapsedMilliseconds/(double)1000, 2));
         data.RunStats = res.Stats;
     }
     bool logged = false;
     if (!string.IsNullOrEmpty(res.System_Error))
     {
         reExp.Utils.Log.LogInfo("Linux " + res.System_Error, "RunDotNet");
         data.Errors.Add(res.System_Error);
         Utils.Log.LogCodeToDB(data.Program, "Linux: system error");
         return data;
     }
     if (!string.IsNullOrEmpty(res.Errors))
     {
         data.Errors.Add(res.Errors);
         if (!logged)
         {
             Utils.Log.LogCodeToDB(data.Program, "Linux: error");
             logged = true;
         }
     }
     if (res.Exit_Code < 0)
     {
         data.Errors.Add(res.Exit_Status);
         if (!logged)
         {
             Utils.Log.LogCodeToDB(data.Program, "Linux: negative exit code");
             logged = true;
         }
     }
     if (!string.IsNullOrEmpty(res.Warnings))
     {
         data.Warnings.Add(res.Warnings);
         if (!logged)
         {
             Utils.Log.LogCodeToDB(data.Program, "Linux: warnings");
             logged = true;
         }
     }
     data.Output = res.Output;
     if (!logged)
     {
         Utils.Log.LogCodeToDB(data.Program, "Linux: ok");
         logged = true;
     }
     return data;
 }