Exemplo n.º 1
0
        /// <summary>
        ///     Gets the parsed configuration.
        /// </summary>
        /// <param name="profiles">The profiles.</param>
        /// <param name="startupProjects">The startup projects.</param>
        /// <param name="currentStartupProjects">The current startup projects.</param>
        /// <returns>The parsed configuration.</returns>
        private ParsedConfiguration GetParsedConfiguration(ICollection <Profile> profiles, ICollection <string> startupProjects, ICollection <string> currentStartupProjects)
        {
            var parseConfigurationEventArgs = new ParseConfigurationEventArgs(profiles, startupProjects, currentStartupProjects);

            ParseConfiguration?.Invoke(this, parseConfigurationEventArgs);
            return(parseConfigurationEventArgs.ParsedConfiguration);
        }
        public void TestCurrentConfig()
        {
            ParseConfiguration config = Client.GetCurrentConfiguration();

            Assert.AreEqual("testValue", config["testKey"]);
            Assert.AreEqual("testValue", config.Get <string>("testKey"));
        }
Exemplo n.º 3
0
 public void SetUp()
 {
     Trigger = new AutoResetEvent(false);
     if (NeedAServer)
     {
         Server = new FakeServer();
         ParseConfiguration.Configure("the-app-id", "shhh", c => c.ConnectTo("http://localhost:" + FakeServer.Port + "/"));
     }
     BeforeEachTest();
 }
Exemplo n.º 4
0
        public async Task Test_AngleSharpParser_OnFullReadFile_And_Count_ResultTexts()
        {
            var fileName = Path.Combine(TestContext.CurrentContext.GetTestProjectPath(),
                                        @"SampleFiles\Создаем программное обеспечение для бизнеса - SimbirSoft.html");

            var fileContent = await File.ReadAllTextAsync(fileName);

            var configuration = ParseConfiguration.Default();
            var parser        = new AngleSharpParser(configuration.ExcludeTags);
            var texts         = (await parser.ParseAsync(fileContent)).ToList();

            Assert.AreEqual(290, texts.Count);
        }
Exemplo n.º 5
0
        public void Test_ManualParser_OnFullReadFile_And_Count_ResultTexts()
        {
            var fileName = Path.Combine(TestContext.CurrentContext.GetTestProjectPath(),
                                        @"SampleFiles\Создаем программное обеспечение для бизнеса - SimbirSoft.html");

            var fileContent = File.ReadAllText(fileName);

            var configuration = ParseConfiguration.Default();
            var parser        = new ManualParser(configuration.ExcludeTags);

            parser.ParseBlock(fileContent);

            Assert.AreEqual(250, parser.ResultTexts.Count());
        }
        protected override bool Handle(ParseCommand command)
        {
            if (!File.Exists(command.InputPath))
            {
                _logger.Error("Incorrect input path");
                return(false);
            }

            string path = Path.GetDirectoryName(command.InputPath);

            if (path == null)
            {
                _logger.Error("Can't get parent directory");
                return(false);
            }

            _logger.Info("===================================================");
            _logger.Info("                      PARSING");
            _logger.Info("===================================================");
            _logger.Info("SETUP");
            _logger.Info($"Deserializing {Path.GetFileName(command.InputPath)}...");
            ParseConfiguration configuration = JsonConvert.DeserializeObject <ParseConfiguration>(File.ReadAllText(command.InputPath));

            if (configuration == null)
            {
                _logger.Error($"Failed to deserialize {Path.GetFileName(command.InputPath)}");
                return(false);
            }

            DateTime start = DateTime.Now;

            foreach (Parser parser in _parsers)
            {
                _logger.Info("---------------------------------------------------");
                parser.Parse(configuration, path);
            }

            _logger.Info("===================================================");
            TimeSpan timeElapsed = DateTime.Now - start;

            _logger.Info($"Parsing finished in {(timeElapsed.TotalMinutes >= 1 ? timeElapsed.Minutes + "mn " : string.Empty)}{timeElapsed.Seconds}s");
            _logger.Info("===================================================");
            return(true);
        }
Exemplo n.º 7
0
        public IEnumerable <Event> Parse(ParseConfiguration config)
        {
            var cities = config.City.Split(' ');

            foreach (var city in cities)
            {
                var events = GetEvents(city);

                foreach (var eventNode in events)
                {
                    if (!CanParse(eventNode))
                    {
                        continue;
                    }

                    if (IsTypeAndCostNull(config.Type, config.Cost))
                    {
                        AddParsedEvent(eventNode, city);
                    }
                    else if (IsCostNull(config.Type, config.Cost))
                    {
                        if (NodeDesc(eventNode).Contains(config.Type))
                        {
                            AddParsedEvent(eventNode, city);
                        }
                    }
                    else if (IsTypeNull(config.Type))
                    {
                        if (NodeCost(eventNode).Contains(config.Cost))
                        {
                            AddParsedEvent(eventNode, city);
                        }
                    }
                    else
                    {
                        if (NodeCost(eventNode).Contains(config.Cost) && NodeDesc(eventNode).Contains(config.Type))
                        {
                            AddParsedEvent(eventNode, city);
                        }
                    }
                }
            }
            return(_eventsList);
        }
Exemplo n.º 8
0
        public async Task Test_RunFullReadStraregy_OnFullReadFile_And_Count_Output_Lines()
        {
            var fileName = Path.Combine(TestContext.CurrentContext.GetTestProjectPath(),
                                        @"SampleFiles\Создаем программное обеспечение для бизнеса - SimbirSoft.html");

            var fileContent = await File.ReadAllTextAsync(fileName);

            var configuration = ParseConfiguration.Default();
            var sb            = new StringBuilder();

            configuration.TextWriter = new StringWriter(sb);

            var strategy = new PartialReadParseStrategy(configuration);
            await strategy.Parse(fileContent);

            var outResult = sb.ToString();
            var tokens    = outResult.Split("\n");

            Assert.AreEqual(729, tokens.Length);
        }
Exemplo n.º 9
0
        public async Task Test_RunPartialReadStraregy_OnFileStream_And_Count_Output_Lines()
        {
            var fileName = Path.Combine(TestContext.CurrentContext.GetTestProjectPath(),
                                        @"SampleFiles\Метаданные HTML-документа.html");

            using var streamReader = new StreamReader(fileName);

            var configuration = ParseConfiguration.Default();
            var sb            = new StringBuilder();

            configuration.TextWriter = new StringWriter(sb);

            var strategy = new PartialReadParseStrategy(configuration);
            await strategy.Parse(streamReader);

            var outResult = sb.ToString();
            var tokens    = outResult.Split("\n");

            Assert.AreEqual(502, tokens.Length);
        }
Exemplo n.º 10
0
 public FullReadParseStrategy(ParseConfiguration configuration) : base(configuration)
 {
 }
        public void GetConfigServers_NpgsqlTest_ReturnIsNotNull()
        {
            ParseConfiguration parseConfiguration = new ParseConfiguration();

            Assert.IsNotNull(parseConfiguration.GetConfigServers_Npgsql());
        }
Exemplo n.º 12
0
 protected ParseStrategyBase(ParseConfiguration configuration)
 {
     Configuration = configuration;
 }
Exemplo n.º 13
0
 protected ParseStrategyBase()
 {
     Configuration = ParseConfiguration.Default();
 }