Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fixes from CodeFactor #90

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions src/net/Wexflow.Clients.Manager/Login.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Configuration;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -92,22 +92,19 @@ private void Authenticate()
}

public static string GetMd5(string input)
{
// Use input string to calculate MD5 hash
using (var md5 = MD5.Create())
{
var inputBytes = Encoding.ASCII.GetBytes(input);
var hashBytes = md5.ComputeHash(inputBytes);

// Convert the byte array to hexadecimal string
var sb = new StringBuilder();
// ReSharper disable once ForCanBeConvertedToForeach
for (var i = 0; i < hashBytes.Length; i++)
{
_ = sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}
{
// Use input string to calculate MD5 hash
var inputBytes = Encoding.ASCII.GetBytes(input);
var hashBytes = MD5.HashData(inputBytes);

// Convert the byte array to hexadecimal string
var sb = new StringBuilder();
// ReSharper disable once ForCanBeConvertedToForeach
for (var i = 0; i < hashBytes.Length; i++)
{
_ = sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}

private void LnkForgotPassword_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Expand Down
29 changes: 13 additions & 16 deletions src/net/Wexflow.Core.Db/Db.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
Expand Down Expand Up @@ -134,21 +134,18 @@ protected void InsertDefaultUser()
public abstract void Dispose();

public static string GetMd5(string input)
{
// Use input string to calculate MD5 hash
using (var md5 = MD5.Create())
{
var inputBytes = Encoding.ASCII.GetBytes(input);
var hashBytes = md5.ComputeHash(inputBytes);

// Convert the byte array to hexadecimal string
var sb = new StringBuilder();
for (var i = 0; i < hashBytes.Length; i++)
{
_ = sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}
{
// Use input string to calculate MD5 hash
var inputBytes = Encoding.ASCII.GetBytes(input);
var hashBytes = MD5.HashData(inputBytes);

// Convert the byte array to hexadecimal string
var sb = new StringBuilder();
for (var i = 0; i < hashBytes.Length; i++)
{
_ = sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}
}
}
31 changes: 14 additions & 17 deletions src/net/Wexflow.Core.Service.Client/WexflowServiceClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using System;
using System.Net;
using System.Security.Cryptography;
Expand All @@ -17,22 +17,19 @@ public WexflowServiceClient(string uri)
}

private static string GetMd5(string input)
{
// Use input string to calculate MD5 hash
using (var md5 = MD5.Create())
{
var inputBytes = Encoding.ASCII.GetBytes(input);
var hashBytes = md5.ComputeHash(inputBytes);

// Convert the byte array to hexadecimal string
var sb = new StringBuilder();
// ReSharper disable once ForCanBeConvertedToForeach
for (var i = 0; i < hashBytes.Length; i++)
{
_ = sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}
{
// Use input string to calculate MD5 hash
var inputBytes = Encoding.ASCII.GetBytes(input);
var hashBytes = MD5.HashData(inputBytes);

// Convert the byte array to hexadecimal string
var sb = new StringBuilder();
// ReSharper disable once ForCanBeConvertedToForeach
for (var i = 0; i < hashBytes.Length; i++)
{
_ = sb.Append(hashBytes[i].ToString("x2"));
}
return sb.ToString();
}

private static string Base64Encode(string plainText)
Expand Down
8 changes: 4 additions & 4 deletions src/net/Wexflow.Core/Workflow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -584,7 +584,7 @@ private void Load(string xml)
var taskNodes = GetTaskNodes(xExectionGraph);

// Check startup node, parallel tasks and infinite loops
if (taskNodes.Any())
if (taskNodes.Length != 0)
{
CheckStartupNode(taskNodes, "Startup node with parentId=-1 not found in ExecutionGraph execution graph.");
}
Expand Down Expand Up @@ -1313,7 +1313,7 @@ private Status RunTasks(Node[] nodes, Task[] tasks, bool force)
var warning = false;
var atLeastOneSucceed = false;

if (nodes.Any())
if (nodes.Length != 0)
{
var startNode = GetStartupNode(nodes);

Expand Down Expand Up @@ -1386,7 +1386,7 @@ private void RunSequentialTasks(IEnumerable<Task> tasks, ref bool success, ref b
}
}

if (enumerable.Any() && !success && atLeastOneSucceed)
if (enumerable.Length != 0 && !success && atLeastOneSucceed)
{
warning = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/net/Wexflow.Server/WexflowService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Nancy;
using Nancy;
using Nancy.Extensions;
using Nancy.IO;
using Nancy.Responses;
Expand Down Expand Up @@ -1172,7 +1172,7 @@ private void GetSettings()
{
var o = JObject.Parse(File.ReadAllText(WexflowServer.WexflowEngine.TasksSettingsFile));
dynamic token = o.SelectToken(args.taskName);
taskSettings = token != null ? token.ToObject<TaskSetting[]>() : new TaskSetting[] { };
taskSettings = token != null ? token.ToObject<TaskSetting[]>() : Array.Empty<TaskSetting>();
}
catch (Exception e)
{
Expand Down Expand Up @@ -2891,7 +2891,7 @@ private XElement NodeToBlockly(Core.ExecutionGraph.Graph graph, Core.ExecutionGr
{
var block = new XElement("block");

if (nodes.Any())
if (nodes.Length != 0)
{
if (node is If)
{
Expand Down
4 changes: 2 additions & 2 deletions src/net/Wexflow.Tasks.FilesConcat/FilesConcat.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Text;
using System.Threading;
Expand Down Expand Up @@ -82,7 +82,7 @@ private bool ConcatFiles(ref bool atLeastOneSucceed)
_ = builder.Append(Path.GetFileNameWithoutExtension(file.FileName));
if (i < files.Length - 1)
{
_ = builder.Append("_");
_ = builder.Append('_');
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/net/Wexflow.Tasks.FilesJoiner/FilesJoiner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Linq;
using System.Threading;
Expand Down Expand Up @@ -28,7 +28,7 @@ public FilesJoiner(XElement xe, Workflow wf) : base(xe, wf)

private int GetNumberPartInt(string path)
{
var lastUnderscoreIndex = path.LastIndexOf("_", StringComparison.InvariantCulture);
var lastUnderscoreIndex = path.LastIndexOf('_');
if (lastUnderscoreIndex == -1)
{
return -1;
Expand All @@ -41,7 +41,7 @@ private int GetNumberPartInt(string path)

private string GetNumberPartString(string path)
{
var lastUnderscoreIndex = path.LastIndexOf("_", StringComparison.InvariantCulture);
var lastUnderscoreIndex = path.LastIndexOf('_');
if (lastUnderscoreIndex == -1)
{
return path;
Expand Down
6 changes: 3 additions & 3 deletions src/net/Wexflow.Tasks.MailsSender/Mail.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
Expand Down Expand Up @@ -85,14 +85,14 @@ public static Mail Parse(MailsSender mailsSender, XElement xe, FileInf[] attachm
var from = mailsSender.ParseVariables(xe.XPathSelectElement("From")?.Value);
var to = mailsSender.ParseVariables(xe.XPathSelectElement("To")?.Value).Split(',');

string[] cc = { };
string[] cc = System.Array.Empty<string>();
var ccElement = xe.XPathSelectElement("Cc");
if (ccElement != null)
{
cc = mailsSender.ParseVariables(ccElement.Value).Split(',');
}

string[] bcc = { };
string[] bcc = System.Array.Empty<string>();
var bccElement = xe.XPathSelectElement("Bcc");
if (bccElement != null)
{
Expand Down
3 changes: 1 addition & 2 deletions src/netcore/Wexflow.Server/WexflowService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Newtonsoft.Json;
Expand Down Expand Up @@ -3559,7 +3559,6 @@ private void DeleteWorkflows()
Console.WriteLine(e);
tres = false;
}

}
}
res = tres;
Expand Down
Loading