public async Task ReceiveAsync(MediaMoverContext context, MediaFile mediaFile, Stream stream)
        {
            Guard.NotNull(context, nameof(context));
            Guard.NotNull(mediaFile, nameof(mediaFile));

            // store data into file
            if (stream != null && stream.Length > 0)
            {
                var filePath = GetPath(mediaFile);

                if (!await _fileSystem.FileExistsAsync(filePath))
                {
                    // TBD: (mc) We only save the file if it doesn't exist yet.
                    // This should save time and bandwidth in the case where the target
                    // is a cloud based file system (like Azure BLOB).
                    // In such a scenario it'd be advisable to copy the files manually
                    // with other - maybe more performant - tools before performing the provider switch.

                    // Create directory if it does not exist yet
                    await _fileSystem.TryCreateDirectoryAsync(Path.GetDirectoryName(filePath));

                    using (stream)
                    {
                        await _fileSystem.SaveStreamAsync(filePath, stream);
                    }

                    context.AffectedFiles.Add(filePath);
                }
            }
        }
Exemplo n.º 2
0
        public virtual async Task <(long fileCount, long totalSize)> CacheStatisticsAsync()
        {
            long fileCount = 0;
            long totalSize = 0;

            if (!await _fileSystem.FileExistsAsync(_thumbsRootDir))
            {
                return(0, 0);
            }

            fileCount = await _fileSystem.CountFilesAsync(_thumbsRootDir, deep : true);

            totalSize = await _fileSystem.GetDirectorySizeAsync(_thumbsRootDir);

            return(fileCount, totalSize);
        }