Exemple #1
0
        private static void ParseProjectInfo(ISolutionProjectInfo projectInfo, FilePathAbsolute baseDirectory, List<FilePathAbsolute> filePathListe)
        {
            string rawProjectPath = baseDirectory.ParentDirectoryPath.Path + @"\" + projectInfo.RawProjectPath;
            FilePathAbsolute absoluteProjectPath = new FilePathAbsolute(rawProjectPath);

            if (!absoluteProjectPath.Path.EndsWith(".csproj")) { return; }
            IProjectInfo project = new Project(absoluteProjectPath.FileInfo);

            foreach (var referenceInfo in project.ProjectReferenceListe)
            {
                try
                {
                    string rawReferencePath = absoluteProjectPath.ParentDirectoryPath.Path + @"\" + referenceInfo.RawReferencePath;
                    FilePathAbsolute absoluteReferencePath = new FilePathAbsolute(rawReferencePath);
                    filePathListe.Add(absoluteReferencePath);
                }
                catch (Exception) { }
            }
            foreach (var referenceInfo in project.AssemblyReferenceListe)
            {
                try
                {
                    string rawReferencePath = absoluteProjectPath.ParentDirectoryPath.Path + @"\" + referenceInfo.RawReferencePath;
                    FilePathAbsolute absoluteReferencePath = new FilePathAbsolute(rawReferencePath);
                    filePathListe.Add(absoluteReferencePath);
                }
                catch (Exception) { }
            }

            filePathListe.Add(absoluteProjectPath);
        }
Exemple #2
0
 public string GetRelativePath(string absoluteFilePath, string absoluteDirectoryPath)
 {
     FilePathAbsolute filePathAbsolute1 = new FilePathAbsolute(absoluteFilePath);
     DirectoryPathAbsolute directoryPathAbsolute1 = new DirectoryPathAbsolute(absoluteDirectoryPath);
     FilePathRelative filePathRelative1 = filePathAbsolute1.GetPathRelativeFrom(directoryPathAbsolute1);
     return filePathRelative1.Path;
 }
Exemple #3
0
        public void Test_InvalidInputPathBadFormatting3()
        {
            string reason;

            Assert.IsFalse(PathHelper.IsValidAbsolutePath(@"C:\..\Dir1\File.txt", out reason));
            FilePath filePath = new FilePathAbsolute(@"C:\..\Dir1\File.txt");
        }
Exemple #4
0
        public void Test_InvalidInputPathNoParentDir()
        {
            string reason;

            Assert.IsFalse(PathHelper.IsValidAbsolutePath(@"File.txt", out reason));
            FilePath filePath = new FilePathAbsolute("File.txt");
        }
Exemple #5
0
        public void Test_GetRelativePath()
        {
            FilePathAbsolute      filePathTo;
            DirectoryPathAbsolute directoryPathFrom;

            ;

            filePathTo        = new FilePathAbsolute(@"C:\Dir1\File.txt");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
            Assert.IsTrue(filePathTo.GetPathRelativeFrom(directoryPathFrom).Path == @".\File.txt");
            Assert.IsTrue(filePathTo.CanGetPathRelativeFrom(directoryPathFrom));

            filePathTo        = new FilePathAbsolute(@"C:\Dir1\Dir2\File.txt");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1\Dir3");
            Assert.IsTrue(filePathTo.GetPathRelativeFrom(directoryPathFrom).Path == @"..\Dir2\File.txt");
            Assert.IsTrue(filePathTo.CanGetPathRelativeFrom(directoryPathFrom));

            filePathTo        = new FilePathAbsolute(@"C:\Dir1\File.txt");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir2");
            Assert.IsTrue(filePathTo.GetPathRelativeFrom(directoryPathFrom).Path == @"..\Dir1\File.txt");
            Assert.IsTrue(filePathTo.CanGetPathRelativeFrom(directoryPathFrom));

            filePathTo        = new FilePathAbsolute(@"C:\Dir1\Dir2\File.txt");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
            Assert.IsTrue(filePathTo.GetPathRelativeFrom(directoryPathFrom).Path == @".\Dir2\File.txt");
            Assert.IsTrue(filePathTo.CanGetPathRelativeFrom(directoryPathFrom));
        }
Exemple #6
0
        public void Test_IncoherentPathModeException1()
        {
            string reason;

            Assert.IsFalse(PathHelper.IsValidAbsolutePath(@".\File.txt", out reason));
            FilePath filePath = new FilePathAbsolute(@".\File.txt");
        }
Exemple #7
0
        public void Test_GetRelativePathWithError6()
        {
            FilePathAbsolute filePathTo = new FilePathAbsolute(@"C:\Dir1\File.txt");

            Assert.IsFalse(filePathTo.CanGetPathRelativeFrom(null));
            filePathTo.GetPathRelativeFrom(null);
        }
Exemple #8
0
        public void Test_InvalidInputPathNull()
        {
            string reason;

            Assert.IsFalse(PathHelper.IsValidAbsolutePath(null, out reason));
            FilePath filePath = new FilePathAbsolute(null);
        }
Exemple #9
0
        public void Test_InvalidInputPathEmpty()
        {
            string reason;

            Assert.IsFalse(PathHelper.IsValidAbsolutePath(string.Empty, out reason));
            FilePath filePath = new FilePathAbsolute(string.Empty);
        }
Exemple #10
0
        public void Test_InvalidInputAbsolutePath3()
        {
            string reason;

            Assert.IsFalse(PathHelper.IsValidAbsolutePath(@"1:\File.txt", out reason));
            FilePath filePath = new FilePathAbsolute(@"1:\File.txt");
        }
