예제 #1
0
        public void TestBinary()
        {
            Tools.PrepareTest(out string sourcePath, out string targetPath, out string logsPath);

            BlennyBackup.Configuration.Pair pair = new BlennyBackup.Configuration.Pair()
            {
                FilterPattern = "*",
                SourcePath    = sourcePath,
                TargetPath    = targetPath
            };

            BlennyBackup.Configuration.PairConfig pairConfig = new BlennyBackup.Configuration.PairConfig
            {
                ComparisonMode = BlennyBackup.Options.ComparisonMode.Binary,
                PairArray      = new BlennyBackup.Configuration.Pair[] { pair },
            };

            Tools.GenerateXML(pairConfig, out string xmlPath);

            BlennyBackup.Options.XmlConfig xmlConfig = new BlennyBackup.Options.XmlConfig
            {
                ConfigFilePath = new string[] { xmlPath },
                LogFilePath    = logsPath,
                ReportCount    = 1,
                FlushDelay     = 5
            };

            Program.SyncXmlPairs(xmlConfig);

            Tools.AssertTarget(targetPath, logsPath, "Compared binary for ");
            Tools.CleanTarget(targetPath, logsPath, xmlPath);
        }
예제 #2
0
        public void TestHash()
        {
            Tools.PrepareTest(out string sourcePath, out string targetPath, out string logsPath);

            BlennyBackup.Configuration.Pair pair = new BlennyBackup.Configuration.Pair()
            {
                FilterPattern = "*",
                SourcePath    = sourcePath,
                TargetPath    = targetPath
            };

            BlennyBackup.Configuration.PairConfig pairConfig = new BlennyBackup.Configuration.PairConfig
            {
                ComparisonMode = BlennyBackup.Options.ComparisonMode.Hash,
                PairArray      = new BlennyBackup.Configuration.Pair[] { pair },
            };

            Tools.GenerateXML(pairConfig, out string xmlPath);

            BlennyBackup.Options.XmlConfig xmlConfig = new BlennyBackup.Options.XmlConfig
            {
                ConfigFilePath = new string[] { xmlPath },
                LogFilePath    = logsPath,
                ReportCount    = 1,
                FlushDelay     = 5
            };

            Program.SyncXmlPairs(xmlConfig);

            Assert.IsTrue(File.Exists(Path.Combine(targetPath, "blenny_backup_hash.txt")));
            Tools.AssertTarget(targetPath, logsPath, "Processed hash for");


            // Test XML ignore list, also make sure that loading hash file do not crash
            BlennyBackup.Configuration.Pair pair_ignore = new BlennyBackup.Configuration.Pair()
            {
                FilterPattern = "*",
                SourcePath    = sourcePath,
                TargetPath    = targetPath,
                IgnoreList    = new string[] { "folder_c/constant.txt", "directory_b/original_2.txt" }
            };

            BlennyBackup.Configuration.PairConfig pairConfig_ignore = new BlennyBackup.Configuration.PairConfig
            {
                ComparisonMode = BlennyBackup.Options.ComparisonMode.Hash,
                PairArray      = new BlennyBackup.Configuration.Pair[] { pair_ignore },
            };

            Tools.GenerateXML(pairConfig_ignore, out xmlPath);
            Program.SyncXmlPairs(xmlConfig);

            string logsContent = File.ReadAllText(logsPath);

            Assert.IsTrue(logsContent.Contains("Processed hash for 1 / 3 files"));

            Tools.CleanTarget(targetPath, logsPath, xmlPath);
        }
예제 #3
0
        public static void GenerateXML(BlennyBackup.Configuration.PairConfig pairConfig, out string xmlPath)
        {
            xmlPath = Path.Combine(TempDirPath, "config.xml");
            if (File.Exists(xmlPath))
            {
                File.Delete(xmlPath);
            }

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(BlennyBackup.Configuration.PairConfig));

            using (var stringWriter = new StringWriter())
                using (XmlWriter writer = XmlWriter.Create(stringWriter, new XmlWriterSettings()
                {
                    Indent = true, NewLineOnAttributes = true, OmitXmlDeclaration = true
                }))
                {
                    xmlSerializer.Serialize(writer, pairConfig);
                    File.WriteAllText(xmlPath, stringWriter.ToString());
                }
        }