public async Task Handle(StartProcessingFile message, IMessageHandlerContext context)
        {
            if (Data.HasStarted)
            {
                _log.Info("Saga has started");
                return;
            }

            _log.Info("Hello from FileProcessor handler");
            _log.InfoFormat("Processing file '{0}' from location '{1}', TotalRecordCount {2}", message.FileName,
                            message.FilePath, message.TotalRecordCount);

            await PopulateSagaData(message);

            // Start processing by retrieving the file
            // breaking the content into chunks
            // process each chunk
            // move the file into "processed" folder

            MarkAsComplete();

            _log.Warn("Saga Complete");

            await Task.CompletedTask;
        }
Example #2
0
        private string ProcessFile(string file, string outPath)
        {
            var inPlaylist = ReadPlaylist(file);

            if (inPlaylist != null)
            {
                StartProcessingFile?.Invoke(this, new ProgressEventArgs(file, inPlaylist.Length));
                string targetDirectory = string.Empty;
                if (_targetStorage is MtpStorage)
                {
                    targetDirectory = HandleContent(file, inPlaylist, AppDomain.CurrentDomain.BaseDirectory, _sourceStorage);
                    CreateTargetPlaylist(inPlaylist, file, targetDirectory, _sourceStorage);
                    return(targetDirectory);
                }
                else
                {
                    targetDirectory = HandleContent(file, inPlaylist, outPath, _targetStorage);
                    CreateTargetPlaylist(inPlaylist, file, targetDirectory, _targetStorage);
                    return(targetDirectory);
                }
            }
            else
            {
                StartProcessingFile?.Invoke(this, new ProgressEventArgs(file, 0));
                return(string.Empty);
            }
        }
        private async Task PopulateSagaData(StartProcessingFile startingMessage)
        {
            Data.HasStarted       = true;
            Data.ImportId         = startingMessage.ImportId;
            Data.FileName         = startingMessage.FileName;
            Data.FilePath         = startingMessage.FilePath;
            Data.TotalRecordCount = startingMessage.TotalRecordCount;

            await Task.CompletedTask;
        }
Example #4
0
        private void CopyToDevice(string inPlaylistName, string fromDirectory, string toDirectory)
        {
            var targetDirectory = CreateTargetDirectory(inPlaylistName, toDirectory, _targetStorage);

            foreach (var sourceFile in _sourceStorage.Directory.GetFiles(fromDirectory, SearchOption.AllDirectories))
            {
                var targetFile = GetTargetFilePath(targetDirectory, sourceFile);
                StartProcessingFile?.Invoke(this, new ProgressEventArgs(targetFile, 0));
                _targetStorage.File.Create(targetFile, _sourceStorage.File.Read(sourceFile));
            }
        }
Example #5
0
        private int CopyContent(string targetDirectory, PlaylistItem[] playlistItems, IStorage storage)
        {
            int fileCopyCount = 0;

            foreach (var playlistItem in playlistItems)
            {
                var sourceFile = playlistItem.FileName;
                var targetFile = GetTargetFilePath(targetDirectory, sourceFile, ++fileCopyCount);
                StartProcessingFile?.Invoke(this, new ProgressEventArgs(targetFile, 0));
                storage.File.Create(targetFile, _sourceStorage.File.Read(sourceFile));
                playlistItem.FileName = Path.GetFileName(targetFile);
            }
            return(fileCopyCount);
        }