Beispiel #1
0
        public void DumpProject(VssProject project, int indent)
        {
            var indentStr = new string(' ', indent);

            physicalNames.Add(project.PhysicalName);
            writer.WriteLine("{0}{1}/ ({2})",
                indentStr, project.Name, project.PhysicalName);

            foreach (VssProject subproject in project.Projects)
            {
                DumpProject(subproject, indent + 2);
            }

            foreach (VssFile file in project.Files)
            {
                physicalNames.Add(file.PhysicalName);
                writer.WriteLine("{0}  {1} ({2}) - {3}",
                    indentStr, file.Name, file.PhysicalName, file.GetPath(project));

                if (IncludeRevisions)
                {
                    foreach (VssFileRevision version in file.Revisions)
                    {
                        writer.WriteLine("{0}    #{1} {2} {3}",
                            indentStr, version.Version, version.User, version.DateTime);
                    }
                }
            }
        }
Beispiel #2
0
 public static RecursionStatus RecurseItems(
     VssProject project, VssProjectCallback projectCallback, VssFileCallback fileCallback)
 {
     if (projectCallback != null)
     {
         RecursionStatus status = projectCallback(project);
         if (status != RecursionStatus.Continue)
         {
             return status;
         }
     }
     foreach (VssProject subproject in project.Projects)
     {
         RecursionStatus status = RecurseItems(
             subproject, projectCallback, fileCallback);
         if (status == RecursionStatus.Abort)
         {
             return status;
         }
     }
     foreach (VssFile file in project.Files)
     {
         RecursionStatus status = fileCallback(project, file);
         if (status == RecursionStatus.Abort)
         {
             return status;
         }
     }
     return RecursionStatus.Continue;
 }
Beispiel #3
0
        public static RecursionStatus RecurseItems(
            VssProject project, VssProjectCallback projectCallback, VssFileCallback fileCallback)
        {
            if (projectCallback != null)
            {
                RecursionStatus status = projectCallback(project);
                if (status != RecursionStatus.Continue)
                {
                    return status;
                }
            }
            foreach (VssProject subproject in project.Projects)
            {
                RecursionStatus status = RecurseItems(
                    subproject, projectCallback, fileCallback);
                if (status == RecursionStatus.Abort)
                {
                    return status;
                }
            }

            HashSet<string> locallyProcessedFiles = new HashSet<string>();
            foreach (VssFile file in project.Files)
            {
                RecursionStatus status = fileCallback(project, file);
                locallyProcessedFiles.Add(file.PhysicalName);
                if (status == RecursionStatus.Abort)
                {
                    return status;
                }
            }
            foreach (VssRevision revision in project.Revisions)
            {
                var namedAction = revision.Action as VssNamedAction;
                if (namedAction != null && !namedAction.Name.IsProject)
                {
                    string physicalName = namedAction.Name.PhysicalName;
                    if (!locallyProcessedFiles.Contains(physicalName))
                    {
                        VssFile file = project.GetHistoricalFile(physicalName, namedAction.Name.LogicalName);
                        locallyProcessedFiles.Add(file.PhysicalName);
                        if (File.Exists(file.PhysicalPath) && File.Exists(file.DataPath))
                        {
                            RecursionStatus status = fileCallback(project, file);
                            if (status == RecursionStatus.Abort)
                            {
                                return status;
                            }
                        }
                    }
                }
            }
            return RecursionStatus.Continue;
        }
Beispiel #4
0
        internal VssDatabase(string path, Encoding encoding)
        {
            if (Type.GetType("Mono.Runtime") != null)
            {
                RootProjectFile = RootProjectFile.ToLower();
            }

            this.basePath = path;
            this.encoding = encoding;

            iniPath = Path.Combine(path, "srcsafe.ini");
            var iniReader = new SimpleIniReader(iniPath);
            iniReader.Parse();

            dataPath = Path.Combine(path, iniReader.GetValue("Data_Path", "data"));

            var namesPath = Path.Combine(dataPath, "names.dat");
            nameFile = new NameFile(namesPath, encoding);

            rootProject = OpenProject(null, RootProjectFile, RootProjectName);
        }
