Exemple #1
0
        public void Execute(SeedArgs args)
        {
            var providerFactory = DbProviderFactories.GetFactory(args.Provider);

            var inputData = JObject.Parse(File.ReadAllText(args.InputFile));

            using (this.connection = providerFactory.CreateConnection())
            {
                this.connection.ConnectionString = args.ConnectionString;
                this.connection.Open();

                this.sql = new SqlHelper(this.connection);

                foreach (var table in inputData.Properties())
                {
                    SeedTable(table);
                }
            }
        }
Exemple #2
0
        public void Execute(DumpArgs args)
        {
            var providerFactory = DbProviderFactories.GetFactory(args.Provider);

            using (this.connection = providerFactory.CreateConnection())
            {
                this.connection.ConnectionString = args.ConnectionString;
                this.connection.Open();

                Log.Info("Dumping table {0}", args.TableName);

                this.sql = new SqlHelper(this.connection);

                this.tableOps = this.sql.GetTableOperations(args.TableName);

                var records = this.tableOps.GetRecords(args.Condition, args.Columns ?? new string[0]).ToList();

                JObject outputFile;
                JArray result;

                if (args.Append && File.Exists(args.OutputFile))
                {
                    outputFile = JObject.Parse(File.ReadAllText(args.OutputFile));

                    var temp = outputFile.Property(args.TableName);

                    if (temp == null)
                    {
                        result = new JArray();

                        outputFile.Add(new JProperty(args.TableName, result));
                    }
                    else
                    {
                        result = (JArray) temp.Value;
                    }
                }
                else
                {
                    outputFile =  new JObject();
                    result = new JArray();

                    outputFile.Add(args.TableName, result);
                }

                foreach (var record in records)
                {
                    JObject outputEntry;

                    outputEntry = new JObject();

                    foreach (var property in record)
                    {
                        outputEntry.Add(property.Key, new JValue(property.Value));
                    }

                    Merge(result, outputEntry);
                }

                File.WriteAllText(args.OutputFile, outputFile.ToString());
            }
        }