Generate() public method

public Generate ( ICollection resources, bool scriptUpdate = false ) : string
resources ICollection
scriptUpdate bool
return string
コード例 #1
0
        private static void ExportResources()
        {
            if (_settings.ExportFromDatabase)
            {
                SetConnectionString();
            }

            Console.WriteLine("Starting export...");
            var    extractor = new ResourceExporter();
            var    resources = extractor.Export(_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!");
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            _settings = ParseArguments(args);

            if (_settings.ShowHelp)
            {
                ShowHelp(_settings.OptionSet);
                return;
            }

            if (string.IsNullOrEmpty(_settings.SourceDirectory))
            {
                Console.WriteLine("ERROR: Source directory parameter is missing!");
                Console.WriteLine();
                ShowHelp(_settings.OptionSet);
                return;
            }

            if (!Directory.Exists(_settings.SourceDirectory))
            {
                throw new IOException($"Source directory `{_settings.SourceDirectory}` does not exist!");
            }

            if (!File.Exists(Path.Combine(_settings.SourceDirectory, "web.config")))
            {
                throw new IOException($"File `web.config` file not found in `{_settings.SourceDirectory}`!");
            }

            Directory.SetCurrentDirectory(_settings.SourceDirectory);
            ReadConnectionString(_settings);
            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(_settings.SourceDirectory, "App_Data"));

            if (_settings.ExportResources)
            {
                try
                {
                    Console.WriteLine("Export started.");
                    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;
                }
            }

            if (_settings.ImportResources)
            {
                Console.WriteLine("Import started!");

                var importer = new ResourceImporter();
                importer.Import(_settings);

                Console.WriteLine("Import completed!");
            }

            if (!_settings.ExportResources && !_settings.ImportResources)
            {
                Console.WriteLine("No command specified.");
                Console.WriteLine("Try 'DbLocalizationProvider.MigrationTool.exe --help' for more information.");
            }

            if (Debugger.IsAttached)
            {
                Console.ReadLine();
            }
        }
コード例 #3
0
        public static void Main(string[] args)
        {
            _settings = ParseArguments(args);

            if (_settings.ShowHelp)
            {
                ShowHelp(_settings.OptionSet);
                return;
            }

            if (string.IsNullOrEmpty(_settings.SourceDirectory))
            {
                Console.WriteLine("ERROR: Source directory parameter is missing!");
                Console.WriteLine();
                ShowHelp(_settings.OptionSet);
                return;
            }

            if (!Directory.Exists(_settings.SourceDirectory))
            {
                throw new IOException($"Source directory {_settings.SourceDirectory} does not exist!");
            }

            Directory.SetCurrentDirectory(_settings.SourceDirectory);
            ReadConnectionString(_settings);
            AppDomain.CurrentDomain.SetData("DataDirectory", Path.Combine(_settings.SourceDirectory, "App_Data"));

            if (_settings.ExportResources)
            {
                try
                {
                    Console.WriteLine("Export started.");
                    var extractor = new ResourceExtractor();
                    var resources = extractor.Extract(_settings);
                    string generatedScript;

                    if (_settings.Json)
                    {
                        var serializer = new JsonDataSerializer();
                        generatedScript = serializer.Serialize(resources);
                    }
                    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;
                }
            }

            if (_settings.ImportResources)
            {
                Console.WriteLine("Import started!");

                var importer = new ResourceImporter();
                importer.Import(_settings);

                Console.WriteLine("Import completed!");
            }

            if (!_settings.ExportResources && !_settings.ImportResources)
            {
                Console.WriteLine("No command specified.");
                Console.WriteLine("Try 'DbLocalizationProvider.MigrationTool.exe --help' for more information.");
            }

            if (Debugger.IsAttached)
            {
                Console.ReadLine();
            }
        }
コード例 #4
0
        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);
        }