public string Save(RegexData data)
        {
            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            if (string.IsNullOrEmpty(data.Pattern))
            {
                data.Pattern = string.Empty;
            }
            if (string.IsNullOrEmpty(data.Substitution))
            {
                data.Substitution = string.Empty;
            }
            if (string.IsNullOrEmpty(data.Text))
            {
                data.Text = string.Empty;
            }
            string guid = Model.SaveRegexReplace(data);

            SavedItem item = new SavedItem();

            if (!string.IsNullOrEmpty(guid))
            {
                item.Url = Utils.Utils.GetUrl(Utils.Utils.PagesEnum.Replace) + "/" + guid;
            }
            else
            {
                item.Url = "";
            }

            return(json.Serialize(item));
        }
Exemplo n.º 2
0
        public static string SaveRegex(RegexData data)
        {
            var guid = Utils.Utils.GetGuid();

            try
            {
                string options = "";
                foreach (var o in data.Options)
                    options += o ? "1" : "0";
                DB.DB.Regex_Insert(data.Pattern, data.Text, data.SavedOutput, options, guid, SessionManager.UserId);

                if (SessionManager.IsUserInSession())
                {
                    int uid = (int)SessionManager.UserId;
                    Task.Run(() =>
                    {
                        Search.PutUserItem(new UsersItem()
                        {
                            Date = DateTime.Now,
                            Guid = guid,
                            ID = "regex_" + guid,
                            UserId = uid,
                            Regex = data.Pattern,
                            Text = data.Text
                        });
                    });
                }
            }
            catch (Exception e)
            {
                Utils.Log.LogInfo(e.Message, e, "error");
                return "";
            }
            return guid;
        }
Exemplo n.º 3
0
 public string TakeText(RegexData data)
 {
     string res = Logic.TakeText(data);
     if(res.Length >= Compression.MaxUncompressedLength)
         Compression.SetCompression();
     return res;
 }
Exemplo n.º 4
0
        public ActionResult Index(RegexData data)
        {
            Compression.SetCompression();
            data.Describtions = (new OptionDescribtion()).GetDescribtions();
            data.IsReplace    = false;

            //retrieve saved regex
            if (!string.IsNullOrEmpty(HttpContext.Request.QueryString["code"]))
            {
                var regex = Model.GetRegex(HttpContext.Request["code"]);
                data.Pattern = regex.Pattern;
                data.Text    = regex.Text;
                if (regex.Options != null)
                {
                    data.Options = regex.Options;
                }
                data.Result   = regex.Output;
                data.IsResult = true;
                return(View(data));
            }
            //save regex
            if (data.ShouldSave)
            {
                if (string.IsNullOrEmpty(data.Pattern))
                {
                    data.Pattern = string.Empty;
                }
                if (string.IsNullOrEmpty(data.Text))
                {
                    data.Text = string.Empty;
                }
                string guid = Model.SaveRegex(data);
                if (!string.IsNullOrEmpty(guid))
                {
                    data.SavedUrl = Utils.Utils.GetUrl(Utils.Utils.PagesEnum.Tester) + "?code=" + guid;
                }
                else
                {
                    data.SavedUrl = "";
                }
                data.SavedOutput = "";
                data.ShouldSave  = false;
                return(View(data));
            }

            if (string.IsNullOrEmpty(data.Pattern) && string.IsNullOrEmpty(data.Text))
            {
                data.IsResult = false;
                return(View(data));
            }

            data.IsResult = true;
            data.Result   = Logic.TakeText(data);
            return(View(data));
        }
