Esempio n. 1
0
        public override IDictionary <string, string> Parse(string line, int lineNumber, int lineNumberFromBottom)
        {
            if (!_firstHasMatched)
            {
                var result1 = First.Parse(line, lineNumber, lineNumberFromBottom);
                if (First.HasMatched)
                {
                    _firstHasMatched = true;
                    _firstResult     = result1;
                    PageNumber       = Second.PageNumber;
                }
            }

            if (_firstHasMatched)
            {
                var result2 = Second.Parse(line, lineNumber, lineNumberFromBottom);
                if (Second.HasMatched)
                {
                    HasMatched = true;
                    var accumulated = new Dictionary <String, String>(_firstResult).Merge(result2);
                    return((HasFactory)
                                ? new Dictionary <string, string> {
                        { Key, Factory(accumulated) }
                    }
                                : accumulated);
                }
            }
            return(new Dictionary <string, string>());
        }
Esempio n. 2
0
        public static bool ExecuteTool(IEnumerable <IMaster> tools, string alias, IParse parser, Action <Exception> setError)
        {
            var tool = tools.FirstOrDefault(x => alias.StartsWith(x.Alias));

            if (tool == null)
            {
                return(false);
            }

            try {
                var a    = alias.Replace(tool.Alias, "").Trim();
                var args = tool.Parser?.Parse(a) ?? parser.Parse(a);
                if (args.Any() && args[0].Split(' ')[0].StartsWith("dev"))
                {
                    HandleDev(alias, tool.Parser ?? parser);
                    Console.WriteLine("Dev. Command handled!");
                    return(true);
                }
                tool.Execute(args, Launcher.Current.ShowData);
                return(true);
            } catch (Exception e) {
                setError(e);
                return(false);
            }
        }
Esempio n. 3
0
        public IDictionary <string, string> Parse(string line, int lineNumber, int lineNumberFromBottom)
        {
            var result = P.Parse(line, lineNumber, lineNumberFromBottom);

            if (P.HasMatched)
            {
                throw new ArgumentException($"Pattern for [{P.Key}] expected to fail. Value: [{string.Join(",", result.Select(kv => kv.Key + ":" + kv.Value).ToArray())}]", innerException: null);
            }
            return(new Dictionary <string, string>());
        }
Esempio n. 4
0
        public IDictionary <string, string> Parse(string line, int lineNumber, int lineNumberFromBottom)
        {
            var result = P.Parse(line, lineNumber, lineNumberFromBottom);

            if (P.HasMatched)
            {
                this.HasMatched = true;
                return(result);
            }
            return(new Dictionary <string, string>());
        }
Esempio n. 5
0
        public List <Person> Parse(string file)
        {
            if (file.Contains(".csv"))
            {
                _parseStrategie = new CsvParser(file);
            }
            else if (file.Contains(".xml"))
            {
                _parseStrategie = new XmlParser(file);
            }


            return(_parseStrategie.Parse());
        }
Esempio n. 6
0
        public ActionResult Create()
        {
            try
            {
                IFormFile file = Request.Form.Files.Single();

                List <string[]> list       = parsing.Parse(file);
                string          JSONresult = JsonConvert.SerializeObject(list);

                return(Ok(JSONresult));
            }
            catch
            {
                return(BadRequest());
            }
        }
Esempio n. 7
0
        public IDictionary <string, string> Parse(string line, int lineNumber, int lineNumberFromBottom)
        {
            var result = P.Parse(line, lineNumber, lineNumberFromBottom);

            if (P.HasMatched)
            {
                this.HasMatched = true;
                if (!Predicate(result))
                {
                    throw new ArgumentException($"Invalid parsed value for [{P.Key}]. Value: [{string.Join(",", result.Select(kv => kv.Key + ":" + kv.Value).ToArray())}]");
                }

                return(result);
            }
            return(new Dictionary <string, string>());
        }
Esempio n. 8
0
        public virtual bool Parse(T target, U source)
        {
            bool flag = false;

            try
            {
                if (m_Parse != null)
                {
                    flag = m_Parse.Parse(target, source);
                }
                else
                {
                    flag = false;
                }
            }
            catch (Exception)
            {
                flag = false;
            }
            return(flag);
        }
