internal static void Register(CommandLineApplication app, Func <ILogger> getLogger) { app.Command("remove", RemoveCmd => { RemoveCmd.Command("source", SourceCmd => { CommandArgument name = SourceCmd.Argument( "name", Strings.SourcesCommandNameDescription); CommandOption configfile = SourceCmd.Option( "--configfile", Strings.Option_ConfigFile, CommandOptionType.SingleValue); SourceCmd.HelpOption("-h|--help"); SourceCmd.Description = Strings.RemoveSourceCommandDescription; SourceCmd.OnExecute(() => { var args = new RemoveSourceArgs() { Name = name.Value, Configfile = configfile.Value(), }; RemoveSourceRunner.Run(args, getLogger); return(0); }); }); RemoveCmd.Command("client-cert", ClientCertCmd => { CommandOption packagesource = ClientCertCmd.Option( "-s|--package-source", Strings.Option_PackageSource, CommandOptionType.SingleValue); CommandOption configfile = ClientCertCmd.Option( "--configfile", Strings.Option_ConfigFile, CommandOptionType.SingleValue); ClientCertCmd.HelpOption("-h|--help"); ClientCertCmd.Description = Strings.RemoveClientCertCommandDescription; ClientCertCmd.OnExecute(() => { var args = new RemoveClientCertArgs() { PackageSource = packagesource.Value(), Configfile = configfile.Value(), }; RemoveClientCertRunner.Run(args, getLogger); return(0); }); }); RemoveCmd.HelpOption("-h|--help"); RemoveCmd.Description = Strings.Remove_Description; RemoveCmd.OnExecute(() => { app.ShowHelp("remove"); return(0); }); }); }
int CopyServerTables(string sourceTable, string targetTable) { int copyTableCount = 0, copyTableTotal = 0, copied = 0, copyRecordCount = SourceCmd.TableCount(sourceTable); int deleted = targetCmd.ModifyTable("DELETE " + targetTable); for (copyLoop = 0; copyLoop < 100 && !Abort && !SQLHandler.HasErrors && copyTableCount >= 0 && (copied += copyTableCount) < copyRecordCount;) { int targetCount = targetCmd.TableCount(targetTable); Status(string.Format("SP Copying {0,8:n0} Records to {1} {2}", copyRecordCount, targetTable, ++copyLoop > 1 ? string.Format("(Pass {0} - {1:n0} Remaining)", copyLoop, copyRecordCount - targetCount) : "")); if (copyLoop > 1) { copied = targetCount; // A timeout must have occurred. Sync up copied total to actual... } SQLHandler.Clear(); CopyServerTables(targetTable, ref copyTableCount, ref copyTableTotal); if (SQLHandler.HasErrors) { Memo("Error", string.Format("Copy {0}Table: {1, 7} Records to {2} WERE NOT COPIED. See errors below -\r\n\r\n{3}", copyModifier, "ERROR", targetTable, SQLHandler.Errors)); } } Status(""); return(copyTableCount < 0 ? copyTableCount : copyTableTotal); }
bool CopyTable(string sourceTable, string targetTable, string modifier) { bool copyBySchema = false, okay = false; copyModifier = modifier; if (!SourceCmd.TableExists(sourceTable)) { Memo("Error", string.Format("Copy {0}Tables: {1,7} Source table not found - {2}", modifier, "Error", sourceTable)); } else if (!TargetCmd.TableExists(targetTable) && !(copyBySchema = CreateTargetTableSchema(sourceTable, targetTable))) { Memo("Error", string.Format("Copy {0}Tables: {1,7} Unable to create missing target table '{2}'{3}", modifier, "ERROR", targetTable, !SQLHandler.HasErrors ? "" : string.Format(". See errors below\r\n{0}", SQLHandler.Errors))); } else if (sourceObject.ServerID == targetObject.ServerID) { int count = CopyServerTables(sourceTable, targetTable); if (okay = count >= 0) { Memo("Memo", string.Format("Copy {0}Tables: {1, 7:n0} Records {2} {3}", modifier, count, targetTable, copyBySchema ? "- Created by Schema" : "")); } else { Memo("Error", string.Format("Copy {0}Tables: {1, 7} UNABLE TO COPY records to [{2}].{3}", modifier, "ERROR", targetObject.ServerID, targetTable)); } } else { int sourceCount = 0, targetCount = 0; CopySourceToTargetTable(sourceTable, targetTable, ref sourceCount, ref targetCount); if (okay = (sourceCount == targetCount)) { Memo("Memo", string.Format("Copy {0}Tables: {1, 7:n0} Records {2} {3}", modifier, sourceCount, targetTable, copyBySchema ? "- Created by Schema" : "")); } else { Memo("Error", string.Format("Copy {0}Tables: {1, 7} {2} of {3} Records Copied To [{4}].{5} {6}{7}", modifier, "ERROR", targetCount == 0 ? "None" : "Only " + targetCount.ToString("N0"), sourceCount, targetObject.ServerID, targetTable, copyBySchema ? "- Created by Schema" : "", !SQLHandler.HasErrors ? "" : " See errors below -\r\n\r\n" + SQLHandler.Errors)); } } return(okay); }
internal static void Register(CommandLineApplication app, Func <ILogger> getLogger) { app.Command("list", ListCmd => { ListCmd.Command("source", SourceCmd => { CommandOption format = SourceCmd.Option( "--format", Strings.SourcesCommandFormatDescription, CommandOptionType.SingleValue); CommandOption configfile = SourceCmd.Option( "--configfile", Strings.Option_ConfigFile, CommandOptionType.SingleValue); SourceCmd.HelpOption("-h|--help"); SourceCmd.Description = Strings.ListSourceCommandDescription; SourceCmd.OnExecute(() => { var args = new ListSourceArgs() { Format = format.Value(), Configfile = configfile.Value(), }; ListSourceRunner.Run(args, getLogger); return(0); }); }); ListCmd.Command("client-cert", ClientCertCmd => { CommandOption configfile = ClientCertCmd.Option( "--configfile", Strings.Option_ConfigFile, CommandOptionType.SingleValue); ClientCertCmd.HelpOption("-h|--help"); ClientCertCmd.Description = Strings.ListClientCertCommandDescription; ClientCertCmd.OnExecute(() => { var args = new ListClientCertArgs() { Configfile = configfile.Value(), }; ListClientCertRunner.Run(args, getLogger); return(0); }); }); ListCmd.HelpOption("-h|--help"); ListCmd.Description = Strings.List_Description; ListCmd.OnExecute(() => { app.ShowHelp("list"); return(0); }); }); }
internal static void Register(CommandLineApplication app, Func <ILogger> getLogger) { app.Command("disable", DisableCmd => { DisableCmd.Command("source", SourceCmd => { CommandArgument name = SourceCmd.Argument( "name", Strings.SourcesCommandNameDescription); CommandOption configfile = SourceCmd.Option( "--configfile", Strings.Option_ConfigFile, CommandOptionType.SingleValue); SourceCmd.HelpOption("-h|--help"); SourceCmd.Description = Strings.DisableSourceCommandDescription; SourceCmd.OnExecute(() => { var args = new DisableSourceArgs() { Name = name.Value, Configfile = configfile.Value(), }; DisableSourceRunner.Run(args, getLogger); return(0); }); }); DisableCmd.HelpOption("-h|--help"); DisableCmd.Description = Strings.Disable_Description; DisableCmd.OnExecute(() => { app.ShowHelp("disable"); return(0); }); }); }
internal static void Register(CommandLineApplication app, Func <ILogger> getLogger) { app.Command("update", UpdateCmd => { UpdateCmd.Command("source", SourceCmd => { CommandArgument name = SourceCmd.Argument( "name", Strings.SourcesCommandNameDescription); CommandOption source = SourceCmd.Option( "-s|--source", Strings.SourcesCommandSourceDescription, CommandOptionType.SingleValue); CommandOption username = SourceCmd.Option( "-u|--username", Strings.SourcesCommandUserNameDescription, CommandOptionType.SingleValue); CommandOption password = SourceCmd.Option( "-p|--password", Strings.SourcesCommandPasswordDescription, CommandOptionType.SingleValue); CommandOption storePasswordInClearText = SourceCmd.Option( "--store-password-in-clear-text", Strings.SourcesCommandStorePasswordInClearTextDescription, CommandOptionType.NoValue); CommandOption validAuthenticationTypes = SourceCmd.Option( "--valid-authentication-types", Strings.SourcesCommandValidAuthenticationTypesDescription, CommandOptionType.SingleValue); CommandOption configfile = SourceCmd.Option( "--configfile", Strings.Option_ConfigFile, CommandOptionType.SingleValue); SourceCmd.HelpOption("-h|--help"); SourceCmd.Description = Strings.UpdateSourceCommandDescription; SourceCmd.OnExecute(() => { var args = new UpdateSourceArgs() { Name = name.Value, Source = source.Value(), Username = username.Value(), Password = password.Value(), StorePasswordInClearText = storePasswordInClearText.HasValue(), ValidAuthenticationTypes = validAuthenticationTypes.Value(), Configfile = configfile.Value(), }; UpdateSourceRunner.Run(args, getLogger); return(0); }); }); UpdateCmd.HelpOption("-h|--help"); UpdateCmd.Description = Strings.Update_Description; UpdateCmd.OnExecute(() => { app.ShowHelp("update"); return(0); }); }); }
internal static void Register(CommandLineApplication app, Func <ILogger> getLogger) { app.Command("update", UpdateCmd => { UpdateCmd.Command("source", SourceCmd => { CommandArgument name = SourceCmd.Argument( "name", Strings.SourcesCommandNameDescription); CommandOption source = SourceCmd.Option( "-s|--source", Strings.SourcesCommandSourceDescription, CommandOptionType.SingleValue); CommandOption username = SourceCmd.Option( "-u|--username", Strings.SourcesCommandUsernameDescription, CommandOptionType.SingleValue); CommandOption password = SourceCmd.Option( "-p|--password", Strings.SourcesCommandPasswordDescription, CommandOptionType.SingleValue); CommandOption storePasswordInClearText = SourceCmd.Option( "--store-password-in-clear-text", Strings.SourcesCommandStorePasswordInClearTextDescription, CommandOptionType.NoValue); CommandOption validAuthenticationTypes = SourceCmd.Option( "--valid-authentication-types", Strings.SourcesCommandValidAuthenticationTypesDescription, CommandOptionType.SingleValue); CommandOption configfile = SourceCmd.Option( "--configfile", Strings.Option_ConfigFile, CommandOptionType.SingleValue); SourceCmd.HelpOption("-h|--help"); SourceCmd.Description = Strings.UpdateSourceCommandDescription; SourceCmd.OnExecute(() => { var args = new UpdateSourceArgs() { Name = name.Value, Source = source.Value(), Username = username.Value(), Password = password.Value(), StorePasswordInClearText = storePasswordInClearText.HasValue(), ValidAuthenticationTypes = validAuthenticationTypes.Value(), Configfile = configfile.Value(), }; UpdateSourceRunner.Run(args, getLogger); return(0); }); }); UpdateCmd.Command("client-cert", ClientCertCmd => { CommandOption packagesource = ClientCertCmd.Option( "-s|--package-source", Strings.Option_PackageSource, CommandOptionType.SingleValue); CommandOption path = ClientCertCmd.Option( "--path", Strings.Option_Path, CommandOptionType.SingleValue); CommandOption password = ClientCertCmd.Option( "--password", Strings.Option_Password, CommandOptionType.SingleValue); CommandOption storepasswordincleartext = ClientCertCmd.Option( "--store-password-in-clear-text", Strings.Option_StorePasswordInClearText, CommandOptionType.NoValue); CommandOption storelocation = ClientCertCmd.Option( "--store-location", Strings.Option_StoreLocation, CommandOptionType.SingleValue); CommandOption storename = ClientCertCmd.Option( "--store-name", Strings.Option_StoreName, CommandOptionType.SingleValue); CommandOption findby = ClientCertCmd.Option( "--find-by", Strings.Option_FindBy, CommandOptionType.SingleValue); CommandOption findvalue = ClientCertCmd.Option( "--find-value", Strings.Option_FindValue, CommandOptionType.SingleValue); CommandOption force = ClientCertCmd.Option( "-f|--force", Strings.Option_Force, CommandOptionType.NoValue); CommandOption configfile = ClientCertCmd.Option( "--configfile", Strings.Option_ConfigFile, CommandOptionType.SingleValue); ClientCertCmd.HelpOption("-h|--help"); ClientCertCmd.Description = Strings.UpdateClientCertCommandDescription; ClientCertCmd.OnExecute(() => { var args = new UpdateClientCertArgs() { PackageSource = packagesource.Value(), Path = path.Value(), Password = password.Value(), StorePasswordInClearText = storepasswordincleartext.HasValue(), StoreLocation = storelocation.Value(), StoreName = storename.Value(), FindBy = findby.Value(), FindValue = findvalue.Value(), Force = force.HasValue(), Configfile = configfile.Value(), }; UpdateClientCertRunner.Run(args, getLogger); return(0); }); }); UpdateCmd.HelpOption("-h|--help"); UpdateCmd.Description = Strings.Update_Description; UpdateCmd.OnExecute(() => { app.ShowHelp("update"); return(0); }); }); }
internal static void Register(CommandLineApplication app, Func <ILogger> getLogger) { app.Command("add", AddCmd => { AddCmd.Command("source", SourceCmd => { var Source = SourceCmd.Argument( "PackageSourcePath", Strings.SourcesCommandSourceDescription); var name = SourceCmd.Option( "-n|--name", Strings.SourcesCommandNameDescription, CommandOptionType.SingleValue); var username = SourceCmd.Option( "-u|--username", Strings.SourcesCommandUserNameDescription, CommandOptionType.SingleValue); var password = SourceCmd.Option( "-p|--password", Strings.SourcesCommandPasswordDescription, CommandOptionType.SingleValue); var storePasswordInClearText = SourceCmd.Option( "--store-password-in-clear-text", Strings.SourcesCommandStorePasswordInClearTextDescription, CommandOptionType.NoValue); var validAuthenticationTypes = SourceCmd.Option( "--valid-authentication-types", Strings.SourcesCommandValidAuthenticationTypesDescription, CommandOptionType.SingleValue); var configfile = SourceCmd.Option( "--configfile", Strings.Option_ConfigFile, CommandOptionType.SingleValue); SourceCmd.HelpOption("-h|--help"); SourceCmd.Description = Strings.AddSourceCommandDescription; SourceCmd.OnExecute(() => { var args = new AddSourceArgs() { Source = Source.Value, Name = name.Value(), Username = username.Value(), Password = password.Value(), StorePasswordInClearText = storePasswordInClearText.HasValue(), ValidAuthenticationTypes = validAuthenticationTypes.Value(), Configfile = configfile.Value(), }; AddSourceRunner.Run(args, getLogger); return(0); }); }); AddCmd.HelpOption("-h|--help"); AddCmd.Description = Strings.Add_Description; AddCmd.OnExecute(() => { app.ShowHelp("add"); return(0); }); }); }
void CopySourceToTargetTable(string sourceTable, string targetTable, ref int sourceCount, ref int targetCount) { bool hasTargetTable = TargetCmd.TableExists(targetTable); int ix = targetTable.IndexOf('.') + 1, loop = 0; string targetUserTable = targetObject.SchemaTable, // targetTable.Substring(ix), txt = ""; Abort = false; targetCount = 0; int copySourceCount = sourceCount = SourceCmd.TableCount(sourceTable); Status(string.Format("Retrieving {0:n0} Records", sourceCount)); do { if (!SourceCmd.OpenReader("SELECT * FROM " + sourceTable)) { break; } // // Replenish count if first pass generates 'IDENTITY_INSERT' errors // if (SQLHandler.TryAgain && loop++ == 0) { copySourceCount = sourceCount; targetCount = 0; SQLHandler.TryAgain = false; } try { string insertColumnNames = sourceCmd.ReaderInsertColumnNames, identityInsertOn = SQLHandler.Identity && sourceCmd.ReaderHasIdentity && hasTargetTable ? "SET IDENTITY_INSERT " + targetUserTable + " ON " : "", identityInsertOff = SQLHandler.Identity && identityInsertOn.Length > 0 ? "SET IDENTITY_INSERT " + targetUserTable + " OFF " : ""; if (hasTargetTable) { targetCmd.ModifyTable("DELETE " + targetUserTable); } Status("Copying " + sourceTable + (identityInsertOn.Length > 0 ? "(*)" : "") + " - " + copySourceCount.ToString("D0")); StringBuilder cmd = new StringBuilder(); while (!Abort && copySourceCount > 0 && // Avoids duplicate key errors !sourceCmd.ReaderEnd) { cmd.Length = 0;; while (cmd.Length < 8000 && sourceCmd.ReaderRead()) { txt = hasTargetTable ? string.Format("{0} INSERT INTO {1} {2} VALUES {3} {4} \r\n", identityInsertOn, targetUserTable, insertColumnNames, sourceCmd.ReaderInsertColumnValues, identityInsertOff) : string.Format("SELECT {0} INTO {1}\r\n", sourceCmd.ReaderObjectValues, targetUserTable); copySourceCount--; if (cmd.Length + txt.Length < 8000) { cmd.Append(txt); } else { break; } hasTargetTable = true; // If there was not target table, the first 'SELECT...' will have created it! txt = ""; } int cnt = cmd.Length > 0 ? targetCmd.ModifyTable(cmd.ToString()) : 0; if (cnt < 0 && txt.Length == 0) { break; } targetCount += cnt; if (txt.Length > 0) { if ((cnt = targetCmd.ModifyTable(txt)) < 0) { break; } else { targetCount += cnt; } } Status(string.Format("Copying {0,8:n0} Records to {1} - {2:n0} Remaining", sourceCount, targetTable, copySourceCount)); } } //catch(Exception e) //{ // VELog.Error("VEDataAdminCopy.CopySourceToTargetTable: Exception - " + e.Message); //} finally { sourceCmd.CloseReader(); Status(""); } }while (SQLHandler.TryAgain && !Abort); //if(sourceCount != targetCount) // VELog.Exception("VEDataAdmin.CopySourceToTarget: ", // new Exception(string.Format("## {0} Copying Table: {1} of {2} Records Were Copied - copySourceCount = {3}; SQLTryAgain = {4}", // "ERROR", // targetCount == 0 ? "None" : "Only " + targetCount.ToString("N0"), // sourceCount, copySourceCount, SQLTryAgain))); }