Exemple #1
0
        public bool newTransaction(SerializedVersion newVersion)
        {
            this.checkAuthentication();

            if (this.transactionEnabled)
            {
                throw new FaultException <ServiceErrorMessage>(new ServiceErrorMessage(ServiceErrorMessage.TRANSACTIONALREADYENABLED));
            }

            FBVersion vers    = FBVersion.deserialize(newVersion.encodedVersion);
            FBVersion current = FBVersion.deserialize(this.getCurrentVersion().encodedVersion);

            if (vers.Equals(current))
            {
                return(false);
            }

            this.transactionEnabled = true;
            this.inSyncVersion      = vers;

            String newDirPath = this.user.rootDirectory.FullName;

            newDirPath      += "\\" + this.inSyncVersion.timestamp.ToString(directoryFormat, CultureInfo.InvariantCulture);
            this.transactDir = Directory.CreateDirectory(newDirPath);
            if (this.transactDir == null)
            {
                throw new FaultException <ServiceErrorMessage>(new ServiceErrorMessage(ServiceErrorMessage.CREATEVERSIONDIRECTORYFAILED));
            }

            necessaryFiles = new ThreadSafeList <FBFile>(FBVersion.getNecessaryFilesToUpgrade(this.inSyncVersion, this.realFiles.filesAlreadyRepresented()));

            return(true);
        }
        public void NecessaryFilesToUpgradeTest()
        {
            string[] lines1 = { "First line", "Second line", "Third line" };
            string[] lines2 = { "First line", "Second line", "NO" };
            System.IO.Directory.CreateDirectory("asd");
            System.IO.Directory.CreateDirectory(@"asd\ciao");
            DirectoryInfo rinfo = new DirectoryInfo("asd");

            System.IO.File.WriteAllLines(@"asd\uno.txt", lines1);
            System.IO.File.WriteAllLines(@"asd\ciao\due.txt", lines1);
            System.IO.File.WriteAllLines(@"asd\ciao\tre.txt", lines1);
            System.IO.File.WriteAllLines(@"asd\ciao\quattro.txt", lines1);

            FBVersionBuilder vb = new FBVersionBuilder(rinfo.FullName);

            FolderBackup.Shared.FBVersion vold = (FolderBackup.Shared.FBVersion)vb.generate();
            System.IO.File.WriteAllLines(@"asd\ciao\cinque.txt", lines2);
            System.IO.File.WriteAllLines(@"asd\sei.txt", lines2);
            System.IO.File.WriteAllLines(@"asd\sette.txt", lines1);
            FolderBackup.Shared.FBVersion vnew = (FolderBackup.Shared.FBVersion)vb.generate();

            FBVersion diff = vnew - vold;

            List <FBFile> fl = FBVersion.getNecessaryFilesToUpgrade(vnew, vold.fileList);

            Assert.AreEqual(fl.Count, 1);
            FBFileBuilder fb        = new FBFileBuilder(@"asd\ciao\cinque.txt");
            FBFile        necessary = (FBFile)fb.generate();

            Assert.AreEqual(fl[0], necessary);

            System.IO.Directory.Delete("asd", true);
        }
Exemple #3
0
        public byte[][] getFilesToUpload()
        {
            this.checkAuthentication();
            this.checkTransactionIsEnabled();

            necessaryFiles     = new ThreadSafeList <FBFile>(FBVersion.getNecessaryFilesToUpgrade(this.inSyncVersion, this.realFiles.filesAlreadyRepresented()));
            this.uploadedFiles = new PhysicFilesList();

            byte[][] ret = new byte[necessaryFiles.Count][];
            for (int i = 0; i < necessaryFiles.Count; ++i)
            {
                ret[i] = necessaryFiles.ElementAt(i).serialize();
            }
            return(ret);
        }