private void initializeUser() { if (!File.Exists(this.user.rootDirectory + @"\files.bin")) //primo accesso { this.realFiles = new PhysicFilesList(); Stream FilesStream = File.OpenWrite(this.user.rootDirectory + @"\files.bin"); BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(FilesStream, realFiles); FilesStream.Close(); this.user.rootDirectory.CreateSubdirectory(firstDirectory); FBVersionBuilder vb = new FBVersionBuilder(user.rootDirectory.FullName + @"\" + firstDirectory); FBVersion v = (FBVersion)vb.generate(); FilesStream = File.OpenWrite(this.user.rootDirectory.FullName + @"\" + firstDirectory + @"\version.bin"); serializer.Serialize(FilesStream, v); FilesStream.Close(); } else { Stream FilesStream1 = File.OpenRead(this.user.rootDirectory + @"\files.bin"); BinaryFormatter deserializer = new BinaryFormatter(); this.realFiles = (PhysicFilesList)deserializer.Deserialize(FilesStream1); FilesStream1.Close(); } }
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); }
public bool commit() { this.checkAuthentication(); this.checkTransactionIsEnabled(); FBVersionBuilder fvb = new FBVersionBuilder(this.ptransactDir.FullName); FBVersion actualVersion = (FBVersion)fvb.generate(); actualVersion.timestamp = inSyncVersion.timestamp; foreach (KeyValuePair <String, SecureChannel> pair in channels) { pair.Value.join(); } if (this.necessaryFiles.Count == 0) { Stream FileStream = File.Create(this.transactDir.FullName + @"\version.bin"); BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(FileStream, this.inSyncVersion); FileStream.Close(); if (this.uploadedFiles != null) { realFiles.add(this.uploadedFiles); } FileStream = File.Open(this.user.rootDirectory + @"\files.bin", FileMode.Create, FileAccess.Write, FileShare.None); serializer.Serialize(FileStream, realFiles); FileStream.Close(); this.uploadedFiles = null; this.transactDir = null; this.inSyncVersion = null; this.transactionEnabled = false; return(true); } else { throw new FaultException <ServiceErrorMessage>(new ServiceErrorMessage(ServiceErrorMessage.SYNCNOTTERMINATED)); } }
public bool rollback() { this.checkAuthentication(); this.checkTransactionIsEnabled(); if (this.transactDir != null) { this.transactDir.Delete(true); this.transactDir = null; } this.inSyncVersion = null; this.transactionEnabled = false; foreach (PhysicFile pf in this.uploadedFiles.list) { File.Delete(pf.getRealFileInfo().FullName); } this.uploadedFiles = null; return(true); }
public void add(PhysicFilesList pfl) { list.AddRange(pfl.list); }
public void add(PhysicFilesList pfl) { lock (this) list.AddRange(pfl.list); }
public bool rollback() { this.checkAuthentication(); this.checkTransactionIsEnabled(); if (this.transactDir != null) { this.transactDir.Delete(true); this.transactDir = null; } this.inSyncVersion = null; this.transactionEnabled = false; foreach (PhysicFile pf in this.uploadedFiles.list) { File.Delete(pf.getRealFileInfo().FullName); } this.uploadedFiles = null; return true; }
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; }
public bool commit() { this.checkAuthentication(); this.checkTransactionIsEnabled(); FBVersionBuilder fvb = new FBVersionBuilder(this.ptransactDir.FullName); FBVersion actualVersion = (FBVersion)fvb.generate(); actualVersion.timestamp = inSyncVersion.timestamp; foreach(KeyValuePair<String, SecureChannel> pair in channels) { pair.Value.join(); } if (this.necessaryFiles.Count == 0) { Stream FileStream = File.Create(this.transactDir.FullName + @"\version.bin"); BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(FileStream, this.inSyncVersion); FileStream.Close(); if(this.uploadedFiles != null) realFiles.add(this.uploadedFiles); FileStream = File.Open(this.user.rootDirectory + @"\files.bin", FileMode.Create, FileAccess.Write, FileShare.None); serializer.Serialize(FileStream, realFiles); FileStream.Close(); this.uploadedFiles = null; this.transactDir = null; this.inSyncVersion = null; this.transactionEnabled = false; return true; } else throw new FaultException<ServiceErrorMessage>(new ServiceErrorMessage(ServiceErrorMessage.SYNCNOTTERMINATED)); }