Skip to content

Commit

Permalink
refactor: remove task return type from sheets generate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
akiver committed Jul 15, 2022
1 parent 46f01b7 commit ea5e273
Show file tree
Hide file tree
Showing 26 changed files with 365 additions and 457 deletions.
20 changes: 10 additions & 10 deletions Services/Concrete/Excel/MultipleExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,25 @@ public override async Task<IWorkbook> Generate()

cancellationToken.ThrowIfCancellationRequested();
_configuration.OnGeneratingXlsxFile?.Invoke();
await _generalSheet.Generate();
_generalSheet.Generate();
cancellationToken.ThrowIfCancellationRequested();
await _playersSheet.Generate();
_playersSheet.Generate();
cancellationToken.ThrowIfCancellationRequested();
await _teamsSheet.Generate();
_teamsSheet.Generate();
cancellationToken.ThrowIfCancellationRequested();
await _mapsSheet.Generate();
_mapsSheet.Generate();
cancellationToken.ThrowIfCancellationRequested();
await _weaponsSheet.Generate();
_weaponsSheet.Generate();
cancellationToken.ThrowIfCancellationRequested();
await _roundsSheet.Generate();
_roundsSheet.Generate();
cancellationToken.ThrowIfCancellationRequested();
await _killsSheet.Generate();
_killsSheet.Generate();
cancellationToken.ThrowIfCancellationRequested();
await _killMatrixSheet.Generate();
_killMatrixSheet.Generate();
cancellationToken.ThrowIfCancellationRequested();
await _flashMatrixPlayersSheet.Generate();
_flashMatrixPlayersSheet.Generate();
cancellationToken.ThrowIfCancellationRequested();
await _flashMatrixTeamsSheet.Generate();
_flashMatrixTeamsSheet.Generate();
cancellationToken.ThrowIfCancellationRequested();

return Workbook;
Expand Down
7 changes: 3 additions & 4 deletions Services/Concrete/Excel/Sheets/AbstractSheet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NPOI.SS.UserModel;

namespace Services.Concrete.Excel.Sheets
Expand All @@ -11,7 +10,7 @@ public abstract class AbstractSheet

protected Dictionary<string, CellType> Headers;

protected abstract Task GenerateContent();
protected abstract void GenerateContent();

protected void GenerateHeaders()
{
Expand All @@ -26,10 +25,10 @@ protected void GenerateHeaders()
};
}

public async Task Generate()
public void Generate()
{
GenerateHeaders();
await GenerateContent();
GenerateContent();
}

public void SetCellValue(IRow row, int index, CellType cellType, dynamic value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Core.Models;
using Core.Models.Events;
using NPOI.SS.UserModel;
Expand Down Expand Up @@ -75,7 +74,7 @@ public override void AddDemo(Demo demo)
}
}

protected override Task GenerateContent()
protected override void GenerateContent()
{
_playerNamePerSteamId = _playerNamePerSteamId.OrderBy(k => k.Value).ToDictionary(x => x.Key, x => x.Value);

Expand Down Expand Up @@ -104,8 +103,6 @@ protected override Task GenerateContent()
SetCellValue(row, columnNumber++, CellType.Numeric, duration);
}
}

return Task.CompletedTask;
}

private bool IsMaxPlayerLimitReached()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Core.Models;
using Core.Models.Events;
using NPOI.SS.UserModel;
Expand Down Expand Up @@ -33,7 +32,7 @@ public override void AddDemo(Demo demo)
ComputeTeamStats(demo.TeamT, demo.TeamCT, blindEvents);
}

protected override Task GenerateContent()
protected override void GenerateContent()
{
_teamNames.Sort();

Expand All @@ -57,8 +56,6 @@ protected override Task GenerateContent()
SetCellValue(row, killColumnNumber++, CellType.Numeric, duration);
}
}

return Task.CompletedTask;
}

private void ComputeTeamStats(Team team, Team oppositeTeam, List<PlayerBlindedEvent> blindEvents)
Expand Down
5 changes: 1 addition & 4 deletions Services/Concrete/Excel/Sheets/Multiple/GeneralSheet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Core.Models;
using NPOI.SS.UserModel;

