コード例 #1
0
        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);
        }
コード例 #2
0
        public override FBAbstractElement generate()
        {
            DirectoryInfo dinfo = new DirectoryInfo(this.path);
            FBDirectory newDir = new FBDirectory(dinfo.Name);

            foreach (DirectoryInfo dir in dinfo.GetDirectories())
            {
                FBDirectoryBuilder db = new FBDirectoryBuilder(dir.FullName);
                newDir.addContent(db.generate());
            }

            foreach (FileInfo fil in dinfo.GetFiles())
            {
                FBFileBuilder fb = new FBFileBuilder(fil.FullName);
                newDir.addContent(fb.generate());
            }

            return newDir;
        }
コード例 #3
0
        private void uploadFile(Stream fileStream)
        {
            string path = this.server.user.rootDirectory.FullName + "\\"
                + DateTime.UtcNow.ToString("yyyy_MM_dd_HH_mm_ss_fff",
                CultureInfo.InvariantCulture);
            FBFile newFile;
            FBFileBuilder fb;

            UsefullMethods.SaveStreamToFile(fileStream, path);
            fb = new FBFileBuilder(path);
            newFile = (FBFile)fb.generate();

            if (!this.server.necessaryFiles.Contains(newFile))
            {
                File.Delete(path);
                this.errorEvent(token);
                return;
            }

            this.completeEvent(newFile, new PhysicFile(newFile, path), token);
        }
コード例 #4
0
        override public FBAbstractElement generate()
        {
            DirectoryInfo dinfo  = new DirectoryInfo(this.path);
            FBDirectory   newDir = new FBDirectory(dinfo.Name);

            foreach (DirectoryInfo dir in dinfo.GetDirectories())
            {
                if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                {
                    FBDirectoryBuilder db = new FBDirectoryBuilder(dir.FullName);
                    newDir.addContent(db.generate());
                }
            }

            foreach (FileInfo fil in dinfo.GetFiles())
            {
                FBFileBuilder fb = new FBFileBuilder(fil.FullName);
                newDir.addContent(fb.generate());
            }

            return(newDir);
        }
コード例 #5
0
ファイル: Session.cs プロジェクト: Crizio/folderbackuper
        public string uploadFile(Stream fileStream)
        {
            string path = this.user.rootDirectory.FullName + "\\" + DateTime.UtcNow.ToString("yyyy_MM_dd_HH_mm_ss_fff", CultureInfo.InvariantCulture);
            FBFile newFile;
            FBFileBuilder fb;
            fileStream.Seek(20, SeekOrigin.Begin);
            SaveStreamToFile(fileStream, path);
            fb = new FBFileBuilder(path);
            newFile = (FBFile) fb.generate();

            if (!this.necessaryFiles.Contains(newFile))
            {
                File.Delete(path);
                throw new FaultException<ServiceErrorMessage>(new ServiceErrorMessage(ServiceErrorMessage.FILENOTNECESSARY));
            }

            this.uploadedFiles.add(new PhysicFile(newFile, path));

            this.necessaryFiles.Remove(newFile);
            return newFile.hash;
        }