示例#1
0
        public ActionResult Format(string regex, string text, int?startOrder, int?startNumber, string light)
        {
            text = HttpUtility.UrlDecode(text);
            if (string.IsNullOrWhiteSpace(text))
            {
                return(this.Fail("Nothing given to format."));
            }
            regex = HttpUtility.UrlDecode(regex);
            if (string.IsNullOrWhiteSpace(regex))
            {
                return(this.Fail("No regular expression supplied."));
            }
            var matches = Regex.Matches(text, regex, RegexOptions.IgnoreCase);
            var dbRegex = this.Database.RegexFormats.Get(r => r.Regex == regex).FirstOrDefault();

            if (dbRegex == null)
            {
                dbRegex = new FormatRegex {
                    Regex = regex
                };
                this.Database.RegexFormats.Insert(dbRegex);
                this.Database.Save();
            }
            var import = new ImportGroup {
                Lights = {}
            };

            foreach (Match match in matches)
            {
                var order       = match.Groups ["o"];
                var number      = match.Groups ["n"];
                var importTruth = new ImportTruth {
                    Order  = order.Success ? Convert.ToInt32(order.Value) : startOrder,
                    Number = number.Success ? Convert.ToInt32(number.Value) : startNumber,
                    Text   = match.Groups ["t"].Value.Replace("\n", " ").Trim()
                };
                import.Truths.Add(importTruth);
                if (startOrder.HasValue)
                {
                    startOrder++;
                }
                if (startNumber.HasValue)
                {
                    if (startNumber < 0)
                    {
                        startNumber--;
                    }
                    else
                    {
                        startNumber++;
                    }
                }
            }
            return(Json(new { status = SUCCESS, items = import, regexId = dbRegex.Id, regexText = HttpUtility.UrlEncode(regex) }));
        }
示例#2
0
        public ActionResult Format(string regex, string text, int?startOrder, int?startNumber)
        {
            text = HttpUtility.UrlDecode(text);
            if (string.IsNullOrWhiteSpace(text))
            {
                return(this.Fail("Nothing given to format."));
            }
            regex = HttpUtility.UrlDecode(regex);
            if (string.IsNullOrWhiteSpace(regex))
            {
                return(this.Fail("No regular expression supplied."));
            }
            var matches = Regex.Matches(text, regex, RegexOptions.IgnoreCase);
            var dbRegex = this.Database.RegexFormats.Get(r => r.Regex == regex).FirstOrDefault();

            if (dbRegex == null)
            {
                dbRegex = new FormatRegex {
                    Regex = regex
                };
                this.Database.RegexFormats.Insert(dbRegex);
                this.Database.Save();
            }
            /*type|order|number|text...*/
            var itemList = string.Empty;

            foreach (Match match in matches)
            {
                var order  = match.Groups ["o"];
                var number = match.Groups ["n"];
                itemList += string.Format("{0}|{1}|{2}",
                                          order.Success ? Convert.ToInt32(order.Value) : startOrder,
                                          number.Success ? Convert.ToInt32(number.Value) : startNumber,
                                          match.Groups ["t"].Value.Replace("\"", "&quot;").Trim()
                                          );
                itemList += Environment.NewLine;
                if (startOrder.HasValue)
                {
                    startOrder++;
                }
                if (startNumber.HasValue)
                {
                    if (startNumber < 0)
                    {
                        startNumber--;
                    }
                    else
                    {
                        startNumber++;
                    }
                }
            }

            return(Json(new { status = SUCCESS, items = itemList.Trim(), regexId = dbRegex.Id, regexText = HttpUtility.UrlEncode(regex) }));
        }
示例#3
0
            public MaskMatchedVersion(string version)
            {
                var maskMatch = FormatRegex.Match(version);

                IsValid  = maskMatch.Success;
                Major    = new Component(maskMatch.Groups["Major"]);
                Minor    = new Component(maskMatch.Groups["Minor"]);
                Build    = new Component(maskMatch.Groups["Build"]);
                Revision = new Component(maskMatch.Groups["Revision"]);
                Tag      = new TagComponent(maskMatch.Groups["PreRelease"]);
            }