Exemple #11
0
 public void Test_FileDontExist()
 {
     DirForTest.Delete();
     string           dirForTestWithExecutingAssemblyFilePath = DirForTest.ExecutingAssemblyFilePathInDirForTest;
     FilePathAbsolute filePathAbsolute = new FilePathAbsolute(dirForTestWithExecutingAssemblyFilePath);
     FileInfo         fileInfo         = filePathAbsolute.FileInfo;
 }
Exemple #12
0
        public void Test_InvalidInputAbsoluteURNPath()
        {
            string reason;

            Assert.IsFalse(PathHelper.IsValidAbsolutePath(@"http://www.NDepend.com/File.txt", out reason));
            FilePath filePath = new FilePathAbsolute(@"http://www.NDepend.com/File.txt");
        }
Exemple #13
0
        public void Test_GetRelativePathWithError4()
        {
            FilePathAbsolute      filePathTo        = FilePathAbsolute.Empty;
            DirectoryPathAbsolute directoryPathFrom = new DirectoryPathAbsolute(@"D:\Dir1");

            Assert.IsFalse(filePathTo.CanGetPathRelativeFrom(directoryPathFrom));
            filePathTo.GetPathRelativeFrom(directoryPathFrom);
        }
Exemple #14
0
        public void Test_GetRelativePathWithError5()
        {
            FilePathAbsolute      filePathTo        = new FilePathAbsolute(@"C:\Dir1\File.txt");
            DirectoryPathAbsolute directoryPathFrom = DirectoryPathAbsolute.Empty;

            Assert.IsFalse(filePathTo.CanGetPathRelativeFrom(directoryPathFrom));
            filePathTo.GetPathRelativeFrom(directoryPathFrom);
        }
        public void Test_GetHashCodeThroughDictionary()
        {
            Dictionary <BasePath, string> dico          = new Dictionary <BasePath, string>();
            DirectoryPathAbsolute         directoryPath = new DirectoryPathAbsolute(@"C:\Dir1");
            FilePathAbsolute filePath = new FilePathAbsolute(@"c:\dir1\Dir2\file.txt");

            dico.Add(directoryPath, directoryPath.Path);
            dico.Add(filePath, filePath.Path);
            Assert.IsTrue(dico[filePath] == @"c:\dir1\Dir2\file.txt");
        }
        public void Test_GetHashCodeThroughDictionary()
        {
            Dictionary<BasePath, string> dico = new Dictionary<BasePath, string>();
             DirectoryPathAbsolute directoryPath = new DirectoryPathAbsolute(@"C:\Dir1");
             FilePathAbsolute filePath = new FilePathAbsolute(@"c:\dir1\Dir2\file.txt");

             dico.Add(directoryPath, directoryPath.Path);
             dico.Add(filePath, filePath.Path);
             Assert.IsTrue(dico[filePath] == @"c:\dir1\Dir2\file.txt");
        }
 public void Test_GetHashCodeThroughDictionary_ErrorOnPathValue()
 {
     Dictionary<BasePath, string> dico = new Dictionary<BasePath, string>();
      FilePathAbsolute filePath1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
      FilePathAbsolute filePath2 = new FilePathAbsolute(@"c:\dir1\file.txt");
      Assert.IsTrue(filePath1 == filePath2);
      Assert.IsTrue(filePath1.GetHashCode() == filePath2.GetHashCode());
      dico.Add(filePath1, filePath1.Path);
      dico.Add(filePath2, filePath2.Path); // <- filePath1 & filePath2 are 2 different object with same value
 }
Exemple #18
0
        public void Test_EmptyFilePathAbsolute()
        {
            //Debug.Assert(false);
            FilePathAbsolute filePath = FilePathAbsolute.Empty;

            Assert.IsTrue(filePath.IsEmpty);
            Assert.IsTrue(filePath.IsAbsolutePath);
            Assert.IsTrue(filePath.IsFilePath);
            Assert.IsFalse(filePath.IsDirectoryPath);
        }
Exemple #19
0
      public void Test_Drive() {
         DirectoryPathAbsolute directoryPathAbsolute = new DirectoryPathAbsolute(@"C:\Dir1");
         Assert.IsTrue(directoryPathAbsolute.Drive == "C");
         directoryPathAbsolute = new DirectoryPathAbsolute(@"c:\Dir1");
         Assert.IsTrue(directoryPathAbsolute.Drive == "c");

         FilePathAbsolute filePathAbsolute = new FilePathAbsolute(@"C:\Dir1\File.txt");
         Assert.IsTrue(filePathAbsolute.Drive == "C");
         filePathAbsolute = new FilePathAbsolute(@"c:\Dir1\File.txt");
         Assert.IsTrue(filePathAbsolute.Drive == "c");
      }
        public void Test_GetHashCodeThroughDictionary_ErrorOnPathValue()
        {
            Dictionary <BasePath, string> dico = new Dictionary <BasePath, string>();
            FilePathAbsolute filePath1         = new FilePathAbsolute(@"C:\Dir1\File.txt");
            FilePathAbsolute filePath2         = new FilePathAbsolute(@"c:\dir1\file.txt");

            Assert.IsTrue(filePath1 == filePath2);
            Assert.IsTrue(filePath1.GetHashCode() == filePath2.GetHashCode());
            dico.Add(filePath1, filePath1.Path);
            dico.Add(filePath2, filePath2.Path); // <- filePath1 & filePath2 are 2 different object with same value
        }
