Exemplo n.º 1
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 (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
                        });
                    });
                }
            }
            catch (Exception e)
            {
                Utils.Log.LogInfo(e.Message, "error");
                return("");
            }
            return(guid);
        }
Exemplo n.º 2
0
        public static RedisData GetRundotnetDataFromRedis(RundotnetData data)
        {
            try
            {
                if (data.LanguageChoice == LanguagesEnum.Octave)
                {
                    return(null);
                }

                var conn = RedisConnection;
                JavaScriptSerializer json = new JavaScriptSerializer();
                string key = json.Serialize(new RedisData()
                {
                    Program        = data.Program,
                    Input          = data.LanguageChoice == LanguagesEnum.Prolog ? data.Input + "\nhalt." : data.Input,
                    Args           = data.CompilerArgs,
                    LanguageChoice = (int)data.LanguageChoice
                });
                key = Utils.EncryptionUtils.CreateMD5Hash(key);
                var bytes = conn.Strings.Get(redis_db, key).Result;
                if (bytes == null)
                {
                    return(null);
                }
                string val = Encoding.UTF8.GetString(bytes);
                return(json.Deserialize <RedisData>(GlobalUtils.Utils.Decompress(val)));
            }
            catch (Exception e)
            {
                Utils.Log.LogInfo(e.Message, "redis get error");
                return(null);
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public static void InsertRundotnetDataToRedis(RundotnetData data)
        {
            try
            {
                if (data.LanguageChoice == LanguagesEnum.Octave)
                {
                    return;
                }

                var conn = RedisConnection;
                JavaScriptSerializer json = new JavaScriptSerializer();
                string key = json.Serialize(new RedisData()
                {
                    Program        = data.Program,
                    Input          = data.Input,
                    Args           = data.CompilerArgs,
                    LanguageChoice = (int)data.LanguageChoice
                });
                key = Utils.EncryptionUtils.CreateMD5Hash(key);
                string val = json.Serialize(new RedisData()
                {
                    Program        = data.Program,
                    Input          = data.Input,
                    Args           = data.CompilerArgs,
                    LanguageChoice = (int)data.LanguageChoice,
                    WholeError     = data.WholeError,
                    WholeWarning   = data.WholeWarning,
                    WholeOutput    = data.Output,
                    RunStatus      = data.RunStats
                });
                val = GlobalUtils.Utils.Compress(val);
                conn.Strings.Set(redis_db, new Dictionary <string, byte[]>()
                {
                    { key, Encoding.UTF8.GetBytes(val) }
                }).Wait();
                conn.Keys.Expire(redis_db, key, 24 * 60 * 60);
            }
            catch (Exception e)
            {
                Utils.Log.LogInfo(e.Message, "redis insert error");
            }
        }
Exemplo n.º 5
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");
            }
        }