private string GetPassword(CommandLineParser parser, WorkingDirectory workingDir) { string pwd = null; if (null != parser && null != parser.Password && parser.Password.Length != 0) { pwd = parser.Password; } else { LoginCommand loginCommand = new LoginCommand(workingDir.CvsRoot); loginCommand.Execute(); pwd = loginCommand.Password; } if (null == pwd) { pwd = String.Empty; } return pwd; }
private void DoExecute() { string[] args = this._args; CommandLineParser parser = new CommandLineParser (args); ICommand command = null; try { command = parser.Execute (); } catch (CommandLineParseException e) { Writer.WriteLine( String.Format("{0}{1}{2}", Usage.General, Environment.NewLine, e.Message)); return; } catch (Exception e) { ExitProgram("Exception parsing command.", e); } if (null != command) { // might need to move this up to the library, make working // directory a public property?? Not sure. WorkingDirectory workingDirectory = parser.CurrentWorkingDirectory; string password = this.GetPassword(parser, workingDirectory); // Create CVSServerConnection object that has the ICommandConnection CVSServerConnection serverConn = new CVSServerConnection(workingDirectory); if (parser.Verbose) { serverConn.RequestMessageEvent += new MessageEventHandler(Writer.WriteLine); serverConn.ResponseMessageEvent += new MessageEventHandler(Writer.WriteLine); } serverConn.StartProcessEvent += new ProcessEventHandler(Writer.StartProcess); serverConn.StopProcessEvent += new ProcessEventHandler(Writer.StopProcess); serverConn.ResponseMessageEvents.UpdatedResponseMessageEvent += new MessageEventHandler(Writer.WriteLine); serverConn.ResponseMessageEvents.ClearStaticDirectoryResponseMessageEvent += new MessageEventHandler(Writer.WriteLine); serverConn.ResponseMessageEvents.SetStaticDirectoryResponseMessageEvent += new MessageEventHandler(Writer.WriteLine); serverConn.ResponseMessageEvents.ErrorResponseMessageEvent += new MessageEventHandler(Writer.WriteError); serverConn.ResponseMessageEvents.ListResponseMessageEvent += new MessageEventHandler(Writer.WriteLine); if (null == serverConn) { string msg = "Unable to connect to server."; ExitProgram(msg); } try{ // try connecting with empty password for anonymous users serverConn.Connect(workingDirectory, password); } catch (AuthenticationException e){ string msg = String.Format("Fatal error, aborting. cvs [login aborted]: {0}: unknown user or bad password.", workingDirectory.CvsRoot.User); ExitProgram(msg, e); } catch (Exception ex) { string msg = String.Format("Fatal cvs error ( {0} ).", ex.Message); ExitProgram(msg, ex); } // Execute the command on cvs repository. command.Execute(serverConn); serverConn.Close(); } }