Beispiel #1
0
        public byte[] Read(string path, long offset, int length)
        {
            if (!_fileUtils.FileExists(path))
            {
                throw new Exception(ImageNotExistMassage);
            }
            var data = new byte[length];

            using var fs = new FileStream(path, FileMode.Open)
                  {
                      Position = offset
                  };
            var bytesRead = 0;

            while (bytesRead < length)
            {
                var read = fs.Read(data, bytesRead, length - bytesRead);
                if (read == 0)
                {
                    throw new Exception(ErrorReadingFile);
                }
                bytesRead += read;
            }

            return(data);
        }
Beispiel #2
0
 public DateTime GetLastModTimeForPath(string path)
 {
     if (DirectoryUtils.DirectoryExists(path))
     {
         return(DirectoryUtils.GetLastModTimeForDirectory(path));
     }
     else if (FileUtils.FileExists(path))
     {
         return(FileUtils.LastWriteTimeForFile(path));
     }
     else
     {
         throw new FileNotFoundException(String.Format("file not found `{0}'", path));
     }
 }
Beispiel #3
0
        public override void Build()
        {
            var zipFileName = ZipFileName.Value;
            var directory   = Directory.Value;

            if (!FileUtils.FileExists(zipFileName) || (FileUtils.LastWriteTimeForFile(zipFileName) < DirectoryUtils.GetLastModTimeForDirectory(directory)))
            {
                FileUtils.DeleteFile(zipFileName);
                ZipFileCreator.CreateZipFile(zipFileName, directory);
            }
        }
        public void SendFile(string path)
        {
            if (_fileUtils.FileExists(path))
            {
                var fileName = _fileUtils.GetFileName(path);
                _communication.Write(_conversionHandler.ConvertIntToBytes(fileName.Length));
                _communication.Write(_conversionHandler.ConvertStringToBytes(fileName));

                var fileSize = _fileUtils.GetFileSize(path);
                _communication.Write(_conversionHandler.ConvertLongToBytes(fileSize));
                SendFileWithStream(fileSize, path);
            }
            else
            {
                throw new Exception("Image doesn't exist");
            }
        }
Beispiel #5
0
 public bool FileExists(string filename)
 {
     return(FileUtils.FileExists(filename));
 }