Exemple #1
0
        /// <summary>Consumes the specified message.</summary>
        /// <param name="message">The message.</param>
        public void Consume(ProcessFileCommand message)
        {
            _logger.DebugFormat("ProcessFileCommand with {0}", message.PathToFile);

            // first call to the saga, initialize the state
            if (State.IsInitialized == false)
            {
                _logger.InfoFormat("Initializing {0}", Id.ToString());
                State.Database      = string.Format(@"d:\temp\sea\{0}.mdb", Id.ToString());
                State.IsInitialized = true;
            }
            // save the last action for checking the timeout
            State.LastAction = DateTime.Now;

            // remind myself to check the last action after 30 minutes
            var thirtyMinuteDelay = State.LastAction.Add(TimeSpan.FromSeconds(10));

            _bus.DelaySend(thirtyMinuteDelay,
                           new CheckReadyCommand {
                CorrelationId = Id
            });

            // save file to database
            _bus.Send(new WriteDatabaseCommand {
                Database = State.Database, Data = "*"
            });
        }
 public NotificationModel()
 {
     ProcessFileCommand         = new ProcessFileCommand(this);
     ChooseCountryFolderCommand = new ChooseCountryFolderCommand(this);
     ChooseFileCommand          = new ChooseFileCommand(this);
     FilePathLabel          = StringConsts.FilePathLabelConst;
     FileProcessingLabel    = StringConsts.FileProcessingLabelConst;
     CountryFolderPathLabel = StringConsts.CountryFolderPathLabelConst;
 }
Exemple #3
0
 public MainViewModel()
 {
     ProcessFileCommand         = new ProcessFileCommand(this);
     ChooseCountryFolderCommand = new ChooseCountryFolderCommand(this);
     ChooseFileCommand          = new ChooseFileCommand(this);
     FilePathLabel           = StringConsts.FilePathLabelConst;
     FileProcessingLabel     = StringConsts.FileProcessingLabelConst;
     CountryFolderPathLabel  = StringConsts.CountryFolderPathLabelConst;
     FileProcessingLabelData = string.Empty;
 }
 public MainViewModel()
 {
     ProcessFileCommand         = new ProcessFileCommand(this);
     ChooseInputFileCommand     = new ChooseInputFileCommand(this);
     ChooseProxiesFileCommand   = new ChooseProxiesFileCommand(this);
     ChooseResultFolderCommand  = new ChooseResultFolderCommand(this);
     InputFileProcessingLabel   = StringConsts.InputFilePathLabel;
     ProxiesFileProcessingLabel = StringConsts.ProxyFilePathLabel;
     FileProcessingLabel        = StringConsts.FileProcessingLabelConst;
     ResultFolderLabel          = StringConsts.FileProcessingLabelData_Choose_folder;
     FileProcessingLabelData    = string.Empty;
     initPaths();
 }
 public YahooScraperViewModel()
 {
     ProcessFileCommand         = new ProcessFileCommand(this);
     ChooseCountryFolderCommand = new ChooseFolderForStoringCommand(this);
     ChooseFileCommand          = new ChooseFileCommand(this);
     FilePathLabel              = StringConsts.FilePathLabelConst;
     FileProcessingLabel        = StringConsts.FileProcessingLabelConst;
     FolderForStoringFilesLabel = StringConsts.CountryFolderPathLabelConst;
     FileProcessingLabelData    = string.Empty;
     DateFromLabel              = StringConsts.DateFromLabelConst;
     DateToLabel      = StringConsts.DateToLabelConst;
     SelectedDateFrom = DateTime.Now;
     SelectedDateTo   = DateTime.Now;
 }
Exemple #6
0
        public async Task Handle_AllConditionsMet_Success()
        {
            // Arrange
            var temporaryFileName = "file-name";
            var product1          = new Product
            {
                Id = Guid.NewGuid()
            };

            var product2 = new Product
            {
                Id = Guid.NewGuid()
            };

            var command = new ProcessFileCommand
            {
                TemporaryFileName = temporaryFileName
            };

            var fileReader = new Mock <IFileReader>();
            var fileWriter = new Mock <IFileWriter>();

            fileReader
            .Setup(x => x.ReadAsync())
            .Returns(new[] { "item1", "item2" }.ToAsyncEnumerable());

            _temporaryStorage
            .Setup(x => x.OpenForRead(temporaryFileName))
            .Returns(fileReader.Object);

            _mainStorage
            .Setup(x => x.CreateFile(It.IsAny <string>()))
            .Returns(fileWriter.Object);

            _fileToProductConverter
            .Setup(x => x.Convert(fileReader.Object))
            .Returns(new[] { product1, product2 }.ToAsyncEnumerable());

            _productTofileConverter
            .Setup(x => x.Convert(product1))
            .Returns(AsyncEnumerable.Empty <string>());

            _productTofileConverter
            .Setup(x => x.Convert(product2))
            .Returns(AsyncEnumerable.Empty <string>());

            _productRepository
            .SetupSequence(x => x.FindAsync(It.IsAny <Expression <Func <Product, bool> > >()))
            .ReturnsAsync(Enumerable.Empty <Product>())
            .ReturnsAsync(new[] { product2 });

            // Act
            await _handler.Handle(command, CancellationToken.None);

            // Assert
            _temporaryStorage.Verify(x => x.OpenForRead(temporaryFileName), Times.Once);
            _fileToProductConverter.Verify(x => x.Convert(It.IsAny <IFileReader>()), Times.Once);
            _productRepository.Verify(x => x.FindAsync(It.IsAny <Expression <Func <Product, bool> > >()), Times.Exactly(2));
            _productRepository.Verify(x => x.CreateAsync(product1), Times.Once);
            _productRepository.Verify(x => x.UpdateAsync(product2), Times.Once);

            fileWriter.Verify(x => x.WriteAsync(It.IsAny <IAsyncEnumerable <string> >()), Times.Exactly(2));
        }