public void Import(MigrationToolOptions settings) { var sourceImportFilePath = Path.Combine(settings.SourceDirectory, "localization-resource-translations.sql"); if (!File.Exists(sourceImportFilePath)) { throw new IOException($"Import source file '{sourceImportFilePath}' not found!"); } // create DB structures in target database var updater = new SchemaUpdater(); updater.Execute(new UpdateSchema.Command()); var fileInfo = new FileInfo(sourceImportFilePath); var script = fileInfo.OpenText().ReadToEnd(); using (var connection = new SqlConnection(settings.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(script, connection)) { command.ExecuteNonQuery(); } } }
public void Import(MigrationToolOptions settings) { var sourceImportFilePath = Path.Combine(settings.SourceDirectory, "localization-resource-translations.sql"); if (!File.Exists(sourceImportFilePath)) { throw new IOException($"Source file '{sourceImportFilePath}' for import not found!"); } // create DB structures in target database using (var db = new LanguageEntities(settings.ConnectionString)) { var resource = db.LocalizationResources.Where(r => r.Id == 0); } var fileInfo = new FileInfo(sourceImportFilePath); var script = fileInfo.OpenText().ReadToEnd(); using (var connection = new SqlConnection(settings.ConnectionString)) { connection.Open(); using (var command = new SqlCommand(script, connection)) { command.ExecuteNonQuery(); } } }
private ICollection <LocalizationResource> GetXmlResources(MigrationToolOptions settings) { // test few default conventions (lazy enough to read from EPiServer Framework configuration file) string resourceFilesSourceDir; if (!string.IsNullOrEmpty(settings.ResourceDirectory)) { resourceFilesSourceDir = Path.Combine(settings.SourceDirectory, settings.ResourceDirectory); } else { resourceFilesSourceDir = Path.Combine(settings.SourceDirectory, "Resources\\LanguageFiles"); if (!Directory.Exists(resourceFilesSourceDir)) { resourceFilesSourceDir = Path.Combine(settings.SourceDirectory, "lang"); } } if (!Directory.Exists(resourceFilesSourceDir)) { throw new IOException($"Default resource directory '{resourceFilesSourceDir}' does not exist or can't be found. Use `-resourceDirectory` argument"); } var resourceFiles = Directory.GetFiles(resourceFilesSourceDir, "*.xml"); if (!resourceFiles.Any()) { Console.WriteLine($"No resource files found in '{resourceFilesSourceDir}'"); } var fileProcessor = new ResourceFileProcessor(settings.IgnoreDuplicateKeys); return(fileProcessor.ParseFiles(resourceFiles)); }
public static int Main(string[] args) { var parser = new Parser(with => { with.EnableDashDash = true; with.HelpWriter = Console.Error; }); var result = parser.ParseArguments <MigrationToolOptions>(args).WithParsed(parsed => { _settings = parsed; if (string.IsNullOrEmpty(parsed.TargetDirectory)) { _settings.TargetDirectory = parsed.SourceDirectory; } }); if (result.Tag == ParserResultType.NotParsed) { return(-1); } if (!Directory.Exists(_settings.SourceDirectory)) { throw new IOException($"Source directory `{_settings.SourceDirectory}` does not exist!"); } try { if (_settings.ExportResources) { ExportResources(); } if (_settings.ImportResources) { ImportResources(); } } catch (Exception e) { Console.WriteLine($"Error running tool: {e.Message}"); return(-1); } if (!_settings.ExportResources && !_settings.ImportResources) { Console.WriteLine("No command specified. Please make up your mind, either you want to export or import resources."); Console.WriteLine("Try 'DbLocalizationProvider.MigrationTool.exe --help' for more information."); } if (Debugger.IsAttached) { Console.ReadLine(); } return(0); }
private void InitializeDb(MigrationToolOptions settings) { try { var updater = new SchemaUpdater(); updater.Execute(new UpdateSchema.Command()); } catch { // it's OK to have exception here } }
private void InitializeDb(MigrationToolOptions settings) { // initialize DB - to generate data structures { try { using (var db = new LanguageEntities(settings.ConnectionString)) { var resource = db.LocalizationResources.Where(r => r.Id == 0); } } catch { // it's OK to have exception here } } }
internal ICollection <LocalizationResource> Export(MigrationToolOptions settings) { ICollection <LocalizationResource> resources = new List <LocalizationResource>(); if (settings.ExportFromXmlOnly) { resources = GetXmlResources(settings); } if (settings.ExportFromDatabase) { var repo = new ResourceRepository(); resources = repo.GetAll().ToList(); InitializeDb(settings); } return(resources); }
internal ICollection <LocalizationResource> Extract(MigrationToolOptions settings) { ICollection <LocalizationResource> resources = new List <LocalizationResource>(); if (settings.ExportFromXmlOnly) { resources = GetXmlResources(settings); } if (settings.ExportFromDatabase) { using (var db = new LanguageEntities(settings.ConnectionString)) { resources = db.LocalizationResources.Include(r => r.Translations).ToList(); } InitializeDb(settings); } return(resources); }
public static int Main(string[] args) { var parser = new Parser(with => { with.EnableDashDash = true; with.HelpWriter = Console.Error; }); var result = parser.ParseArguments <MigrationToolOptions>(args).WithParsed(parsed => { _settings = parsed; if (string.IsNullOrEmpty(parsed.TargetDirectory)) { _settings.TargetDirectory = parsed.SourceDirectory; } }); if (result.Tag == ParserResultType.NotParsed) { return(-1); } if (!Directory.Exists(_settings.SourceDirectory)) { throw new IOException($"Source directory `{_settings.SourceDirectory}` does not exist!"); } if (_settings.ExportResources) { try { if (_settings.ExportFromDatabase) { SetConnectionString(); } Console.WriteLine("Starting export..."); var extractor = new ResourceExtractor(); var resources = extractor.Extract(_settings); string generatedScript; if (_settings.Json) { var serializer = new JsonResourceExporter(); generatedScript = serializer.Export(resources).SerializedData; } else { var scriptGenerator = new SqlScriptGenerator(); generatedScript = scriptGenerator.Generate(resources, _settings.ScriptUpdate); } var scriptFileWriter = new ResultFileWriter(); var outputFile = scriptFileWriter.Write(generatedScript, _settings.TargetDirectory, _settings.Json); Console.WriteLine($"Output file: {outputFile}"); Console.WriteLine("Export completed!"); } catch (Exception e) { Console.WriteLine($"Error running tool: {e.Message}"); return(-1); } } if (_settings.ImportResources) { Console.WriteLine("Starting import..."); SetConnectionString(); var importer = new ResourceImporter(); importer.Import(_settings); Console.WriteLine("Import completed!"); } if (!_settings.ExportResources && !_settings.ImportResources) { Console.WriteLine("No command specified. Please make up your mind, either you want to export or import resources."); Console.WriteLine("Try 'DbLocalizationProvider.MigrationTool.exe --help' for more information."); } if (Debugger.IsAttached) { Console.ReadLine(); } return(0); }