Skip to content

Commit bee9e5f

Browse files
committed
Code cleanup for beta testing
1 parent 9a01583 commit bee9e5f

21 files changed

Lines changed: 3073 additions & 4220 deletions
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27703.2035
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31911.196
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReboundLogParser2", "ReboundLogParser2\ReboundLogParser2.csproj", "{0AB3CBAB-452E-4795-905E-533203939E76}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReboundLogParser", "ReboundLogParser\ReboundLogParser.csproj", "{0AB3CBAB-452E-4795-905E-533203939E76}"
77
EndProject
88
Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
File renamed without changes.

ReboundLogParser/ReboundLogParser/MainForm.Designer.cs

Lines changed: 453 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ReboundLogParser/ReboundLogParser2/Form1.cs renamed to ReboundLogParser/ReboundLogParser/MainForm.cs

Lines changed: 127 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
using System.Linq;
44
using System.Windows.Forms;
55
using System.IO;
6-
using Newtonsoft.Json.Linq;
76
using CefSharp.WinForms;
7+
using Newtonsoft.Json;
8+
using Newtonsoft.Json.Linq;
89

9-
namespace ReboundLogParser2 {
10-
public partial class Form1 : Form
10+
namespace ReboundLogParser {
11+
public partial class MainForm : Form
1112
{
1213
static List<stats> _homeTeamPlayers = new List<stats>();
1314
static List<stats> _awayTeamPlayers = new List<stats>();
@@ -17,48 +18,64 @@ public partial class Form1 : Form
1718
static string _currentPeriod;
1819
static bool _overTime = false;
1920
static string _loadedFile;
21+
static List<string> _loadedFiles = new List<string>();
22+
static List<string> _lastLoadedFiles = new List<string>();
2023
static bool _multipleFiles = false;
21-
const string WRONGPERIODTEXT = "The log file entered is not the 3rd period";
22-
const string MULTIPLEFILESTEXT = "Multiple log files in log folder";
24+
const string WRONGPERIODTEXT = "Period 3 log not found!";
25+
const string MULTIPLEFILESTEXT = "Multiiple logfile mode!";
26+
const string INVALIDJSONTEXT = "Invalid JSON, try again!";
2327
private ChromiumWebBrowser _browser;
24-
private List<string> _homePlayers = null;
25-
private List<string> _awayPlayers = null;
2628
private List<ComboBox> _homePlayerBoxes;
2729
private List<ComboBox> _awayPlayerBoxes;
2830

29-
public Form1()
31+
public MainForm()
3032
{
3133
CefSettings cefSettings = new CefSettings();
3234
CefSharp.Cef.EnableHighDPISupport();
3335
CefSharp.Cef.Initialize(cefSettings);
3436

3537
InitializeComponent();
36-
_homePlayerBoxes = new List<ComboBox>() { comboBox1, comboBox2, comboBox3, comboBox4, comboBox5 };
37-
_awayPlayerBoxes = new List<ComboBox>() { comboBox6, comboBox7, comboBox8, comboBox9, comboBox10 };
38+
_homePlayerBoxes = new List<ComboBox>() { homePlayerBox1, homePlayerBox2, homePlayerBox3, homePlayerBox4, homePlayerBox5 };
39+
_awayPlayerBoxes = new List<ComboBox>() { awayPlayerBox1, awayPlayerBox2, awayPlayerBox3, awayPlayerBox4, awayPlayerBox5 };
3840

3941
_browser = new ChromiumWebBrowser("https://a.leaguerepublic.com/myaccount/login/index.html?lver=2");
4042
cefPanel1.Controls.Add(_browser);
4143
}
4244

43-
44-
private void Form1_Load(object sender, EventArgs e)
45-
{
46-
LoadLogFiles();
47-
}
48-
4945
private void LoadLogsButton_Click(object sender, EventArgs e)
5046
{
51-
LoadLogFiles();
47+
using (OpenFileDialog dialog = new OpenFileDialog())
48+
{
49+
if (dialog.ShowDialog() == DialogResult.OK)
50+
{
51+
var fileTemp = dialog.FileNames.ToList();
52+
if (!_loadedFiles.Any(x => fileTemp.Contains(x)))
53+
{
54+
_loadedFiles.AddRange(fileTemp);
55+
}
56+
LoadLogFiles(_loadedFiles);
57+
}
58+
}
5259
}
5360

54-
private void LoadLogFiles()
61+
private void LoadLogFiles(List<string> fileNames = null)
5562
{
5663
ResetFormData();
57-
LoadAndParseLogFiles();
64+
bool success = LoadAndParseLogFiles(fileNames);
5865
SetLoadedFileDisplays();
66+
if (!success)
67+
{
68+
MultipleFiles.Text = INVALIDJSONTEXT;
69+
MultipleFiles.Visible = true;
70+
if (fileNames != null)
71+
{
72+
_loadedFiles.RemoveAll(file => fileNames.Contains(file) && !_lastLoadedFiles.Contains(file));
73+
}
74+
}
5975
SetTeamAndPeriodLabels();
6076
CheckOvertimeWin();
6177
PopulateDataGrid();
78+
_lastLoadedFiles = new List<string>(_loadedFiles);
6279
}
6380

6481
private void ResetFormData()
@@ -78,26 +95,32 @@ private void ResetFormData()
7895
_loadedFile = String.Empty;
7996
_homeScore = 0;
8097
_awayScore = 0;
98+
_period = 0;
99+
SetTeamAndPeriodLabels();
100+
_overTime = false;
101+
CheckOvertimeWin();
102+
_loadedFile = String.Empty;
103+
LogFileName.Text = String.Empty;
81104
}
82105

83-
static void LoadAndParseLogFiles()
106+
static bool LoadAndParseLogFiles(List<string> fileNames = null)
84107
{
85-
string[] filePaths = Directory.GetFiles(@".\Logs\", "*.json",
86-
SearchOption.TopDirectoryOnly);
87-
88-
for (int m = 0; m < filePaths.Length; m++)
89-
{
90-
ParseJson(@filePaths[m]);
91-
_loadedFile += (@filePaths[m] + " ");
92-
}
93-
if (filePaths.Length > 1)
108+
bool success = false;
109+
fileNames = fileNames ?? new List<string>();
110+
foreach (var fileName in fileNames)
94111
{
95-
_multipleFiles = true;
96-
}
97-
else if (filePaths.Length < 1)
98-
{
99-
_loadedFile = "Problem Loading File";
112+
success = ParseJson(fileName);
113+
if (!success)
114+
{
115+
return success; // Will return false here
116+
}
117+
_loadedFile += $"{fileName}; ";
100118
}
119+
120+
_multipleFiles = fileNames.Count > 1;
121+
_loadedFile = (fileNames.Count() < 1) ? "Problem Loading Files!" : _loadedFile;
122+
123+
return success; // True if successful, false if no files
101124
}
102125

103126
private void SetLoadedFileDisplays()
@@ -109,8 +132,8 @@ private void SetLoadedFileDisplays()
109132

110133
private void SetTeamAndPeriodLabels()
111134
{
112-
HomeTeam.Text = "Home Team: " + _homeScore.ToString();
113-
AwayTeam.Text = "Away Team: " + _awayScore.ToString();
135+
HomeTeam.Text = $"Home Team: {_homeScore}";
136+
AwayTeam.Text = $"Away Team: {_awayScore}";
114137
periodLabel.Text = _period.ToString();
115138

116139
if (_currentPeriod != "3")
@@ -141,9 +164,24 @@ private void PopulateDataGrid()
141164
awayDataGrid.DataSource = _awayTeamPlayers;
142165
}
143166

144-
static void ParseJson(string fileName)
167+
static bool ParseJson(string fileName)
145168
{
146-
dynamic o1 = JObject.Parse(File.ReadAllText(fileName));
169+
dynamic o1 = new JObject();
170+
try
171+
{
172+
o1 = JObject.Parse(File.ReadAllText(fileName));
173+
}
174+
catch (JsonReaderException jex)
175+
{
176+
_loadedFile = $"Problem Loading Files: {jex.Message}";
177+
return false;
178+
}
179+
catch (Exception ex)
180+
{
181+
_loadedFile = $"Problem Loading Files: {ex.Message}";
182+
return false;
183+
}
184+
147185
_overTime = CheckOvertime(o1);
148186
string homeScoreString = o1.score.home;
149187
string awayScoreString = o1.score.away;
@@ -173,6 +211,8 @@ static void ParseJson(string fileName)
173211
}
174212
_homeTeamPlayers.Sort(delegate (stats c1, stats c2) { return c1.PlayerName.CompareTo(c2.PlayerName); });
175213
_awayTeamPlayers.Sort(delegate (stats c1, stats c2) { return c1.PlayerName.CompareTo(c2.PlayerName); });
214+
215+
return true;
176216
}
177217

178218
static bool CheckOvertime(dynamic statsObject)
@@ -318,35 +358,35 @@ private void TeamComboBox_SelectedIndexChanged(object sender, EventArgs e)
318358
var isHomeTeamBox = _homePlayerBoxes.Any(box => box.Name.Equals(changedComboBox.Name));
319359
var teamBoxes = (isHomeTeamBox ? _homePlayerBoxes : _awayPlayerBoxes);
320360

321-
var boxesWithDuplicateSelections = teamBoxes.GroupBy(b => b.SelectedItem)
322-
.Where(g => g.Count() > 1 && g.Key != null)
323-
.Select(a => a.Key)
361+
var boxesWithDuplicateSelections = teamBoxes.GroupBy(box => box.SelectedItem)
362+
.Where(groupings => groupings.Count() > 1 && groupings.Key != null)
363+
.Select(boxBySelectedItem => boxBySelectedItem.Key)
324364
.ToList();
325365
foreach (var dupePlayer in boxesWithDuplicateSelections)
326366
{
327367
if (dupePlayer != null)
328368
{
329-
var boxes = teamBoxes.Select(x => x)
330-
.Where(y => y.SelectedItem != null
331-
&& y.SelectedItem.Equals(dupePlayer));
369+
var boxes = teamBoxes.Select(box => box)
370+
.Where(selectedBox => selectedBox.SelectedItem != null
371+
&& selectedBox.SelectedItem.Equals(dupePlayer));
332372
foreach (var box in boxes)
333373
{
334374
box.BackColor = System.Drawing.Color.Red;
335375
}
336376
}
337377
}
338378

339-
var boxesWithoutDuplicateSelections = teamBoxes.GroupBy(a => a.SelectedItem)
340-
.Where(g => g.Count() <= 1 || g.Key == null)
341-
.Select(b => b.Key)
379+
var boxesWithoutDuplicateSelections = teamBoxes.GroupBy(box => box.SelectedItem)
380+
.Where(groupings => groupings.Count() <= 1 || groupings.Key == null)
381+
.Select(boxBySelectedItem => boxBySelectedItem.Key)
342382
.ToList();
343383
foreach (var nonDupePlayer in boxesWithoutDuplicateSelections)
344384
{
345385
if (nonDupePlayer != null)
346386
{
347-
var boxes = teamBoxes.Select(x => x)
348-
.Where(y => y.SelectedItem == null
349-
|| y.SelectedItem.Equals(nonDupePlayer));
387+
var boxes = teamBoxes.Select(box => box)
388+
.Where(boxBySelectedItem => boxBySelectedItem.SelectedItem == null
389+
|| boxBySelectedItem.SelectedItem.Equals(nonDupePlayer));
350390
foreach (var box in boxes)
351391
{
352392
box.BackColor = default;
@@ -357,5 +397,42 @@ private void TeamComboBox_SelectedIndexChanged(object sender, EventArgs e)
357397
var selectedTeamStatsButton = isHomeTeamBox ? SendHomeStatsButton : SendAwayStatsButton;
358398
selectedTeamStatsButton.Enabled = boxesWithDuplicateSelections.Count() == 0;
359399
}
400+
401+
private void DragDropPanel_DragOver(object sender, DragEventArgs e)
402+
{
403+
if (e.Data.GetDataPresent(DataFormats.FileDrop))
404+
{
405+
e.Effect = DragDropEffects.Link;
406+
}
407+
else
408+
{
409+
e.Effect = DragDropEffects.None;
410+
}
411+
}
412+
413+
private void DragDropPanel_DragDrop(object sender, DragEventArgs e)
414+
{
415+
var dropFiles = e.Data.GetData(DataFormats.FileDrop); // get all files dropped
416+
List<string> files = new List<string>();
417+
files.AddRange((dropFiles as string[]).ToList()); ;
418+
if (files != null && files.Any())
419+
{
420+
foreach (var file in files)
421+
{
422+
if (!_loadedFiles.Contains(file))
423+
{
424+
_loadedFiles.Add(file);
425+
}
426+
}
427+
LoadLogFiles(_loadedFiles);
428+
}
429+
}
430+
431+
private void ClearLogsButton_Click(object sender, EventArgs e)
432+
{
433+
_loadedFiles.Clear();
434+
_lastLoadedFiles.Clear();
435+
ResetFormData();
436+
}
360437
}
361438
}

0 commit comments

Comments
 (0)