public override void write(File file) { Console.WriteLine("#DS write " + file.FileName + " is waiting because the server is freezed "); monitor.WaitOne(); Console.WriteLine("#DS write " + file.FileName + " will execute "); new DSstateNormal(Ds).write(file); }
//receives a new filemetadata, //inserts the file in a roundRobin manner and returns //the position in witch the fileMetadata was saved public void addFileContent(File file) { //int filePosition = nextFreePosition; int filePosition = findRegisterPosition(); Files[filePosition] = file; //nextFreePosition = ( nextFreePosition + 1 ) % capacity; // return filePosition; }
public static File readFileFromDisk(String clientName, String name, Int32 version) { System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(File)); string dirName = Properties.Resources.TEMP_DIR + "\\" + clientName + getFileName(name, version) ; System.IO.StreamReader fileReader = new System.IO.StreamReader(dirName); File file = new File(); file = (File) reader.Deserialize(fileReader); fileReader.Close(); return file; }
public void write(File file) { if (AccessCounter.ContainsKey(file.FileName)) { FileAccessCounter counter = AccessCounter[file.FileName]; counter.WriteCounter++; } else { FileAccessCounter fileCounter = new FileAccessCounter(file.FileName); fileCounter.WriteCounter++; AccessCounter[file.FileName] = fileCounter; } State.write(file); //WriteCounter++; }
public WriteFileService(ClientState clientState, File file) : base(clientState) { NewFile = file; }
public static void writeFileToDisk(File file, String clientName) { string dirName = Properties.Resources.TEMP_DIR + "\\" + clientName; Util.createDir(dirName); System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(File)); System.IO.StreamWriter fileWriter = new System.IO.StreamWriter(@dirName + getFileName(file.FileName, file.Version)); writer.Serialize(fileWriter, file); fileWriter.Close(); }
public override void write(File file) { if (file == null) { return; } if (!Ds.FileLocks.ContainsKey(file.FileName)) { Ds.FileLocks.Add(file.FileName, new System.Threading.ReaderWriterLockSlim()); } Ds.FileLocks[file.FileName].EnterWriteLock(); if (Ds.Files.ContainsKey(file.FileName)) { if (Ds.Files[file.FileName].Version > file.Version) { //trying to write an old version -> discard the write Ds.FileLocks[file.FileName].ExitWriteLock(); return; } else if (Ds.Files[file.FileName].Version == file.Version) { int actualClientId = getClientId(Ds.Files[file.FileName].clientId); int newClientId = getClientId(file.clientId); Console.WriteLine("DS write - actual: " + actualClientId + ", new: " + newClientId); if (actualClientId < newClientId) { //in case we have a draw (concurrent writes from diferent clients) //we save the version of the client with smallest id and so we discard the //request if the new user has a bigger id than the actual Ds.FileLocks[file.FileName].ExitWriteLock(); return; } } //the write will be persisted!! //if we allready have an old version of the file we delete it Ds.Files.Remove(file.FileName); } //creates a new file Ds.Files.Add(file.FileName, file); try { Console.WriteLine("#DS: write fileName: " + file.FileName + ", version: " + file.Version + ", content: " + System.Text.Encoding.UTF8.GetString(file.Content)); Util.writeFileToDisk(file, "" + Ds.Id); Ds.makeCheckpoint(); } finally { Ds.FileLocks[file.FileName].ExitWriteLock(); } Ds.WriteCounter++; }
public abstract void write(File file);
public void setFileContent(int position, File fileContent) { Files[position] = fileContent; }
public File(File file) { FileName = file.FileName; Version = file.Version; Content = file.Content; }
public BufferedWriteRequest(File file) { File = file; }
public override void write(File file) { failError(file.FileName); }