Skip to content

Commit

Permalink
cleanup, use var
Browse files Browse the repository at this point in the history
  • Loading branch information
IMamic23 committed May 28, 2024
1 parent e0cd591 commit d7e7aa3
Show file tree
Hide file tree
Showing 28 changed files with 179 additions and 186 deletions.
4 changes: 2 additions & 2 deletions BetsKiller.API.NBAcom/Helpers/StringTransformator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public class StringTransformator
{
public static string RemoveSpecialCharacters(string str)
{
StringBuilder sb = new StringBuilder();
foreach (char c in str)
var sb = new StringBuilder();
foreach (var c in str)
{
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '.' || c == '_' || c == ' ' || c == '/' || c == ':' || c == '-' || c == '?' || c == '=')
{
Expand Down
10 changes: 5 additions & 5 deletions BetsKiller.API.NBAcom/Methods/Method.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class Method

protected XmlDocument XmlDocument
{
get { return this._xmlDocument; }
get { return _xmlDocument; }
}

#endregion
Expand All @@ -26,12 +26,12 @@ protected XmlDocument XmlDocument

protected void GetData()
{
using (WebClient webClient = new WebClient())
using (var webClient = new WebClient())
{
string response = webClient.DownloadString(this.Url);
var response = webClient.DownloadString(Url);

this._xmlDocument = new XmlDocument();
this._xmlDocument.LoadXml(response);
_xmlDocument = new XmlDocument();
_xmlDocument.LoadXml(response);
}
}

Expand Down
8 changes: 4 additions & 4 deletions BetsKiller.API.NBAcom/Methods/MethodNews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public MethodNews()

public List<News> Get()
{
base.GetData();
GetData();

List<News> listNews = new List<News>();
var listNews = new List<News>();

XmlNodeList items = base.XmlDocument.SelectNodes("//channel/item");
var items = XmlDocument.SelectNodes("//channel/item");

foreach (XmlNode item in items)
{
News news = new News();
var news = new News();

news.Title = StringTransformator.RemoveSpecialCharacters(WebUtility.HtmlDecode(item.SelectSingleNode("title").InnerText));
news.Link = StringTransformator.RemoveSpecialCharacters(WebUtility.HtmlDecode(item.SelectSingleNode("link").InnerText));
Expand Down
21 changes: 10 additions & 11 deletions BetsKiller.API.NBAcom/Methods/MethodPowerRankings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Configuration;
using System.Net;
using System.Text.RegularExpressions;
using System.Xml;

namespace BetsKiller.API.NBAcom.Methods
{
Expand Down Expand Up @@ -34,27 +33,27 @@ public MethodPowerRankings()

public List<PowerRankings> Get()
{
base.GetData();
GetData();

List<PowerRankings> powerRankings = new List<PowerRankings>();
var powerRankings = new List<PowerRankings>();

// Get current power ranking link
XmlNodeList items = base.XmlDocument.SelectNodes("//channel/item");
string currentPowerRankingLink = StringTransformator.RemoveSpecialCharacters(items[0].SelectSingleNode("link").InnerText);
var items = XmlDocument.SelectNodes("//channel/item");
var currentPowerRankingLink = StringTransformator.RemoveSpecialCharacters(items[0].SelectSingleNode("link").InnerText);

// Load HTML document from link
HtmlDocument htmlDocument = new HtmlDocument();
using (WebClient webClient = new WebClient())
var htmlDocument = new HtmlDocument();
using (var webClient = new WebClient())
{
string response = webClient.DownloadString(currentPowerRankingLink);
var response = webClient.DownloadString(currentPowerRankingLink);
htmlDocument.LoadHtml(response);
}

// Parse HTML document
HtmlNodeCollection teams = htmlDocument.DocumentNode.SelectNodes("//div[@class='nbaArticlePRItem']");
foreach (HtmlNode team in teams)
var teams = htmlDocument.DocumentNode.SelectNodes("//div[@class='nbaArticlePRItem']");
foreach (var team in teams)
{
PowerRankings powerRanking = new PowerRankings();
var powerRanking = new PowerRankings();

powerRanking.TeamName = team.SelectSingleNode("div[2]/b[1]").InnerText.Trim();
powerRanking.Rank = team.SelectSingleNode("div[1]/div[1]/div[1]/p").InnerHtml.Trim();
Expand Down
8 changes: 3 additions & 5 deletions BetsKiller.API.NBAcom/_Example/UseMethods.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using BetsKiller.API.NBAcom.Entities;
using BetsKiller.API.NBAcom.Methods;
using System.Collections.Generic;
using BetsKiller.API.NBAcom.Methods;

namespace BetsKiller.API.NBAcom._Example
{
public class UseMethods
{
public static void Start()
{
MethodNews methodNews = new MethodNews();
List<News> news = methodNews.Get();
var methodNews = new MethodNews();
var news = methodNews.Get();
}
}
}
10 changes: 5 additions & 5 deletions BetsKiller.API.Rotoworld/Methods/MethodHtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class MethodHtml

protected HtmlDocument HtmlDocument
{
get { return this._htmlDocument; }
get { return _htmlDocument; }
}

#endregion
Expand All @@ -26,12 +26,12 @@ protected HtmlDocument HtmlDocument

protected void GetData()
{
using (WebClient webClient = new WebClient())
using (var webClient = new WebClient())
{
string response = webClient.DownloadString(this.Url);
var response = webClient.DownloadString(Url);

this._htmlDocument = new HtmlDocument();
this._htmlDocument.LoadHtml(response);
_htmlDocument = new HtmlDocument();
_htmlDocument.LoadHtml(response);
}
}

Expand Down
23 changes: 11 additions & 12 deletions BetsKiller.API.Rotoworld/Methods/MethodInjuries.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BetsKiller.API.Rotoworld.Entities;
using BetsKiller.API.Rotoworld.Helpers;
using HtmlAgilityPack;
using System.Collections.Generic;
using System.Configuration;
using System.Net;
Expand Down Expand Up @@ -29,23 +28,23 @@ public MethodInjuries()

public List<Injury> Get()
{
base.GetData();
GetData();

List<Injury> injuries = new List<Injury>();
var injuries = new List<Injury>();

// Iterate teams
HtmlNodeCollection teams = base.HtmlDocument.DocumentNode.SelectNodes("//div[@class='pb']");
foreach (HtmlNode team in teams)
var teams = HtmlDocument.DocumentNode.SelectNodes("//div[@class='pb']");
foreach (var team in teams)
{
string teamName = team.SelectSingleNode("div").InnerText;
var teamName = team.SelectSingleNode("div").InnerText;

// Iterate players
HtmlNodeCollection players = team.SelectNodes("table/tr");
for (int i = 1; i < players.Count; i++)
var players = team.SelectNodes("table/tr");
for (var i = 1; i < players.Count; i++)
{
HtmlNodeCollection playerData = players[i].SelectNodes("td");
var playerData = players[i].SelectNodes("td");

Injury injury = new Injury();
var injury = new Injury();

injury.TeamName = teamName;
injury.PlayerName = StringTransformator.RemoveSpecialCharacters(WebUtility.HtmlDecode(playerData[0].InnerText));
Expand All @@ -55,10 +54,10 @@ public List<Injury> Get()
injury.Type = StringTransformator.RemoveSpecialCharacters(WebUtility.HtmlDecode(playerData[5].InnerText));
injury.Returns = StringTransformator.RemoveSpecialCharacters(WebUtility.HtmlDecode(playerData[6].InnerText));

string report = playerData[1].SelectSingleNode("div/div[1]").InnerText;
var report = playerData[1].SelectSingleNode("div/div[1]").InnerText;
injury.Report = StringTransformator.RemoveSpecialCharacters(WebUtility.HtmlDecode(report));

string reportUpdateDate = playerData[1].SelectSingleNode("div/div[3]").InnerText;
var reportUpdateDate = playerData[1].SelectSingleNode("div/div[3]").InnerText;
injury.ReportUpdateDate = WebUtility.HtmlDecode(reportUpdateDate);

injuries.Add(injury);
Expand Down
8 changes: 4 additions & 4 deletions BetsKiller.API.Rotoworld/Methods/MethodNews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public MethodNews()

public List<News> Get()
{
base.GetData();
GetData();

List<News> listNews = new List<News>();
var listNews = new List<News>();

XmlNodeList items = base.XmlDocument.SelectNodes("//channel/item");
var items = XmlDocument.SelectNodes("//channel/item");

foreach (XmlNode item in items)
{
News news = new News();
var news = new News();

news.Title = StringTransformator.RemoveSpecialCharacters(WebUtility.HtmlDecode(item.SelectSingleNode("title").InnerText));
news.Link = StringTransformator.RemoveSpecialCharacters(WebUtility.HtmlDecode(item.SelectSingleNode("link").InnerText));
Expand Down
10 changes: 5 additions & 5 deletions BetsKiller.API.Rotoworld/Methods/MethodXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class MethodXml

protected XmlDocument XmlDocument
{
get { return this._xmlDocument; }
get { return _xmlDocument; }
}

#endregion
Expand All @@ -26,12 +26,12 @@ protected XmlDocument XmlDocument

protected void GetData()
{
using (WebClient webClient = new WebClient())
using (var webClient = new WebClient())
{
string response = webClient.DownloadString(this.Url);
var response = webClient.DownloadString(Url);

this._xmlDocument = new XmlDocument();
this._xmlDocument.LoadXml(response);
_xmlDocument = new XmlDocument();
_xmlDocument.LoadXml(response);
}
}

Expand Down
2 changes: 0 additions & 2 deletions BetsKiller.BL/BetsKiller.BL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.0\lib\net45\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.0\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
Expand All @@ -72,7 +71,6 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WebMatrix.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="WebMatrix.WebData, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="WebMatrix.WebData, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.WebData.3.2.3\lib\net45\WebMatrix.WebData.dll</HintPath>
</Reference>
Expand Down
1 change: 0 additions & 1 deletion BetsKiller.ViewModel/BetsKiller.ViewModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
<Reference Include="System.Web.Helpers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.3.2.0\lib\net45\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.2.0\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
Expand Down
2 changes: 1 addition & 1 deletion Jobs/BetsKiller.Jobs/JobEveryDay0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override void Job()
IEnumerable<UserProfile> userProfiles = this._repository.SelectUserProfiles(null, null, null).ToList();
IEnumerable<Role> roles = this._repository.SelectRoles().ToList();

foreach (UserProfile userProfile in userProfiles)
foreach (var userProfile in userProfiles)
{
if (userProfile.RoleActiveTo.HasValue
&& userProfile.RoleActiveTo.Value.Date < DateTime.Now.Date
Expand Down
20 changes: 10 additions & 10 deletions Jobs/BetsKiller.Jobs/JobEveryDay9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override void Job()
* Update NBA teams.
*/

LoadTeamsNBA loadTeamsNba = new LoadTeamsNBA();
var loadTeamsNba = new LoadTeamsNBA();
loadTeamsNba.Start();

Thread.Sleep(base.WAIT_TIME);
Expand All @@ -33,7 +33,7 @@ protected override void Job()
* Load new NBA leaders.
*/

LoadLeadersNBA loadLeadersNba = new LoadLeadersNBA();
var loadLeadersNba = new LoadLeadersNBA();
loadLeadersNba.Start();

Thread.Sleep(base.WAIT_TIME);
Expand All @@ -43,7 +43,7 @@ protected override void Job()
* Load new NBA rosters.
*/

LoadRostersNBA loadRostersNba = new LoadRostersNBA();
var loadRostersNba = new LoadRostersNBA();
loadRostersNba.Start();

Thread.Sleep(base.WAIT_TIME);
Expand All @@ -53,29 +53,29 @@ protected override void Job()
* Load new NBA draft data.
*/

LoadDraftNBA loadDrafNba = new LoadDraftNBA();
var loadDrafNba = new LoadDraftNBA();
loadDrafNba.Start();

Thread.Sleep(base.WAIT_TIME);

/*
* Update events data from past days.
*/
DateTime today = DateTime.Now;
string dateToday = today.Year.ToString() + today.Month.ToString().PadLeft(2, '0') + today.Day.ToString().PadLeft(2, '0');
var today = DateTime.Now;
var dateToday = today.Year.ToString() + today.Month.ToString().PadLeft(2, '0') + today.Day.ToString().PadLeft(2, '0');

DateTime yesterday = DateTime.Now.AddDays(-1);
string dateYesterday = yesterday.Year.ToString() + yesterday.Month.ToString().PadLeft(2, '0') + yesterday.Day.ToString().PadLeft(2, '0');
var yesterday = DateTime.Now.AddDays(-1);
var dateYesterday = yesterday.Year.ToString() + yesterday.Month.ToString().PadLeft(2, '0') + yesterday.Day.ToString().PadLeft(2, '0');

LoadEventsNBA loadEventsNba = new LoadEventsNBA(new List<string>() { dateToday, dateYesterday });
var loadEventsNba = new LoadEventsNBA(new List<string>() { dateToday, dateYesterday });
loadEventsNba.Start();

Thread.Sleep(base.WAIT_TIME);

/*
* Load standings
*/
LoadStandings loadStandings = new LoadStandings();
var loadStandings = new LoadStandings();
loadStandings.Start();
}

Expand Down
4 changes: 2 additions & 2 deletions Jobs/BetsKiller.Jobs/JobEveryHours2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override void Job()
* Load new news
*/

LoadNews loadNews = new LoadNews();
var loadNews = new LoadNews();
loadNews.Start();

Thread.Sleep(base.WAIT_TIME);
Expand All @@ -30,7 +30,7 @@ protected override void Job()
* Load new injuries
*/

LoadInjuries loadInjuries = new LoadInjuries();
var loadInjuries = new LoadInjuries();
loadInjuries.Start();
}

Expand Down
2 changes: 1 addition & 1 deletion Jobs/BetsKiller.Jobs/JobEveryMonday15.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected override void Job()
* Load new NBA power rankings
*/

LoadPowerRankingsNBA loadPowerRankingNBA = new LoadPowerRankingsNBA();
var loadPowerRankingNBA = new LoadPowerRankingsNBA();
loadPowerRankingNBA.Start();
}

Expand Down
10 changes: 5 additions & 5 deletions Jobs/BetsKiller.Jobs/JobEveryMonday9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ protected override void Job()
/*
* LoadScheduleResultsNBA for the next one week to refresh data.
*/
DateTime today = DateTime.Now;
string since = today.Year.ToString() + today.Month.ToString().PadLeft(2, '0') + today.Day.ToString().PadLeft(2, '0');
var today = DateTime.Now;
var since = today.Year.ToString() + today.Month.ToString().PadLeft(2, '0') + today.Day.ToString().PadLeft(2, '0');

DateTime finish = today.AddDays(7);
string until = finish.Year.ToString() + finish.Month.ToString().PadLeft(2, '0') + finish.Day.ToString().PadLeft(2, '0');
var finish = today.AddDays(7);
var until = finish.Year.ToString() + finish.Month.ToString().PadLeft(2, '0') + finish.Day.ToString().PadLeft(2, '0');

LoadScheduleResultsNBA loadScheduleResultsNBA = new LoadScheduleResultsNBA(since, until);
var loadScheduleResultsNBA = new LoadScheduleResultsNBA(since, until);
loadScheduleResultsNBA.Start();
}

Expand Down
Loading

0 comments on commit d7e7aa3

Please sign in to comment.