예제 #1
0
        public static string GetClosestExistingDirectory(string dir)
        {
            if (string.IsNullOrEmpty(dir))
            {
                return(null);
            }

            try
            {
                DirectoryPathAbsolute last = new DirectoryPathAbsolute(dir);
                if (last.Exists)
                {
                    return(last.Path);
                }
                else if (last.ParentDirectoryPath.Exists)
                {
                    return(last.ParentDirectoryPath.Path);
                }
                else if (last.ParentDirectoryPath.ParentDirectoryPath.Exists)
                {
                    return(last.ParentDirectoryPath.ParentDirectoryPath.Path);
                }
            }
            catch (Exception ex)
            {
                Trace.Write(ex);
            }

            return(null);
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        /// <summary>
        /// check if the search item path is a subdirectory of the rootDir
        /// </summary>
        /// <param name="rootDir"></param>
        /// <param name="searchItem"></param>
        /// <returns></returns>
        public static bool IsSubdirectory(string rootDir, string searchItem)
        {
            var root   = new DirectoryPathAbsolute(rootDir);
            var search = new DirectoryPathAbsolute(searchItem);

            return(search.IsChildDirectoryOf(root));
        }
예제 #4
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);
        }
예제 #5
0
        private void QuickOpen(string dir)
        {
            this.txtFolder.Text = dir;
            this.flowDiscs.Controls.Clear();

            if (string.IsNullOrEmpty(dir))
            {
                this.flowDiscs.Controls.Add(new ErrorItem("Please choose a folder containing your disc backups."));
                return;
            }

            try
            {
                var discs = new List <Disc>();
                var dirs  = new DirectoryPathAbsolute(dir).ChildrenDirectoriesPath;

                foreach (var d in dirs)
                {
                    if (Directory.Exists(Path.Combine(d.Path, "VIDEO_TS")))
                    {
                        discs.Add(new Disc(d.Path, "DVD"));
                    }
                    else if (Directory.Exists(Path.Combine(Path.Combine(d.Path, "BDMV"), "PLAYLIST")))
                    {
                        discs.Add(new Disc(d.Path, "Bluray"));
                    }
                    else if (Directory.Exists(Path.Combine(d.Path, "ADV_OBJ")))
                    {
                        discs.Add(new Disc(d.Path, "HDDVD"));
                    }
                }

                foreach (var disc in discs)
                {
                    var di = new DiscItem(disc);
                    di.Opened += (s, e) =>
                    {
                        this.DiscPath     = ((Disc)((DiscItem)s).Tag).Path;
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                        this.Close();
                    };
                    this.flowDiscs.Controls.Add(di);
                }

                if (discs.Count == 0)
                {
                    this.flowDiscs.Controls.Add(new ErrorItem("No discs found.  Please select your backup folder containing discs."));
                }
            }
            catch (Exception ex)
            {
                this.flowDiscs.Controls.Add(new ErrorItem(ex.Message));
            }
        }
예제 #6
0
 /// <summary>
 /// check if the search item path is a subdirectory of the rootDir
 /// </summary>
 /// <param name="rootDir"></param>
 /// <param name="searchItem"></param>
 /// <returns></returns>
 public static bool IsSubdirectory(string rootDir, string searchItem)
 {
     if (rootDir.StartsWith("\\")) //network disk?
     {
         return(searchItem.StartsWith(rootDir, StringComparison.InvariantCultureIgnoreCase));
     }
     else
     {
         var root   = new DirectoryPathAbsolute(rootDir);
         var search = new DirectoryPathAbsolute(searchItem);
         return(search.IsChildDirectoryOf(root));
     }
 }
예제 #7
0
        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");
            }
        }
예제 #8
0
        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");
            }
        }
예제 #9
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);
 }
        public void OnSessionStarting(string parameter, IList <string> projectPaths)
        {
            _projectPath = projectPaths.Select(p => new DirectoryPathAbsolute(p))
                           .First(ass => ass.ChildrenFilesPath.Where(p => p.FileName == "Web.config").Any());

            _port = parameter;
            string content =
                @"taskkill /F /IM WebDev.WebServer40.EXE
START /D ""C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0\"" /B WebDev.WebServer40.EXE /port:"
                + _port + @" /path:" + _projectPath.Path.InQuotes() + @" /vpath:""/""";

            cmdPath = Path.GetTempFileName();

            cmdPath = Path.ChangeExtension(cmdPath, "cmd");
            File.WriteAllText(cmdPath, content, Encoding.ASCII);
        }
        public void OnSessionStarting(string parameter, IList<string> projectPaths)
        {

            _projectPath = projectPaths.Select(p => new DirectoryPathAbsolute(p))
             .First(ass => ass.ChildrenFilesPath.Where(p => p.FileName == "Web.config").Any());


            _port = parameter;
            string content =
@"taskkill /F /IM WebDev.WebServer40.EXE
START /D ""C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0\"" /B WebDev.WebServer40.EXE /port:" 
+ _port + @" /path:" + _projectPath.Path.InQuotes() + @" /vpath:""/""";

             cmdPath = Path.GetTempFileName();
            

            cmdPath = Path.ChangeExtension(cmdPath, "cmd");
            File.WriteAllText(cmdPath, content, Encoding.ASCII);
       


        }
예제 #12
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);
 }
예제 #13
0
        public Disc(string path, string type)
        {
            var dir = new DirectoryPathAbsolute(path);

            this.Path = path;
            this.Type = type;
            this.Name = dir.DirectoryName;

            var exts = new List <string>();

            if (dir.ChildrenFilesPath.Any(x => x.FileExtension == ".xml"))
            {
                exts.Add("xml");
            }
            else if (dir.ChildrenFilesPath.Any(x => x.FileExtension == ".chapters"))
            {
                exts.Add("chapter");
            }
            else if (dir.ChildrenFilesPath.Any(x => x.FileExtension == ".txt"))
            {
                exts.Add("txt");
            }
            this.FoundExtractions = exts.ToArray();
        }
예제 #14
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;
    }