/// <summary> /// Exports the specified script info. /// </summary> /// <param name="scriptInfo">The script info.</param> /// <returns></returns> public FileInfo[] Export(ScriptInfoCollection scriptInfo) { List<FileInfo> files = new List<FileInfo>(); scriptInfo = ParseCollection(scriptInfo); foreach (ScriptInfo info in scriptInfo) { if (info.ScriptMode == ScriptMode.NotSet) { info.ScriptMode = sqlConfiguration.DefaultScriptMode; } using (IHarvester harvester = CreateHarvestor(info)) { FileInfo file = harvester.WriteHeader(); Trace.WriteLineIf(Tracer.Trace.TraceInfo, string.Format(" * {0}", file.Name)); if (harvester.WriteContent()) { harvester.WriteFooter(); files.Add(file); } else { // no content, abort file Trace.WriteLineIf( Tracer.Trace.TraceVerbose, string.Format("Abort table {0} as no content", info.Name)); harvester.Cancel(); } } } return files.ToArray(); }
private ScriptInfoCollection ParseCollection(ScriptInfoCollection config) { if (config.Contains("*")) { using ( IDbCommand cmd = database.CreateCommand( "Select Object_Name(object_id) as TableName From sys.objects Where type='U'")) { cmd.CommandType = CommandType.Text; using (IDataReader reader = database.ExecuteReader(cmd)) { ScriptInfoCollection collection = new ScriptInfoCollection(); while (reader.Read()) { collection.Add( new ScriptInfo((string)reader["TableName"], string.Empty, config["*"].ScriptMode)); } return collection; } } } else { return config; } }