コード例 #1
0
        private void ProcessOneFile(
            FileInfo fileInfo,
            string directory,
            BlobService blobService,
            DataService dataService)
        {
            try
            {
                var fileName         = fileInfo.Name;
                var directoryAbove   = Directory.GetParent(directory);
                var fileRelativePath = fileInfo.Directory?.FullName
                                       .Substring(directoryAbove.FullName.Length);
                var blobFilePath = Path
                                   .Combine(fileRelativePath, fileName)
                                   .TrimStart('/', '\\');
                fileRelativePath = Path
                                   .Combine(fileRelativePath, fileInfo.Name);

                var songInfo = GetSongInfo(fileInfo, dataService, fileRelativePath);

                songInfo.Extension    = fileInfo.Extension.TrimStart('.');
                songInfo.RelativePath = fileRelativePath;

                dataService.UpdateSongInfo(songInfo);

                blobService.UpdateBlob(blobFilePath, fileInfo.FullName);

                if (!string.IsNullOrEmpty(songInfo.Album.ImagePath))
                {
                    songInfo.Album.ImagePath.Split(';')
                    .ToList().ForEach(i =>
                    {
                        var physicalPath = Path
                                           .Combine(fileInfo.DirectoryName, i);
                        blobService
                        .UpdateImageBlob(i, physicalPath);
                    });
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                _logger.Error(e, "Error occurred while processing file!");
            }
        }
コード例 #2
0
        public void SynchronizeStorage()
        {
            _logger.Information("Starting synchronization...");
            _logger.Information(
                $"Parameters: \nSearchFolders: \"{string.Join(',', _searchFolders)}\"\nExtensions: {string.Join(',', _extensions)}\n");

            var blobService = new BlobService(_logger);
            var dataService = new DataService(_configuration);

            _searchFolders.ForEach(directory =>
            {
                var directoryInfo = new DirectoryInfo(directory);
                var files         = directoryInfo
                                    .GetFilesByExtensions(_extensions.ToList())
                                    .ToList();

                files.ForEach(fileInfo =>
                {
                    ProcessOneFile(fileInfo, directory, blobService, dataService);
                });
            });

            _logger.Information("Synchronization finished...");
        }