Пример #1
0
        public async Task InitDbFromPoFiles(LocalizationDbContext localizationDbContext)
        {
            Logger.LogInformation("Importing PO files in db");

            var basePath = "Localization";

            IReadOnlyDictionary <string, POCatalog> TextCatalogs = new Dictionary <string, POCatalog>();

            var textCatalogFiles = _environment.ContentRootFileProvider.GetDirectoryContents(basePath)
                                   .Where(fi => !fi.IsDirectory && ".po".Equals(Path.GetExtension(fi.Name)))
                                   .ToArray();

            var textCatalogs = new List <(string FileName, string Culture, POCatalog Catalog)>();

            var parserSettings = new POParserSettings
            {
                SkipComments    = true,
                SkipInfoHeaders = true,
            };

            Parallel.ForEach(textCatalogFiles,
                             () => new POParser(parserSettings),
                             (file, s, p) =>
            {
                try
                {
                    POParseResult result;
                    using (var stream = file.CreateReadStream())
                        result = p.Parse(new StreamReader(stream));

                    if (result.Success)
                    {
                        lock (textCatalogs)
                            textCatalogs.Add((file.Name, result.Catalog.GetCultureName(), result.Catalog));
                    }
        public async Task InitDbFromPoFiles(LocalizationDbContext localizationDbContext)
        {
            Logger.LogInformation("Importing PO files in db");

            var basePath = "Localization";

            IReadOnlyDictionary <string, POCatalog> TextCatalogs = new Dictionary <string, POCatalog>();

            var cultures = _environment.ContentRootFileProvider.GetDirectoryContents(basePath)
                           .Where(fi => fi.IsDirectory)
                           .Select(fi => fi.Name)
                           .ToArray();

            var textCatalogFiles = cultures.SelectMany(
                c => _environment.ContentRootFileProvider.GetDirectoryContents(Path.Combine(basePath, c))
                .Where(fi => !fi.IsDirectory && ".po".Equals(Path.GetExtension(fi.Name), StringComparison.OrdinalIgnoreCase)),
                (c, f) => (Culture: c, FileInfo: f));

            var textCatalogs = new List <(string FileName, string Culture, POCatalog Catalog)>();

            var parserSettings = new POParserSettings
            {
                SkipComments    = true,
                SkipInfoHeaders = true,
            };

            Parallel.ForEach(textCatalogFiles,
                             () => new POParser(parserSettings),
                             (it, s, p) =>
            {
                POParseResult result;
                using (var stream = it.FileInfo.CreateReadStream())
                    result = p.Parse(new StreamReader(stream));

                if (result.Success)
                {
                    if (result.Catalog.GetCultureName() != it.Culture)
                    {
                        Logger.LogWarning($"Translation file '{Path.Combine(basePath, it.Culture, it.FileInfo.Name)}' language / folder mismatch.");
                    }
                    else
                    {
                        lock (textCatalogs)
                            textCatalogs.Add((it.FileInfo.Name, it.Culture, result.Catalog));
                    }
Пример #3
0
 public DatabaseInitializer(
     TenantStoreDbContext tenantStoreDbContext,
     LocalizationDbContext localizationDbContext,
     ApplicationDbContext context,
     PersistedGrantDbContext persistedGrantContext,
     ConfigurationDbContext configurationContext,
     UserManager <ApplicationUser> userManager,
     RoleManager <ApplicationRole> roleManager,
     ApplicationPermissions applicationPermissions,
     ILogger <DatabaseInitializer> logger)
 {
     _tenantStoreDbContext  = tenantStoreDbContext;
     _localizationDbContext = localizationDbContext;
     _persistedGrantContext = persistedGrantContext;
     _configurationContext  = configurationContext;
     _context                = context;
     _userManager            = userManager;
     _roleManager            = roleManager;
     _applicationPermissions = applicationPermissions;
     _logger = logger;
 }