Exemple #21
0
        public void Test_Drive()
        {
            DirectoryPathAbsolute directoryPathAbsolute = new DirectoryPathAbsolute(@"C:\Dir1");

            Assert.IsTrue(directoryPathAbsolute.Drive == "C");
            directoryPathAbsolute = new DirectoryPathAbsolute(@"c:\Dir1");
            Assert.IsTrue(directoryPathAbsolute.Drive == "c");

            FilePathAbsolute filePathAbsolute = new FilePathAbsolute(@"C:\Dir1\File.txt");

            Assert.IsTrue(filePathAbsolute.Drive == "C");
            filePathAbsolute = new FilePathAbsolute(@"c:\Dir1\File.txt");
            Assert.IsTrue(filePathAbsolute.Drive == "c");
        }
Exemple #22
0
        public void Test_DirInfo_FileInfo_ChildrenOfDir()
        {
            DirForTest.EnsureDirForTestExistAndEmpty();
             string dirForTestPath = DirForTest.Dir;
             DirectoryPathAbsolute directoryPathAbsolute = new DirectoryPathAbsolute(dirForTestPath);
             DirectoryInfo directoryInfo = directoryPathAbsolute.DirectoryInfo;
             Assert.IsTrue(directoryInfo != null);

             DirForTest.CopyExecutingAssemblyFileInDirForTest();
             string dirForTestWithExecutingAssemblyFilePath = DirForTest.ExecutingAssemblyFilePathInDirForTest;
             FilePathAbsolute filePathAbsolute = new FilePathAbsolute(dirForTestWithExecutingAssemblyFilePath);
             FileInfo fileInfo = filePathAbsolute.FileInfo;
             Assert.IsTrue(fileInfo != null);
        }
Exemple #23
0
        public void Test_NormalizePath()
        {
            FilePath path = new FilePathRelative(@".\File.txt");

            Assert.IsTrue(path.Path == @".\File.txt");

            path = new FilePathRelative(@".\\File.txt\\");
            Assert.IsTrue(path.Path == @".\File.txt");

            path = new FilePathRelative(@".\/dir1\//\dir2\/dir3///\File.txt/");
            Assert.IsTrue(path.Path == @".\dir1\dir2\dir3\File.txt");

            path = new FilePathAbsolute(@"C:/dir1/dir2/\File.txt");
            Assert.IsTrue(path.Path == @"C:\dir1\dir2\File.txt");
        }
Exemple #24
0
        public void Test_DirInfo_FileInfo_ChildrenOfDir()
        {
            DirForTest.EnsureDirForTestExistAndEmpty();
            string dirForTestPath = DirForTest.Dir;
            DirectoryPathAbsolute directoryPathAbsolute = new DirectoryPathAbsolute(dirForTestPath);
            DirectoryInfo         directoryInfo         = directoryPathAbsolute.DirectoryInfo;

            Assert.IsTrue(directoryInfo != null);

            DirForTest.CopyExecutingAssemblyFileInDirForTest();
            string           dirForTestWithExecutingAssemblyFilePath = DirForTest.ExecutingAssemblyFilePathInDirForTest;
            FilePathAbsolute filePathAbsolute = new FilePathAbsolute(dirForTestWithExecutingAssemblyFilePath);
            FileInfo         fileInfo         = filePathAbsolute.FileInfo;

            Assert.IsTrue(fileInfo != null);
        }
Exemple #25
0
      public void Test_Exist() {
         DirForTest.Delete();
         string dirForTestPath = DirForTest.Dir;
         DirectoryPathAbsolute directoryPathAbsolute = new DirectoryPathAbsolute(dirForTestPath);
         Assert.IsFalse(directoryPathAbsolute.Exists);

         DirForTest.EnsureDirForTestExistAndEmpty();
         Assert.IsTrue(directoryPathAbsolute.Exists);

         string dirForTestWithExecutingAssemblyFilePath = DirForTest.ExecutingAssemblyFilePathInDirForTest;
         FilePathAbsolute filePathAbsolute = new FilePathAbsolute(dirForTestWithExecutingAssemblyFilePath);
         Assert.IsFalse(filePathAbsolute.Exists);

         DirForTest.CopyExecutingAssemblyFileInDirForTest();
         Assert.IsTrue(filePathAbsolute.Exists);
      }
Exemple #26
0
        public void Test_ParentDirectoryPath()
        {
            DirectoryPath path = new FilePathRelative(@".\File.txt").ParentDirectoryPath;

            Assert.IsTrue(path.Path == @".");

            path = new FilePathAbsolute(@"C:\File.txt").ParentDirectoryPath;
            Assert.IsTrue(path.Path == @"C:");

            path = new FilePathRelative(@".\\File.txt").ParentDirectoryPath;
            Assert.IsTrue(path.Path == @".");

            path = new FilePathAbsolute(@"C:\\\\File.txt").ParentDirectoryPath;
            Assert.IsTrue(path.Path == @"C:");

            path = new FilePathAbsolute(@"C:\dir1\\//dir2\File.txt").ParentDirectoryPath;
            Assert.IsTrue(path.Path == @"C:\dir1\dir2");
        }
Exemple #27
0
        public void Test_FileName()
        {
            string fileName = new FilePathRelative(@".\File.txt").FileName;

            Assert.IsTrue(fileName == @"File.txt");

            fileName = new FilePathAbsolute(@"C:\File.txt").FileName;
            Assert.IsTrue(fileName == @"File.txt");

            fileName = new FilePathRelative(@".\\File.txt").FileName;
            Assert.IsTrue(fileName == @"File.txt");

            fileName = new FilePathAbsolute(@"C:\\\\File.txt").FileName;
            Assert.IsTrue(fileName == @"File.txt");

            fileName = new FilePathAbsolute(@"C:\dir1\\//dir2\File.txt").FileName;
            Assert.IsTrue(fileName == @"File.txt");
        }
