Beispiel #1
0
        public void Test_InvalidInputPathBadFormatting14()
        {
            string reason;

            Assert.IsFalse(PathHelper.IsValidRelativePath(@"..\Dir1\..\..\Dir1\File.txt", out reason));
            FilePath filePath = new FilePathRelative(@"..\Dir1\..\..\Dir1\File.txt");
        }
Beispiel #2
0
        public void Test_GetAbsolutePathPathWithError6()
        {
            FilePathRelative directoryPathTo = new FilePathRelative(@"..\..\Dir1\File.txt");

            Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(null));
            directoryPathTo.GetAbsolutePathFrom(null);
        }
Beispiel #3
0
        public void Test_IncoherentPathModeException2()
        {
            string reason;

            Assert.IsFalse(PathHelper.IsValidRelativePath(@"C:\File.txt", out reason));
            FilePath filePath = new FilePathRelative(@"C:\File.txt");
        }
Beispiel #4
0
        public void Test_GetAbsolutePath()
        {
            FilePathRelative      filePathTo;
            DirectoryPathAbsolute directoryPathFrom;

            filePathTo        = new FilePathRelative(@"..\File.txt");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
            Assert.IsTrue(filePathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\File.txt");
            Assert.IsTrue(filePathTo.CanGetAbsolutePathFrom(directoryPathFrom));

            filePathTo        = new FilePathRelative(@".\File.txt");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
            Assert.IsTrue(filePathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1\File.txt");
            Assert.IsTrue(filePathTo.CanGetAbsolutePathFrom(directoryPathFrom));

            filePathTo        = new FilePathRelative(@"..\Dir2\File.txt");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
            Assert.IsTrue(filePathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir2\File.txt");
            Assert.IsTrue(filePathTo.CanGetAbsolutePathFrom(directoryPathFrom));

            filePathTo        = new FilePathRelative(@"..\..\Dir4\Dir5\File.txt");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir3");
            Assert.IsTrue(filePathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1\Dir4\Dir5\File.txt");
            Assert.IsTrue(filePathTo.CanGetAbsolutePathFrom(directoryPathFrom));

            filePathTo        = new FilePathRelative(@".\..\Dir4\Dir5\File.txt");
            directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir3");
            Assert.IsTrue(filePathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1\Dir2\Dir4\Dir5\File.txt");
            Assert.IsTrue(filePathTo.CanGetAbsolutePathFrom(directoryPathFrom));
        }
Beispiel #5
0
        public void Test_GetAbsolutePathPathWithError5()
        {
            FilePathRelative      directoryPathTo   = new FilePathRelative(@"..\..\Dir1\File.txt");
            DirectoryPathAbsolute directoryPathFrom = DirectoryPathAbsolute.Empty;

            Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));
            directoryPathTo.GetAbsolutePathFrom(directoryPathFrom);
        }
Beispiel #6
0
        public void Test_GetAbsolutePathPathWithError4()
        {
            FilePathRelative      directoryPathTo   = FilePathRelative.Empty;
            DirectoryPathAbsolute directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");

            Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));
            directoryPathTo.GetAbsolutePathFrom(directoryPathFrom);
        }
Beispiel #7
0
        public void Test_EmptyFilePathRelative()
        {
            FilePathRelative filePath = FilePathRelative.Empty;

            Assert.IsTrue(filePath.IsEmpty);
            Assert.IsTrue(filePath.IsRelativePath);
            Assert.IsTrue(filePath.IsFilePath);
            Assert.IsFalse(filePath.IsDirectoryPath);
        }
Beispiel #8
0
        public void Test_FileNameWithoutExtension()
        {
            FilePath filePath = new FilePathRelative(@".\File.txt");

            Assert.IsTrue(filePath.FileNameWithoutExtension == "File");

            filePath = new FilePathRelative(@".\File");
            Assert.IsTrue(filePath.FileNameWithoutExtension == "File");

            filePath = new FilePathRelative(@".\File.tmp.exe");
            Assert.IsTrue(filePath.FileNameWithoutExtension == "File.tmp");
        }
Beispiel #9
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");
        }
