コード例 #1
0
        public static async Task Main(string[] args)
        {
            Console.WriteLine(DBCToolsExtensions.BuildToolsWelcomeMessage("CreateJSON"));

            //Try to load configuration file
            Config = new ApplicationConfigurationLoader().BuildConfigFile();

            if (!Directory.Exists(Config.DiffOutputPath))
            {
                Directory.CreateDirectory(Config.DiffOutputPath);
            }

            Parallel.ForEach(Directory.GetFiles(Config.DbcOutputPath).Select(Path.GetFileNameWithoutExtension), async dbcFile =>
            {
                DbcTypeParser parser = new DbcTypeParser();
                if (!parser.HasDbcType(dbcFile))
                {
                    //TODO: We should create a logger specifically for Program.
                    if (Config.LoggingLevel >= LogLevel.Warning)
                    {
                        Console.WriteLine($"Encountered unknown DBC Type: {dbcFile}. Will skip.");
                    }

                    return;
                }

                IServiceProvider provider = new JSONContainerServiceBuilder(Config, dbcFile).Build();

                using (var scope = provider.CreateScope())
                {
                    ILogger <Program> logger = scope.ServiceProvider.GetService <ILogger <Program> >();

                    try
                    {
                        if (logger.IsEnabled(LogLevel.Information))
                        {
                            logger.LogInformation($"Populating CSV file for DBC: {dbcFile}");
                        }

                        //This may look silly but we want to support the 50+ DBC types so
                        //it needs to be handle magically otherwise we'd have to write code for each one.
                        IDbcTargetFillable tableFiller = scope.ServiceProvider.GetService <IDbcTargetFillable>();

                        await tableFiller.FillAsync()
                        .ConfigureAwait(false);
                    }
                    catch (Exception e)
                    {
                        if (logger.IsEnabled(LogLevel.Error))
                        {
                            logger.LogError($"Encountered Exception: {e.Message} \n\n Stack: {e.StackTrace}");
                        }

                        throw;
                    }
                }
            });

            Console.WriteLine("Finished. Press any key!");
        }
コード例 #2
0
        static async Task Main(string[] args)
        {
            Console.WriteLine(DBCToolsExtensions.BuildToolsWelcomeMessage("CreateGDBC"));

            //Try to load configuration file
            Config = new ApplicationConfigurationLoader().BuildConfigFile();

            DbcTypeParser dbcTypeParser = new DbcTypeParser();

            Directory.CreateDirectory($"G{Config.DbcOutputPath}");

            //For each implement DBCType we should try to build a DBC file for it.
            foreach (Type dbcType in dbcTypeParser.ComputeAllKnownDbcTypes())
            {
                string           dbcName  = dbcTypeParser.GetDbcName(dbcType);
                IServiceProvider provider = new CreateGDbcContainerServiceBuilder(Config, dbcType).Build();

                using (IServiceScope scope = provider.CreateScope())
                {
                    IDbcTargetFillable fillable = scope.ServiceProvider.GetService <IDbcTargetFillable>();

                    if (fillable == null)
                    {
                        throw new InvalidOperationException($"Failed to load Fillable for Type: {dbcType.Name}");
                    }

                    await fillable.FillAsync();

                    using (Stream ms = scope.ServiceProvider.GetRequiredService <Stream>())
                    {
                        //it is important to reset this position
                        //Since we're 20 bytes in after likely writing the header last
                        //Though the above statement could change, either way we want to be at the begining.
                        ms.Position = 0;

                        //It is possible nothing has been written, this is kinda hacky to put this
                        //and leak this in a couple places. But it means no entires were found.
                        if (ms.Length == 0)
                        {
                            continue;
                        }

                        //Once everything has been filled we should create the file
                        using (FileStream fs = new FileStream($"G{Config.DbcOutputPath}/{dbcName}.gdbc", FileMode.CreateNew, FileAccess.ReadWrite))
                        {
                            await ms.CopyToAsync(fs);
                        }
                    }
                }
            }

            Console.WriteLine("Finished. Press any key!");
        }
コード例 #3
0
        static async Task Main(string[] args)
        {
            Console.WriteLine(DBCToolsExtensions.BuildToolsWelcomeMessage("CreateDatabase"));

            //Try to load configuration file
            Config = new ApplicationConfigurationLoader().BuildConfigFile();

            //TODO: This is just test code, we want to handle inputs better.
            Console.WriteLine($"Will create tables and database if they do not exist.");

            //TODO: We shouldn't check everytime we create a DBC table. Do this elsewhere
            await CreateDatabaseIfNotCreated();

            foreach (string dbcFile in Directory.GetFiles("DBC").Select(Path.GetFileNameWithoutExtension))
            {
                //TODO: Register in IoC
                DbcTypeParser parser = new DbcTypeParser();
                if (!parser.HasDbcType(dbcFile))
                {
                    //TODO: We should create a logger specifically for Program.
                    if (Config.LoggingLevel > LogLevel.Warning)
                    {
                        Console.WriteLine($"Encountered unknown DBC Type: {dbcFile}. Will skip.");
                    }

                    continue;
                }

                //We should check if we know a DBC file of this type.
                IServiceProvider provider = new CreateDatabaseContainerServiceBuilder(Config, dbcFile).Build();

                Stopwatch watch = new Stopwatch();
                watch.Start();
                using (var scope = provider.CreateScope())
                {
                    ILogger <Program> logger = scope.ServiceProvider.GetService <ILogger <Program> >();

                    try
                    {
                        if (Config.LoggingLevel > LogLevel.Information)
                        {
                            logger.LogInformation($"Populating table for DBC: {dbcFile}");
                        }

                        //This may look silly but we want to support the 50+ DBC types so
                        //it needs to be handle magically otherwise we'd have to write code for each one.
                        IDbcTargetFillable tableFiller = scope.ServiceProvider.GetService <IDbcTargetFillable>();

                        await tableFiller.FillAsync();
                    }
                    catch (Exception e)
                    {
                        if (logger.IsEnabled(LogLevel.Error))
                        {
                            logger.LogError($"Encountered Exception: {e.Message} \n\n Stack: {e.StackTrace}");
                        }

                        throw;
                    }
                    finally
                    {
                        await scope.ServiceProvider.GetService <DbContext>().DisposeAsync();
                    }
                }

                watch.Stop();

                if (Config.LoggingLevel > LogLevel.Information)
                {
                    Console.WriteLine($"Created Table: {dbcFile} In Milliseconds: {watch.ElapsedMilliseconds}");
                }
            }

            Console.WriteLine("Finished. Press any key!");
        }