Exemple #1
0
        public void MakeConnection_Good()
        {
            LOGGER.Debug("Entering MakeConnection_Good");
            CvsRoot          root    = new CvsRoot(this.Settings.Config.Cvsroot);
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.Settings.Config.LocalPath,
                                     this.Settings.Config.Module);

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection, "Should have a connection object.  WorkingDirectory=[" + working + "]");

            try {
                connection.Connect(working, this.Settings.Config.ValidPassword);
            } catch (Exception e) {
                Assert.Fail(e.ToString() + "; WorkingDirectory=[" + working + "]");
            }
            connection.Close();
        }
Exemple #2
0
        public void MakeConnection_Bad()
        {
            CvsRoot root = new CvsRoot(this.Settings.Config.Cvsroot);

            root.User = "******";
            WorkingDirectory working =
                new WorkingDirectory(root,
                                     this.Settings.Config.LocalPath,
                                     this.Settings.Config.Module);

            CVSServerConnection connection = new CVSServerConnection();

            Assert.IsNotNull(connection, "Should have a connection object.");

            try {
                connection.Connect(working, this.Settings.Config.InvalidPassword);
            } catch (AuthenticationException e) {
                connection.Close();
                throw e;
            }
        }
Exemple #3
0
        public IExternalSource Checkout(string cvsroot, string module, string password, 
            out string target)
        {
            //Set temp checkout dir
            target = System.IO.Path.Combine(Globals.TempDirectory, Guid.NewGuid().ToString());
            Directory.CreateDirectory(target);

            //Setup CVS vars
            CvsRoot root = new CvsRoot(cvsroot);
            WorkingDirectory working = new WorkingDirectory(root, target, module);

            CVSServerConnection connection = new CVSServerConnection();
            if (connection == null)
                throw new ToolExecutionException("Unable to connect to the CVS server");

            //Connect to CVS
            ICSharpCode.SharpCvsLib.Commands.ICommand command =
                new CheckoutModuleCommand(working);
            if (command == null)
                throw new ToolExecutionException("Failure to create a checkout command object");
            try {
                connection.Connect(working, password);
            } catch (AuthenticationException) {
                throw new ToolExecutionException("CVS rejected access (doublecheck all fields): Authentication failure");
            } catch (Exception er) {
                throw new ToolExecutionException("CVS rejected access (doublecheck all fields): " + er.Message);
            }

            //Execute checkout command
            try {
                command.Execute(connection);
                connection.Close();
            } catch (Exception er) {
                throw new ToolExecutionException("CVS error: " + er.Message);
            }

            //Create source from module root
            return CreateSource(Path.Combine(target, module));
        }
        /// <summary>
        /// Process the login command with cvs library API calls.
        /// </summary>
        public void Execute () {
            if (null != this.CvsRoot && this.CvsRoot.TransportProtocol != 
                ICSharpCode.SharpCvsLib.Misc.CvsRoot.ProtocolType.pserver) {
                LOGGER.Debug(string.Format("cvs [login aborted]: The :{0}: protocol does not support the login command",
                    this.CvsRoot.Protocol));
                return;
            }

            CVSServerConnection serverConn = 
                new CVSServerConnection(CurrentWorkingDirectory);
            try {
                serverConn.Connect(CurrentWorkingDirectory, password);
            } catch (ICSharpCode.SharpCvsLib.Exceptions.AuthenticationException) {
                try {
                    this.password = 
                        PServerProtocol.PromptForPassword(this.CvsRoot.ToString());
                    if (this.password == null) {
                        this.password = string.Empty;
                    }
                    Manager manager = new Manager(this.workingDirectory.LocalDirectory);
                    manager.UpdatePassFile(this.password, this.CvsRoot);

                    serverConn.Connect(CurrentWorkingDirectory, password);
                } catch (ICSharpCode.SharpCvsLib.Exceptions.AuthenticationException e) {
                    ConsoleMain.ExitProgram(e.Message);
                }
            }
        }
        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();
            }
        }
        /// <summary>
        /// Produce the report
        /// </summary>
        public LogReport Run(string password)
        {
          // read Root and Repository from local directory
            if (null == this.cvsRoot) {
                Manager manager = new Manager(localDirectory);
                Root root = (Root)manager.FetchSingle (localDirectory,
                    Factory.FileType.Root);
                cvsRoot = new CvsRoot(root.FileContents);
            }
           
            if (null == this.workingDirectory) {
                workingDirectory = new WorkingDirectory(cvsRoot,
                    localDirectory,
                    module);
            }
            
            // Get a connection
            CVSServerConnection connection = new CVSServerConnection();

        	connection.Connect(workingDirectory, password);
        	
        	return Run(connection);
        }