Exemple #28
0
        public void Test_PathModeOk()
        {
            FilePath path = new FilePathRelative(@".\File.txt");

            Assert.IsTrue(path.IsRelativePath);
            //Assert.IsTrue(path.ToString() == @".\File.txt");

            path = new FilePathAbsolute(@"C:\File.txt");
            Assert.IsTrue(path.IsAbsolutePath);

            path = new FilePathAbsolute(@"c:\File.txt");
            Assert.IsTrue(path.IsAbsolutePath);

            path = new FilePathRelative(@".\dir...1\File.txt");
            Assert.IsTrue(path.IsRelativePath);

            path = new FilePathAbsolute(@"C:\dir...1\File.txt");
            Assert.IsTrue(path.IsAbsolutePath);
        }
Exemple #29
0
        public void Test_Exist()
        {
            DirForTest.Delete();
            string dirForTestPath = DirForTest.Dir;
            DirectoryPathAbsolute directoryPathAbsolute = new DirectoryPathAbsolute(dirForTestPath);

            Assert.IsFalse(directoryPathAbsolute.Exists);

            DirForTest.EnsureDirForTestExistAndEmpty();
            Assert.IsTrue(directoryPathAbsolute.Exists);

            string           dirForTestWithExecutingAssemblyFilePath = DirForTest.ExecutingAssemblyFilePathInDirForTest;
            FilePathAbsolute filePathAbsolute = new FilePathAbsolute(dirForTestWithExecutingAssemblyFilePath);

            Assert.IsFalse(filePathAbsolute.Exists);

            DirForTest.CopyExecutingAssemblyFileInDirForTest();
            Assert.IsTrue(filePathAbsolute.Exists);
        }
Exemple #30
0
        public void Test_FileExtension()
        {
            FilePath filePath = new FilePathRelative(@".\File.txt");

            Assert.IsTrue(filePath.FileExtension == @".txt");
            Assert.IsTrue(filePath.HasExtension(@".txt"));
            Assert.IsTrue(filePath.HasExtension(@".TxT"));
            Assert.IsTrue(filePath.HasExtension(@".TXT"));

            filePath = new FilePathRelative(@".\File");
            Assert.IsTrue(filePath.FileExtension == string.Empty);

            filePath = new FilePathRelative(@".\File.");
            Assert.IsTrue(filePath.FileExtension == string.Empty);

            filePath = new FilePathAbsolute(@"C:\dir1\\//dir2\File.txt.Exe");
            Assert.IsTrue(filePath.FileExtension == @".Exe");
            Assert.IsTrue(filePath.HasExtension(@".exe"));
        }
Exemple #31
0
 public void Test_InvalidInputPathNull()
 {
     string reason;
      Assert.IsFalse(PathHelper.IsValidAbsolutePath(null, out reason));
      FilePath filePath = new FilePathAbsolute(null);
 }
Exemple #32
0
        public void Test_NormalizePath()
        {
            FilePath path = new FilePathRelative(@".\File.txt");
             Assert.IsTrue(path.Path == @".\File.txt");

             path = new FilePathRelative(@".\\File.txt\\");
             Assert.IsTrue(path.Path == @".\File.txt");

             path = new FilePathRelative(@".\/dir1\//\dir2\/dir3///\File.txt/");
             Assert.IsTrue(path.Path == @".\dir1\dir2\dir3\File.txt");

             path = new FilePathAbsolute(@"C:/dir1/dir2/\File.txt");
             Assert.IsTrue(path.Path == @"C:\dir1\dir2\File.txt");
        }
Exemple #33
0
        public void Test_PathEquality()
        {
            //
            // filePathRelative
            //
            FilePathRelative filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
            FilePathRelative filePathRelative2 = new FilePathRelative(@"..\\dir1//file.TXT");

            Assert.IsTrue(filePathRelative1.Equals(filePathRelative2));
            Assert.IsTrue(filePathRelative1 == filePathRelative2);

            filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
            filePathRelative2 = new FilePathRelative(@".\Dir1\File.txt");
            Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
            Assert.IsFalse(filePathRelative1 == filePathRelative2);

            filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
            filePathRelative2 = new FilePathRelative(@"..\Dir1\Dir2\File.txt");
            Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
            Assert.IsFalse(filePathRelative1 == filePathRelative2);

            filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
            filePathRelative2 = new FilePathRelative(@"..\Dir1\File.tx");
            Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
            Assert.IsFalse(filePathRelative1 == filePathRelative2);

            //
            // filePathAbsolute
            //
            FilePathAbsolute filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
            FilePathAbsolute filePathAbsolute2 = new FilePathAbsolute(@"C:\\dir1//file.TXT");

            Assert.IsTrue(filePathAbsolute1.Equals(filePathAbsolute2));
            Assert.IsTrue(filePathAbsolute1 == filePathAbsolute2);

            filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
            filePathAbsolute2 = new FilePathAbsolute(@"D:\Dir1\File.txt");
            Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
            Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

            filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
            filePathAbsolute2 = new FilePathAbsolute(@"C:\Dir1\Dir2\File.txt");
            Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
            Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

            filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
            filePathAbsolute2 = new FilePathAbsolute(@"C:\Dir1\File.tx");
            Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
            Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

            //
            // Mix between filePathAbsolute and filePathRelative
            //
            filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
            filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
            Assert.IsFalse(filePathAbsolute1.Equals(filePathRelative1));
            Assert.IsFalse(filePathAbsolute1 == filePathRelative1);

            //
            // Mix between directoryPath and filePath
            //
            DirectoryPathAbsolute directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\File");

            filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File");
            Assert.IsFalse(directoryPathAbsolute1.Equals(filePathAbsolute1));
            Assert.IsFalse(filePathAbsolute1.Equals(directoryPathAbsolute1));
            Assert.IsFalse(filePathAbsolute1 == directoryPathAbsolute1);

            DirectoryPathRelative directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\File");

            filePathRelative1 = new FilePathRelative(@"..\Dir1\File");
            Assert.IsFalse(directoryPathRelative1.Equals(filePathRelative1));
            Assert.IsFalse(filePathRelative1.Equals(directoryPathRelative1));
            Assert.IsFalse(filePathRelative1 == directoryPathRelative1);
        }
