Exemplo n.º 1
0
 private IEnumerable <Item> _getItems(IEnumerable <RawFileData> files, IProgressionHandler progress)
 {
     try
     {
         var filteredFiles = files.Where(file => file.Type == FileType.Model).ToArray();
         var hashes        = filteredFiles.Select(x => x.Hash).ToArray();
         var fileCount     = filteredFiles.Count();
         _logger.LogTrace("creating {0} items: {1}", fileCount, hashes);
         var res = filteredFiles
                   .GroupBy(fileEx => fileEx.HashKey)
                   .Select(fileGroup =>
         {
             var itemId = ItemId.New();
             return(new Item(
                        ItemName.From(fileGroup.First().Path.GetFilenameWithoutExtension().Value),
                        null,
                        new ItemVersion(
                            itemId,
                            fileGroup.Key,
                            new Version(1, 0, 0),
                            fileGroup.Select(file => file.GetFileData())
                            ).AsArray(),
                        itemId));
         }).ToArray();
         progress.Current++;
         _logger.LogInformation("created {0} items with a total of {1} Versions", res.Count(), res.SelectMany(item => item.Versions).Count());
         return(res);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "item-creation failed");
         return(null);
     }
 }
Exemplo n.º 2
0
 private IEnumerable <RawFileData> _getFilePathsForDirectory(IProgressionHandler progress)
 {
     _logger.LogTrace("reading local files");
     progress.State = JobState.InProgress;
     try
     {
         var res = _fileSetupService
                   .Directories
                   .Items
                   .SelectMany(dir =>
                               dir.Directory.GetFiles()
                               .Select(file => new RawFileData(dir, FilePath.From(file)))
                               )
                   .Where(file => file.Type.IsIn(FileType.Image, FileType.Model));
         progress.State = JobState.Done;
         progress.Current++;
         _logger.LogTrace("found {0} files", res.Count());
         return(res);
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, "files could not be read.");
         progress.State   = JobState.Failed;
         progress.Details = ex.ToString();
         throw ex;
     }
 }