Example #1
0
        public void TestProperties()
        {
            LogRevision logRevision = new LogRevision();

            logRevision.Revision = "1.2";
            Assert.AreEqual("1.2", logRevision.Revision);

            logRevision.Timestamp = new DateTime(2004, 3, 7, 23, 50, 48, 123);
            Assert.AreEqual(2004, logRevision.Timestamp.Year);
            Assert.AreEqual(3, logRevision.Timestamp.Month);
            Assert.AreEqual(7, logRevision.Timestamp.Day);
            Assert.AreEqual(23, logRevision.Timestamp.Hour);
            Assert.AreEqual(50, logRevision.Timestamp.Minute);
            Assert.AreEqual(48, logRevision.Timestamp.Second);
            Assert.AreEqual(123, logRevision.Timestamp.Millisecond);

            logRevision.Author = "gne";
            Assert.AreEqual("gne", logRevision.Author);

            logRevision.State = "Exp";
            Assert.AreEqual("Exp", logRevision.State);

            logRevision.Comment = "my comment";
            Assert.AreEqual("my comment", logRevision.Comment);

            logRevision.LinesAdded = 15;
            Assert.AreEqual(15, logRevision.LinesAdded);

            logRevision.LinesDeleted = 23;
            Assert.AreEqual(23, logRevision.LinesDeleted);

            logRevision.Branches = "1.1";
            Assert.AreEqual("1.1", logRevision.Branches);
        }
Example #2
0
        public void TestDefaultCtor()
        {
            LogRevision logRevision = new LogRevision();

            Assert.AreEqual("", logRevision.Revision);
            //Assert.AreEqual(DateTime.Now, this.Timestamp);
            Assert.AreEqual("", logRevision.Author);
            Assert.AreEqual("", logRevision.State);
            Assert.AreEqual("", logRevision.Comment);
            Assert.AreEqual(0, logRevision.LinesAdded);
            Assert.AreEqual(0, logRevision.LinesDeleted);
            Assert.AreEqual("", logRevision.Branches);
        }
Example #3
0
        public void TestRevisions()
        {
            LogFile logFile = new LogFile(settings.GetCvsRoot());

            LogRevision logRevision1 = new LogRevision();

            logRevision1.Revision = "1.1";
            logFile.AddRevision(logRevision1);

            LogRevision logRevision2 = new LogRevision();

            logRevision2.Revision = "1.2";
            logFile.AddRevision(logRevision2);

            LogRevision logRevision3 = new LogRevision();

            logRevision3.Revision = "1.3";
            logFile.AddRevision(logRevision3);

            Assert.AreEqual(3, logFile.Count);

            // Test indexer
            Assert.AreEqual("1.1", logFile[0].Revision);
            Assert.AreEqual("1.2", logFile[1].Revision);
            Assert.AreEqual("1.3", logFile[2].Revision);

            // Test foreach
            int nIndex = 0;

            foreach (LogRevision logRevision in logFile)
            {
                Assert.IsTrue(nIndex <= 2);
                if (nIndex == 0)
                {
                    Assert.AreEqual("1.1", logRevision.Revision);
                }
                else if (nIndex == 1)
                {
                    Assert.AreEqual("1.2", logRevision.Revision);
                }
                else if (nIndex == 2)
                {
                    Assert.AreEqual("1.3", logRevision.Revision);
                }

                nIndex++;
            }
        }
Example #4
0
        /// <summary>
        /// This is called for each Message response we receive from the cvs server.
        /// </summary>
        public void OnMessage(string message)
        {
//            System.Console.WriteLine(message);

            // for some reason the message handler is now preceeding
            // each message with "cvs server: " so we need to strip this off first
            if (message.StartsWith("cvs server: "))
            {
                message = message.Substring(12);
            }

            // only process the lines starting with "M "
            if (message.StartsWith("M "))
            {
                // Strip of the leading "M "
                message = message.Substring(2);

                if (message.StartsWith(revisionEndPrefix))
                {
                    // seperator between file and revision or between revisions
                    if (logState == LogState.WANT_FILE_HEADER_START)
                    {
                        // ignore this (shouldn't happen)
                    }
                    else if (logState == LogState.WANT_FILE_HEADER || logState == LogState.WANT_FILE_DESCRIPTION)
                    {
                        // this is the seperator between te file header and the first revision
                    }
                    else
                    {
                        // seperator between revisions
                        curLogFile.AddRevision(curLogRevision);
                    }
                    curLogRevision = new LogRevision();
                    logState       = LogState.WANT_REVISION;
                }
                else if (message.StartsWith(fileEndPrefix))
                {
                    // seperator between files
                    if (logState == LogState.WANT_FILE_HEADER_START)
                    {
                        // ignore this (shouldn't happen)
                    }
                    else if (logState == LogState.WANT_FILE_HEADER || logState == LogState.WANT_FILE_DESCRIPTION)
                    {
                        // file with no revisions
                        curLogReport.AddFile(curLogFile);
                    }
                    else
                    {
                        // first add the revision
                        curLogFile.AddRevision(curLogRevision);
                        curLogRevision = new LogRevision();
                        // and now the file
                        curLogReport.AddFile(curLogFile);
                    }
                    curLogFile = new LogFile(this.cvsRoot);
                    logState   = LogState.WANT_FILE_HEADER_START;
                }
                else
                {
                    switch (logState)
                    {
                    case LogState.WANT_FILE_HEADER_START:              // drop into WANT_FILE_HEADER
                    case LogState.WANT_FILE_HEADER_SYMBOLIC_NAMES:     // drop into WANT_FILE_HEADER
                    case LogState.WANT_FILE_HEADER:
                        OnMessageHeader(message);
                        break;

                    case LogState.WANT_FILE_DESCRIPTION:
                        OnMessageDescription(message);
                        break;

                    case LogState.WANT_REVISION:
                        OnMessageRevision(message);
                        break;
                    }
                }
            }
        }
