Exemple #1
0
        public void Serialization()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            Directory.CreateDirectory(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);
            byte[] data = null;

            using (MemoryStream stream = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(stream, edi);
                data = stream.ToArray();
            }

            Assert.IsNotNull(data);
            ConditionAssert.Greater(data.Length, 0);

            using (MemoryStream stream = new MemoryStream(data))
            {
                BinaryFormatter       bf   = new BinaryFormatter();
                ExtendedDirectoryInfo edi2 = bf.Deserialize(stream) as ExtendedDirectoryInfo;
                Assert.IsNotNull(edi2);
                Assert.AreEqual(edi.FullName, edi2.FullName);
            }
        }
Exemple #2
0
        public void Constructor()
        {
            try
            {
                ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(null);
            }
            catch (ArgumentNullException)
            {
                Assert.IsTrue(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }

            try
            {
                ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(String.Empty);
            }
            catch (ArgumentException)
            {
                Assert.IsTrue(true);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
Exemple #3
0
        public void Create1()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }

            Assert.IsFalse(Directory.Exists(path), "Unable to delete the test directory.");

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            DirectorySecurity directorySecurity = new DirectorySecurity();

            directorySecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));
            edi.Create(directorySecurity);
            Assert.IsTrue(Directory.Exists(path));

            DirectorySecurity           actualDirectorySecurity = Directory.GetAccessControl(path);
            AuthorizationRuleCollection rules = actualDirectorySecurity.GetAccessRules(true, true, typeof(NTAccount));

            foreach (AuthorizationRule rule in rules)
            {
                FileSystemAccessRule accessRule = (FileSystemAccessRule)rule;

                if (accessRule.IdentityReference.Value == "Everyone")
                {
                    Assert.IsTrue(accessRule.AccessControlType == AccessControlType.Allow);
                    Assert.IsTrue(accessRule.FileSystemRights == FileSystemRights.FullControl);
                }
            }
        }
Exemple #4
0
        public ConfigIntegrator(Param param, bool filesMoved)
        {
            this.param          = param;
            this.totalSitio     = param.dataToProcess.totalSitio;
            this.MCSteps        = param.dataToProcess.maxInterations * totalSitio * 5;
            this.valueDivResult = param.dataToResults.valueDivResult;
            this.valueDiscard   = param.dataToResults.valueDiscard;
            this.maxInterations = param.dataToProcess.maxInterations;

            this.dirBaseServer = new ExtendedDirectoryInfo(DirBaseService.GetDirBaseService().dirBaseServer);
            this.dirBaseWeb    = new ExtendedDirectoryInfo(DirBaseService.GetDirBaseService().dirBaseWeb);

            if (!filesMoved)
            {
                this.movimentsOccurred = ExtendedStreamReader.LinesOfFile(dirBaseWeb.FullName() + this.param.dataToProcess.Guid + @"\Debug\Debug.dat");
            }
            else
            {
                this.movimentsOccurred = ExtendedStreamReader.LinesOfFile(dirBaseWeb.FullName() + this.param.dataToProcess.Guid + @"\Result\Debug.dat");
            }

            this.delta = (movimentsOccurred - valueDiscard) / valueDivResult;

            this.mcSteps = param.dataToProcess.maxInterations * 5 * param.dataToProcess.totalSitio;
        }
        public static void Decompress(SIO.FileInfo zipFile, ExtendedDirectoryInfo targetDir, string fileFilter)
        {
            FastZip fastZip = new FastZip();

            fastZip.ExtractZip(zipFile.FullName, targetDir.FullName(), fileFilter);
            fastZip = null;
        }
Exemple #6
0
        public void Properties()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            Directory.CreateDirectory(path);
            DirectoryInfo di = new DirectoryInfo(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            Assert.AreEqual(edi.Root.FullName, di.Root.FullName);
            Assert.AreEqual(edi.Parent.FullName, di.Parent.FullName);
            Assert.AreEqual(edi.Name, di.Name);
            Assert.AreEqual(edi.LastWriteTimUtc, di.LastWriteTimeUtc);
            Assert.AreEqual(edi.LastWriteTime, di.LastWriteTime);
            Assert.AreEqual(edi.LastAccessTimeUtc, di.LastAccessTimeUtc);
            Assert.AreEqual(edi.LastAccessTime, di.LastAccessTime);
            Assert.AreEqual(edi.FullName, di.FullName);
            Assert.AreEqual(edi.Extension, di.Extension);
            Assert.AreEqual(edi.Exists, di.Exists);
            Assert.AreEqual(edi.CreationTime, di.CreationTime);
            Assert.AreEqual(edi.CreateTimeUtc, di.CreationTimeUtc);
            Assert.AreEqual(edi.Attributes, di.Attributes);
        }
        public static void Compress(Guid guid, SIO.FileInfo zipFile, ExtendedDirectoryInfo baseDiretory, bool recursive, string fileFilter)
        {
            FastZip fastZip = new FastZip();

            fastZip.CreateEmptyDirectories = true;
            fastZip.CreateZip(zipFile.FullName, baseDiretory.FullName(), recursive, fileFilter);
            fastZip = null;
        }
