public void Init() { _log = Substitute.For<ILog>(); _dateCalculator = Substitute.For<IDateCalculator>(); _powerService = Substitute.For<IPowerService>(); _positionAggregator = Substitute.For<IPositionAggregator>(); _fileNameGenerator = Substitute.For<IFileNameGenerator>(); _reportContentWriter = Substitute.For<IReportContentWriter>(); _file = Substitute.For<IFile>(); _reportGenerator = new ReportGenerator(_log, _dateCalculator, _powerService, _positionAggregator, _fileNameGenerator, _reportContentWriter, _file); _reportFolder = @"C:\Temp\"; _dates = new DateResult { ExtractDateTime = new DateTime(2015, 10, 5, 23, 34, 0), RequestDate = new DateTime(2015, 10, 6) }; _powerTradeOne = new PowerTrade(); _powerTradeTwo = new PowerTrade(); _powerTrades = new[] { _powerTradeOne, _powerTradeTwo }; _powerPosition = new PowerPosition(); _fileName = "PowerPositions.csv"; _content = "Local time, Volume etc"; _dateCalculator.Calculate().Returns(_dates); _powerService.GetTrades(_dates.RequestDate).Returns(_powerTrades); _positionAggregator.Aggregate(_dates.RequestDate, Arg.Is<List<PowerTrade>>(x => x[0] == _powerTradeOne && x[1] == _powerTradeTwo)).Returns(_powerPosition); _fileNameGenerator.Generate(_dates.ExtractDateTime).Returns(_fileName); _reportContentWriter.Write(_powerPosition).Returns(_content); }
public void WillCreateTheReportFileNameBasedOnTheExtractTimeInTheDefinedFormat() { var extractTime = new DateTime(2015, 6, 12, 18, 36, 45); var fileName = _generator.Generate(extractTime); Assert.AreEqual("PowerPosition_20150612_1836.csv", fileName); }
public void Init() { _log = Substitute.For <ILog>(); _dateCalculator = Substitute.For <IDateCalculator>(); _powerService = Substitute.For <IPowerService>(); _positionAggregator = Substitute.For <IPositionAggregator>(); _fileNameGenerator = Substitute.For <IFileNameGenerator>(); _reportContentWriter = Substitute.For <IReportContentWriter>(); _file = Substitute.For <IFile>(); _reportGenerator = new ReportGenerator(_log, _dateCalculator, _powerService, _positionAggregator, _fileNameGenerator, _reportContentWriter, _file); _reportFolder = @"C:\Temp\"; _dates = new DateResult { ExtractDateTime = new DateTime(2015, 10, 5, 23, 34, 0), RequestDate = new DateTime(2015, 10, 6) }; _powerTradeOne = new PowerTrade(); _powerTradeTwo = new PowerTrade(); _powerTrades = new[] { _powerTradeOne, _powerTradeTwo }; _powerPosition = new PowerPosition(_dates.RequestDate); _fileName = "PowerPositions.csv"; _content = "Local time, Volume etc"; _dateCalculator.Calculate().Returns(_dates); _powerService.GetTrades(_dates.RequestDate).Returns(_powerTrades); _positionAggregator.Aggregate(_dates.RequestDate, Arg.Is <List <PowerTrade> >(x => x[0] == _powerTradeOne && x[1] == _powerTradeTwo)).Returns(_powerPosition); _fileNameGenerator.Generate(_dates.ExtractDateTime).Returns(_fileName); _reportContentWriter.Write(_powerPosition).Returns(_content); }
public void Generate(string reportFolder) { _log.Info("ReportGenerator started"); var dates = _dateCalculator.Calculate(); _log.InfoFormat("Report ExtractDateTime: {0}, PowerService request date: {1}", dates.ExtractDateTime, dates.RequestDate); // added a retry to the power service as this is an external call and not something we have control over // retry could be changed to catch specific exceptions var trades = new RetryBlock <IList <PowerTrade> >(() => _powerService.GetTrades(dates.RequestDate).ToList()) .WithMaxRetries(3) .WithWaitBetweenRetries(1000) .WithActionBetweenRetries(ex => _log.Warn(($"Retrying after error during GetTrades, exception: {ex}"))) .Execute(); _log.InfoFormat("{0} trade returned", trades.Count); var position = _positionAggregator.Aggregate(dates.RequestDate, trades); var fileName = _fileNameGenerator.Generate(dates.ExtractDateTime); var content = _reportContentWriter.Write(position); var fullFilePath = Path.Combine(reportFolder, fileName); _file.WriteAllText(fullFilePath, content); _log.InfoFormat("ReportGenerator complete: {0}", fullFilePath); }
public async Task <string> SaveFileAsync(IFormFile file) { var fileName = Path.Combine(ContentDirectory, nameGenerator.Generate(Path.GetExtension(file.FileName))); using (var fileStream = new FileStream(fileName, FileMode.Create)) await file.CopyToAsync(fileStream); return(fileName); }
public void GenerateFiles(int filesCount, int contentLength) { for (var i = 0; i < filesCount; ++i) { var generatedFileContent = _contentGenerator.Generate(contentLength); var generatedFileName = _nameGenerator.Generate(); this.WriteBytesToFile(generatedFileName, generatedFileContent); } }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { string fileName = _fileNameGenerator.Generate(); while (fileName != null && await _profile.ParseAsync(_profile.Path.Combine(_parentPath, fileName)) != null) { fileName = _fileNameGenerator.Generate(); } if (fileName == null) { return(ResultCommand.Error(new ArgumentException("Already exists."))); } string newEntryPath = _profile.Path.Combine(_parentPath, fileName); var createddModel = await _profile.DiskIO.CreateAsync(newEntryPath, _isFolder, pm.CancellationToken); return(new NotifyChangedCommand(_profile, newEntryPath, FileExplorer.Defines.ChangeType.Created, _thenFunc(createddModel))); }
public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm) { string path = pm.ReplaceVariableInsideBracketed(PathKey); if (path == null) { return(ResultCommand.Error(new ArgumentException("Path not specified."))); } IDiskProfile profile = pm.GetValue <IDiskProfile>(ProfileKey); if (profile == null) { return(ResultCommand.Error(new ArgumentException(ProfileKey + " is not assigned or not IDiskProfile."))); } string parentPath = profile.Path.GetDirectoryName(path); IFileNameGenerator fNameGenerator = FileNameGenerator.FromNameGenerationMode(NameGenerationMode, profile.Path.GetFileName(path)); string fileName = fNameGenerator.Generate(); while (fileName != null && await profile.ParseAsync(profile.Path.Combine(parentPath, fileName)) != null) { fileName = fNameGenerator.Generate(); } if (fileName == null) { return(ResultCommand.Error(new ArgumentException("Already exists."))); } string newEntryPath = profile.Path.Combine(parentPath, fileName); var createddModel = await profile.DiskIO.CreateAsync(newEntryPath, IsFolder, pm.CancellationToken); logger.Info(String.Format("{0} = {1} ({2})", DestinationKey, createddModel.FullPath, IsFolder ? "Folder" : "File")); pm.SetValue(DestinationKey, createddModel); return(CoreScriptCommands.NotifyEntryChanged(ChangeType.Created, null, DestinationKey, NextCommand)); }
public void Run() { var files = _fileReader.GetFiles(); var fileName = _fileNameGenerator.Generate(DateTime.Now); if (files.All(file => file.FileName != fileName)) { var result = _currencyService.GetLatest(); files.Add(new FileData { FileName = fileName, Data = result }); _fileWriter.Save(fileName, JsonConvert.SerializeObject(result)); } var sendMailsTo = ConfigurationManager.AppSettings["SendMailsTo"]; _emailSender.Send(sendMailsTo, JsonConvert.SerializeObject(files), "Currency Data"); }
string getFileName(string url) { return(fileNameGenerator.Generate(url)); }