Example #5
0
        /// <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);
        }
Example #6
0
        public void TestInvalidIndexZero()
        {
            LogFile logFile = new LogFile(settings.GetCvsRoot());

            LogRevision logRevision = logFile[0];
        }
Example #7
0
//		/// <summary>
//		/// State constructor - initializes all fields to given values
//		/// </summary>
//		public LogFile(string repositoryFnm,
//		               string workingFnm,
//		               string description)
//		{
//System.Console.WriteLine("LogFile({0}, {1}, {2})", repositoryFnm, workingFnm, description);
//		    this.repositoryFnm = repositoryFnm;
//		    this.workingFnm = workingFnm;
//		    this.description = description;
//		}
		
		/// <summary>
		/// Adds a LogRevision to the LogFile
		/// Only called when the LogReport is being constructed
		/// </summary>
		internal void AddRevision(LogRevision revision)
		{
		    revisions.Add(revision);
		}
        /// <summary>
        /// This is called for each Message response we receive from the cvs server.
        /// </summary>
        public void OnMessage(string message)
        {
     
//            System.Console.WriteLine(message);
 
             // for some reason the message handler is now preceeding 
            // each message with "cvs server: " so we need to strip this off first
            if (message.StartsWith("cvs server: "))
            {
                message = message.Substring(12);
            }

            // only process the lines starting with "M "        
            if (message.StartsWith("M ")) {
                // Strip of the leading "M "
                message = message.Substring(2);
                
                if (message.StartsWith(revisionEndPrefix)) {
                    // seperator between file and revision or between revisions
                    if (logState == LogState.WANT_FILE_HEADER_START) {
                        // ignore this (shouldn't happen)
                    }
                    else if (logState == LogState.WANT_FILE_HEADER || logState == LogState.WANT_FILE_DESCRIPTION) {
                        // this is the seperator between te file header and the first revision
                    }
                    else {
                        // seperator between revisions
                        curLogFile.AddRevision(curLogRevision);
                    }
                    curLogRevision = new LogRevision();
                    logState = LogState.WANT_REVISION;    
                }
                else if (message.StartsWith(fileEndPrefix)) {
                    // seperator between files
                    if (logState == LogState.WANT_FILE_HEADER_START) {
                        // ignore this (shouldn't happen)
                    }
                    else if (logState == LogState.WANT_FILE_HEADER || logState == LogState.WANT_FILE_DESCRIPTION) {
                        // file with no revisions
                        curLogReport.AddFile(curLogFile);
                    }
                    else {
                        // first add the revision
                        curLogFile.AddRevision(curLogRevision);
                        curLogRevision = new LogRevision();
                        // and now the file
                        curLogReport.AddFile(curLogFile);
                    }
                    curLogFile = new LogFile(this.cvsRoot);
                    logState = LogState.WANT_FILE_HEADER_START;    
                }
                else {
                    switch (logState) {
                        case LogState.WANT_FILE_HEADER_START:          // drop into WANT_FILE_HEADER
                        case LogState.WANT_FILE_HEADER_SYMBOLIC_NAMES: // drop into WANT_FILE_HEADER
                        case LogState.WANT_FILE_HEADER:
                            OnMessageHeader(message);
                            break;
                                    
                        case LogState.WANT_FILE_DESCRIPTION:
                            OnMessageDescription(message);
                            break;
                        
                        case LogState.WANT_REVISION:
                            OnMessageRevision(message);
                            break;
                    }
                }
            }
        }
        /// <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;
        }
Example #10
0
//		/// <summary>
//		/// State constructor - initializes all fields to given values
//		/// </summary>
//		public LogFile(string repositoryFnm,
//		               string workingFnm,
//		               string description)
//		{
//System.Console.WriteLine("LogFile({0}, {1}, {2})", repositoryFnm, workingFnm, description);
//		    this.repositoryFnm = repositoryFnm;
//		    this.workingFnm = workingFnm;
//		    this.description = description;
//		}

        /// <summary>
        /// Adds a LogRevision to the LogFile
        /// Only called when the LogReport is being constructed
        /// </summary>
        internal void AddRevision(LogRevision revision)
        {
            revisions.Add(revision);
        }