Skip to content

Commit

Permalink
Fix some sonar issues (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
k3ldar authored Aug 21, 2023
1 parent cd6a9cd commit 60e125e
Show file tree
Hide file tree
Showing 33 changed files with 108 additions and 90 deletions.
2 changes: 1 addition & 1 deletion DAL/PluginManager.DAL.TextFiles/Providers/BlogProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void AddComment(in BlogItem blogItem, in BlogComment parentComment, in lo
if (String.IsNullOrEmpty(comment))
throw new ArgumentNullException(nameof(comment));

TimeSpan span = DateTime.Now - new DateTime(2022, 1, 1);
TimeSpan span = DateTime.Now - new DateTime(2022, 1, 1, 0, 0, 0, DateTimeKind.Utc);
BlogComment blogComment = new BlogComment(Convert.ToInt32(span.TotalSeconds), parentComment?.Id, DateTime.Now, userId, userName, true, comment);

if (parentComment == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ private IDynamicContentPage InternalGetCustomPage(ContentPageDataRow pageData)
DynamicContentTemplate pageItem = CreateTemplateItem(classParts[1].Trim(), classParts[0].Trim(), page.UniqueId, out bool templateClassFound);
pageItem.Id = page.Id;
pageItem.UniqueId = page.UniqueId;
pageItem.ActiveFrom = new DateTime(page.ActiveFromTicks);
pageItem.ActiveTo = new DateTime(page.ActiveToTicks);
pageItem.ActiveFrom = new DateTime(page.ActiveFromTicks, DateTimeKind.Utc);
pageItem.ActiveTo = new DateTime(page.ActiveToTicks, DateTimeKind.Utc);
string data = page.Data;

if (templateClassFound)
Expand Down
6 changes: 3 additions & 3 deletions Demo/NetCorePluginDemoWebsite/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
},
"SieraDeltaGeoIpPluginConfiguration": {
"GeoIpProvider": "Firebird",
"DatabaseConnectionString": "T:\\GeoIpProvider.dat",
"DatabaseConnectionString": "c:\\Tools\\GeoIp\\GeoIpProvider.dat",
"CacheAllData": true,
"CountryList": [
"GB",
Expand All @@ -176,9 +176,9 @@
},
"GeoIpPluginConfiguration": {
"GeoIpProvider": "None",
"Webnet77CSVDataPath": "T:\\geoip\\",
"Webnet77CSVDataPath": "c:\\Tools\\GeoIp\\geoip\\",
"Webnet77CsvUrl": "http://software77.net/geo-ip/?DL=2",
"AutoDownloadWebnet77Data": true,
"AutoDownloadWebnet77Data": false,
"IpStack": {
"ApiKey": ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public long CreateCustomPage()

IDynamicContentPage newPage = new DynamicContentPage(Result);
newPage.Name = $"Page-{Result}";
newPage.ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
newPage.ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
newPage.ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
newPage.ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);

_dynamicContent.Add(newPage);
Save(newPage);
Expand Down Expand Up @@ -311,8 +311,8 @@ private static void LoadDynamicContentVersion1(BinaryReader reader, DynamicConte
dynamicContentPage.RouteName = ReadStringData(reader);
dynamicContentPage.BackgroundColor = ReadStringData(reader);
dynamicContentPage.BackgroundImage = ReadStringData(reader);
dynamicContentPage.ActiveFrom = new DateTime(reader.ReadInt64());
dynamicContentPage.ActiveTo = new DateTime(reader.ReadInt64());
dynamicContentPage.ActiveFrom = new DateTime(reader.ReadInt64(), DateTimeKind.Utc);
dynamicContentPage.ActiveTo = new DateTime(reader.ReadInt64(), DateTimeKind.Utc);
int itemCount = reader.ReadInt32();
int item = 0;

Expand All @@ -327,8 +327,8 @@ private static void LoadDynamicContentVersion1(BinaryReader reader, DynamicConte
throw new InvalidOperationException();

DynamicContentTemplate instance = CreateTemplateItem(classParts[1].Trim(), classParts[0].Trim(), uniqueId, out bool templateClassFound);
instance.ActiveFrom = new DateTime(reader.ReadInt64());
instance.ActiveTo = new DateTime(reader.ReadInt64());
instance.ActiveFrom = new DateTime(reader.ReadInt64(), DateTimeKind.Utc);
instance.ActiveTo = new DateTime(reader.ReadInt64(), DateTimeKind.Utc);
string data = ReadStringData(reader);

if (templateClassFound)
Expand Down Expand Up @@ -402,10 +402,17 @@ private void InitializeDynamicContent()

foreach (string page in pages)
{
IDynamicContentPage convertedPage = ReadFileContents(page);

if (convertedPage != null)
_dynamicContent.Add(convertedPage);
try
{
IDynamicContentPage convertedPage = ReadFileContents(page);

if (convertedPage != null)
_dynamicContent.Add(convertedPage);
}
catch
{
// ignore as couldn't load
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Plugins/DynamicContent.Plugin/Model/EditTemplateModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public sealed class EditTemplateModel

public EditTemplateModel()
{
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public FormCheckBoxTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public FormListBoxTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public FormRadioGroupTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public FormSubmitButtonTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public FormTextBoxTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public HorizontalRuleTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
4 changes: 2 additions & 2 deletions Plugins/DynamicContent.Plugin/Templates/HtmlTextTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public HtmlTextTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public LargeHeaderTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public MediumHeaderTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
4 changes: 2 additions & 2 deletions Plugins/DynamicContent.Plugin/Templates/ParagraphTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public ParagraphTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public SmallHeaderTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
4 changes: 2 additions & 2 deletions Plugins/DynamicContent.Plugin/Templates/SpacerTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public SpacerTemplate()
WidthType = DynamicContentWidthType.Columns;
Height = 200;
HeightType = DynamicContentHeightType.Pixels;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public YouTubeVideoTemplate()
WidthType = DynamicContentWidthType.Columns;
Height = 450;
HeightType = DynamicContentHeightType.Pixels;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
_autoPlay = true;
}

Expand Down
3 changes: 2 additions & 1 deletion Plugins/GeoIpPlugin/Classes/LoadWebNet77Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ private bool CanDownloadWebnet77Data()
}
else
{
File.WriteAllText(_webNetDownloadDataFile, DateTime.UtcNow.Ticks.ToString());
if (Directory.Exists(Path.GetDirectoryName(_webNetDownloadDataFile)))
File.WriteAllText(_webNetDownloadDataFile, DateTime.UtcNow.Ticks.ToString());
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions Plugins/ImageManager.Plugin/Templates/ImageTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public ImageTemplate()
WidthType = DynamicContentWidthType.Columns;
Height = 200;
HeightType = DynamicContentHeightType.Pixels;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
Data = String.Empty;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public GenericTextTemplate()
{
WidthType = DynamicContentWidthType.Columns;
Width = 12;
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59);
ActiveFrom = new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc);
ActiveTo = new DateTime(2050, 12, 31, 23, 59, 59, DateTimeKind.Utc);
}

#endregion Constructors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ private void ValiddateResourceUri(string value)

private void ValidateResourceYoutube(string value)
{
Match match = Regex.Match(value, "[a-zA-Z0-9_-]");
Match match = Regex.Match(value, "[a-zA-Z0-9_-]", RegexOptions.CultureInvariant, TimeSpan.FromMilliseconds(1500));

if (!match.Success || String.IsNullOrEmpty(value))
{
Expand Down
10 changes: 5 additions & 5 deletions Plugins/Spider.Plugin/Classes/Robots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public bool AgentRemove(string agentName)
if (!_agents.ContainsKey(agentName))
return false;

if (_agents[agentName].Any(item => !item.IsCustom))
if (_agents[agentName].Exists(item => !item.IsCustom))
return false;

return _agents.Remove(agentName);
Expand Down Expand Up @@ -167,7 +167,7 @@ public bool AddAllowedRoute(string agent, string route)
if (!Agents.Contains(agent))
throw new ArgumentException("Agent not registered", nameof(agent));

if (_customRoutes.Any(r => r.Agent.Equals(agent) && r.Route.Equals(route)))
if (_customRoutes.Exists(r => r.Agent.Equals(agent) && r.Route.Equals(route)))
return false;

_customRoutes.Add(new RobotRouteData(agent, null, route, true, true));
Expand All @@ -186,7 +186,7 @@ public bool AddDeniedRoute(string agent, string route)
if (!Agents.Contains(agent))
throw new ArgumentException("Agent not registered", nameof(agent));

if (_customRoutes.Any(r => r.Agent.Equals(agent) && r.Route.Equals(route)))
if (_customRoutes.Exists(r => r.Agent.Equals(agent) && r.Route.Equals(route)))
return false;

_customRoutes.Add(new RobotRouteData(agent, null, route, false, true));
Expand Down Expand Up @@ -257,7 +257,7 @@ private void AddCustomRoutesToKnownAgents()
_agents.Add(item.Agent, new List<IRobotRouteData>());
}

if (_agents[item.Agent].Any(l => l.IsCustom && l.Route.Equals(item.Route)))
if (_agents[item.Agent].Exists(l => l.IsCustom && l.Route.Equals(item.Route)))
continue;

_agents[item.Agent].Add(item);
Expand Down Expand Up @@ -342,7 +342,7 @@ private static void AddUserAgentToDictionary(DenySpiderAttribute denySpiderAttri

string route = denySpiderAttribute.Route;

if (!route.EndsWith("/"))
if (!route.EndsWith('/'))
route += "/";

agentList[denySpiderAttribute.UserAgent].Add(
Expand Down
6 changes: 3 additions & 3 deletions Plugins/Spider.Plugin/Controllers/SpiderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public IActionResult AddCustomRoute(EditRobotsModel model)
if (String.IsNullOrEmpty(model.Route))
ModelState.AddModelError(nameof(EditRobotsModel.Route), "Invalid Route");

if (_robots.DeniedRoutes.Any(dr => dr.UserAgent.Equals(model.AgentName, StringComparison.InvariantCultureIgnoreCase) &&
if (_robots.DeniedRoutes.Exists(dr => dr.UserAgent.Equals(model.AgentName, StringComparison.InvariantCultureIgnoreCase) &&
dr.Route.Equals(model.Route, StringComparison.InvariantCultureIgnoreCase)))
{
ModelState.AddModelError(String.Empty, "Route already exists");
}

if (_robots.CustomRoutes.Any(cr => cr.Agent.Equals(model.AgentName, StringComparison.InvariantCultureIgnoreCase) &&
if (_robots.CustomRoutes.Exists(cr => cr.Agent.Equals(model.AgentName, StringComparison.InvariantCultureIgnoreCase) &&
cr.Route.Equals(model.Route, StringComparison.InvariantCultureIgnoreCase)))
{
ModelState.AddModelError(String.Empty, "Custom route already exists");
Expand All @@ -103,7 +103,7 @@ public IActionResult AddCustomRoute(EditRobotsModel model)
if (!ModelState.IsValid)
return CreateDefaultPartialView();

if (!_robots.Agents.Any(a => a.Equals(model.AgentName, StringComparison.InvariantCultureIgnoreCase)))
if (!_robots.Agents.Exists(a => a.Equals(model.AgentName, StringComparison.InvariantCultureIgnoreCase)))
{
_robots.AgentAdd(model.AgentName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ public IActionResult SeoUpdateData(SeoDataModel model)
model.SeoTags = String.Empty;

_seoProvider.AddKeywords(model.SeoUrl, model.SeoTags.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList());
return Redirect(model.SeoUrl);

if (Url != null && Url.IsLocalUrl(model.SeoUrl))
return Redirect(model.SeoUrl);

return RedirectToAction(nameof(Index));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public IActionResult DeliveryAddressAdd(EditDeliveryAddressViewModel model)
{
GrowlAdd(Languages.LanguageStrings.DeliveryAddressCreated);

if (!String.IsNullOrEmpty(model.ReturnUrl))
if (!String.IsNullOrEmpty(model.ReturnUrl) && Url.IsLocalUrl(model.ReturnUrl))
return new RedirectResult(model.ReturnUrl, false);

return new RedirectResult("/Account/DeliveryAddress", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ public IActionResult SetLanguage(string culture, string returnUrl)
if (_cultureProvider.IsCultureValid(newCulture))
_userCultureChanged.CultureChanged(HttpContext, userSession, newCulture);

return Redirect(returnUrl ?? "/");
string redirectPath = returnUrl ?? "/";

if (Url.IsLocalUrl(redirectPath))
return Redirect(redirectPath);

return RedirectToAction("Index", "Home");
}
}

Expand Down
Loading

0 comments on commit 60e125e

Please sign in to comment.