예제 #1
0
    public async Task BuildNuGetIndex()
    {
        const string outputFolder = "BuildNuGetIndexTest";

        // Arrange
        var builder = new IndexBuilder();

        builder.Sources.Add(new IndexSourceEntry(TestNuGetFeedUrl));

        // Act
        var index = await builder.BuildAsync(outputFolder);

        // Assert
        Assert.True(index.TryGetNuGetSourcePath(TestNuGetFeedUrl, out _));
        Assert.True(Directory.Exists(index.BaseUrl.LocalPath));
    }
예제 #2
0
    public async Task BuildGbIndex()
    {
        const string outputFolder = "BuildGBIndexTest";
        const int    heroesGameId = 6061;

        // Arrange
        var builder = new IndexBuilder();

        builder.Sources.Add(new IndexSourceEntry(heroesGameId));

        // Act
        var index = await builder.BuildAsync(outputFolder);

        // Assert
        Assert.True(index.TryGetGameBananaSourcePath(heroesGameId, out _));
        Assert.True(Directory.Exists(index.BaseUrl.LocalPath));
    }
예제 #3
0
        public async Task Run()
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("BUILD INDEX\n");
            Console.ResetColor();

            Console.WriteLine(
                $"Profile path: {_profilePath}\n" +
                $"Database name: {_dbName}\n" +
                $"Database type: {_dbType}\n");

            Serilog.Log.Information("BUILD INDEX");
            IIndexBuilderFactory factory = null;
            string connString            = string.Format(
                _options.Configuration[$"ConnectionStrings:{_dbType}"], _dbName);
            ITableInitializer initializer = null;

            switch (_dbType.ToLowerInvariant())
            {
            case "mysql":
                factory = new MySqlIndexBuilderFactory(
                    LoadText(_profilePath),
                    connString);
                initializer = new MySqlTableInitializer(
                    new MySqlDbConnectionFactory(connString));
                break;

            case "pgsql":
                factory = new PgSqlIndexBuilderFactory(
                    LoadText(_profilePath),
                    connString);
                initializer = new PgSqlTableInitializer(
                    new PgSqlDbConnectionFactory(connString));
                break;

            default:
                throw new ArgumentException("Invalid db type: " + _dbType);
            }
            factory.BufferSize = _bufferSize;

            initializer.Initialize(_clear);

            ProgressBar mainBar = new ProgressBar(100, null, new ProgressBarOptions
            {
                DisplayTimeInRealTime = true,
                EnableTaskBarProgress = true
            });
            ProgressBarOptions childBarOptionns = new ProgressBarOptions
            {
                DisplayTimeInRealTime = false,
                CollapseWhenFinished  = true
            };
            Dictionary <string, ChildProgressBar> childBars =
                new Dictionary <string, ChildProgressBar>();
            Regex r = new Regex(@"^\[([^]]+)\]", RegexOptions.Compiled);

            foreach (DocumentDefinition document in factory.Profile.Documents)
            {
                using (IndexBuilder builder = factory.GetBuilder(null, _options.Logger))
                {
                    builder.PartitionCount   = _partitionCount;
                    builder.MinPartitionSize = _minPartitionSize;
                    builder.RecordLimit      = _recordLimit;

                    await builder.BuildAsync(document.Id, CancellationToken.None,
                                             new Progress <ProgressReport>(report =>
                    {
                        IProgressBar bar = mainBar;
                        Match m = r.Match(report.Message ?? "");
                        if (m.Success)
                        {
                            if (!childBars.ContainsKey(m.Groups[1].Value))
                            {
                                childBars[m.Groups[1].Value] =
                                    mainBar.Spawn(100, m.Groups[1].Value,
                                                  childBarOptionns);
                            }
                            bar = childBars[m.Groups[1].Value];
                        }
                        bar.Tick(report.Percent, report.Message);
                    }));
                }
            }
        }