public WriteOutputStockPriceCsvFileOutput Execute(WriteOutputStockPriceCsvFileInput input) { // Assign and Validate Input _input = input; _input.ValidateInput(); using (var fs = new FileStream(_input.FilePath, FileMode.Create)) { using (var sw = new StreamWriter(fs)) { var headerLine = string.Format("{0},{1},{2},{3},{4},{5, 10},{6}", "Date", "Open", "High", "Low", "Close", "Volume", "SwingPoint"); sw.WriteLine(headerLine); foreach (var stockPriceRow in _input.DetailsList) { var detailLine = string.Format("{0:MM/dd/yyyy},{1:0.00},{2:0.00},{3:0.00},{4:0.00},{5, 10},{6}", stockPriceRow.PriceDate.ToString("MM/dd/yyyy"), stockPriceRow.OpenPrice, stockPriceRow.HighPrice, stockPriceRow.LowPrice, stockPriceRow.ClosePrice, stockPriceRow.ShareVolume, stockPriceRow.SwingPoint); sw.WriteLine(detailLine); } _output.IsSuccessfullyWritten = true; } } return(_output); }
public WriteOutputStockPriceCsvFileOutput Execute(WriteOutputStockPriceCsvFileInput input) { // Assign and Validate Input _input = input; _input.ValidateInput(); using (var fs = new FileStream(_input.FilePath, FileMode.Create)) { using (var sw = new StreamWriter(fs)) { var headerLine = string.Format("{0},{1},{2},{3},{4},{5, 10},{6}", "Date", "Open", "High", "Low", "Close", "Volume", "SwingPoint"); sw.WriteLine(headerLine); foreach (var stockPriceRow in _input.DetailsList) { var detailLine = string.Format("{0:MM/dd/yyyy},{1:0.00},{2:0.00},{3:0.00},{4:0.00},{5, 10},{6}", stockPriceRow.PriceDate.ToString("MM/dd/yyyy"), stockPriceRow.OpenPrice, stockPriceRow.HighPrice, stockPriceRow.LowPrice, stockPriceRow.ClosePrice, stockPriceRow.ShareVolume, stockPriceRow.SwingPoint); sw.WriteLine(detailLine); } _output.IsSuccessfullyWritten = true; } } return _output; }
private static bool WriteStockPriceDetailsToFile(string filename, List <dynamic> stockPriceList) { var outputFilePath = string.Format(@"../../Data/Output/{0}.csv", filename); var input = new WriteOutputStockPriceCsvFileInput(); input.FilePath = outputFilePath; input.HeadersList = new List <dynamic>(); // TODO: Send the list of Headers input.DetailsList = stockPriceList; var output = new WriteOutputStockPriceCsvFile().Execute(input); return(output.IsSuccessfullyWritten); }
private static bool WriteStockPriceDetailsToFile(string filename, List<dynamic> stockPriceList) { var outputFilePath = string.Format(@"../../Data/Output/{0}.csv", filename); var input = new WriteOutputStockPriceCsvFileInput(); input.FilePath = outputFilePath; input.HeadersList = new List<dynamic>(); // TODO: Send the list of Headers input.DetailsList = stockPriceList; var output = new WriteOutputStockPriceCsvFile().Execute(input); return output.IsSuccessfullyWritten; }