Exemple #8
0
        public void ExtractDocument(string fileName)
        {
            //GICO.WriteLine(String.Format("{0} {1}:{2}", DateTime.Now, "ExtractDocument", fileName));
            SIO.FileInfo          tempFile = new SIO.FileInfo(uploadFolder.FullName + fileName);
            ExtendedDirectoryInfo tempDir  = new ExtendedDirectoryInfo(dirBaseServer.FullName + Path.GetFileNameWithoutExtension(tempFile.Name));

            Directory.CreateDirectory(tempDir.FullName());

            ExtractFile(tempFile, tempDir);
        }
Exemple #9
0
        public void ToStringTest()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            Directory.CreateDirectory(path);

            DirectoryInfo         di  = new DirectoryInfo(path);
            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            Assert.AreEqual(di.ToString(), edi.ToString());
        }
Exemple #10
0
        public void Properties2()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            Directory.CreateDirectory(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            edi.CreationTime = new DateTime(2006, 1, 1);

            DirectoryInfo di = new DirectoryInfo(path);

            Assert.AreEqual(edi.CreationTime, di.CreationTime);
        }
Exemple #11
0
        public void GetAccessControl1()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            Directory.CreateDirectory(path);
            DirectoryInfo di = new DirectoryInfo(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            DirectorySecurity actual   = edi.GetAccessControl(AccessControlSections.All);
            DirectorySecurity expected = di.GetAccessControl(AccessControlSections.All);

            CollectionAssert.AreEqual(expected.GetSecurityDescriptorBinaryForm(), actual.GetSecurityDescriptorBinaryForm());
        }
Exemple #12
0
        public void DirectoryOwner()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            Directory.CreateDirectory(path);

            DirectoryInfo     di       = new DirectoryInfo(path);
            DirectorySecurity ds       = di.GetAccessControl(AccessControlSections.Owner);
            string            expected = ds.GetOwner(typeof(NTAccount)).ToString();

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);
            string actual = edi.DirectoryOwner;

            Assert.AreEqual(expected, actual);
        }
Exemple #13
0
        protected FilingSummary BuildAndVerifyRecursive(string folder, string instanceName, string taxonomyName)
        {
            Console.WriteLine("=================================================");
            Console.WriteLine("  BUILD AND VERIFY " + folder + "...");
            Console.WriteLine("=================================================");

            string baselineResultFolder = PathCombine(this.baseDir, folder, "Results");

            this.resultsPath = baselineResultFolder;

            if (!BuildAndVerifyWithoutResults && !Directory.Exists(this.resultsPath))
            {
                throw new Exception("There are no results to verify againsts.");
            }

            string generatedResultFolder = PathCombine(this.baseDir, folder, "Reports");

            this.reportsPath = generatedResultFolder;

            string failedResultsFolder = Path.GetDirectoryName(generatedResultFolder);

            failedResultsFolder = Path.Combine(failedResultsFolder, "Failures");
            CleanAndPrepareFolder(failedResultsFolder);

            FilingSummary fs = BuildFiling(folder, instanceName, taxonomyName);

            using (ErrorWriter writer = new ErrorWriter())
            {
                ExtendedDirectoryInfo baselineResultInfo  = new ExtendedDirectoryInfo(baselineResultFolder);
                ExtendedDirectoryInfo generatedResultInfo = new ExtendedDirectoryInfo(generatedResultFolder);
                VerifyIndividualReports(writer, baselineResultInfo, generatedResultInfo, failedResultsFolder);
                VerifyCharts(writer, baselineResultInfo, generatedResultInfo);

                if (writer.HasErrors)
                {
                    writer.Flush();
                    writer.SaveResults(failedResultsFolder);

                    Console.Write(writer.GetStringBuilder().ToString().Trim());
                    throw new Exception(writer.GetStringBuilder().ToString().Trim());
                }
            }

            return(fs);
        }