Expand Down Expand Up @@ -74,7 +73,7 @@ public override void AddDemo(Demo demo)
}
}

protected override Task GenerateContent()
protected override void GenerateContent()
{
int rowNumber = 1;
foreach (Demo demo in _demos)
Expand Down Expand Up @@ -130,8 +129,6 @@ protected override Task GenerateContent()
SetCellValue(row, columnNumber++, CellType.String, demo.Comment);
SetCellValue(row, columnNumber, CellType.Boolean, demo.CheaterCount);
}

return Task.CompletedTask;
}
}
}
5 changes: 1 addition & 4 deletions Services/Concrete/Excel/Sheets/Multiple/KillMatrixSheet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Core.Models;
using Core.Models.Events;
using NPOI.SS.UserModel;
Expand Down Expand Up @@ -75,7 +74,7 @@ public override void AddDemo(Demo demo)
}
}

protected override Task GenerateContent()
protected override void GenerateContent()
{
_playerNamePerSteamId = _playerNamePerSteamId.OrderBy(k => k.Value).ToDictionary(x => x.Key, x => x.Value);

Expand Down Expand Up @@ -104,8 +103,6 @@ protected override Task GenerateContent()
SetCellValue(row, killColumnNumber++, CellType.Numeric, killCount);
}
}

return Task.CompletedTask;
}

private bool IsMaxPlayerLimitReached()
Expand Down
5 changes: 1 addition & 4 deletions Services/Concrete/Excel/Sheets/Multiple/KillsSheet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Core.Models;
using Core.Models.Events;
using NPOI.SS.UserModel;
Expand Down Expand Up @@ -59,7 +58,7 @@ public override void AddDemo(Demo demo)
}
}

protected override Task GenerateContent()
protected override void GenerateContent()
{
int rowNumber = 1;
foreach (KeyValuePair<string, KillEvent[]> kvp in _KillsPerDemoId)
Expand Down Expand Up @@ -103,8 +102,6 @@ protected override Task GenerateContent()
SetCellValue(row, columnNumber, CellType.Numeric, kill.Point.VictimZ);
}
}

return Task.CompletedTask;
}
}
}
5 changes: 1 addition & 4 deletions Services/Concrete/Excel/Sheets/Multiple/MapsSheet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Core.Models;
using NPOI.SS.UserModel;

Expand Down Expand Up @@ -68,7 +67,7 @@ public override void AddDemo(Demo demo)
}
}

protected override Task GenerateContent()
protected override void GenerateContent()
{
int rowCount = 1;
foreach (Map map in _maps)
Expand All @@ -90,8 +89,6 @@ protected override Task GenerateContent()
SetCellValue(row, columnNumber++, CellType.Numeric, map.BombPlantedOnACount);
SetCellValue(row, columnNumber, CellType.Numeric, map.BombPlantedOnBCount);
}

return Task.CompletedTask;
}

private void ComputeGlobalStats(Demo demo, Map map)
Expand Down
5 changes: 1 addition & 4 deletions Services/Concrete/Excel/Sheets/Multiple/PlayersSheet.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Core.Models;
using NPOI.SS.UserModel;
using Services.Models.Excel;
Expand Down Expand Up @@ -170,7 +169,7 @@ public override void AddDemo(Demo demo)
}
}

protected override Task GenerateContent()
protected override void GenerateContent()
{
int rowCount = 1;
foreach (KeyValuePair<Player, PlayerStats> playerData in _playersData)
Expand Down Expand Up @@ -257,8 +256,6 @@ protected override Task GenerateContent()
SetCellValue(row, columnNumber++, CellType.Boolean, playerData.Value.IsVacBanned);
SetCellValue(row, columnNumber, CellType.Boolean, playerData.Value.IsOverwatchBanned);
}

return Task.CompletedTask;
}
}
}
5 changes: 1 addition & 4 deletions Services/Concrete/Excel/Sheets/Multiple/RoundsSheet.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Core.Models;
using NPOI.SS.UserModel;

Expand Down Expand Up @@ -61,7 +60,7 @@ public override void AddDemo(Demo demo)
}
}