Beispiel #5
0
        public void AddItem(VssProject project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            else if (project.Database != database)
            {
                throw new ArgumentException("Project database mismatch", "project");
            }

            rootProjects.AddLast(project);

            PathMatcher exclusionMatcher = null;
            if (!string.IsNullOrEmpty(excludeFiles))
            {
                var excludeFileArray = excludeFiles.Split(
                    new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                exclusionMatcher = new PathMatcher(excludeFileArray);
            }

            workQueue.AddLast(delegate(object work)
            {
                logger.WriteSectionSeparator();
                LogStatus(work, "Building revision list");

                logger.WriteLine("Root project: {0}", project.Path);
                logger.WriteLine("Excluded files: {0}", excludeFiles);

                int excludedProjects = 0;
                int excludedFiles = 0;
                var stopwatch = Stopwatch.StartNew();
                VssUtil.RecurseItems(project,
                    delegate(VssProject subproject)
                    {
                        if (workQueue.IsAborting)
                        {
                            return RecursionStatus.Abort;
                        }

                        var path = subproject.Path;
                        if (exclusionMatcher != null && exclusionMatcher.Matches(path))
                        {
                            logger.WriteLine("Excluding project {0}", path);
                            ++excludedProjects;
                            return RecursionStatus.Skip;
                        }

                        ProcessItem(subproject, path, exclusionMatcher);
                        ++projectCount;
                        return RecursionStatus.Continue;
                    },
                    delegate(VssProject subproject, VssFile file)
                    {
                        if (workQueue.IsAborting)
                        {
                            return RecursionStatus.Abort;
                        }

                        var path = file.GetPath(subproject);
                        if (exclusionMatcher != null && exclusionMatcher.Matches(path))
                        {
                            logger.WriteLine("Excluding file {0}", path);
                            ++excludedFiles;
                            return RecursionStatus.Skip;
                        }

                        // only process shared files once (projects are never shared)
                        if (!processedFiles.Contains(file.PhysicalName))
                        {
                            processedFiles.Add(file.PhysicalName);
                            ProcessItem(file, path, exclusionMatcher);
                            ++fileCount;
                        }
                        return RecursionStatus.Continue;
                    });
                stopwatch.Stop();

                logger.WriteSectionSeparator();
                logger.WriteLine("Analysis complete in {0:HH:mm:ss}", new DateTime(stopwatch.ElapsedTicks));
                logger.WriteLine("Projects: {0} ({1} excluded)", projectCount, excludedProjects);
                logger.WriteLine("Files: {0} ({1} excluded)", fileCount, excludedFiles);
                logger.WriteLine("Revisions: {0}", revisionCount);
            });
        }
Beispiel #6
0
 public string GetPath(VssProject project)
 {
     return project.Path + VssDatabase.ProjectSeparator + Name;
 }
Beispiel #7
0
 public ProjectAnalyzer(WorkQueue workQueue, Logger logger, VssProject vssRootProject)
     : base(workQueue, logger)
 {
     this.vssRootProject = vssRootProject;
 }
Beispiel #8
0
        private void ProcessProject(VssProject project, string path, PathMatcher exclusionMatcher)
        {
            try
            {
                ProjectLocation projectLocation;
                if (sortedProjectLocations.TryGetValue(project.PhysicalName, out projectLocation))
                    logger.WriteLine("Unexpected: ProjectAnalyzer.ProcessProject: sortedProjectLocations already contains project: {0}", project.PhysicalName);
                else
                {
                    projectLocation = new ProjectLocation(project.PhysicalName, path);
                    sortedProjectLocations[project.PhysicalName] = projectLocation;
                };

                foreach (VssRevision vssRevision in project.Revisions)
                {
                    var actionType = vssRevision.Action.Type;
                    var namedAction = vssRevision.Action as VssNamedAction;
                    if (namedAction != null)
                    {
                        var targetPath = path + VssDatabase.ProjectSeparator + namedAction.Name.LogicalName;
                        if (exclusionMatcher != null && exclusionMatcher.Matches(targetPath))
                        {
                            // project action targets an excluded file
                            continue;
                        }

                        if (namedAction.Name.IsProject)
                        {
                            if (
                                (actionType == VssActionType.Delete) ||
                                (actionType == VssActionType.Destroy)
                            )
                                deletedProjects.Add(namedAction.Name.PhysicalName);
                            else if (
                                (actionType == VssActionType.Recover) ||
                                (actionType == VssActionType.Share)
                            )
                                deletedProjects.Remove(namedAction.Name.PhysicalName);
                        }
                        else
                        {
                            if (
                                (actionType == VssActionType.Delete) ||
                                (actionType == VssActionType.Destroy)
                            )
                                projectLocation.DeletedFiles.Add(namedAction.Name.PhysicalName);
                            else if (
                                (actionType == VssActionType.Recover) ||
                                (actionType == VssActionType.Share)
                            )
                                projectLocation.DeletedFiles.Remove(namedAction.Name.PhysicalName);
                        }

                    }
                }
            }
            catch (RecordException e)
            {
                var message = string.Format("ProjectAnalyzer.ProcessProject: Failed to process project for {0} ({1}): {2}",
                    path, project.PhysicalName, ExceptionFormatter.Format(e));
                LogException(e, message);
                ReportError(message);
            }
        }
Beispiel #9
0
 private static string BuildPath(VssProject parent, string logicalName)
 {
     return (parent != null) ? parent.Path + ProjectSeparator + logicalName : logicalName;
 }
Beispiel #10
0
 internal VssProject OpenProject(VssProject parent, string physicalName, string logicalName)
 {
     var itemName = new VssItemName(logicalName, physicalName, true);
     var logicalPath = BuildPath(parent, logicalName);
     var physicalPath = GetDataPath(physicalName);
     return new VssProject(this, itemName, physicalPath, logicalPath);
 }
Beispiel #11
0
        public VssItem GetItemPhysical(string physicalName)
        {
            physicalName = physicalName.ToUpper();

            if (physicalName == RootProjectFile)
            {
                return rootProject;
            }

            var physicalPath = GetDataPath(physicalName);
            var itemFile = new ItemFile(physicalPath, encoding);
            var isProject = (itemFile.Header.ItemType == ItemType.Project);
            var logicalName = GetFullName(itemFile.Header.Name);
            var itemName = new VssItemName(logicalName, physicalName, isProject);
            VssItem item;
            if (isProject)
            {
                var parentFile = ((ProjectHeaderRecord)itemFile.Header).ParentFile;
                var parent = (VssProject)GetItemPhysical(parentFile);
                var logicalPath = BuildPath(parent, logicalName);
                item = new VssProject(this, itemName, physicalPath, logicalPath);
            }
            else
            {
                item = new VssFile(this, itemName, physicalPath);
            }
            item.ItemFile = itemFile;
            return item;
        }
Beispiel #12
0
 public void DumpProject(VssProject project)
 {
     DumpProject(project, 0);
 }
Beispiel #13
0
        public void AddItem(VssProject project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            PathMatcher exclusionMatcher = null;
            if (!string.IsNullOrEmpty(excludeFiles))
            {
                var excludeFileArray = excludeFiles.Split(
                    new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                exclusionMatcher = new PathMatcher(excludeFileArray);
            }

            workQueue.AddLast(delegate(object work)
            {
                logger.WriteSectionSeparator();
                LogStatus(work, "Building file location dictionary");

                logger.WriteLine("Root project: {0}", project.Path);
                logger.WriteLine("Excluded files: {0}", excludeFiles);

                int excludedFiles = 0;
                var stopwatch = Stopwatch.StartNew();
                VssUtil.RecurseItems(project,
                    delegate(VssProject subproject)
                    {
                        if (workQueue.IsAborting)
                        {
                            return RecursionStatus.Abort;
                        }
                        return RecursionStatus.Continue;
                    },
                    delegate(VssProject subproject, VssFile file)
                    {
                        if (workQueue.IsAborting)
                        {
                            return RecursionStatus.Abort;
                        }

                        var path = file.GetPath(subproject);
                        if (exclusionMatcher != null && exclusionMatcher.Matches(path))
                        {
                            logger.WriteLine("Excluding file {0}", path);
                            ++excludedFiles;
                            return RecursionStatus.Skip;
                        }

                        // Don't process files in deleted projects
                        if (!projectAnalyzer.DeletedProjects.Contains(subproject.PhysicalName))
                        {
                            ProjectLocation projectLocation;
                            if (!projectAnalyzer.SortedProjectLocations.TryGetValue(subproject.PhysicalName, out projectLocation))
                            {
                                // If the project is not found it is (i.e. should) be due to exclusionMatcher
                                //logger.WriteLine("Unexpected: FileAnalyzer: SortedProjectLocations does not contain project: {0}", subproject.PhysicalName);
                            }
                            else if (!projectLocation.DeletedFiles.Contains(file.PhysicalName))
                            {
                                // If the file is shared it might be in more than one project...
                                // But this should not happen using this alternate import method!
                                if (processedFiles.Contains(file.PhysicalName))
                                {
                                    ++sharedFileCount;
                                    logger.WriteLine("Unexpected: FileAnalyzer: File shared in more tha one project: {0}: {1}", file.PhysicalName, subproject.Path);
                                }
                                else
                                {
                                    processedFiles.Add(file.PhysicalName);
                                    FileLocation fileLocation;
                                    if (sortedFileLocations.TryGetValue(file.PhysicalName, out fileLocation))
                                        logger.WriteLine("Unexpected: FileAnalyzer: sortedFileLocations already contains file: {0}", file.PhysicalName);
                                    else
                                    {
                                        fileLocation = new FileLocation(file.PhysicalName, file.GetPath(subproject));
                                        sortedFileLocations[file.PhysicalName] = fileLocation;
                                    }
                                    ++fileCount;
                                }
                            }
                        }

                        return RecursionStatus.Continue;
                    });
                stopwatch.Stop();

                logger.WriteSectionSeparator();
                logger.WriteLine("Analysis complete in {0:HH:mm:ss}", new DateTime(stopwatch.ElapsedTicks));
                logger.WriteLine("Files: {0} ({1} excluded)", fileCount, excludedFiles);
                logger.WriteLine("Shared Files: {0}", sharedFileCount);

                if (sharedFileCount > 0)
                {
                    workQueue.Abort();
                    MessageBox.Show("Shared files exist!  " +
                        "This alternate logic depends on files existing in only one location.  " +
                        "Please resolve before reattempting conversion.",
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            });
        }
Beispiel #14
0
        public void AddItem(VssProject project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            else if (project.Database != database)
            {
                throw new ArgumentException("Project database mismatch", "project");
            }

            rootProjects.AddLast(project);

            PathMatcher exclusionMatcher = null;

            if (!string.IsNullOrEmpty(excludeFiles))
            {
                var excludeFileArray = excludeFiles.Split(
                    new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                exclusionMatcher = new PathMatcher(excludeFileArray);
            }

            workQueue.AddLast(delegate(object work)
            {
                logger.WriteSectionSeparator();
                LogStatus(work, "Building revision list");

                logger.WriteLine("Root project: {0}", project.Path);
                logger.WriteLine("Excluded files: {0}", excludeFiles);

                int excludedProjects = 0;
                int excludedFiles    = 0;
                var stopwatch        = Stopwatch.StartNew();
                VssUtil.RecurseItems(project,
                                     delegate(VssProject subproject)
                {
                    if (workQueue.IsAborting)
                    {
                        return(RecursionStatus.Abort);
                    }

                    var path = subproject.Path;
                    if (exclusionMatcher != null && exclusionMatcher.Matches(path))
                    {
                        logger.WriteLine("Excluding project {0}", path);
                        ++excludedProjects;
                        return(RecursionStatus.Skip);
                    }

                    ProcessItem(subproject, path, exclusionMatcher);
                    ++projectCount;
                    return(RecursionStatus.Continue);
                },
                                     delegate(VssProject subproject, VssFile file)
                {
                    if (workQueue.IsAborting)
                    {
                        return(RecursionStatus.Abort);
                    }

                    var path = file.GetPath(subproject);
                    if (exclusionMatcher != null && exclusionMatcher.Matches(path))
                    {
                        logger.WriteLine("Excluding file {0}", path);
                        ++excludedFiles;
                        return(RecursionStatus.Skip);
                    }

                    // only process shared files once (projects are never shared)
                    if (!processedFiles.Contains(file.PhysicalName))
                    {
                        processedFiles.Add(file.PhysicalName);
                        ProcessItem(file, path, exclusionMatcher);
                        ++fileCount;
                    }
                    return(RecursionStatus.Continue);
                });
                stopwatch.Stop();

                logger.WriteSectionSeparator();
                logger.WriteLine("Analysis complete in {0:HH:mm:ss}", new DateTime(stopwatch.ElapsedTicks));
                logger.WriteLine("Projects: {0} ({1} excluded)", projectCount, excludedProjects);
                logger.WriteLine("Files: {0} ({1} excluded)", fileCount, excludedFiles);
                logger.WriteLine("Revisions: {0}", revisionCount);
            });
        }