Exemplo n.º 5
0
        public ActionResult Index(RegexData data)
        {
            Compression.SetCompression();
            data.IsReplace = true;
            data.Describtions = (new OptionDescribtion()).GetDescribtions();

            //retrieve saved regex replace
            if (!string.IsNullOrEmpty(HttpContext.Request.QueryString["code"]))
            {
                var regexReplace = Model.GetRegexReplace(HttpContext.Request["code"]);
                data.Pattern = regexReplace.Pattern;
                data.Substitution = regexReplace.Replacement;
                data.Text = regexReplace.Text;
                if (regexReplace.Options != null)
                    data.Options = regexReplace.Options;
                data.Result = regexReplace.Output;
                data.IsResult = true;
                return View(data);
            }

            //save regex replace
            if (data.ShouldSave)
            {
                if (string.IsNullOrEmpty(data.Pattern))
                    data.Pattern = string.Empty;
                if (string.IsNullOrEmpty(data.Substitution))
                    data.Substitution = string.Empty;
                if (string.IsNullOrEmpty(data.Text))
                    data.Text = string.Empty;
                string guid = Model.SaveRegexReplace(data);
                if (!string.IsNullOrEmpty(guid))
                    data.SavedUrl = Utils.Utils.GetUrl(Utils.Utils.PagesEnum.Replace) + "?code=" + guid;
                else
                    data.SavedUrl = "";
                data.SavedOutput = "";
                data.ShouldSave = false;
                return View(data);
            }

            if (string.IsNullOrEmpty(data.Pattern) && string.IsNullOrEmpty(data.Substitution) && string.IsNullOrEmpty(data.Text))
            {
                data.IsResult = false;
                return View(data);
            }

            data.IsResult = true;
            data.Result = Logic.TakeText(data);

            return View(data);
        }
Exemplo n.º 6
0
        public static string TakeText(RegexData data)
        {
            try
            {
                if (data.Pattern == null)
                {
                    data.Pattern = "";
                }
                if (!string.IsNullOrEmpty(data.Text) && data.Text.Contains("\r"))
                {
                    data.Text = data.Text.Replace("\r", "");
                }

                int maxLength = 500000;
                if (!string.IsNullOrEmpty(data.Text) && data.Text.Length > maxLength)
                {
                    return(string.Format("Text is too long (max {0} characters).", maxLength));
                }
                if (!string.IsNullOrEmpty(data.Pattern) && data.Pattern.Length > maxLength)
                {
                    return(string.Format("Pattern is too long (max {0} characters).", maxLength));
                }
                if (!string.IsNullOrEmpty(data.Substitution) && data.Substitution.Length > maxLength)
                {
                    return(string.Format("Substitution is too long (max {0} characters).", maxLength));
                }

                Job    job    = new Job(data);
                Thread worker = new Thread(job.DoWork);
                worker.Start();
                int secToWait = 20;
                worker.Join(secToWait * 1000);
                if (worker.ThreadState != ThreadState.Stopped)
                {
                    worker.Abort();
                    return(string.Format("The computation taking too long ( > {0} sec). Giving up.", secToWait));
                }
                else
                {
                    return(job.Result);
                }
            }
            catch (Exception e)
            {
                reExp.Utils.Log.LogInfo(e.Message + " \n" + e.StackTrace + " \n", e, "ERROR_IN_LOGIC");
                return("Error occurred. We'll examine why.");
            }
        }
Exemplo n.º 7
0
        public string Save(RegexData data)
        {
            Compression.SetCompression();
            JavaScriptSerializer json = new JavaScriptSerializer();

            if (string.IsNullOrEmpty(data.Pattern))
                data.Pattern = string.Empty;
            if (string.IsNullOrEmpty(data.Text))
                data.Text = string.Empty;
            string guid = Model.SaveRegex(data);

            SavedItem item = new SavedItem();
            if (!string.IsNullOrEmpty(guid))
                item.Url = Utils.Utils.GetUrl(Utils.Utils.PagesEnum.Tester)+"/"+guid;
            else
                item.Url = "";

            return json.Serialize(item);
        }
