public override void WriteUsage() { Console.WriteLine(this.Name + ": " + base.Description); Console.WriteLine(string.Empty); Console.WriteLine(CommandResources.GetString(CommandResources.ResourceID.Label_Usage)); Console.WriteLine(" " + CommandResources.GetString(CommandResources.ResourceID.ProgramUsage)); Console.WriteLine(string.Empty); NameValueCollection nameValueArgs = new NameValueCollection(); List <Command> list = new List <Command>(); list.Add(new DeployCommand(nameValueArgs)); StringBuilder builder = new StringBuilder(); string str4 = CommandResources.GetString(CommandResources.ResourceID.Label_Commands); builder.Append(str4); foreach (Command command in list) { builder.Append(Environment.NewLine); builder.Append(command.GetSummary()); } Console.WriteLine(builder.ToString()); Console.WriteLine(string.Empty); Console.WriteLine(this.Example); Console.WriteLine(string.Empty); Console.WriteLine(ConsoleHelper.Wrap(this.Notes, 2, Console.BufferWidth, -2)); Console.WriteLine(string.Empty); }
public static void ValidateDatabase(string database) { Regex regex = new Regex(@"^[a-zA-Z]([a-zA-Z]|[0-9]|[!@#\$%\^&'\)\(\.\-_\{\}~\.]){0,62}$"); if (!regex.Match(database).Success) { throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.DatabaseInvalid, new object[] { database }), "Database", System.Diagnostics.TraceLevel.Error); } }
public static void ValidateEncryptionKey(NameValueCollection nameValueArgs) { if (nameValueArgs["CompanyName"] != null) { nameValueArgs.Set("CompanyName", nameValueArgs["CompanyName"].Trim()); } if ((nameValueArgs["CompanyName"] == null) || (nameValueArgs["CompanyName"].Length == 0)) { throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.CompanyNameNotSpecified, new object[] { }), "CompanyName", System.Diagnostics.TraceLevel.Error); } }
public static void ValidateServer(string server) { IPAddress address; if (!IPAddress.TryParse(server, out address)) { Regex regex = new Regex(@"^((np|tcp|spx|adsp|rpc|vines):)?([a-zA-Z]|[0-9]|[!@#\$%\^&'\)\(\.\-_\{\}~\.\\]){0,256}((,[0-9]{1,5})|(,(ncacn_np|ncacn_ip_tcp|ncacn_nb_nb|ncacn_spx|ncacn_vns_spp|ncadg_ip_udp|ncadg_ipx|ncalrpc)))?(\\([a-zA-Z]|[0-9]|[!@#\$%\^&'\)\(\.\-_\{\}~\.\\]){0,256})?$"); if (!regex.Match(server).Success) { throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.ServerInvalid, new object[] { server }), "Server", System.Diagnostics.TraceLevel.Error); } } }
public static void ValidateTimeout(NameValueCollection nameValueArgs) { int timeout; if (nameValueArgs["Timeout"] != null) { nameValueArgs.Set("Timeout", nameValueArgs["Timeout"].Trim()); } if ((nameValueArgs["Timeout"] != null) && (!int.TryParse(nameValueArgs["Timeout"], out timeout))) { throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.TimeoutInvalid, new object[] { }), "Timeout", System.Diagnostics.TraceLevel.Error); } }
protected override CommandLineArgDescriptorList GetParameterDescriptors() { CommandLineArgDescriptor[] collection = new CommandLineArgDescriptor[] { new CommandLineArgDescriptor(true, "NonEncryptedFile", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_NonEncryptedFile), CommandLineArgDescriptor.ArgumentType.String), new CommandLineArgDescriptor(true, "CompanyName", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_CompanyName), CommandLineArgDescriptor.ArgumentType.String), new CommandLineArgDescriptor(true, "Server", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_Server), CommandLineArgDescriptor.ArgumentType.String), new CommandLineArgDescriptor(true, "Database", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_Database), CommandLineArgDescriptor.ArgumentType.String), new CommandLineArgDescriptor(true, "Timeout", CommandResources.GetString(CommandResources.ResourceID.ParamDesc_Timeout), CommandLineArgDescriptor.ArgumentType.String) }; CommandLineArgDescriptorList list = new CommandLineArgDescriptorList(); list.AddRange(collection); return(list); }
public static void ValidateEncryptedFile(NameValueCollection nameValueArgs) { if ((nameValueArgs["NonEncryptedFile"] != null) && (nameValueArgs["NonEncryptedFile"].Length > 0)) { System.IO.FileInfo fi = new System.IO.FileInfo(nameValueArgs["NonEncryptedFile"]); if (!fi.Exists) { throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.NonEncryptedFileNotFound, new object[] { fi.FullName }), "NonEncryptedFile", System.Diagnostics.TraceLevel.Error); } } else { throw new CommandLineArgumentException(CommandResources.GetString(CommandResources.ResourceID.NonEncryptedFileNotSpecified), "NonEncryptedFile", System.Diagnostics.TraceLevel.Error); } }
public static void ValidateServerDatabase(NameValueCollection nameValueArgs) { Trace.WriteLine("Validating Server and Database parameters..."); if ((nameValueArgs["Server"] != null) && (nameValueArgs["Server"].Length > 0)) { if ((nameValueArgs["Database"] == null) || (nameValueArgs["Database"].Length == 0)) { throw new CommandLineArgumentException(CommandResources.GetString(CommandResources.ResourceID.DatabaseNotSpecified), "Database", System.Diagnostics.TraceLevel.Error); } } else { bizilante.SSO.Helper.SSO sso = new bizilante.SSO.Helper.SSO(); sso.GetSecretServerName(); nameValueArgs.Set("Server", sso.DBServer); if ((nameValueArgs["Database"] == null) || (nameValueArgs["Database"].Length == 0)) { nameValueArgs.Set("Database", sso.DB); } } ValidateServer(nameValueArgs["Server"]); ValidateDatabase(nameValueArgs["Database"]); }
public override void Execute() { try { string[] values = base.Args.GetValues((string)null); if ((values != null) && (values.Length > 0)) { string str = values[0]; throw new CommandLineArgumentException(CommandResources.GetFormattedString(CommandResources.ResourceID.UnknownCommand, new object[] { str }), null, TraceLevel.Error); } this.WriteUsage(); base.commandResult = new CommandResult(); } catch (Exception exception) { Trace.WriteLine(exception.ToString()); base.WriteLogEntry(LogEntryType.Error, exception.Message); base.commandResult = new CommandResult(exception); if ((exception is OutOfMemoryException) || (exception is StackOverflowException)) { throw; } } }
public override void WriteUsageHint() { Console.WriteLine(CommandResources.GetFormattedString(CommandResources.ResourceID.ProgramUsageHint, new object[] { this.Name })); }
public override void Execute() { try { this.Validate(); string key = base.Args["CompanyName"]; string file = base.Args["NonEncryptedFile"]; string timeout = base.Args["Timeout"]; string formattedString = CommandResources.GetFormattedString(CommandResources.ResourceID.Deploy, new object[] { key, file }); base.WriteLogEntry(LogEntryType.Information, formattedString); // We need to show the identity used to deploy to SSO System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent(); if (null != identity) { WriteLogEntry(LogEntryType.Verbose, string.Format("Current WindowsIdentity: AuthenticationType:{0} - IsAuthenticated:{1} - Name:{2}", identity.AuthenticationType, identity.IsAuthenticated, identity.Name)); using (System.Security.Principal.WindowsImpersonationContext context = identity.Impersonate()) { identity = System.Security.Principal.WindowsIdentity.GetCurrent(); if (null != identity) { WriteLogEntry(LogEntryType.Verbose, string.Format("Impersonated WindowsIdentity: AuthenticationType:{0} - IsAuthenticated:{1} - Name:{2}", identity.AuthenticationType, identity.IsAuthenticated, identity.Name)); } // Deploy the non encrypted SSO XML file. //System.Diagnostics.Debugger.Launch(); string title; DeploySSO deploy = new DeploySSO() { NonEncryptedFile = file, CompanyName = key }; deploy.Overwrite = true; // We always overwrite the current SSO application settings deploy.Log += new DeploySSO.LogHandler(deploy_Log); deploy.Execute(out title); formattedString = CommandResources.GetFormattedString(CommandResources.ResourceID.DeploySuccess, new object[] { title }); base.WriteLogEntry(LogEntryType.Information, formattedString); } } identity = System.Security.Principal.WindowsIdentity.GetCurrent(); if (null != identity) { WriteLogEntry(LogEntryType.Verbose, string.Format("After impersonation WindowsIdentity: AuthenticationType:{0} - IsAuthenticated:{1} - Name:{2}", identity.AuthenticationType, identity.IsAuthenticated, identity.Name)); } base.commandResult = new CommandResult(); } catch (Exception exception2) { base.ShowError(exception2); base.commandResult = new CommandResult(exception2); if ((exception2 is OutOfMemoryException) || (exception2 is StackOverflowException)) { throw; } } }