public void TestFiles() { LogReport logReport = new LogReport(); LogFile logFile1 = new LogFile(settings.GetCvsRoot()); logFile1.RepositoryFnm = "File1"; logReport.AddFile(logFile1); LogFile logFile2 = new LogFile(settings.GetCvsRoot()); logFile2.RepositoryFnm = "File2"; logReport.AddFile(logFile2); LogFile logFile3 = new LogFile(settings.GetCvsRoot()); logFile3.RepositoryFnm = "File3"; logReport.AddFile(logFile3); Assert.AreEqual(3, logReport.Count); // Test indexer Assert.AreEqual("File1", logReport[0].RepositoryFnm); Assert.AreEqual("File2", logReport[1].RepositoryFnm); Assert.AreEqual("File3", logReport[2].RepositoryFnm); // Test foreach int nIndex = 0; foreach (LogFile logFile in logReport) { Assert.IsTrue(nIndex <= 2); if (nIndex == 0) { Assert.AreEqual("File1", logFile.RepositoryFnm); } else if (nIndex == 1) { Assert.AreEqual("File2", logFile.RepositoryFnm); } else if (nIndex == 2) { Assert.AreEqual("File3", logFile.RepositoryFnm); } nIndex++; } }
/// <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 TestInvalidIndexZero() { LogReport logReport = new LogReport(); LogFile logFile = logReport[0]; }
public void TestDefaultCtor() { LogReport logReport = new LogReport(); Assert.AreEqual(0, logReport.Count); }
/// <summary> /// Format the LogReport into a change log /// which will be written to textWriter /// </summary> private void FormatReport(XmlTextWriter textWriter, LogReport logReport) { LogRevision logRevision; // This is where we accumulate information on all the entries from the log command SortedList entries = new SortedList(); LogEntry entry; string prevRevision; // now collect together revisions that were checked-in together foreach (LogFile logFile in logReport) { // foreach (LogRevision logRevision in logFile) // traverse revisions in reverse order so we look at oldest first // which simplifies the remembering the previous revision prevRevision = ""; for (int idx = logFile.Count - 1; idx >= 0; idx--) { logRevision = logFile[idx]; entry = new LogEntry(logRevision.Timestamp, logRevision.Author, logRevision.Comment); // determine if this entry already exists if (entries.ContainsKey(entry.Key)) { // need to update an existing entry entry = (LogEntry)entries[entry.Key]; } else { // add new entry entries.Add(entry.Key, entry); } // finally add details about the file/revision entry.AddFileRevision(logFile.WorkingFnm, logRevision.Revision, prevRevision); prevRevision = logRevision.Revision; } } // now finally produce the XML report // try { textWriter.Formatting = Formatting.Indented; textWriter.WriteStartDocument(); textWriter.WriteStartElement("changelog"); // add the entries ... foreach (DictionaryEntry de in entries) { LogEntry logEntry = (LogEntry)de.Value; logEntry.ExportToXml(textWriter, nameMap); } // finish off textWriter.WriteEndElement(); // changelog textWriter.WriteEndDocument(); textWriter.Close(); // } catch (Exception e) { // System.Console.WriteLine("XML write error: {0}", e.Message); // throw e; // } }
/// <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 Test() { SharpCvsLibTestsConfig settings; string section = SharpCvsLibTestsConfigHandler.APP_CONFIG_SECTION; //System.Console.WriteLine("section={0}", section); settings = (SharpCvsLibTestsConfig)ConfigurationSettings.GetConfig(section); //System.Console.WriteLine("target-directory={0}", settings.TargetDirectory); //System.Console.WriteLine("password={0}", settings.ValidPassword); string moduleName = settings.Module; string workingDir = settings.TargetDirectory; string password = settings.ValidPassword; bool foundTestFile1 = false; bool foundTestFile2 = false; LogRevision logRevision; LogSymbolicName symbolicName; LogReportCommand logCommand = new LogReportCommand(moduleName, workingDir); // // logCommand.SetLastNDays(7); // // or logCommand.StartDate = new DateTime(...); // // and/or logCommand.EndDate = new DateTime(...); // LogReport logReport = logCommand.Run(password); Assert.AreEqual(16, logReport.Count); foreach (LogFile logFile in logReport) { if (logFile.WorkingFnm.EndsWith("test-file.txt")) { Assert.IsTrue(!foundTestFile1); foundTestFile1 = true; Assert.AreEqual("/cvsroot/sharpcvslib-test/sharpcvslib-test-repository/test-file.txt,v", logFile.RepositoryFnm); Assert.AreEqual("test-file.txt", logFile.WorkingFnm); Assert.AreEqual("", logFile.Description); // check the revisions Assert.AreEqual(3, logFile.Count); // most recent version will be first logRevision = logFile[0]; Assert.AreEqual("1.3", logRevision.Revision); CheckDate(2003, 9, 14, 1, 8, 21, logRevision.Timestamp); Assert.AreEqual("claytonharbour", logRevision.Author); Assert.AreEqual("Exp", logRevision.State); Assert.AreEqual(3, logRevision.LinesAdded); Assert.AreEqual(1, logRevision.LinesDeleted); Assert.AreEqual("*** empty log message ***", logRevision.Comment); logRevision = logFile[1]; Assert.AreEqual("1.2", logRevision.Revision); CheckDate(2003, 9, 14, 1, 7, 15, logRevision.Timestamp); Assert.AreEqual("claytonharbour", logRevision.Author); Assert.AreEqual("Exp", logRevision.State); Assert.AreEqual(3, logRevision.LinesAdded); Assert.AreEqual(1, logRevision.LinesDeleted); Assert.AreEqual("Added line.", logRevision.Comment); logRevision = logFile[2]; Assert.AreEqual("1.1", logRevision.Revision); CheckDate(2003, 9, 14, 1, 5, 51, logRevision.Timestamp); Assert.AreEqual("claytonharbour", logRevision.Author); Assert.AreEqual("Exp", logRevision.State); Assert.AreEqual(0, logRevision.LinesAdded); Assert.AreEqual(0, logRevision.LinesDeleted); Assert.AreEqual("Various changes for sticky tag support. Looked at implementing a message event handling system for request/ responses to output server messages (similar to tortoise).", logRevision.Comment); // check the symbolic names // check the revisions Assert.AreEqual(3, logFile.SymbolicNames.Count); symbolicName = logFile.SymbolicNames[0]; Assert.AreEqual("V0_3", symbolicName.Name); Assert.AreEqual("1.3", symbolicName.Revision); symbolicName = logFile.SymbolicNames[1]; Assert.AreEqual("V0_2", symbolicName.Name); Assert.AreEqual("1.2", symbolicName.Revision); symbolicName = logFile.SymbolicNames[2]; Assert.AreEqual("V0_1", symbolicName.Name); Assert.AreEqual("1.1", symbolicName.Revision); } if (logFile.WorkingFnm.EndsWith("test-file-2.txt")) { Assert.IsTrue(!foundTestFile2); foundTestFile2 = true; Assert.AreEqual("/cvsroot/sharpcvslib-test/sharpcvslib-test-repository/src/test-file-2.txt,v", logFile.RepositoryFnm); Assert.AreEqual("src/test-file-2.txt", logFile.WorkingFnm); Assert.AreEqual("", logFile.Description); Assert.AreEqual(1, logFile.Count); // most recent version will be first logRevision = logFile[0]; Assert.AreEqual("1.1", logRevision.Revision); CheckDate(2003, 9, 14, 15, 57, 48, logRevision.Timestamp); Assert.AreEqual("claytonharbour", logRevision.Author); Assert.AreEqual("Exp", logRevision.State); Assert.AreEqual(0, logRevision.LinesAdded); Assert.AreEqual(0, logRevision.LinesDeleted); Assert.AreEqual("*** empty log message ***", logRevision.Comment); } } Assert.IsTrue(foundTestFile1); Assert.IsTrue(foundTestFile2); // ... // foreach (LogRevision logRevision in logFile) // { // ... // } // } }