Exemple #34
0
 public void Test_InvalidInputAbsolutePath4()
 {
     FilePath filePath = new FilePathAbsolute(@"C:File.txt");
 }
Exemple #35
0
        public void Test_PathModeOk()
        {
            FilePath path = new FilePathRelative(@".\File.txt");
             Assert.IsTrue(path.IsRelativePath);
             //Assert.IsTrue(path.ToString() == @".\File.txt");

             path = new FilePathAbsolute(@"C:\File.txt");
             Assert.IsTrue(path.IsAbsolutePath);

             path = new FilePathAbsolute(@"c:\File.txt");
             Assert.IsTrue(path.IsAbsolutePath);

             path = new FilePathRelative(@".\dir...1\File.txt");
             Assert.IsTrue(path.IsRelativePath);

             path = new FilePathAbsolute(@"C:\dir...1\File.txt");
             Assert.IsTrue(path.IsAbsolutePath);
        }
Exemple #36
0
 /// <summary>
 /// Returns a relative path string from a full path.
 /// </summary>
 /// <returns></returns>
 public static string GetRelativePath(string rootDir, string filePath)
 {
     if (rootDir == null || filePath == null) return filePath;
     if (IsSubdirectory(rootDir, filePath))
     {
         var filePathAbsolute = new FilePathAbsolute(filePath);
         var directoryPathAbsolute = new DirectoryPathAbsolute(rootDir);
         FilePathRelative filePathRelative = filePathAbsolute.GetPathRelativeFrom(directoryPathAbsolute);
         return filePathRelative.Path;
     }
     return filePath;
 }
