示例#1
0
 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);
 }
示例#2
0
        //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;
        }
示例#3
0
文件: Util.cs 项目: hfcorreia/padi-fs
        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;
        }
示例#4
0
        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++;
        }
示例#5
0
 public WriteFileService(ClientState clientState, File file)
     : base(clientState)
 {
     NewFile = file;
 }
示例#6
0
文件: Util.cs 项目: hfcorreia/padi-fs
        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();
        }
示例#7
0
        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++;
        }
示例#8
0
 public abstract void write(File file);
示例#9
0
 public void setFileContent(int position, File fileContent)
 {
     Files[position] = fileContent;
 }
示例#10
0
文件: File.cs 项目: hfcorreia/padi-fs
 public File(File file)
 {
     FileName = file.FileName;
     Version = file.Version;
     Content = file.Content;
 }
示例#11
0
 public BufferedWriteRequest(File file)
 {
     File = file;
 }
示例#12
0
 public override void write(File file)
 {
     failError(file.FileName);
 }