Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/07/19 14:44:13 (5 years ago)
Author:
mkommend
Message:

#2829: Updated HiveDrain to .Net version 4.6.1 and added handling of invalid characters in filenames.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • misc/tools/HeuristicLab.HiveDrain/HeuristicLab.HiveDrain/JobDownloader.cs

    r15347 r17194  
    2323using System.Collections.Generic;
    2424using System.IO;
     25using System.Linq;
    2526using System.Threading;
    2627using HeuristicLab.Clients.Hive;
     
    5152      Semaphore limitSemaphore = new Semaphore(HeuristicLabHiveDrainApplication.MaxParallelDownloads, HeuristicLabHiveDrainApplication.MaxParallelDownloads);
    5253
     54      var invalidChars = Path.GetInvalidFileNameChars();
     55
    5356      foreach (Job j in jobsLoaded) {
    5457        if (string.IsNullOrEmpty(NamePattern) || j.Name.Contains(NamePattern)) {
    55           string jobPath = Path.Combine(RootLocation, String.Format("{0} - {1}", j.Name, j.Id));
    5658          log.LogMessage(String.Format("\"{0}\": {1}", j.Name, j.Id));
     59
     60
     61          var jobName = j.Name;
     62          //handle invalid characters in fileNames
     63          if (invalidChars.Any(c => jobName.Contains(c))) {
     64            log.LogMessage("Job name contains characters that cannot be used as filename. Invalid characters are replaced with '_'.");
     65            foreach (var c in invalidChars) {
     66              jobName = jobName.Replace(c, '_');
     67            }
     68          }
     69
     70          string jobPath = Path.Combine(RootLocation, String.Format("{0} - {1}", jobName, j.Id));
     71
    5772
    5873          if (OneFile) {
    5974            JobTaskOneFileDownloader taskDownloader = new JobTaskOneFileDownloader(jobPath, j, limitSemaphore, log);
    6075            taskDownloader.Start();
    61           } else {
     76          }
     77          else {
    6278            JobTaskDownloader taskDownloader = new JobTaskDownloader(jobPath, j, limitSemaphore, log);
    6379            taskDownloader.Start();
    6480          }
    65         } else {
     81        }
     82        else {
    6683          log.LogMessage(String.Format("\"{0}\": {1} ---> ignored", j.Name, j.Id));
    6784        }
Note: See TracChangeset for help on using the changeset viewer.