Пример #1
0
        public void RevertWithFileDeletion()
        {
            this.TestInitialize();
            string[] lines = { "First line", "Second line", "Third line" };
            System.IO.File.WriteAllLines(@"asd\ciao\tre.txt", lines);

            FBVersionBuilder vb = new FBVersionBuilder(rinfo.FullName);

            FolderBackup.Shared.FBVersion v = (FolderBackup.Shared.FBVersion)vb.generate();

            SerializedVersion serV = new SerializedVersion(v.serialize());

            server.newTransaction(serV);

            server.commit();

            UploadData ud = server.resetToPreviousVersion(1);

            UsefullMethods.ReceiveFile(ud.ip, ud.port, ud.token, @"asd\asd.zip");

            String             ignore;
            List <Instruction> instructionList = UsefullMethods.ExtractInstructions(@"asd\asd.zip", out ignore);

            Assert.IsTrue(instructionList.Count == 1);
            Assert.IsTrue(instructionList[0].cmd == InstructionType.DELETE);
            Assert.IsTrue(instructionList[0].src == @"ciao\tre.txt");
        }
Пример #2
0
        public void GetFileTest()
        {
            doTransaction();
            server.commit();

            FBVersion vers = new FBVersion();
            FBFile    file = (FBFile)(new FBFileBuilder(@"asd\due.txt")).generate();

            vers.addElement(file);
            SerializedVersion serV = new SerializedVersion(vers.serialize());
            var uploadData         = server.getFile(serV);

            UsefullMethods.ReceiveFile(uploadData.ip, uploadData.port, uploadData.token, @"asd\test.txt");
            String content = File.ReadAllText(@"asd\test.txt");

            Assert.IsTrue(content.Contains("Third lines"));
        }
Пример #3
0
        private void resetVersion(UploadData ud, FBVersion v)
        {
            string filename = Path.GetTempFileName();

            UsefullMethods.ReceiveFile(ud.ip, ud.port, ud.token, filename);

            String             pathFiles;
            List <Instruction> instructionList = UsefullMethods.ExtractInstructions(filename, out pathFiles);

            instructionList.Sort((emp1, emp2) => emp1.cmd.CompareTo(emp2.cmd));
            foreach (Instruction i in instructionList)
            {
                ExecuteInstruction(i, pathFiles);
            }
            CleanUpDir(v.root, "");
            StartSync();
        }
Пример #4
0
        public string getFile(FBFile f)
        {
            SerializedVersion serV   = new SerializedVersion();
            FBVersion         tmpVer = new FBVersion();

            tmpVer.addElement(f);
            serV.encodedVersion = tmpVer.serialize();
            var    uploadData = server.getFile(serV);
            string tmpPath    = Path.GetTempPath() + f.Name;

            if (File.Exists(tmpPath))
            {
                File.Delete(tmpPath);
            }
            UsefullMethods.ReceiveFile(uploadData.ip, uploadData.port, uploadData.token, tmpPath);
            return(tmpPath);
        }
Пример #5
0
        public void RevertWithNewFile()
        {
            this.TestInitialize();
            string[] lines = { "First line", "Second line", "Third line", "Fourth line" };
            System.IO.File.WriteAllLines(@"asd\ciao\tre.txt", lines);

            FBVersionBuilder vb = new FBVersionBuilder(rinfo.FullName);

            FolderBackup.Shared.FBVersion v = (FolderBackup.Shared.FBVersion)vb.generate();

            SerializedVersion serV = new SerializedVersion(v.serialize());

            server.newTransaction(serV);
            FileStream fstream = new FileStream(@"asd\ciao\tre.txt", FileMode.Open, FileAccess.Read);

            server.getFilesToUpload();
            UploadData credential = server.uploadFile();

            UsefullMethods.SendFile(credential.ip, credential.port, credential.token, fstream);
            server.commit();

            System.IO.File.Delete(@"asd\ciao\tre.txt");
            vb   = new FBVersionBuilder(rinfo.FullName);
            v    = (FolderBackup.Shared.FBVersion)vb.generate();
            serV = new SerializedVersion(v.serialize());

            server.newTransaction(serV);

            server.commit();

            UploadData ud = server.resetToPreviousVersion(1);

            UsefullMethods.ReceiveFile(ud.ip, ud.port, ud.token, @"asd\asd.zip");

            String             ignore;
            List <Instruction> instructionList = UsefullMethods.ExtractInstructions(@"asd\asd.zip", out ignore);

            Assert.IsTrue(instructionList.Count == 1);
            Assert.IsTrue(instructionList[0].cmd == InstructionType.NEW);
            Assert.IsTrue(instructionList[0].dst == @"ciao\tre.txt");
        }