From cadb2c681d01147bd39959f7e3e00cbabd1a5ba7 Mon Sep 17 00:00:00 2001 From: codefactor-io Date: Mon, 28 Oct 2024 07:20:59 +0000 Subject: [PATCH] [CodeFactor] Apply fixes --- src/net/Wexflow.Clients.Manager/Login.cs | 31 +++++++++---------- src/net/Wexflow.Core.Db/Db.cs | 29 ++++++++--------- .../WexflowServiceClient.cs | 31 +++++++++---------- src/net/Wexflow.Core/Workflow.cs | 8 ++--- src/net/Wexflow.Server/WexflowService.cs | 6 ++-- .../Wexflow.Tasks.FilesConcat/FilesConcat.cs | 4 +-- .../Wexflow.Tasks.FilesJoiner/FilesJoiner.cs | 6 ++-- src/net/Wexflow.Tasks.MailsSender/Mail.cs | 6 ++-- src/netcore/Wexflow.Server/WexflowService.cs | 3 +- 9 files changed, 57 insertions(+), 67 deletions(-) diff --git a/src/net/Wexflow.Clients.Manager/Login.cs b/src/net/Wexflow.Clients.Manager/Login.cs index cea124288..4b2f5235b 100644 --- a/src/net/Wexflow.Clients.Manager/Login.cs +++ b/src/net/Wexflow.Clients.Manager/Login.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Configuration; using System.Diagnostics; using System.IO; @@ -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) diff --git a/src/net/Wexflow.Core.Db/Db.cs b/src/net/Wexflow.Core.Db/Db.cs index 858a9f404..e8b9f56b7 100644 --- a/src/net/Wexflow.Core.Db/Db.cs +++ b/src/net/Wexflow.Core.Db/Db.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Security.Cryptography; using System.Text; @@ -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(); } } } diff --git a/src/net/Wexflow.Core.Service.Client/WexflowServiceClient.cs b/src/net/Wexflow.Core.Service.Client/WexflowServiceClient.cs index aedaad2ab..9c3a8d8f7 100644 --- a/src/net/Wexflow.Core.Service.Client/WexflowServiceClient.cs +++ b/src/net/Wexflow.Core.Service.Client/WexflowServiceClient.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; using System; using System.Net; using System.Security.Cryptography; @@ -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) diff --git a/src/net/Wexflow.Core/Workflow.cs b/src/net/Wexflow.Core/Workflow.cs index 927d36e28..0616abdf9 100644 --- a/src/net/Wexflow.Core/Workflow.cs +++ b/src/net/Wexflow.Core/Workflow.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Globalization; @@ -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."); } @@ -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); @@ -1386,7 +1386,7 @@ private void RunSequentialTasks(IEnumerable tasks, ref bool success, ref b } } - if (enumerable.Any() && !success && atLeastOneSucceed) + if (enumerable.Length != 0 && !success && atLeastOneSucceed) { warning = true; } diff --git a/src/net/Wexflow.Server/WexflowService.cs b/src/net/Wexflow.Server/WexflowService.cs index 9163497ec..60f86179b 100644 --- a/src/net/Wexflow.Server/WexflowService.cs +++ b/src/net/Wexflow.Server/WexflowService.cs @@ -1,4 +1,4 @@ -using Nancy; +using Nancy; using Nancy.Extensions; using Nancy.IO; using Nancy.Responses; @@ -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() : new TaskSetting[] { }; + taskSettings = token != null ? token.ToObject() : Array.Empty(); } catch (Exception e) { @@ -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) { diff --git a/src/net/Wexflow.Tasks.FilesConcat/FilesConcat.cs b/src/net/Wexflow.Tasks.FilesConcat/FilesConcat.cs index a7e3e7d90..38fe12ac8 100644 --- a/src/net/Wexflow.Tasks.FilesConcat/FilesConcat.cs +++ b/src/net/Wexflow.Tasks.FilesConcat/FilesConcat.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Text; using System.Threading; @@ -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('_'); } } diff --git a/src/net/Wexflow.Tasks.FilesJoiner/FilesJoiner.cs b/src/net/Wexflow.Tasks.FilesJoiner/FilesJoiner.cs index 346839f9f..8b410e3be 100644 --- a/src/net/Wexflow.Tasks.FilesJoiner/FilesJoiner.cs +++ b/src/net/Wexflow.Tasks.FilesJoiner/FilesJoiner.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Linq; using System.Threading; @@ -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; @@ -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; diff --git a/src/net/Wexflow.Tasks.MailsSender/Mail.cs b/src/net/Wexflow.Tasks.MailsSender/Mail.cs index 89fcfd993..71fabb7d5 100644 --- a/src/net/Wexflow.Tasks.MailsSender/Mail.cs +++ b/src/net/Wexflow.Tasks.MailsSender/Mail.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using System.Net; using System.Net.Mail; using System.Net.Mime; @@ -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(); var ccElement = xe.XPathSelectElement("Cc"); if (ccElement != null) { cc = mailsSender.ParseVariables(ccElement.Value).Split(','); } - string[] bcc = { }; + string[] bcc = System.Array.Empty(); var bccElement = xe.XPathSelectElement("Bcc"); if (bccElement != null) { diff --git a/src/netcore/Wexflow.Server/WexflowService.cs b/src/netcore/Wexflow.Server/WexflowService.cs index 8d97d6470..7224e226e 100644 --- a/src/netcore/Wexflow.Server/WexflowService.cs +++ b/src/netcore/Wexflow.Server/WexflowService.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Newtonsoft.Json; @@ -3559,7 +3559,6 @@ private void DeleteWorkflows() Console.WriteLine(e); tres = false; } - } } res = tres;