Exemple #14
0
        public void Exists()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            try
            {
                Directory.CreateDirectory(path);

                ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);
                Assert.IsNotNull(edi);

                Assert.IsTrue(edi.Exists);
            }
            catch (Exception e)
            {
                Assert.Fail(e.Message);
            }
        }
Exemple #15
0
        public void MoveTo()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            Directory.CreateDirectory(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            string path2 = Path.Combine(Path.GetTempPath(), "CadruTestMoved");

            edi.MoveTo(path2);

            Assert.IsTrue(Directory.Exists(path2));

            Directory.Delete(path2);
        }
Exemple #16
0
        public void Create()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }

            Assert.IsFalse(Directory.Exists(path), "Unable to delete the test directory.");

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            edi.Create();
            Assert.IsTrue(Directory.Exists(path));
        }
Exemple #17
0
        public void Properties1()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            Directory.CreateDirectory(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            edi.Attributes |= FileAttributes.ReadOnly;

            DirectoryInfo di = new DirectoryInfo(path);

            Assert.AreEqual(edi.Attributes, di.Attributes);

            di.Attributes &= ~FileAttributes.ReadOnly;
        }
Exemple #18
0
        public void GetDirectories2()
        {
            string        path = Path.GetTempPath();
            DirectoryInfo di   = new DirectoryInfo(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            DirectoryInfo[] actual   = edi.GetDirectories("*", SearchOption.TopDirectoryOnly);
            DirectoryInfo[] expected = di.GetDirectories("*", SearchOption.TopDirectoryOnly);

            CollectionAssert.AreEqual(expected, actual, ComparisonComparer <DirectoryInfo> .Create((a, b) => a.FullName.CompareTo(b.FullName)));

            foreach (DirectoryInfo d in actual)
            {
                Assert.IsTrue(Array.Exists(expected,
                                           delegate(DirectoryInfo o)
                {
                    return(d.FullName == o.FullName);
                }));
            }
        }
Exemple #19
0
        public void SetAccessControl()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            Directory.CreateDirectory(path);

            DirectoryInfo     di       = new DirectoryInfo(path);
            DirectorySecurity expected = di.GetAccessControl(AccessControlSections.All);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            DirectorySecurity directorySecurity = new DirectorySecurity();

            directorySecurity.AddAccessRule(new FileSystemAccessRule("Everyone", FileSystemRights.FullControl, AccessControlType.Allow));

            edi.SetAccessControl(directorySecurity);

            Assert.AreNotEqual(expected.GetSecurityDescriptorBinaryForm(), edi.GetAccessControl().GetSecurityDescriptorBinaryForm());

            DirectorySecurity           actualDirectorySecurity = Directory.GetAccessControl(path);
            AuthorizationRuleCollection rules = actualDirectorySecurity.GetAccessRules(true, true, typeof(NTAccount));

            foreach (AuthorizationRule rule in rules)
            {
                FileSystemAccessRule accessRule = (FileSystemAccessRule)rule;

                if (accessRule.IdentityReference.Value == "Everyone")
                {
                    Assert.IsTrue(accessRule.AccessControlType == AccessControlType.Allow);
                    Assert.IsTrue(accessRule.FileSystemRights == FileSystemRights.FullControl);
                }
            }

            di.SetAccessControl(expected);
        }
Exemple #20
0
        public void Delete1()
        {
            string path = Path.Combine(Path.GetTempPath(), "CadruTest");

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }

            Assert.IsFalse(Directory.Exists(path), "Unable to delete the test directory.");

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            string path2 = edi.CreateSubdirectory("Subdir").FullName;

            Assert.IsTrue(Directory.Exists(path));

            File.WriteAllText(Path.Combine(path2, "testfile.txt"), "This is a test.");
            edi.Delete(true);

            Assert.IsFalse(Directory.Exists(path), "Unable to delete the test directory.");
        }
Exemple #21
0
        public void GetFileSystemInfos1()
        {
            string        path = Path.GetTempPath();
            DirectoryInfo di   = new DirectoryInfo(path);

            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(path);

            Assert.IsNotNull(edi);

            FileSystemInfo[] actual   = edi.GetFileSystemInfos("*");
            FileSystemInfo[] expected = di.GetFileSystemInfos("*");

            CustomAssert.IsNotEmpty(actual);
            CollectionAssert.AllItemsAreNotNull(actual);

            foreach (FileSystemInfo f in actual)
            {
                Assert.IsTrue(Array.Exists(expected,
                                           delegate(FileSystemInfo o)
                {
                    return(f.FullName == o.FullName);
                }));
            }
        }
