Example #1
0
 public override void Execute(
     Job job, 
     Action<string> updateStatus,
     IRepository repositoryService, 
     IJobManager jobManager)
 {
     foreach(var file in job.Files.OfType<CreateFile>())
     {
         updateStatus(string.Format("Downloading file: \"{0}\"...", file.Name));
         using(var stream = repositoryService.Download(file.Link.Id))
         {
             using(var fstream = new FileStream(
                 Path.Combine(Directory.GetCurrentDirectory(), string.Format("{0}.data", file.Name)),
                 FileMode.Create))
             {
                 var buff = new byte[256];
                 while(true)
                 {
                     var isCompleted = stream.Read(buff, 0, buff.Length) < buff.Length;
                     fstream.Write(buff, 0, buff.Length);
                     if(isCompleted)
                         break;
                 }
             }
         }
     }
 }
Example #2
0
 private static string ReadFile(IRepository repository, Guid id, int bufferSize)
 {
     using (Perfomance.Trace("Download with buffer size {0} Kbytes", bufferSize / 1024).BindToConsole())
     {
         using (var reader = new StreamReader(repository.Download(id), Encoding.Default, false, bufferSize))
         {
             var text = reader.ReadToEnd();
             return text;
         }
     }
 }