Beispiel #1
0
        public void CopyDirectoryTest()
        {
            FileInfo[] except =
            {
                new FileInfo(@".\FileSystemCopyTest\File1.txt"),
                new FileInfo(@".\FileSystemCopyTest\File2.txt"),
                new FileInfo(@".\FileSystemCopyTest\Directory1\File1.txt"),
                new FileInfo(@".\FileSystemCopyTest\Directory1\File2.txt"),
                new FileInfo(@".\FileSystemCopyTest\Directory1\.DotFolderTest\File1.txt"),
                new FileInfo(@".\FileSystemCopyTest\Directory1\.DotFolderTest\File2.txt")
            };
            try
            {
                Directory.Delete(@".\FileSystemCopyTest", true);
            }
            catch (System.IO.DirectoryNotFoundException)
            {
                Console.WriteLine("copy target not found, pass");
            }
            RecursiveDirectoryIterator actual = FSUtil.CopyDirectory(new DirectoryInfo(@".\FileSystemTest\"),
                                                                     new DirectoryInfo(@".\FileSystemCopyTest\"));

            for (int i = 0; i < 6; i++)
            {
                string except_fullpath = except[i].FullName;
                string actual_fullpath = actual[i].FullName;
                Assert.AreEqual(except_fullpath, actual_fullpath, "\nexcxept:{0}\nActual{1}", except_fullpath, actual_fullpath);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create a project and return a <c>ProjectInfo</c> object repersent it
        /// </summary>
        /// <param name="Name">Project Name</param>
        /// <param name="ProjectLocation">Where the new project locates</param>
        /// <returns><c>ProjectInfo</c> represent the created project</returns>
        virtual public ProjectInfo CreateFormThis(string Name, DirectoryInfo ProjectLocation)
        {
            RecursiveDirectoryIterator iter = FSUtil.CopyFilesToDirectory(files, Location, ProjectLocation);

            ProcessFiles(Name, ref iter);
            var ret_value = new ProjectInfo(Name, iter.OriginalDirectoryInfo, iter);

            ret_value.Save();
            return(ret_value);
        }
Beispiel #3
0
        public void CopyDirectoryTest()
        {
            FileInfo[] except =
            {
                new FileInfo(@".\FileSystemCopyTest\File1.txt"),
                new FileInfo(@".\FileSystemCopyTest\File2.txt"),
                new FileInfo(@".\FileSystemCopyTest\Directory1\File1.txt"),
                new FileInfo(@".\FileSystemCopyTest\Directory1\File2.txt"),
                new FileInfo(@".\FileSystemCopyTest\Directory1\.DotFolderTest\File1.txt"),
                new FileInfo(@".\FileSystemCopyTest\Directory1\.DotFolderTest\File2.txt")
            };
            Directory.Delete(@".\FileSystemCopyTest", true);
            RecursiveDirectoryIterator actual = FSUtil.CopyDirectory(new DirectoryInfo(@".\FileSystemTest\"),
                                                                     new DirectoryInfo(@".\FileSystemCopyTest\"));

            for (int i = 0; i < 6; i++)
            {
                string except_fullpath = except[i].FullName;
                string actual_fullpath = actual[i].FullName;
                Assert.AreEqual(except_fullpath, actual_fullpath, "\nexcxept:{0}\nActual{1}", except_fullpath, actual_fullpath);
            }
        }
Beispiel #4
0
        public void GetFileList()
        {
            RecursiveDirectoryIterator iter = new RecursiveDirectoryIterator(@".\FileSystemTest");

            Debug.WriteLine(iter.OriginalDirectoryInfo.FullName);
            FileInfo[] except =
            {
                new FileInfo(@".\FileSystemTest\File1.txt"),
                new FileInfo(@".\FileSystemTest\File2.txt"),
                new FileInfo(@".\FileSystemTest\Directory1\File1.txt"),
                new FileInfo(@".\FileSystemTest\Directory1\File2.txt"),
                new FileInfo(@".\FileSystemTest\Directory1\.DotFolderTest\File1.txt"),
                new FileInfo(@".\FileSystemTest\Directory1\.DotFolderTest\File2.txt")
            };
            //CollectionAssert.AreEquivalent(except, iter, "iter not equivent to excepted collection");
            for (int i = 0; i < 6; i++)
            {
                string except_fullpath = except[i].FullName;
                string actual_fullpath = iter[i].FullName;
                Assert.AreEqual(except_fullpath, actual_fullpath, "\nexcxept:{0}\nActual{1}", except_fullpath, actual_fullpath);
            }
        }
Beispiel #5
0
        private void ProcessFiles(string NewName, ref RecursiveDirectoryIterator iter)
        {
            foreach (FileInfo file in iter)
            {
                if (file.Name.Contains("__NAME"))
                {
                    string newpath = file.FullName.Replace("__NAME", NewName);
                    try
                    {
                        file.MoveTo(newpath);
                    }
                    catch (DirectoryNotFoundException e)
                    {
#if DEBUG
                        System.Diagnostics.Debugger.Break();
#endif
                        Console.WriteLine("Direcotry not found?\n" +
                                          newpath + '\n' +
                                          "HRESULT:\n" +
                                          e.HResult);
                        Directory.CreateDirectory(Path.GetDirectoryName(newpath));
                        file.MoveTo(newpath);
                    }
                    catch (FileNotFoundException e)
                    {
                        Console.WriteLine(
                            "????????BUG???????\n" +
                            "IS COPY FILE FAILED?\n" +
                            "Check FSUtil.RecursiveDirectoryItertatior\n" +
                            "Stack Traceback:\n{1}\n" +
                            "Message:\n{2}\n" +
                            "HRESULT:\n{3}\n",
                            e.StackTrace, e.Message, e.HResult);
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Message + e.StackTrace);
                    }

                    //stage2: Change File Content
                    try
                    {
                        byte[] buffier = File.ReadAllBytes(newpath);
                        string content = Encoding.UTF8.GetString(buffier);
                        content.Replace("<NAME>", NewName);
                        buffier = Encoding.UTF8.GetBytes(content);
                        file.OpenWrite().Write(buffier, 0, buffier.Length);
                    }
                    catch (FileNotFoundException e)
                    {
#if DEBUG
                        System.Diagnostics.Debugger.Break();
#endif
                        Console.WriteLine("File Not Found?\n" +
                                          "newpath={0}\n" +
                                          "e:\n{1}\n" +
                                          "HRESULT={2}",
                                          newpath, e, e.HResult);
                    }
                    catch (DirectoryNotFoundException e)
                    {
                        Console.WriteLine("BUG???????\n" +
                                          "newpath={0}\n" +
                                          "e:\n{1}\n" +
                                          "HRESULT={2}",
                                          newpath, e, e.HResult);
                    }
                    catch (System.Security.SecurityException e)
                    {
                        //open a dialog?
                        Console.WriteLine("Check permissions\n" + e.ToString());
                    }
                    catch (Exception e)
                    {
#if DEBUG
                        System.Diagnostics.Debugger.Break();
#endif
                        Console.WriteLine(e.Message + e.HResult.ToString() + e.HResult);
                    }
                }
            }
        }