Exemple #37
0
   static void Main(string[] args) {
      FilePathAbsolute filePathAbsolute1, filePathAbsolute2;
      FilePathRelative filePathRelative1;
      DirectoryPathAbsolute directoryPathAbsolute1;
      DirectoryPathRelative directoryPathRelative1;



      //  Path normalization
      filePathAbsolute1 = new FilePathAbsolute(@"C:/Dir1\\File.txt");
      Debug.Assert(filePathAbsolute1.Path == @"C:\Dir1\File.txt");

      directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:/Dir1\\Dir2\");
      Debug.Assert(directoryPathAbsolute1.Path == @"C:\Dir1\Dir2");

      directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\..\Dir2\.");
      Debug.Assert(directoryPathAbsolute1.Path == @"C:\Dir2");



      // Path comparison
      filePathAbsolute1 = new FilePathAbsolute(@"C:/Dir1\\File.txt");
      filePathAbsolute2 = new FilePathAbsolute(@"C:\DIR1\FILE.TXT");
      Debug.Assert(filePathAbsolute1.Equals(filePathAbsolute2));
      Debug.Assert(filePathAbsolute1 == filePathAbsolute2);



      // Relative -> Absolute path conversion
      filePathRelative1 = new FilePathRelative(@"..\..\Dir1\File.txt");
      directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir2\Dir3\Dir4");
      filePathAbsolute1 = filePathRelative1.GetAbsolutePathFrom(directoryPathAbsolute1);
      Debug.Assert( filePathAbsolute1.Path == @"C:\Dir2\Dir1\File.txt");



      // Absolute -> Relative path conversion
      filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
      directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir2\Dir3\Dir4");
      filePathRelative1 = filePathAbsolute1.GetPathRelativeFrom(directoryPathAbsolute1);
      Debug.Assert(filePathRelative1.Path == @"..\..\..\Dir1\File.txt");



      // Path string validation
      string reason;
      Debug.Assert(PathHelper.IsValidAbsolutePath(@"C:\Dir2\Dir1", out reason));
      Debug.Assert(!PathHelper.IsValidAbsolutePath(@"C:\..\Dir1", out reason));
      Debug.Assert(!PathHelper.IsValidAbsolutePath(@".\Dir1", out reason));
      Debug.Assert(!PathHelper.IsValidAbsolutePath(@"1:\Dir1", out reason));
      Debug.Assert(PathHelper.IsValidRelativePath(@".\Dir1\Dir2", out reason));
      Debug.Assert(PathHelper.IsValidRelativePath(@"..\Dir1\Dir2", out reason));
      Debug.Assert(PathHelper.IsValidRelativePath(@".\Dir1\..\Dir2", out reason));
      Debug.Assert(!PathHelper.IsValidRelativePath(@".\Dir1\..\..\Dir2", out reason));
      Debug.Assert(!PathHelper.IsValidRelativePath(@"C:\Dir1\Dir2", out reason));



      // File name & extension
      filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.cs.Txt");
      Debug.Assert(filePathAbsolute1.FileName == "File.cs.Txt");
      Debug.Assert(filePathAbsolute1.FileNameWithoutExtension == "File.cs");
      Debug.Assert(filePathAbsolute1.FileExtension == ".Txt");
      Debug.Assert(filePathAbsolute1.HasExtension(".txt"));



      // Path browsing
      filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.cs.Txt");
      Debug.Assert(filePathAbsolute1.ParentDirectoryPath.Path == @"C:\Dir1");
      Debug.Assert(filePathAbsolute1.GetBrotherFileWithName("File.xml").Path == @"C:\Dir1\File.xml");
      Debug.Assert(filePathAbsolute1.ParentDirectoryPath.GetChildDirectoryWithName("Dir2").Path == @"C:\Dir1\Dir2");
      Debug.Assert(filePathAbsolute1.ParentDirectoryPath.GetChildDirectoryWithName("..").Path == @"C:");

      directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\Dir2");
      Debug.Assert(directoryPathRelative1.ParentDirectoryPath.Path == @"..\Dir1");



      // Path rebasing
      directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir3");
      DirectoryPathAbsolute directoryPathAbsolute2 = new DirectoryPathAbsolute(@"E:\Dir4\Dir1");
      DirectoryPathAbsolute rebasedPath;
      PathHelper.TryRebasePath(directoryPathAbsolute1, directoryPathAbsolute2, out rebasedPath);
      Debug.Assert(rebasedPath.Path == @"E:\Dir4\Dir1\Dir2\Dir3");


      // List of path  ListOfPathsEquals \ Contains \ TryGetCommonRootDirectory 
      List<DirectoryPathAbsolute> list1 = new List<DirectoryPathAbsolute>();
      List<DirectoryPathAbsolute> list2 = new List<DirectoryPathAbsolute>();
      list1.Add(new DirectoryPathAbsolute(@"C:\Dir1\Dir2"));
      list2.Add(new DirectoryPathAbsolute(@"c:\dir1\dir2"));
      list1.Add(new DirectoryPathAbsolute(@"C:\Dir1\Dir3\Dir4"));
      list2.Add(new DirectoryPathAbsolute(@"c:\dir1\dir3\dir4"));
      Debug.Assert(ListOfPathHelper.ListOfPathsEquals(list1, list2));
      Debug.Assert(ListOfPathHelper.Contains(list1, new DirectoryPathAbsolute(@"C:\Dir1\dir2")));
      ListOfPathHelper.TryGetCommonRootDirectory(list1, out directoryPathAbsolute1);
      Debug.Assert(directoryPathAbsolute1.Path == @"C:\Dir1");


      // List of path   GetListOfUniqueDirsAndUniqueFileNames
      List<FilePathAbsolute> list = new List<FilePathAbsolute>();
      list.Add(new FilePathAbsolute(@"E:\Dir1\Dir2\File1.txt"));
      list.Add(new FilePathAbsolute(@"E:\dir1\dir2\File2.txt"));
      list.Add(new FilePathAbsolute(@"E:\Dir1\Dir2\Dir3\file2.txt"));
      List<DirectoryPathAbsolute> listOfUniqueDirs;
      List<string> listOfUniqueFileNames;
      ListOfPathHelper.GetListOfUniqueDirsAndUniqueFileNames(list, out listOfUniqueDirs, out listOfUniqueFileNames);
      Debug.Assert(listOfUniqueDirs.Count == 2);
      Debug.Assert(listOfUniqueDirs[0].Path == @"E:\Dir1\Dir2");
      Debug.Assert(listOfUniqueDirs[1].Path == @"E:\Dir1\Dir2\Dir3");
      Debug.Assert(listOfUniqueFileNames.Count == 2);
      Debug.Assert(listOfUniqueFileNames[0] == "File1.txt");
      Debug.Assert(listOfUniqueFileNames[1] == "File2.txt");


      // Interaction with System.IO API
      filePathAbsolute1 = new FilePathAbsolute(
         System.Reflection.Assembly.GetExecutingAssembly().Location);
      Debug.Assert(filePathAbsolute1.Exists);
      System.IO.FileInfo fileInfo = filePathAbsolute1.FileInfo;

      directoryPathAbsolute1 = filePathAbsolute1.ParentDirectoryPath as DirectoryPathAbsolute;
      Debug.Assert(directoryPathAbsolute1.Exists);
      System.IO.DirectoryInfo directoryInfo = directoryPathAbsolute1.DirectoryInfo;

      List<DirectoryPathAbsolute> listSubDir = directoryPathAbsolute1.ChildrenDirectoriesPath;
      List<FilePathAbsolute> listSubFile = directoryPathAbsolute1.ChildrenFilesPath;

   }
Exemple #38
0
 /// <summary>
 /// Compares two directory strings
 /// </summary>
 /// <param name="rootDir"></param>
 /// <param name="searchItem"></param>
 /// <returns></returns>
 public static bool CompareDirectories(string rootDir, string searchItem)
 {
     var root = new FilePathAbsolute(Path.GetFullPath(rootDir));
     var search = new FilePathAbsolute(Path.GetFullPath(searchItem));
     return (root == search);
 }
    private void GetBat()
    {
      Microsoft.Win32.OpenFileDialog openFileDialog2 = new Microsoft.Win32.OpenFileDialog();
      openFileDialog2.Filter = "Known file types (*.bat)|*.bat";
      openFileDialog2.Title = "Select a batch file that will be run after completion of the model run";

      if (openFileDialog2.ShowDialog().Value)
      {
        DirectoryPathAbsolute dp = new DirectoryPathAbsolute(Path.GetDirectoryName(models.First().DisplayName));
        FilePathAbsolute fp = new FilePathAbsolute(openFileDialog2.FileName);
        postProcessBat = fp.GetPathRelativeFrom(dp);
        RaisePropertyChanged("PostProcessBat");

      }
    }