protected override Task GenerateContent()
protected override void GenerateContent()
{
int rowNumber = 1;
foreach (KeyValuePair<string, Round[]> kvp in _roundsPerDemoId)
Expand Down Expand Up @@ -110,8 +109,6 @@ protected override Task GenerateContent()
rowNumber++;
}
}

return Task.CompletedTask;
}
}
}
7 changes: 2 additions & 5 deletions Services/Concrete/Excel/Sheets/Multiple/TeamsSheet.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using Core.Models;
using Core.Models.Events;
using NPOI.SS.UserModel;
Expand All @@ -11,7 +10,7 @@ namespace Services.Concrete.Excel.Sheets.Multiple
{
public class TeamsSheet : AbstractMultipleSheet
{
List<Team> _teams = new List<Team>();
readonly List<Team> _teams = new List<Team>();

public TeamsSheet(IWorkbook workbook)
{
Expand Down Expand Up @@ -86,7 +85,7 @@ public override void AddDemo(Demo demo)
}
}

protected override Task GenerateContent()
protected override void GenerateContent()
{
int rowCount = 1;
foreach (Team team in _teams)
Expand Down Expand Up @@ -132,8 +131,6 @@ protected override Task GenerateContent()
SetCellValue(row, columnNumber++, CellType.Numeric, team.IncendiaryThrownCount);
SetCellValue(row, columnNumber, CellType.Numeric, team.DecoyThrownCount);
}

return Task.CompletedTask;
}


Expand Down
5 changes: 1 addition & 4 deletions Services/Concrete/Excel/Sheets/Multiple/WeaponsSheet.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Core.Models;
using Core.Models.Events;
using DemoInfo;
Expand Down Expand Up @@ -88,7 +87,7 @@ public override void AddDemo(Demo demo)
}
}

protected override Task GenerateContent()
protected override void GenerateContent()
{
int rowCount = 1;
foreach (KeyValuePair<Weapon, WeaponsData> weaponData in _data)
Expand All @@ -103,8 +102,6 @@ protected override Task GenerateContent()
SetCellValue(row, columnNumber++, CellType.Numeric, weaponData.Value.Hits);
SetCellValue(row, columnNumber, CellType.Numeric, weaponData.Value.Accurary);
}

return Task.CompletedTask;
}
}
}
32 changes: 14 additions & 18 deletions Services/Concrete/Excel/Sheets/Single/EnryKillsPlayerSheet.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Core.Models;
using NPOI.SS.UserModel;

Expand All @@ -22,26 +21,23 @@ public EntryKillsPlayerSheet(IWorkbook workbook, Demo demo)
Sheet = workbook.CreateSheet("Entry Kills Players");
}

protected override async Task GenerateContent()
protected override void GenerateContent()
{
await Task.Factory.StartNew(() =>
{
int rowNumber = 1;
int rowNumber = 1;

foreach (Player player in Demo.Players)
{
IRow row = Sheet.CreateRow(rowNumber);
int columnNumber = 0;
SetCellValue(row, columnNumber++, CellType.String, player.Name);
SetCellValue(row, columnNumber++, CellType.String, player.SteamId.ToString());
SetCellValue(row, columnNumber++, CellType.Numeric, player.EntryKills.Count);
SetCellValue(row, columnNumber++, CellType.Numeric, player.EntryKillWonCount);
SetCellValue(row, columnNumber++, CellType.Numeric, player.EntryKillLossCount);
SetCellValue(row, columnNumber, CellType.Numeric, player.RatioEntryKill);
foreach (Player player in Demo.Players)
{
IRow row = Sheet.CreateRow(rowNumber);
int columnNumber = 0;
SetCellValue(row, columnNumber++, CellType.String, player.Name);
SetCellValue(row, columnNumber++, CellType.String, player.SteamId.ToString());
SetCellValue(row, columnNumber++, CellType.Numeric, player.EntryKills.Count);
SetCellValue(row, columnNumber++, CellType.Numeric, player.EntryKillWonCount);
SetCellValue(row, columnNumber++, CellType.Numeric, player.EntryKillLossCount);
SetCellValue(row, columnNumber, CellType.Numeric, player.RatioEntryKill);

rowNumber++;
}
});
rowNumber++;
}
}
}
}
Loading

0 comments on commit ea5e273

Please sign in to comment.