Beispiel #10
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");
        }
Beispiel #11
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");
        }
Beispiel #12
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);
        }
Beispiel #13
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"));
        }
Beispiel #14
0
        public void Test_FileNameWithoutExtension()
        {
            FilePath filePath = new FilePathRelative(@".\File.txt");
             Assert.IsTrue(filePath.FileNameWithoutExtension == "File");

             filePath = new FilePathRelative(@".\File");
             Assert.IsTrue(filePath.FileNameWithoutExtension == "File");

             filePath = new FilePathRelative(@".\File.tmp.exe");
             Assert.IsTrue(filePath.FileNameWithoutExtension == "File.tmp");
        }
Beispiel #15
0
        public void Test_GetAbsolutePath()
        {
            FilePathRelative filePathTo;
             DirectoryPathAbsolute directoryPathFrom;

             filePathTo = new FilePathRelative(@"..\File.txt");
             directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
             Assert.IsTrue(filePathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\File.txt");
             Assert.IsTrue(filePathTo.CanGetAbsolutePathFrom(directoryPathFrom));

             filePathTo = new FilePathRelative(@".\File.txt");
             directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
             Assert.IsTrue(filePathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1\File.txt");
             Assert.IsTrue(filePathTo.CanGetAbsolutePathFrom(directoryPathFrom));

             filePathTo = new FilePathRelative(@"..\Dir2\File.txt");
             directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1");
             Assert.IsTrue(filePathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir2\File.txt");
             Assert.IsTrue(filePathTo.CanGetAbsolutePathFrom(directoryPathFrom));

             filePathTo = new FilePathRelative(@"..\..\Dir4\Dir5\File.txt");
             directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir3");
             Assert.IsTrue(filePathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1\Dir4\Dir5\File.txt");
             Assert.IsTrue(filePathTo.CanGetAbsolutePathFrom(directoryPathFrom));

             filePathTo = new FilePathRelative(@".\..\Dir4\Dir5\File.txt");
             directoryPathFrom = new DirectoryPathAbsolute(@"C:\Dir1\Dir2\Dir3");
             Assert.IsTrue(filePathTo.GetAbsolutePathFrom(directoryPathFrom).Path == @"C:\Dir1\Dir2\Dir4\Dir5\File.txt");
             Assert.IsTrue(filePathTo.CanGetAbsolutePathFrom(directoryPathFrom));
        }
Beispiel #16
0
 public void Test_HasExtensionError1()
 {
     FilePath filePath = new FilePathRelative(@".\File");
      Assert.IsTrue(filePath.HasExtension(string.Empty));
 }
Beispiel #17
0
 public void Test_HasExtensionError3()
 {
     FilePath filePath = new FilePathRelative(@".\File.");
      Assert.IsTrue(filePath.HasExtension("."));
 }
Beispiel #18
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");
        }
    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");

      }
    }
Beispiel #20
0
        public void Test_ParentDirectoryPath()
        {
            DirectoryPath path = new FilePathRelative(@".\Dir1").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @".");

             path = new DirectoryPathRelative(@".\Dir1\\Dir2").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @".\Dir1");

             path = new DirectoryPathAbsolute(@"C:\Dir1").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @"C:");

             path = new DirectoryPathRelative(@".\\Dir1").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @".");

             path = new DirectoryPathAbsolute(@"C:\\\\Dir1\\Dir2").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @"C:\Dir1");

             path = new DirectoryPathAbsolute(@"C:\dir1\\//dir2\").ParentDirectoryPath;
             Assert.IsTrue(path.Path == @"C:\dir1");
        }