Exemplo n.º 8
0
        public ActionResult Index(RegexData data, string savedNr = null)
        {
            Compression.SetCompression();
            data.Describtions = (new OptionDescribtion()).GetDescribtions();
            data.IsReplace = false;

            //retrieve saved regex
            savedNr = savedNr ?? HttpContext.Request.QueryString["code"];
            if (!string.IsNullOrEmpty(savedNr))
            {
                var regex = Model.GetRegex(savedNr);
                data.Pattern = regex.Pattern;
                data.Text = regex.Text;
                if (regex.Options != null)
                    data.Options = regex.Options;
                data.Result = regex.Output;
                return View(data);
            }

            return View(data);
        }
        public ActionResult Index(RegexData data, string savedNr = null)
        {
            Compression.SetCompression();
            data.Describtions = (new OptionDescribtion()).GetDescribtions();

            //retrieve saved regex replace
            savedNr = savedNr ?? HttpContext.Request.QueryString["code"];
            if (!string.IsNullOrEmpty(savedNr))
            {
                var regexReplace = Model.GetRegexReplace(savedNr);
                data.Pattern      = regexReplace.Pattern;
                data.Substitution = regexReplace.Replacement;
                data.Text         = regexReplace.Text;
                if (regexReplace.Options != null)
                {
                    data.Options = regexReplace.Options;
                }
                data.Result = regexReplace.Output;
                return(View(data));
            }

            return(View(data));
        }
Exemplo n.º 10
0
        public static string TakeText(RegexData data)
        {
            try
            {
                if (data.Pattern == null)
                    data.Pattern = "";
                if (!string.IsNullOrEmpty(data.Text) && data.Text.Contains("\r"))
                    data.Text = data.Text.Replace("\r", "");

                int maxLength = 500000;
                if (!string.IsNullOrEmpty(data.Text) && data.Text.Length > maxLength)
                    return string.Format("Text is too long (max {0} characters).", maxLength);
                if (!string.IsNullOrEmpty(data.Pattern) && data.Pattern.Length > maxLength)
                    return string.Format("Pattern is too long (max {0} characters).", maxLength);
                if (!string.IsNullOrEmpty(data.Substitution) && data.Substitution.Length > maxLength)
                    return string.Format("Substitution is too long (max {0} characters).", maxLength);

                Job job = new Job(data);
                Thread worker = new Thread(job.DoWork);
                worker.Start();
                int secToWait = 20;
                worker.Join(secToWait * 1000);
                if (worker.ThreadState != ThreadState.Stopped)
                {
                    worker.Abort();
                    return string.Format("The computation taking too long ( > {0} sec). Giving up.", secToWait);
                }
                else
                    return job.Result;
            }
            catch (Exception e)
            {
                reExp.Utils.Log.LogInfo(e.Message+" \n"+e.StackTrace +" \n", e, "ERROR_IN_LOGIC");
                return "Error occurred. We'll examine why.";
            }
        }
Exemplo n.º 11
0
        public static string SaveRegexReplace(RegexData data)
        {
            Random rg = new Random();
            var guid = Utils.Utils.RandomString() + rg.Next(1000, 100000).ToString();

            try
            {
                string options = "";
                foreach (var o in data.Options)
                    options += o ? "1" : "0";
                DB.DB.Regex_Replace_Insert(data.Pattern, data.Substitution, data.Text, data.SavedOutput, options, guid, SessionManager.UserId);
            }
            catch (Exception)
            {
                return "";
            }
            return guid;
        }
Exemplo n.º 12
0
 public Job(RegexData data)
 {
     this.data = data;
 }
Exemplo n.º 13
0
 public Job(RegexData data)
 {
     this.data = data;
 }
Exemplo n.º 14
0
 public string TakeText(RegexData data)
 {
     Compression.SetCompression();
     data.IsReplace = false;
     return Logic.TakeText(data);
 }
Exemplo n.º 15
0
 public string TakeText(RegexData data)
 {
     Compression.SetCompression();
     data.IsReplace = true;
     return(Logic.TakeText(data));
 }