private static TradeHistory ProcessFile(string path) { if (!GetAssetNameFromPath(path, out string asset)) { return(null); } TradeHistory history = new TradeHistory(asset); using (StreamReader reader = new StreamReader(path)) { while (!reader.EndOfStream) { string line = reader.ReadLine(); history.ParseTrade(line); } } return(history); }
private void loadFromToolStripMenuItem_Click(object sender, EventArgs e) { _table.Clear(); using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) { DialogResult result = folderBrowserDialog.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(folderBrowserDialog.SelectedPath)) { string[] filePaths = Directory.GetFiles(folderBrowserDialog.SelectedPath); foreach (string path in filePaths) { TradeHistory tradeHistory = ProcessFile(path); AssetSummary assetSummary = tradeHistory.GetSummary(); object[] rowData = { assetSummary.Asset, assetSummary.NumberOfTrades, assetSummary.AverageWinPercentage, assetSummary.NumberOfTradesOverTenPercent, assetSummary.AveragePercentGainOverTenPercent, assetSummary.NumberOfWins, assetSummary.NumberOfLosses, assetSummary.AverageLosingPercent }; object[] row = new object[rowData.Length + assetSummary.NumberInMonth.Length]; rowData.CopyTo(row, 0); assetSummary.NumberInMonth.CopyTo(row, rowData.Length); _table.Rows.Add(row); } } } }