Esempio n. 9
0
        public IDictionary <string, string> Parse(string line, int lineNumber, int lineNumberFromBottom)
        {
            var result1 = Parser1.Parse(line, lineNumber, lineNumberFromBottom);

            if (Parser1.HasMatched)
            {
                HasMatched = true;
                return(result1);
            }
            else
            {
                PageNumber = Parser2.PageNumber;
                var result2 = Parser2.Parse(line, lineNumber, lineNumberFromBottom);
                if (Parser2.HasMatched)
                {
                    HasMatched = true;
                    return(result2);
                }
            }
            return(new Dictionary <string, string>());
        }
Esempio n. 10
0
        private void Parsing(object paring)
        {
            IParse parser = paring as IParse;

            if (parser == null)
            {
                return;
            }
            //Stopwatch sw = new Stopwatch();

            while (true)
            {
                try
                {
                    // sw.Start();
                    var rezult = parser.Parse();
                    _currentBets[parser.Bookmaker] = rezult;
                }
                catch (ThreadAbortException)
                {
                    Logger.AddLog(
                        $"{parser.GetType()} Успели спарсить только {_currentBets[parser.Bookmaker].Count} ставок. Нехватило времени.",
                        Logger.LogTarget.ParserManager, Logger.LogLevel.Warn);
                }
                catch (Exception ex)
                {
                    Logger.AddLog(
                        $"{parser.GetType()} не спарсили все ставки, а только {_currentBets[parser.Bookmaker].Count} ставки. И вот почему: {ex.Message}",
                        Logger.LogTarget.ParserManager, Logger.LogLevel.Epic);
                }
                finally
                {
                    //var workTime = (int)sw.ElapsedMilliseconds;
                    //if (workTime < 2500)
                    //    Thread.Sleep(2500 - workTime);
                    //sw.Reset();
                }
            }
        }
Esempio n. 11
0
        public IDictionary <string, string> Parse(string line, int lineNumber, int lineNumberFromBottom)
        {
            if (!_wasEvaluated)
            {
                var p = If.Parse(line, lineNumber, lineNumberFromBottom);
                if (If.HasMatched)
                {
                    _wasEvaluated   = true;
                    _predicateHolds = Predicate(p.Values.FirstOrDefault());

                    _output.Merge(p);
                }
            }
            if (_wasEvaluated && _predicateHolds)
            {
                var result = Then.Parse(line, lineNumber, lineNumberFromBottom);
                if (Then.HasMatched)
                {
                    _output.Merge(result);

                    HasMatched = true;
                    return(_output);
                }
            }
            if (_wasEvaluated && !_predicateHolds && Else != null)
            {
                var result = Else.Parse(line, lineNumber, lineNumberFromBottom);
                if (Else.HasMatched)
                {
                    _output.Merge(result);

                    HasMatched = true;
                    return(_output);
                }
            }

            return(new Dictionary <string, string>());
        }
Esempio n. 12
0
        public IDictionary <string, string> Parse(string line, int lineNumber, int lineNumberFromBottom)
        {
            var p = Parser.Parse(line, lineNumber, lineNumberFromBottom);

            if (Parser.HasMatched)
            {
                HasMatched = true;

                var input = p.Values;

                var innerParsers = new Dictionary <String, IList <IParse> >
                {
                    { "_", Parsers }
                };
                var parsinator = new Parser(innerParsers);
                var result     = parsinator.Parse(new List <List <string> > {
                    input.ToList()
                });

                return(result.FirstOrDefault().Value ?? new Dictionary <String, String>());
            }
            return(new Dictionary <string, string>());
        }
Esempio n. 13
0
 public static bool ExecuteTool(IEnumerable <IMaster> tools, string alias, IParse parser, Action <Exception> setError)
 {
     foreach (var tool in tools)
     {
         if (alias.StartsWith(tool.Alias))
         {
             try {
                 var a    = alias.Replace(tool.Alias, "").Trim();
                 var args = tool.Parser?.Parse(a) ?? parser.Parse(a);
                 //if (args.Any() && args[0].Split(' ')[0].StartsWith("dev")) {
                 //    HandleDev(alias, tool.Parser ?? parser);
                 //    return true;
                 //}
                 tool.Execute(args, Launcher.Current.ShowData);
                 return(true);
             } catch (Exception e) {
                 setError(e);
                 return(false);
             }
         }
     }
     return(false);
 }
Esempio n. 14
0
        private static void HandleDev(string args, IParse parser)
        {
            var res = parser.Parse(args);

            Launcher.Current.ShowData(string.Join(" || ", res.Skip(2)));
        }