Exemple #40
0
		/// <summary>
		/// Verifies if the two absolute file paths are the same.
		/// </summary>
		/// <param name="fileName1">File path 1</param>
		/// <param name="fileName2">File path 2</param>
		/// <returns></returns>
		public static bool IsTheSameFile(string fileName1, string fileName2)
		{
			FilePathAbsolute filePathAbsolute1 = new FilePathAbsolute(fileName1);
			FilePathAbsolute filePathAbsolute2 = new FilePathAbsolute(fileName2);
			return filePathAbsolute1 == filePathAbsolute2;
		}
        private void menuFileOpen_Click(object sender, System.EventArgs e)
        {
            openFileDialog.Filter = "Supported Files |*.ifo;*.xpl;*.mpls;*.txt;*.xml;*.chapters|DVD IFO Files (*.ifo)|*.ifo|HD-DVD Xml Playlist Files (*.xpl)|*.xpl|Blu-Ray Playlist Files (*.mpls)|*.mpls|Chapters Text Files (*.txt)|*.txt|Matroska XML Files (*.xml)|*.xml|Chapters Files (*.chapters)|*.chapters|All files (*.*)|*.*";
              openFileDialog.FilterIndex = 0;
              openFileDialog.AutoUpgradeEnabled = true;

              if (!string.IsNullOrEmpty(Settings.Default.LastOpenDir))
              {
            FilePathAbsolute last = new FilePathAbsolute(Settings.Default.LastOpenDir);
            if (last.Exists)
              openFileDialog.InitialDirectory = last.Path;
            else if (last.ParentDirectoryPath.Exists)
              openFileDialog.InitialDirectory = last.ParentDirectoryPath.Path;
            else if (last.ParentDirectoryPath.ParentDirectoryPath.Exists)
              openFileDialog.InitialDirectory = last.ParentDirectoryPath.ParentDirectoryPath.Path;
              }
              openFileDialog.RestoreDirectory = true;

              if (openFileDialog.ShowDialog() == DialogResult.OK)
              {
            Settings.Default.LastOpenDir = new FilePathAbsolute(openFileDialog.FileName).Path;
            Settings.Default.Save();
            OpenFile(openFileDialog.FileName);
              }
        }
Exemple #42
0
 public void Test_InvalidInputPathEmpty()
 {
     string reason;
      Assert.IsFalse(PathHelper.IsValidAbsolutePath(string.Empty, out reason));
      FilePath filePath = new FilePathAbsolute(string.Empty);
 }
        private static string GetFilePathAbsoluteFrom(string baseAbsolutePath, string relativePath)
        {
            var absoluteBase = new FilePathAbsolute(baseAbsolutePath).ParentDirectoryPath;
            var relativeFilePath = new FilePathRelative(relativePath);

            return relativeFilePath.GetAbsolutePathFrom(absoluteBase).Path;
        }
Exemple #44
0
 /// <summary>
 /// Returns a relative path string from a full path.
 /// </summary>
 /// <returns></returns>
 public static string GetRelativePath(string rootDir, string filePath)
 {
     if (rootDir == null || filePath == null) return filePath;
     if (IsSubdirectory(rootDir, filePath))
     {
         if (rootDir.StartsWith("\\")) //network disk?
         {
             return "." + filePath.Substring(rootDir.Length);
         }
         else
         {
             var filePathAbsolute = new FilePathAbsolute(filePath);
             var directoryPathAbsolute = new DirectoryPathAbsolute(rootDir);
             FilePathRelative filePathRelative = filePathAbsolute.GetPathRelativeFrom(directoryPathAbsolute);
             return filePathRelative.Path;
         }
     }
     return filePath;
 }
    private void GetMshe()
    {
      Microsoft.Win32.OpenFileDialog openFileDialog2 = new Microsoft.Win32.OpenFileDialog();
      openFileDialog2.Filter = "Known file types (*.she)|*.she";
      openFileDialog2.Title = "Select the Mike She file corresponding to the first .pst-file";

      if (openFileDialog2.ShowDialog().Value)
      {
        DirectoryPathAbsolute dp = new DirectoryPathAbsolute(Path.GetDirectoryName(models.First().DisplayName));
        FilePathAbsolute fp = new FilePathAbsolute(openFileDialog2.FileName);
        mikeSheFileName = fp.GetPathRelativeFrom(dp);
        RaisePropertyChanged("MikeSheFileName");

      }
    }
 private static string GetFilePathRelativeFrom(string baseAbsolutePath, string absolutePath)
 {
     var currentAbsoluteDirectoryPath = new FilePathAbsolute(baseAbsolutePath).ParentDirectoryPath;
     return new FilePathAbsolute(absolutePath).GetPathRelativeFrom(currentAbsoluteDirectoryPath).Path;
 }
Exemple #47
0
 public void Test_InvalidInputPathNoParentDir()
 {
     string reason;
      Assert.IsFalse(PathHelper.IsValidAbsolutePath(@"File.txt", out reason));
      FilePath filePath = new FilePathAbsolute("File.txt");
 }
    private void Run()
    {
      DirectoryPathAbsolute dp = new DirectoryPathAbsolute(Path.GetDirectoryName(models.First().DisplayName));

      ScenariosToRun = new ConcurrentStack<ScenarioRun>(Runs.Where(var=>var.RunThis));
      foreach (var v in models)
      {
        v.ResultFileNames.Clear();
        DirectoryPathAbsolute dp2 = new DirectoryPathAbsolute(Path.GetDirectoryName(v.DisplayName));

        foreach (var file in FileNamesToCopy)
        {
          FilePathAbsolute fp = new FilePathAbsolute(file);
          var rp = fp.GetPathRelativeFrom(dp);
          v.ResultFileNames.Add(rp.GetAbsolutePathFrom(dp2).Path);
        }

        if (v is PestModel)
        {
          ((PestModel)v).MsheFileName = mikeSheFileName.GetAbsolutePathFrom(dp2).Path;
          ((PestModel)v).PostProcessBatFile = postProcessBat.GetAbsolutePathFrom(dp2).Path;
        }
        Thread.Sleep(TimeSpan.FromMinutes(1));
        RunNext(v);
      }
    }