Beispiel #21
0
 public void Test_InvalidInputPathBadFormatting14()
 {
     string reason;
      Assert.IsFalse(PathHelper.IsValidRelativePath(@"..\Dir1\..\..\Dir1\", out reason));
      FilePath filePath = new FilePathRelative(@"..\Dir1\..\..\Dir1\");
 }
Beispiel #22
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);
        }
Beispiel #23
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);
        }
Beispiel #24
0
        public void Test_HasExtensionError1()
        {
            FilePath filePath = new FilePathRelative(@".\File");

            Assert.IsTrue(filePath.HasExtension(string.Empty));
        }
Beispiel #25
0
 public void Test_IncoherentPathModeException2()
 {
     string reason;
      Assert.IsFalse(PathHelper.IsValidRelativePath(@"C:\File.txt", out reason));
      FilePath filePath = new FilePathRelative(@"C:\File.txt");
 }
Beispiel #26
0
 public void Test_GetAbsolutePathPathWithError5()
 {
     FilePathRelative directoryPathTo = new FilePathRelative(@"..\..\Dir1\File.txt");
      DirectoryPathAbsolute directoryPathFrom = DirectoryPathAbsolute.Empty;
      Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(directoryPathFrom));
      directoryPathTo.GetAbsolutePathFrom(directoryPathFrom);
 }
Beispiel #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");
        }
Beispiel #28
0
        public void Test_HasExtensionError3()
        {
            FilePath filePath = new FilePathRelative(@".\File.");

            Assert.IsTrue(filePath.HasExtension("."));
        }
        private static string GetFilePathAbsoluteFrom(string baseAbsolutePath, string relativePath)
        {
            var absoluteBase = new FilePathAbsolute(baseAbsolutePath).ParentDirectoryPath;
            var relativeFilePath = new FilePathRelative(relativePath);

            return relativeFilePath.GetAbsolutePathFrom(absoluteBase).Path;
        }
    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");

      }
    }
Beispiel #31
0
 public void Test_GetAbsolutePathPathWithError6()
 {
     FilePathRelative directoryPathTo = new FilePathRelative(@"..\..\Dir1\File.txt");
      Assert.IsFalse(directoryPathTo.CanGetAbsolutePathFrom(null));
      directoryPathTo.GetAbsolutePathFrom(null);
 }
    private void FromXML(XDocument XDoc)
    {

      var Elem = XDoc.Element("ScenarioRuns");

      var m = Elem.Element("ModelFiles");
      if (m != null)
      {
        foreach (var f in m.Elements("FileName"))
        {
          this.LoadModel(f.Value);
        }
      }

      OutputDirectory = Elem.Element("OutputDirectory").Value;
      Prefix = Elem.Element("Prefix").Value;

      m = Elem.Element("MikeSheFileName");
      if (m != null)
      {
        mikeSheFileName = new FilePathRelative(m.Value);
        RaisePropertyChanged("MikeSheFileName");
      }

      m = Elem.Element("PostProcessBatFile");
      if (m != null)
      {
        postProcessBat = new FilePathRelative(m.Value);
        RaisePropertyChanged("PostProcessBat");
      }


      var fs = Elem.Element("FilesToCopy");
      if (fs != null)
      {
        foreach (var f in fs.Elements("FileName"))
        {
          this.FileNamesToCopy.Add(f.Value);
        }
      }


      var slf = Elem.Element("SimlabFileName");
      if (slf != null)
      {
        loadSimLab(slf.Value);
      }

      var sctorun = Elem.Element("ScenariosToRun");

      if (sctorun != null & Runs != null)
      {
        var splits = sctorun.Value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
        
        foreach (var r in Runs)
          r.RunThis = false;

        foreach (var s in splits)
        {          
          int index;
          if (int.TryParse(s, out index))
          {
            if (index <= Runs.Count)
            {
              var r = Runs.SingleOrDefault(var => var.Number == index);
              if (r != null)
                r.RunThis = true;
            }
          }
        }
      }
    }
Beispiel #33
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;

   }
Beispiel #34
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);
        }
Beispiel #35
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"));
        }