Exemplo n.º 1
0
 public static void ReceiveFile(FileDetails f, Stream s, BinaryReader br)
 {
     new BinaryFormatter().Serialize(s, f.NameOfFile); //Send FileName to source machine.
     if (File.Exists(f.NameOfFile)) File.Delete(f.NameOfFile); //Hidden files have to be deleted first
     using (var fs = new FileStream(f.NameOfFile, FileMode.Create))
         WriteFileContentsReceived(br, fs);
     File.SetLastWriteTime(f.NameOfFile, f.LastModified);
 }
Exemplo n.º 2
0
        public IEnumerable <FileDetails> GetFilesToBeTransferred()
        {
            var         currentFilesDict = _currentFiles.ToDictionary(f => f.NameOfFile);
            FileDetails desti            = null;

            return(_expectedFiles.Where(source => !currentFilesDict.TryGetValue(source.NameOfFile, out desti) ||
                                        !FileDetails.IsEqualDateAndSize(source, desti)));
        }
Exemplo n.º 3
0
 private void AddChildFiles(string dir)
 {
     foreach (var f in Directory.GetFiles(dir))
     {
         _files.Add(FileDetails.Get(f));
     }
     foreach (var d in Directory.GetDirectories(dir))
     {
         AddChildFiles(d);
     }
 }
Exemplo n.º 4
0
 public static void ReceiveFile(FileDetails f, Stream s, BinaryReader br)
 {
     new BinaryFormatter().Serialize(s, f.NameOfFile); //Send FileName to source machine.
     if (File.Exists(f.NameOfFile))
     {
         File.Delete(f.NameOfFile);                            //Hidden files have to be deleted first
     }
     using (var fs = new FileStream(f.NameOfFile, FileMode.Create))
         WriteFileContentsReceived(br, fs);
     File.SetLastWriteTime(f.NameOfFile, f.LastModified);
 }
Exemplo n.º 5
0
        private static void WriteFileContentsReceived(BinaryReader br, Stream fileStream)
        {
            long i      = 0;
            var  length = br.ReadInt64();

            for (var bytesToRead = length; bytesToRead > 0; bytesToRead--)
            {
                fileStream.WriteByte(br.ReadByte());
                if (i++ > 0 && i % 50000 == 0)
                {
                    Console.Write("Length {1}. Completed {0}%        \r", Math.Round(i * 100.0 / length), FileDetails.Formatted(length));
                }
            }
            Console.Write("{0,50}\r", "");
        }
Exemplo n.º 6
0
 public static bool IsEqualDateAndSize(FileDetails a, FileDetails b)
 {
     return(a.Size == b.Size && a.LastModified == b.LastModified);
 }
Exemplo n.º 7
0
 protected bool Equals(FileDetails other)
 {
     return(string.Equals(NameOfFile, other.NameOfFile));
 }
Exemplo n.º 8
0
 private void SendFileLengthAndContents(Int64 length, Stream fileStream)
 {
     _bw.Write(length);
     for (long i = 0L; i < length; ++i)
     {
         _bw.Write((byte)fileStream.ReadByte());
         if (i > 0 && i % 50000 == 0)
         {
             Console.Write("Length {1}. Completed {0}%        \r", Math.Round(i * 100.0 / length), FileDetails.Formatted(length));
         }
     }
     Console.Write("{0,50}\r", "");
 }
Exemplo n.º 9
0
 public static bool IsEqualDateAndSize(FileDetails a, FileDetails b)
 {
     return a.Size == b.Size && a.LastModified == b.LastModified;
 }
Exemplo n.º 10
0
 protected bool Equals(FileDetails other)
 {
     return string.Equals(NameOfFile, other.NameOfFile);
 }