/// <summary> /// Does the BCP command. /// </summary> /// <param name="cmd">The CMD.</param> /// <param name="sourceTable">The source table.</param> /// <returns>The log text.</returns> private string DoBcpCommand(CmdHelper cmd, string sourceTable) { string outDataFileFullName = ""; string log = ""; cmd.ClearOutput(); cmd.ExecuteCommand("bcp.exe " + GetCommand(sourceTable, out outDataFileFullName)); if (cmd.StdOutput.Length > 0) { log = "Command Output:\r\n{0}\r\n".FormatWith(cmd.StdOutput.ToString()); } if (cmd.StdErr.Length > 0) { log += "Command Output:\r\n{0}\r\n".FormatWith(cmd.StdErr.ToString()); } if (cmd.LastExitCode == 0) { this.SuccessTableCount++; AsyncCompress(outDataFileFullName); } return(log); }
/// <summary> /// Imports the specified CMD. /// </summary> /// <param name="cmd">The CMD.</param> /// <param name="dfi">The dfi.</param> /// <returns><see cref="CmdHelper"/>'s Last Exit code</returns> public int Import(CmdHelper cmd, DataFileInfo dfi) { ////Process.Start("bcp.exe", GetCommand(tableFullName)); cmd.ExecuteCommand( "{0} ".FormatWith(Settings.Default.DataImporter_BCP_Path) + GetCommand(dfi), Properties.Settings.Default.CommandsUserName, Properties.Settings.Default.CommandsPassword, Properties.Settings.Default.CommandsDomain ); return(cmd.LastExitCode); }
/// <summary> /// Run command directly /// </summary> /// <param name="log">The log.</param> /// <param name="cmd">The CMD.</param> /// <returns>Last exit code</returns> public static int RunCommand(out string log, string cmd, string userName = "", string password = "", string domain = "") { CmdHelper cmdHelper = new CmdHelper(); Log.Info("Trying to start \r\n{0}".FormatWith(cmd)); cmdHelper.ExecuteCommand(cmd, userName, password, domain); log = ""; if (cmdHelper.StdOutput.Length > 0) { log = "Command Output:\r\n{0}\r\n".FormatWith(cmdHelper.StdOutput.ToString()); } if (cmdHelper.StdErr.Length > 0) { log += "Command Output:\r\n{0}\r\n".FormatWith(cmdHelper.StdErr.ToString()); } return(cmdHelper.LastExitCode); }
/// <summary> /// Does the sequence. /// </summary> /// <returns>True if success else false.</returns> public bool DoSequence() { try { CmdHelper cmd = new CmdHelper(); foreach (string sourceTable in this.SourceTableList) { cmd.ExecuteCommand("bcp.exe " + this.GetCommand(sourceTable)); this.SuccessTableCount++; } return(true); } catch (Exception ex) { ExceptionHelper.CentralProcess(ex); return(false); } }
/// <summary> /// Does the BCP command ex. /// </summary> /// <param name="cmd">The CMD.</param> /// <param name="serialNo">The serial no.</param> /// <param name="startRow">The start row.</param> /// <param name="endRow">The end row.</param> /// <param name="tableName">Name of the table.</param> /// <returns>The command text.</returns> private string DoBcpCommandEx(CmdHelper cmd, int serialNo, int startRow, int endRow, string tableName) { string outDataFileFullName = ""; string log = ""; cmd.ClearOutput(); cmd.ExecuteCommand("bcp.exe " + GetCommandEx(serialNo, startRow, endRow, tableName, out outDataFileFullName)); if (cmd.StdOutput.Length > 0) { log = "Command Output:\r\n{0}\r\n".FormatWith(cmd.StdOutput.ToString()); } if (cmd.StdErr.Length > 0) { log += "Command Output:\r\n{0}\r\n".FormatWith(cmd.StdErr.ToString()); } if (cmd.LastExitCode == 0) { AsyncCompress(outDataFileFullName); } return(log); }