private void Checkout() { CvsRoot cvsRoot; try { cvsRoot = this.GetCvsRoot(this.CvsRoot.Text); } catch (CvsRootParseException ex) { this.ErrorLabel.Text = ex.Message; // can't do anything without a root. return; } WorkingDirectory CurrentWorkingDirectory = new WorkingDirectory(cvsRoot, this.LocalDirectory.Text, Module.Text); // Create new CheckoutModuleCommand object ICommand checkoutCommand = new CheckoutModuleCommand(CurrentWorkingDirectory); CVSServerConnection serverConn = new CVSServerConnection(CurrentWorkingDirectory); this.RegisterListenEvents(serverConn); serverConn.Connect(CurrentWorkingDirectory, this.Password.Text); checkoutCommand.Execute(serverConn); serverConn.Close(); }
/// <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); } } }
/// <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)); }
/// <summary> /// Checkout the test repository. This repository is configured in the /// ICSharpConfig.SharpCvsLib.Tests.dll.config file, or if this file /// cannot be found or loaded then the settings are loaded from /// TestConstants class. /// </summary> public void CheckoutTestModule() { CvsRoot root = new CvsRoot(this.settings.Config.Cvsroot); WorkingDirectory working = new WorkingDirectory(root, this.settings.Config.LocalPath, this.settings.Config.Module); System.Console.WriteLine(this.settings.Config.LocalPath); CVSServerConnection connection = new CVSServerConnection(); Assert.IsNotNull(connection, "Should have a connection object."); ICommand command = new CheckoutModuleCommand(working); Assert.IsNotNull(command, "Should have a command object."); try { connection.Connect(working, this.settings.Config.ValidPassword); } catch (AuthenticationException) { Assert.IsTrue(true, "Failed to authenticate with server."); } command.Execute(connection); connection.Close(); }
public void UpdateFromCvsntTest_Checkout() { string cvsPath = Path.Combine(this.settings.Config.LocalPath, CVSNT_MODULE); Manager manager = new Manager(cvsPath); CvsRoot root = new CvsRoot(CVSNT_CVSROOT); WorkingDirectory working = new WorkingDirectory(root, this.settings.Config.LocalPath, CVSNT_MODULE); CVSServerConnection connection = new CVSServerConnection(); Assert.IsNotNull(connection); ICommand command = new CheckoutModuleCommand(working); Assert.IsNotNull(command); try { connection.Connect(working, this.settings.Config.ValidPassword); } catch (AuthenticationException) { Assert.IsTrue(true); } command.Execute(connection); connection.Close(); this.PerformUpdate(); }
private void UpdateAllRecursive(String rootDir, String overrideDirectory) { CvsRoot root = new CvsRoot(this.settings.Config.Cvsroot); WorkingDirectory working = new WorkingDirectory(root, this.settings.Config.LocalPath, this.settings.Config.Module); working.OverrideDirectory = overrideDirectory; CVSServerConnection connection = new CVSServerConnection(); Assert.IsNotNull(connection); ICommand command = new UpdateCommand2(working); Assert.IsNotNull(command); connection.Connect(working, this.settings.Config.ValidPassword); // Update all files... LOGGER.Debug("Fetching all files from rootDir=[" + rootDir + "]"); working.FoldersToUpdate = this.manager.FetchFilesToUpdate(rootDir); command.Execute(connection); connection.Close(); }
/// <summary> /// Registers events that will be listened to. An extension of this might be to add a check box /// that can be unchecked/ checked if the event should be listened to. /// </summary> private void RegisterListenEvents(CVSServerConnection connection) { connection.ResponseMessageEvents.ErrorResponseMessageEvent += new MessageEventHandler(WriteErrorResponse); connection.ResponseMessageEvent += new MessageEventHandler(WriteResponse); connection.ResponseMessageEvents.UpdatedResponseMessageEvent += new MessageEventHandler(WriteUpdatedResponse); }
private void Checkout(WorkingDirectory workingDirectory, CVSServerConnection connection) { Assert.IsNotNull(connection); ICommand command = new CheckoutModuleCommand(workingDirectory); Assert.IsNotNull(command); try { connection.Connect(workingDirectory, this.settings.Config.ValidPassword); } catch (AuthenticationException) { Assert.IsTrue(true); } command.Execute(connection); connection.Close(); }
public void TestAddTag() { CvsRoot root = new CvsRoot(this.settings.Config.Cvsroot); WorkingDirectory workingDirectory = new WorkingDirectory(root, this.settings.Config.LocalPath, this.settings.Config.Module); CVSServerConnection connection = new CVSServerConnection(); this.Checkout(workingDirectory, connection); RTagCommand command = new RTagCommand(workingDirectory); command.TagName = TEST_TAG_1; connection.Connect(workingDirectory, this.settings.ValidPassword); command.Execute(connection); }
public void UpdateNoCheckoutTest() { CvsRoot root = new CvsRoot(this.settings.Config.Cvsroot); WorkingDirectory working = new WorkingDirectory(root, this.settings.Config.LocalPath, CVSNT_MODULE); CVSServerConnection connection = new CVSServerConnection(); Assert.IsNotNull(connection); ICommand command = new UpdateCommand2(working); Assert.IsNotNull(command); connection.Connect(working, this.settings.Config.ValidPassword); }
private void PerformUpdate() { CvsRoot root = new CvsRoot(CVSNT_CVSROOT); WorkingDirectory working = new WorkingDirectory(root, this.settings.Config.LocalPath, CVSNT_MODULE); CVSServerConnection connection = new CVSServerConnection(); Assert.IsNotNull(connection); ICommand command = new UpdateCommand2(working); Assert.IsNotNull(command); connection.Connect(working, this.settings.Config.ValidPassword); }
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))); }
private void Checkout() { 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."); ICommand command = new CheckoutModuleCommand(working); Assert.IsNotNull(command, "Should have a command object."); connection.Connect(working, this.settings.Config.ValidPassword); command.Execute(connection); connection.Close(); }
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 /// Alternate interface for when we are given a server cooection /// This is needed for the SharpCvsLib command line client /// </summary> public LogReport Run(ICommandConnection connection) { // 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); this.cvsRoot = new CvsRoot(root.FileContents); } if (null == workingDirectory) { Manager manager = new Manager(localDirectory); Repository repository = (Repository)manager.FetchSingle(localDirectory, Factory.FileType.Repository); this.workingDirectory = new WorkingDirectory(cvsRoot, localDirectory, repository.FileContents); } ILogCommand command; // Recursively add all cvs folders/files under the localDirectory System.Console.WriteLine("GNE workingDirectory.WorkingPath = {0}", workingDirectory.WorkingPath); System.Console.WriteLine("GNE localDirectory: {0}", localDirectory); // if (Directory.Exists(workingDirectory.WorkingPath)) { if (Directory.Exists(localDirectory) && File.Exists(Path.Combine(localDirectory, "Repository"))) { workingDirectory.FoldersToUpdate = FetchFiles(localDirectory); command = new LogCommand(workingDirectory, this.workingDirectory.ModuleName, null); } else { command = // GNE - this wont compile new LogCommand(workingDirectory, this.workingDirectory.ModuleName); new RLogCommand(workingDirectory, this.workingDirectory.ModuleName); } // add any date restrictions if (hasStartDate && hasEndDate) { command.AddInclusiveDateRange(startDate, endDate); } else if (hasStartDate) { command.AddInclusiveDateStart(startDate); } else if (hasEndDate) { command.AddInclusiveDateEnd(endDate); } // Initialse state machine curLogReport = new LogReport(); // this is what we are going to return to the caller curLogFile = new LogFile(this.cvsRoot); curLogRevision = new LogRevision(); logState = LogState.WANT_FILE_HEADER_START; if (connection.GetType() == typeof(CVSServerConnection)) { CVSServerConnection cvsServerConnection = (CVSServerConnection)connection; cvsServerConnection.MessageEvent.MessageEvent += new EncodedMessage.MessageHandler(OnMessage); } command.Execute(connection); // return curLogReport but clear our reference to it LogReport report = curLogReport; curLogReport = null; return(report); }
public void AddFilesTest() { this.CheckoutTestModule(); String modulePath = Path.Combine(this.GetTempPath(), this.Settings.Config.Module); String[] files = Directory.GetFiles(modulePath, "*.txt"); Assert.IsTrue(files.Length > 0); ArrayList copiedFiles = new ArrayList(); foreach (String file in files) { LOGGER.Debug("file=[" + file + "]"); // Remove the .txt when everything works, giving me bugs... String newFileName = Guid.NewGuid().ToString() + ".txt"; String fullPath = Path.Combine(modulePath, newFileName); File.Copy(file, fullPath); copiedFiles.Add(fullPath); } 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); AddCommand command = new AddCommand(working); //command.Folders = this.GetFolders(modulePath); command.Folders = this.GetFoldersToAdd(copiedFiles); Assert.IsTrue(command.Folders.Count > 0); LOGGER.Debug("folders count=[" + command.Folders.Count + "]"); foreach (DictionaryEntry folderDic in command.Folders) { Folder folder = (Folder)folderDic.Value; LOGGER.Debug("folder=[" + folder.ToString() + "]"); LOGGER.Debug("entries count=[" + folder.Entries.Count + "]"); } Assert.IsNotNull(command); try { connection.Connect(working, this.Settings.Config.ValidPassword); } catch (AuthenticationException) { // should not get here. Assert.IsTrue(true); } command.Execute(connection); connection.Close(); try { connection.Connect(working, this.Settings.Config.ValidPassword); } catch (AuthenticationException) { Assert.IsTrue(true); } CommitCommand2 commitCommand = new CommitCommand2(working); working.Folders = command.Folders; commitCommand.LogMessage = "AddCommandTest"; commitCommand.Execute(connection); connection.Close(); Manager manager = new Manager(working.WorkingPath); Entries entries = manager.FetchEntries(Path.Combine(modulePath, "Entries")); foreach (String addedFile in copiedFiles) { Assert.IsTrue(entries.Contains(Path.Combine(modulePath, addedFile))); } }