Exemple #49
0
 public void Test_InvalidInputAbsoluteURNPath()
 {
     string reason;
      Assert.IsFalse(PathHelper.IsValidAbsolutePath(@"http://www.NDepend.com/File.txt", out reason));
      FilePath filePath = new FilePathAbsolute(@"http://www.NDepend.com/File.txt");
 }
Exemple #50
0
 public void Test_InvalidInputAbsolutePath4()
 {
     FilePath filePath = new FilePathAbsolute(@"C:File.txt");
 }
Exemple #51
0
 public void Test_InvalidInputAbsolutePath3()
 {
     string reason;
      Assert.IsFalse(PathHelper.IsValidAbsolutePath(@"1:\File.txt", out reason));
      FilePath filePath = new FilePathAbsolute(@"1:\File.txt");
 }
Exemple #52
0
        public void Test_ParentDirectoryPath()
        {
            DirectoryPath path = new FilePathRelative(@".\File.txt").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @".");

             path = new FilePathAbsolute(@"C:\File.txt").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @"C:");

             path = new FilePathRelative(@".\\File.txt").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @".");

             path = new FilePathAbsolute(@"C:\\\\File.txt").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @"C:");

             path = new FilePathAbsolute(@"C:\dir1\\//dir2\File.txt").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @"C:\dir1\dir2");
        }
Exemple #53
0
        public void Test_PathEquality()
        {
            //
             // filePathRelative
             //
             FilePathRelative filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
             FilePathRelative filePathRelative2 = new FilePathRelative(@"..\\dir1//file.TXT");
             Assert.IsTrue(filePathRelative1.Equals(filePathRelative2));
             Assert.IsTrue(filePathRelative1 == filePathRelative2);

             filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
             filePathRelative2 = new FilePathRelative(@".\Dir1\File.txt");
             Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
             Assert.IsFalse(filePathRelative1 == filePathRelative2);

             filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
             filePathRelative2 = new FilePathRelative(@"..\Dir1\Dir2\File.txt");
             Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
             Assert.IsFalse(filePathRelative1 == filePathRelative2);

             filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
             filePathRelative2 = new FilePathRelative(@"..\Dir1\File.tx");
             Assert.IsFalse(filePathRelative1.Equals(filePathRelative2));
             Assert.IsFalse(filePathRelative1 == filePathRelative2);

             //
             // filePathAbsolute
             //
             FilePathAbsolute filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
             FilePathAbsolute filePathAbsolute2 = new FilePathAbsolute(@"C:\\dir1//file.TXT");
             Assert.IsTrue(filePathAbsolute1.Equals(filePathAbsolute2));
             Assert.IsTrue(filePathAbsolute1 == filePathAbsolute2);

             filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
             filePathAbsolute2 = new FilePathAbsolute(@"D:\Dir1\File.txt");
             Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
             Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

             filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
             filePathAbsolute2 = new FilePathAbsolute(@"C:\Dir1\Dir2\File.txt");
             Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
             Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

             filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
             filePathAbsolute2 = new FilePathAbsolute(@"C:\Dir1\File.tx");
             Assert.IsFalse(filePathAbsolute1.Equals(filePathAbsolute2));
             Assert.IsFalse(filePathAbsolute1 == filePathAbsolute2);

             //
             // Mix between filePathAbsolute and filePathRelative
             //
             filePathRelative1 = new FilePathRelative(@"..\Dir1\File.txt");
             filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File.txt");
             Assert.IsFalse(filePathAbsolute1.Equals(filePathRelative1));
             Assert.IsFalse(filePathAbsolute1 == filePathRelative1);

             //
             // Mix between directoryPath and filePath
             //
             DirectoryPathAbsolute directoryPathAbsolute1 = new DirectoryPathAbsolute(@"C:\Dir1\File");
             filePathAbsolute1 = new FilePathAbsolute(@"C:\Dir1\File");
             Assert.IsFalse(directoryPathAbsolute1.Equals(filePathAbsolute1));
             Assert.IsFalse(filePathAbsolute1.Equals(directoryPathAbsolute1));
             Assert.IsFalse(filePathAbsolute1 == directoryPathAbsolute1);

             DirectoryPathRelative directoryPathRelative1 = new DirectoryPathRelative(@"..\Dir1\File");
             filePathRelative1 = new FilePathRelative(@"..\Dir1\File");
             Assert.IsFalse(directoryPathRelative1.Equals(filePathRelative1));
             Assert.IsFalse(filePathRelative1.Equals(directoryPathRelative1));
             Assert.IsFalse(filePathRelative1 == directoryPathRelative1);
        }
Exemple #54
0
 public void Test_DriveFileEmpty()
 {
     FilePathAbsolute filePathAbsolute = FilePathAbsolute.Empty;
     string           drive            = filePathAbsolute.Drive;
 }
Exemple #55
0
        private static void ParseSolutionItem(ISolutionInfo item, List<FilePathAbsolute> filePathListe)
        {
            FilePathAbsolute solution = new FilePathAbsolute(item.SolutionFile.FullName);

            foreach (var projectInfo in item.ProjectListe)
            {
                ParseProjectInfo(projectInfo, solution, filePathListe);
            }

            filePathListe.Add(solution);
        }
 public void Test_InvalidInputPathBadFormatting3()
 {
     string reason;
      Assert.IsFalse(PathHelper.IsValidAbsolutePath(@"C:\..\Dir1\", out reason));
      FilePath filePath = new FilePathAbsolute(@"C:\..\Dir1\");
 }