コード例 #1
0
ファイル: Server.cs プロジェクト: mpuzz/folderbackuper
        public UploadData getFile(SerializedVersion serV)
        {
            FBVersion  ver   = FBVersion.deserialize(serV.encodedVersion);
            PhysicFile found = null;

            if (ver.fileList.Count != 1)
            {
                return(null);
            }

            foreach (FBFile file in ver.fileList)
            {
                found = findPhysicFile(file);
                if (found == null)
                {
                    return(null);
                }
            }

            FileStream fStream = new FileStream(found.getRealFileInfo().FullName,
                                                FileMode.Open, FileAccess.Read);
            String token   = Server.GetUniqueKey(20);
            var    secDown = new SecureDownloader(this, token, null, null, fStream);

            return(new UploadData(UsefullMethods.GetLocalIPAddress(), secDown.port,
                                  token));
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: mpuzz/folderbackuper
 public string registerStep1(string username)
 {
     if (User.getSalt(username) != null)
     {
         return(null);
     }
     return(Server.GetUniqueKey(10));
 }
コード例 #3
0
ファイル: Server.cs プロジェクト: mpuzz/folderbackuper
        public AuthenticationData authStep1(string username)
        {
            string salt = User.getSalt(username);

            if (salt == null)
            {
                throw new FaultException <ServiceErrorMessage>(new ServiceErrorMessage(ServiceErrorMessage.AUTHENTICATIONFAILED));
            }

            String token = Server.GetUniqueKey(20);

            return(new AuthenticationData(salt, token));
        }
コード例 #4
0
ファイル: Server.cs プロジェクト: mpuzz/folderbackuper
        public UploadData uploadFile()
        {
            this.checkAuthentication();
            this.checkTransactionIsEnabled();
            if (uploadedFiles == null)
            {
                return(null);
            }

            string         token   = Server.GetUniqueKey(20);
            SecureUploader channel = new SecureUploader(this, token, this.ManageCompleteUpload, this.ManageFailedUpload);
            UInt16         port    = channel.port;

            this.channels.TryAdd(token, channel);

            return(new UploadData(UsefullMethods.GetLocalIPAddress(), port, token));
        }
コード例 #5
0
ファイル: Server.cs プロジェクト: mpuzz/folderbackuper
        private UploadData resetInternals(FBVersion newVersion, FBVersion current)
        {
            FBVersion diff = newVersion - current;

            newVersion.setAbsoluteNameToFile();
            if (diff.root != null)
            {
                diff.setAbsoluteNameToFile();
            }
            current.setAbsoluteNameToFile();

            List <Instruction> instrucionList = new List <Instruction>();

            try { File.Delete(user.rootDirectory.FullName + @"\tmp.zip"); }
            catch { }

            ZipArchive zip = ZipFile.Open(user.rootDirectory.FullName + @"\tmp.zip", ZipArchiveMode.Update);

            if (diff.fileList != null)
            {
                foreach (FBAbstractElement to in diff.fileList)
                {
                    bool found = false;
                    foreach (FBAbstractElement from in current.fileList)
                    {
                        if (from.Equals(to))
                        {
                            found = true;
                            instrucionList.Add(new Instruction(InstructionType.COPY, from.Name, to.Name));
                            break;
                        }
                    }

                    if (!found)
                    {
                        foreach (PhysicFile ph in realFiles.list)
                        {
                            if (ph.getFBFile().Equals(to))
                            {
                                if (zip.GetEntry(ph.getRealFileInfo().Name) == null)
                                {
                                    zip.CreateEntryFromFile(ph.getRealFileInfo().FullName, ph.getRealFileInfo().Name, CompressionLevel.Optimal);
                                }
                                instrucionList.Add(new Instruction(InstructionType.NEW, ph.getRealFileInfo().Name, to.Name));
                            }
                        }
                    }
                }
            }

            diff = current - newVersion;

            if (diff.fileList != null)
            {
                //diff.setAbsoluteNameToFile();
                foreach (FBAbstractElement toDelete in diff.fileList)
                {
                    instrucionList.Add(new Instruction(InstructionType.DELETE, toDelete.Name, ""));
                }
            }
            Stream          FilesStream = File.OpenWrite(this.user.rootDirectory + @"\instructions.bin");
            BinaryFormatter serializer  = new BinaryFormatter();

            serializer.Serialize(FilesStream, instrucionList);
            FilesStream.Close();

            zip.CreateEntryFromFile(this.user.rootDirectory + @"\instructions.bin", "instructions.bin", CompressionLevel.Optimal);
            File.Delete(this.user.rootDirectory + @"\instructions.bin");
            zip.Dispose();
            FilesStream = new FileStream(user.rootDirectory.FullName + @"\tmp.zip", FileMode.Open, FileAccess.Read);

            string           token = Server.GetUniqueKey(20);
            SecureDownloader sr    = new SecureDownloader(this, token,
                                                          this.ManageCompleteUpload, this.ManageFailedUpload, FilesStream);
            UInt16 port = sr.port;

            return(new UploadData(UsefullMethods.GetLocalIPAddress(), port, token));
        }