コード例 #1
0
        public void Generate(GenerateCommand cmd)
        {
            WriteLine("// <auto-generated />");
            WriteLine("// This file was automatically generated by the PetePocoGenerator");
            WriteLine("// ");
            WriteLine("// The following connection settings were used to generate this file");
            WriteLine("// ");
            WriteLine("//     Connection String: `{0}`", Helpers.zap_password(cmd.ConnectionString));
            WriteLine("//     Provider:               `{0}`", cmd.ProviderName);
            WriteLine("");

            var context = new GenerateContext
            {
                Command = cmd
            };

            var tables = LoadTables(context);

            ApplyTableConfigurations(context, tables);

            WriteFileStarting(context);
            //WriteRecoredClass(context);
            WriteTables(context, tables);

            WriteFileEnding();
        }
コード例 #2
0
        private static void RunWithOptions(ProgramOptions opts)
        {
            GenerateCommand generateCommand = null;

            if (!string.IsNullOrWhiteSpace(opts.ConfigFile))
            {
                var configFileContent = string.Empty;
                using (var fs = new FileStream(opts.ConfigFile, FileMode.Open))
                {
                    using (var sr = new StreamReader(fs))
                    {
                        configFileContent = sr.ReadToEnd();
                    }
                }

                generateCommand = JsonConvert.DeserializeObject <GenerateCommand>(configFileContent);
            }
            else
            {
                generateCommand = new GenerateCommand
                {
                    ConnectionString     = opts.ConnectionString,
                    ProviderName         = opts.ProviderName,
                    ExplicitColumns      = opts.ExplicitColumns,
                    TrackModifiedColumns = opts.TrackModifiedColumns,
                    Namespace            = opts.Namespace,
                    IgnoreColumns        = opts.IgnoreColumns
                };
            }

            IOutput output = null;

            if (string.Equals("file", opts.Output, StringComparison.InvariantCultureIgnoreCase))
            {
                output = new FileOutput(opts.OutputFile);
            }
            else
            {
                output = new ConsoleOutput();
            }

            using (output)
            {
                var generator = new Generator(output);
                generator.Generate(generateCommand);
            }
        }