Exemple #22
0
        /// <summary>
        /// Runs a test on the given base (could be either a folder or zip file containing R Files).  The method can
        /// accept either a zip or a folder of R files.  The name of the folder/zip of the new files must match that
        /// of the base path.
        /// </summary>
        /// <param name="testSummary"></param>
        /// <param name="testErrors"></param>
        /// <param name="baseZipOrDir"></param>
        public static void RunTest(FilingResult testSummaryItem, StringBuilder testErrors, string baseZipOrDir)
        {
            // The name of the filing is used to build all paths
            testSummaryItem.Name = Path.GetFileNameWithoutExtension(baseZipOrDir);
            string filingLogFolder = Test_Abstract.PathCombine(AutoTester.logPath, testSummaryItem.Name);

            // Preparing (clean/create) folders for output
            Test_Abstract.CleanAndPrepareFolder(filingLogFolder);

            int errorCount = 0;

            IDirectoryInfo baseDirInfo = null;
            IDirectoryInfo newDirInfo  = null;

            try
            {
                // The base can be a directory, and if it is, then it needs to be handled differently.
                if (Directory.Exists(baseZipOrDir))
                {
                    baseDirInfo = new ExtendedDirectoryInfo(baseZipOrDir);
                }
                else if (File.Exists(baseZipOrDir))
                {
                    baseDirInfo = new ZipDirectoryInfo(baseZipOrDir);
                }
                else
                {
                    // This shouldn't occur if the method was called from a file listing, but handle anyway
                    string message = "The the zip or folder for the Base filing was missing.  Tried to process the following as a directory and zip file: \r\n\t";
                    message += baseZipOrDir;

                    string resultPath = Test_Abstract.PathCombine(filingLogFolder, "Base Filing Zip or Folder Missing.txt");
                    File.WriteAllText(resultPath, message);

                    testSummaryItem.Success = false;
                    testSummaryItem.Reason  = "The base file name given to the processor could not be found.";
                    return;
                }

                // When picking the new files, prefer directory over zip
                if (Directory.Exists(Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name)))
                {
                    string dirPath = Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name);
                    newDirInfo = new ExtendedDirectoryInfo(dirPath);
                }
                else if (File.Exists(Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name + ".zip")))
                {
                    string zipPath = Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name + ".zip");
                    newDirInfo = new ZipDirectoryInfo(zipPath);
                }
                else
                {
                    string message = "The the zip or folder for the New filing was missing.  Tried the directory: \r\n\t";
                    message += Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name);
                    message += "\r\nAnd the file: \r\n\t";
                    message += Test_Abstract.PathCombine(AutoTester.newFilingsPath, testSummaryItem.Name + ".zip");

                    string resultPath = Test_Abstract.PathCombine(filingLogFolder, "New Filing Zip or Folder Missing.txt");
                    File.WriteAllText(resultPath, message);

                    testSummaryItem.Success = false;
                    testSummaryItem.Reason  = "The new file corresponding to the base file could not be found.";
                    return;
                }

                //
                using (ErrorWriter writer = new ErrorWriter())
                {
                    Test_Abstract.VerifyIndividualReports(writer, baseDirInfo, newDirInfo, filingLogFolder);
                    Test_Abstract.VerifyCharts(writer, baseDirInfo, newDirInfo);

                    if (writer.HasErrors)
                    {
                        writer.Flush();
                        writer.SaveResults(filingLogFolder);

                        testSummaryItem.Errors  = writer.Errors;
                        testSummaryItem.Success = true;
                        testSummaryItem.Reason  = "See error log.";

                        testErrors.AppendFormat("Error in: {0}\r\n{1}\r\n\r\n\r\n", testSummaryItem.Name, writer.GetStringBuilder().ToString().Trim());
                    }
                    else
                    {
                        testSummaryItem.Success = true;
                    }

                    errorCount = writer.Errors;
                }
            }
            catch (Exception e)
            {
                testSummaryItem.Success = false;
                testSummaryItem.Reason  = "Exception) " + e.Message;
            }
            finally
            {
                if (errorCount == 0)
                {
                    try
                    {
                        Directory.Delete(filingLogFolder, true);
                    }
                    catch { }
                }
            }
        }
Exemple #23
0
        public void Constructor1()
        {
            ExtendedDirectoryInfo edi = new ExtendedDirectoryInfo(Path.GetTempPath());

            Assert.IsNotNull(edi);
        }
Exemple #24
0
 private void ExtractFile(SIO.FileInfo fileName, ExtendedDirectoryInfo targetDir)
 {
     Middle.Helpers.CompressionHelpers.Compression.Decompress(fileName, targetDir, string.Empty);
     //File.Delete(fileName.FullName);
 }