From 0a75988ee08c076c44715c0155b91d3d98ce54d1 Mon Sep 17 00:00:00 2001 From: aelassas Date: Sun, 21 Jul 2024 16:06:20 +0100 Subject: [PATCH] General cleanup --- src/net/Wexflow.Server/WexflowService.cs | 22 +- .../VimeoListUploads.cs | 6 +- src/netcore/Wexflow.Server/WexflowService.cs | 214 +++++++++--------- .../ApproveRecord.cs | 4 +- .../Wexflow.Tasks.CsvToSql/CsvToSql.cs | 2 +- .../FileSystemWatcher.cs | 4 +- .../Wexflow.Tasks.FilesJoiner/FilesJoiner.cs | 2 +- .../FilesLoaderEx.cs | 2 +- src/netcore/Wexflow.Tasks.Ftp/PluginFTP.cs | 4 +- src/netcore/Wexflow.Tasks.Ftp/PluginFTPS.cs | 2 +- src/netcore/Wexflow.Tasks.Ftp/PluginSFTP.cs | 2 +- .../Wexflow.Tasks.MailsSender/MailsSender.cs | 2 +- .../RedditListComments.cs | 6 +- .../RedditListPosts.cs | 6 +- src/netcore/Wexflow.Tasks.Rmdir/Rmdir.cs | 2 +- src/netcore/Wexflow.Tasks.Tar/Tar.cs | 2 +- .../VimeoListUploads.cs | 6 +- .../YouTubeListUploads.cs | 6 +- .../YouTubeSearch.cs | 6 +- 19 files changed, 175 insertions(+), 125 deletions(-) diff --git a/src/net/Wexflow.Server/WexflowService.cs b/src/net/Wexflow.Server/WexflowService.cs index 8de9e06c..84ce2600 100644 --- a/src/net/Wexflow.Server/WexflowService.cs +++ b/src/net/Wexflow.Server/WexflowService.cs @@ -2033,7 +2033,11 @@ private SaveResult SaveJsonWorkflow(Core.Db.User user, string json) var retryCount = (int)wi.SelectToken("RetryCount"); var retryTimeout = (int)wi.SelectToken("RetryTimeout"); - if (xdoc.Root == null) throw new InvalidOperationException("Root is null"); + if (xdoc.Root == null) + { + throw new InvalidOperationException("Root is null"); + } + (xdoc.Root.Attribute("id") ?? throw new InvalidOperationException()).Value = workflowId.ToString(); (xdoc.Root.Attribute("name") ?? throw new InvalidOperationException()).Value = workflowName; (xdoc.Root.Attribute("description") ?? throw new InvalidOperationException()).Value = workflowDesc; @@ -2392,7 +2396,11 @@ private void DisableWorkflow() if (wf != null) { var xdoc = wf.XDoc; - if (xdoc.Root == null) throw new InvalidOperationException(); + if (xdoc.Root == null) + { + throw new InvalidOperationException(); + } + var xwfEnabled = xdoc.Root.XPathSelectElement("wf:Settings/wf:Setting[@name='enabled']", wf.XmlNamespaceManager) ?? throw new InvalidOperationException(); (xwfEnabled.Attribute("value") ?? throw new InvalidOperationException()).Value = false.ToString().ToLower(); @@ -2470,7 +2478,11 @@ private void EnableWorkflow() if (wf != null) { var xdoc = wf.XDoc; - if (xdoc.Root == null) throw new InvalidOperationException(); + if (xdoc.Root == null) + { + throw new InvalidOperationException(); + } + var xwfEnabled = xdoc.Root.XPathSelectElement("wf:Settings/wf:Setting[@name='enabled']", wf.XmlNamespaceManager) ?? throw new InvalidOperationException(); (xwfEnabled.Attribute("value") ?? throw new InvalidOperationException()).Value = true.ToString().ToLower(); @@ -2984,7 +2996,9 @@ private XElement SwitchCasesToBlockly(Core.ExecutionGraph.Graph graph, Case @cas } private Core.ExecutionGraph.Node GetStartupNode(IEnumerable nodes) - => nodes.FirstOrDefault(n => n.ParentId == Core.Workflow.START_ID); + { + return nodes.FirstOrDefault(n => n.ParentId == Core.Workflow.START_ID); + } /// /// Returns status count. diff --git a/src/net/Wexflow.Tasks.VimeoListUploads/VimeoListUploads.cs b/src/net/Wexflow.Tasks.VimeoListUploads/VimeoListUploads.cs index 6cc280f5..f45e75c2 100644 --- a/src/net/Wexflow.Tasks.VimeoListUploads/VimeoListUploads.cs +++ b/src/net/Wexflow.Tasks.VimeoListUploads/VimeoListUploads.cs @@ -49,7 +49,11 @@ public override TaskStatus Run() )); } - if (xdoc.Root == null) throw new InvalidOperationException(); + if (xdoc.Root == null) + { + throw new InvalidOperationException(); + } + xdoc.Root.Add(xvideos); xdoc.Save(xmlPath); Files.Add(new FileInf(xmlPath, Id)); diff --git a/src/netcore/Wexflow.Server/WexflowService.cs b/src/netcore/Wexflow.Server/WexflowService.cs index 2ed180c5..bd77e5ef 100644 --- a/src/netcore/Wexflow.Server/WexflowService.cs +++ b/src/netcore/Wexflow.Server/WexflowService.cs @@ -200,7 +200,7 @@ private void Search() var workflows = Array.Empty(); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -262,7 +262,7 @@ private void SearchApprovalWorkflows() var workflows = Array.Empty(); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -337,7 +337,7 @@ private void GetWorkflow() var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -395,7 +395,7 @@ private void GetJob() var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -447,7 +447,7 @@ private void GetJobs() var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -484,7 +484,7 @@ private void StartWorkflow() var workflowId = int.Parse(context.Request.Query["w"].ToString()); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -541,7 +541,7 @@ private void StartWorkflowWithVariables() var workflow = WexflowServer.WexflowEngine.Workflows.First(w => w.Id == workflowId); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -589,7 +589,7 @@ private void StopWorkflow() var instanceId = Guid.Parse(context.Request.Query["i"].ToString()); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -631,7 +631,7 @@ private void SuspendWorkflow() var instanceId = Guid.Parse(context.Request.Query["i"].ToString()); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -671,7 +671,7 @@ private void ResumeWorkflow() var instanceId = Guid.Parse(context.Request.Query["i"].ToString()); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -713,7 +713,7 @@ private void ApproveWorkflow() var instanceId = Guid.Parse(context.Request.Query["i"].ToString()); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -751,7 +751,7 @@ private void RejectWorkflow() var instanceId = Guid.Parse(context.Request.Query["i"].ToString()); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -784,7 +784,7 @@ private void GetTasks() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var wf = WexflowServer.WexflowEngine.GetWorkflow(int.Parse(context.Request.RouteValues["id"]?.ToString() ?? throw new InvalidOperationException())); if (wf != null) @@ -805,11 +805,11 @@ private void GetTasks() attributeInfos.Add(attributeInfo); } - SettingInfo settingInfo = new(setting.Name, setting.Value, attributeInfos.ToArray()); + SettingInfo settingInfo = new(setting.Name, setting.Value, [.. attributeInfos]); settingInfos.Add(settingInfo); } - TaskInfo taskInfo = new(task.Id, task.Name, task.Description, task.IsEnabled, settingInfos.ToArray()); + TaskInfo taskInfo = new(task.Id, task.Name, task.Description, task.IsEnabled, [.. settingInfos]); taskInfos.Add(taskInfo); } @@ -841,7 +841,7 @@ private void GetNewWorkflowId() var workflowId = 0; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { try { @@ -878,7 +878,7 @@ private void GetWorkflowXml() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var wf = WexflowServer.WexflowEngine.GetWorkflow(int.Parse(context.Request.RouteValues["id"]?.ToString() ?? throw new InvalidOperationException())); if (wf != null) @@ -909,7 +909,7 @@ private void GetWorkflowJson() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var wf = WexflowServer.WexflowEngine.GetWorkflow(int.Parse(context.Request.RouteValues["id"]?.ToString() ?? throw new InvalidOperationException())); if (wf != null) @@ -932,7 +932,7 @@ private void GetWorkflowJson() IsApproval = wf.IsApproval, EnableParallelJobs = wf.EnableParallelJobs, Description = wf.Description, - LocalVariables = variables.ToArray(), + LocalVariables = [.. variables], RetryCount = wf.RetryCount, RetryTimeout = wf.RetryTimeout }; @@ -949,15 +949,15 @@ private void GetWorkflowJson() attributes.Add(new AttributeInfo(attr.Name, attr.Value)); } - settings.Add(new SettingInfo(setting.Name, setting.Value, attributes.ToArray())); + settings.Add(new SettingInfo(setting.Name, setting.Value, [.. attributes])); } - tasks.Add(new TaskInfo(task.Id, task.Name, task.Description, task.IsEnabled, settings.ToArray())); + tasks.Add(new TaskInfo(task.Id, task.Name, task.Description, task.IsEnabled, [.. settings])); } Contracts.Workflow.Workflow workflow = new() { WorkflowInfo = wi, - Tasks = tasks.ToArray(), + Tasks = [.. tasks], ExecutionGraph = wf.ExecutionGraph }; @@ -987,18 +987,18 @@ private void GetTaskNames() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { TaskName[] taskNames; try { var array = JArray.Parse(await File.ReadAllTextAsync(WexflowServer.WexflowEngine.TasksNamesFile)); - taskNames = array.ToObject().OrderBy(x => x.Name).ToArray(); + taskNames = [.. array.ToObject().OrderBy(x => x.Name)]; } catch (Exception e) { Console.WriteLine(e); - taskNames = new[] { new TaskName { Name = "TasksNames.json is not valid." } }; + taskNames = [new TaskName { Name = "TasksNames.json is not valid." }]; } await context.Response.WriteAsync(JsonConvert.SerializeObject(taskNames)); @@ -1024,21 +1024,21 @@ private void SearchTaskNames() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { TaskName[] taskNames; try { var array = JArray.Parse(await File.ReadAllTextAsync(WexflowServer.WexflowEngine.TasksNamesFile)); - taskNames = array + taskNames = [.. array .ToObject() .Where(x => x.Name.ToUpper().Contains(keywordToUpper)) - .OrderBy(x => x.Name).ToArray(); + .OrderBy(x => x.Name)]; } catch (Exception e) { Console.WriteLine(e); - taskNames = new[] { new TaskName { Name = "TasksNames.json is not valid." } }; + taskNames = [new TaskName { Name = "TasksNames.json is not valid." }]; } await context.Response.WriteAsync(JsonConvert.SerializeObject(taskNames)); @@ -1062,19 +1062,19 @@ private void GetSettings() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { TaskSetting[] taskSettings; try { var o = JObject.Parse(await File.ReadAllTextAsync(WexflowServer.WexflowEngine.TasksSettingsFile)); var token = o.SelectToken(context.Request.RouteValues["taskName"]?.ToString() ?? throw new InvalidOperationException()); - taskSettings = token != null ? token.ToObject() : Array.Empty(); + taskSettings = token != null ? token.ToObject() : []; } catch (Exception e) { Console.WriteLine(e); - taskSettings = new[] { new TaskSetting { Name = "TasksSettings.json is not valid." } }; + taskSettings = [new TaskSetting { Name = "TasksSettings.json is not valid." }]; } await context.Response.WriteAsync(JsonConvert.SerializeObject(taskSettings)); @@ -1100,7 +1100,7 @@ private void GetTaskXml() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var json = GetBody(context); @@ -1180,7 +1180,7 @@ private void IsWorkflowIdValid() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var workflowId = int.Parse(context.Request.RouteValues["id"]?.ToString() ?? throw new InvalidOperationException()); foreach (var workflow in WexflowServer.WexflowEngine.Workflows) @@ -1213,7 +1213,7 @@ private void IsCronExpressionValid() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var expression = context.Request.Query["e"].ToString(); var res = WexflowEngine.IsCronExpressionValid(expression); @@ -1238,7 +1238,7 @@ private void IsPeriodValid() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var res = TimeSpan.TryParse(context.Request.RouteValues["period"]?.ToString(), out _); await context.Response.WriteAsync(JsonConvert.SerializeObject(res)); @@ -1264,7 +1264,7 @@ private void IsXmlWorkflowValid() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var json = GetBody(context); var o = JObject.Parse(json); @@ -1321,7 +1321,7 @@ private void SaveXmlWorkflow() var xml = (string)o.SelectToken("xml") ?? throw new InvalidOperationException(); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -1837,7 +1837,11 @@ private static SaveResult SaveJsonWorkflow(Core.Db.User user, string json) var retryCount = (int)wi.SelectToken("RetryCount"); var retryTimeout = (int)wi.SelectToken("RetryTimeout"); - if (xdoc.Root == null) throw new InvalidOperationException("Root is null"); + if (xdoc.Root == null) + { + throw new InvalidOperationException("Root is null"); + } + xdoc.Root.Attribute("id")!.Value = workflowId.ToString(); xdoc.Root.Attribute("name")!.Value = workflowName ?? throw new InvalidOperationException(); xdoc.Root.Attribute("description")!.Value = workflowDesc ?? string.Empty; @@ -2108,7 +2112,7 @@ private void SaveWorkflow() var user = WexflowServer.WexflowEngine.GetUser(username); - if (!user.Password.Equals(password)) + if (!user.Password.Equals(password, StringComparison.Ordinal)) { await WriteFalse(context); return; @@ -2160,7 +2164,7 @@ private void DisableWorkflow() var wf = WexflowServer.WexflowEngine.Workflows.FirstOrDefault(w => w.Id == workflowId); var res = false; - if (!user.Password.Equals(password)) + if (!user.Password.Equals(password, StringComparison.Ordinal)) { await WriteFalse(context); return; @@ -2186,7 +2190,11 @@ private void DisableWorkflow() if (wf != null) { var xdoc = wf.XDoc; - if (xdoc.Root is null) throw new InvalidOperationException(" xdoc.Root is null"); + if (xdoc.Root is null) + { + throw new InvalidOperationException(" xdoc.Root is null"); + } + var xwfEnabled = xdoc.Root.XPathSelectElement("wf:Settings/wf:Setting[@name='enabled']", wf.XmlNamespaceManager) ?? throw new InvalidOperationException(); xwfEnabled.Attribute("value")!.Value = false.ToString().ToLower(); @@ -2230,7 +2238,7 @@ private void EnableWorkflow() var wf = WexflowServer.WexflowEngine.Workflows.FirstOrDefault(w => w.Id == workflowId); var res = false; - if (!user.Password.Equals(password)) + if (!user.Password.Equals(password, StringComparison.Ordinal)) { await WriteFalse(context); return; @@ -2256,7 +2264,11 @@ private void EnableWorkflow() if (wf != null) { var xdoc = wf.XDoc; - if (xdoc.Root is null) throw new InvalidOperationException("xdoc.Root is null"); + if (xdoc.Root is null) + { + throw new InvalidOperationException("xdoc.Root is null"); + } + var xwfEnabled = xdoc.Root.XPathSelectElement("wf:Settings/wf:Setting[@name='enabled']", wf.XmlNamespaceManager) ?? throw new InvalidOperationException(); xwfEnabled.Attribute("value")!.Value = true.ToString().ToLower(); @@ -2327,7 +2339,7 @@ private void UploadWorkflow() var isAuthorized = false; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -2409,7 +2421,7 @@ private void DeleteWorkflow() { var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -2457,7 +2469,7 @@ private void GetExecutionGraph() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var wf = WexflowServer.WexflowEngine.GetWorkflow(int.Parse(context.Request.RouteValues["id"]?.ToString() ?? throw new InvalidOperationException())); if (wf != null) @@ -2512,7 +2524,7 @@ private void GetExecutionGraphAsXml() var graph = ""; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var wf = WexflowServer.WexflowEngine.GetWorkflow(int.Parse(context.Request.RouteValues["id"]?.ToString() ?? throw new InvalidOperationException())); if (wf != null) @@ -2555,7 +2567,7 @@ private void GetExecutionGraphAsBlockly() var graph = ""; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var wf = WexflowServer.WexflowEngine.GetWorkflow(int.Parse(context.Request.RouteValues["id"]?.ToString() ?? throw new InvalidOperationException())); if (wf != null) @@ -2694,13 +2706,13 @@ private XElement NodeToBlockly(Core.ExecutionGraph.Graph graph, Core.ExecutionGr else if (!isFlowchart && !isEvent) { block.Add(new XElement("next", - new XElement("block", new XAttribute("type", "onSuccess"), new XElement("statement", new XAttribute("name", "ON_SUCCESS"), NodeToBlockly(graph, GetStartupNode((graph.OnSuccess ?? new Core.ExecutionGraph.GraphEvent(Array.Empty())).Nodes), (graph.OnSuccess ?? new Core.ExecutionGraph.GraphEvent(Array.Empty())).Nodes, false, true, ref depth)) + new XElement("block", new XAttribute("type", "onSuccess"), new XElement("statement", new XAttribute("name", "ON_SUCCESS"), NodeToBlockly(graph, GetStartupNode((graph.OnSuccess ?? new Core.ExecutionGraph.GraphEvent([])).Nodes), (graph.OnSuccess ?? new Core.ExecutionGraph.GraphEvent([])).Nodes, false, true, ref depth)) , new XElement("next", - new XElement("block", new XAttribute("type", "onWarning"), new XElement("statement", new XAttribute("name", "ON_WARNING"), NodeToBlockly(graph, GetStartupNode((graph.OnWarning ?? new Core.ExecutionGraph.GraphEvent(Array.Empty())).Nodes), (graph.OnWarning ?? new Core.ExecutionGraph.GraphEvent(Array.Empty())).Nodes, false, true, ref depth)) + new XElement("block", new XAttribute("type", "onWarning"), new XElement("statement", new XAttribute("name", "ON_WARNING"), NodeToBlockly(graph, GetStartupNode((graph.OnWarning ?? new Core.ExecutionGraph.GraphEvent([])).Nodes), (graph.OnWarning ?? new Core.ExecutionGraph.GraphEvent([])).Nodes, false, true, ref depth)) , new XElement("next", - new XElement("block", new XAttribute("type", "onError"), new XElement("statement", new XAttribute("name", "ON_ERROR"), NodeToBlockly(graph, GetStartupNode((graph.OnError ?? new Core.ExecutionGraph.GraphEvent(Array.Empty())).Nodes), (graph.OnError ?? new Core.ExecutionGraph.GraphEvent(Array.Empty())).Nodes, false, true, ref depth)) + new XElement("block", new XAttribute("type", "onError"), new XElement("statement", new XAttribute("name", "ON_ERROR"), NodeToBlockly(graph, GetStartupNode((graph.OnError ?? new Core.ExecutionGraph.GraphEvent([])).Nodes), (graph.OnError ?? new Core.ExecutionGraph.GraphEvent([])).Nodes, false, true, ref depth)) , new XElement("next", - new XElement("block", new XAttribute("type", "onRejected"), new XElement("statement", new XAttribute("name", "ON_REJECTED"), NodeToBlockly(graph, GetStartupNode((graph.OnRejected ?? new Core.ExecutionGraph.GraphEvent(Array.Empty())).Nodes), (graph.OnRejected ?? new Core.ExecutionGraph.GraphEvent(Array.Empty())).Nodes, false, true, ref depth)) + new XElement("block", new XAttribute("type", "onRejected"), new XElement("statement", new XAttribute("name", "ON_REJECTED"), NodeToBlockly(graph, GetStartupNode((graph.OnRejected ?? new Core.ExecutionGraph.GraphEvent([])).Nodes), (graph.OnRejected ?? new Core.ExecutionGraph.GraphEvent([])).Nodes, false, true, ref depth)) )))))) ))); } @@ -2736,7 +2748,7 @@ private void GetStatusCount() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var statusCount = WexflowServer.WexflowEngine.GetStatusCount(); StatusCount sc = new() @@ -2775,7 +2787,7 @@ private void GetUser() var othuser = WexflowServer.WexflowEngine.GetUser(qusername); - if (othuser.Password.Equals(qpassword)) + if (othuser.Password.Equals(qpassword, StringComparison.Ordinal)) { var user = WexflowServer.WexflowEngine.GetUser(username); var dateTimeFormat = WexflowServer.Config["DateTimeFormat"]; @@ -2819,7 +2831,7 @@ private void SearchUsers() var q = Array.Empty(); var user = WexflowServer.WexflowEngine.GetUser(qusername); - if (user.Password.Equals(qpassword) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(qpassword, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var users = WexflowServer.WexflowEngine.GetUsers(keyword, (UserOrderBy)uo); @@ -2855,7 +2867,7 @@ private void GetNonRestrictedUsers() var q = Array.Empty(); var user = WexflowServer.WexflowEngine.GetUser(qusername); - if (user.Password.Equals(qpassword) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(qpassword, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var users = WexflowServer.WexflowEngine.GetNonRestrictedUsers(); @@ -2895,7 +2907,7 @@ private void SearchAdministrators() var user = WexflowServer.WexflowEngine.GetUser(qusername); - if (user.Password.Equals(qpassword) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(qpassword, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var users = WexflowServer.WexflowEngine.GetAdministrators(keyword, (UserOrderBy)uo); var dateTimeFormat = WexflowServer.Config["DateTimeFormat"]; @@ -2936,7 +2948,7 @@ private void SaveUserWorkflows() var user = WexflowServer.WexflowEngine.GetUser(qusername); - if (user.Password.Equals(qpassword) && user.UserProfile == Core.Db.UserProfile.SuperAdministrator) + if (user.Password.Equals(qpassword, StringComparison.Ordinal) && user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { var userId = o.Value("UserId"); var jArray = o.Value("UserWorkflows"); @@ -2976,7 +2988,7 @@ private void GetUserWorkflows() var user = WexflowServer.WexflowEngine.GetUser(qusername); - if (user.Password.Equals(qpassword) && user.UserProfile == Core.Db.UserProfile.SuperAdministrator) + if (user.Password.Equals(qpassword, StringComparison.Ordinal) && user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { try { @@ -3024,7 +3036,7 @@ private void InsertUser() { var res = false; var user = WexflowServer.WexflowEngine.GetUser(qusername); - if (user.Password.Equals(qpassword) && user.UserProfile == Core.Db.UserProfile.SuperAdministrator) + if (user.Password.Equals(qpassword, StringComparison.Ordinal) && user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { WexflowServer.WexflowEngine.InsertUser(username, password, (Core.Db.UserProfile)userProfile, email); res = true; @@ -3060,7 +3072,7 @@ private void UpdateUser() { var res = false; var user = WexflowServer.WexflowEngine.GetUser(qusername); - if (user.Password.Equals(qpassword) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(qpassword, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { WexflowServer.WexflowEngine.UpdateUser(userId, username, password, (Core.Db.UserProfile)userProfile, email); res = true; @@ -3095,7 +3107,7 @@ private void UpdateUsernameAndEmailAndUserProfile() { var res = false; var user = WexflowServer.WexflowEngine.GetUser(qusername); - if (user.Password.Equals(qpassword) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(qpassword, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { WexflowServer.WexflowEngine.UpdateUsernameAndEmailAndUserProfile(userId, username, email, up); res = true; @@ -3128,7 +3140,7 @@ private void DeleteUser() { var res = false; var user = WexflowServer.WexflowEngine.GetUser(qusername); - if (user.Password.Equals(qpassword) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(qpassword, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { WexflowServer.WexflowEngine.DeleteUser(username, password); res = true; @@ -3248,7 +3260,7 @@ private void SearchHistoryEntriesByPageOrderBy() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var keyword = context.Request.Query["s"].ToString(); var from = double.Parse(context.Request.Query["from"].ToString()); @@ -3298,7 +3310,7 @@ private void SearchEntriesByPageOrderBy() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var keyword = context.Request.Query["s"].ToString(); var from = double.Parse(context.Request.Query["from"].ToString()); @@ -3347,7 +3359,7 @@ private void GetHistoryEntriesCountByDate() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var keyword = context.Request.Query["s"].ToString(); var from = double.Parse(context.Request.Query["from"].ToString()); @@ -3379,7 +3391,7 @@ private void GetEntriesCountByDate() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var keyword = context.Request.Query["s"].ToString(); var from = double.Parse(context.Request.Query["from"].ToString()); @@ -3411,7 +3423,7 @@ private void GetHistoryEntryStatusDateMin() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var date = WexflowServer.WexflowEngine.GetHistoryEntryStatusDateMin(); DateTime baseDate = new(1970, 1, 1); @@ -3438,7 +3450,7 @@ private void GetHistoryEntryStatusDateMax() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var date = WexflowServer.WexflowEngine.GetHistoryEntryStatusDateMax(); DateTime baseDate = new(1970, 1, 1); @@ -3465,7 +3477,7 @@ private void GetEntryStatusDateMin() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var date = WexflowServer.WexflowEngine.GetEntryStatusDateMin(); DateTime baseDate = new(1970, 1, 1); @@ -3492,7 +3504,7 @@ private void GetEntryStatusDateMax() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var date = WexflowServer.WexflowEngine.GetEntryStatusDateMax(); DateTime baseDate = new(1970, 1, 1); @@ -3528,7 +3540,7 @@ private void DeleteWorkflows() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { if (user.UserProfile == Core.Db.UserProfile.SuperAdministrator) { @@ -3587,7 +3599,7 @@ private void GetEntryLogs() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { res = WexflowServer.WexflowEngine.GetEntryLogs(entryId); } @@ -3617,7 +3629,7 @@ private void GetHistoryEntryLogs() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password)) + if (user.Password.Equals(password, StringComparison.Ordinal)) { var res = WexflowServer.WexflowEngine.GetHistoryEntryLogs(entryId); await context.Response.WriteAsync(JsonConvert.SerializeObject(res)); @@ -3644,7 +3656,7 @@ private static string GetFileSize(string filePath) { if (File.Exists(filePath)) { - string[] sizes = { "B", "KB", "MB", "GB", "TB" }; + string[] sizes = ["B", "KB", "MB", "GB", "TB"]; double len = new FileInfo(filePath).Length; var order = 0; while (len >= 1024 && order < sizes.Length - 1) @@ -3683,7 +3695,7 @@ private void UploadVersion() await file.CopyToAsync(ms); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var recordId = context.Request.Query["r"].ToString(); var guid = Guid.NewGuid().ToString(); @@ -3747,7 +3759,7 @@ private void DeleteTempVersionFile() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var path = context.Request.Query["p"].ToString(); @@ -3798,7 +3810,7 @@ private void DeleteTempVersionFiles() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var json = GetBody(context); var o = JObject.Parse(json); @@ -3862,7 +3874,7 @@ private void SaveRecord() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var json = GetBody(context); var o = JObject.Parse(json); @@ -3942,7 +3954,7 @@ private void DeleteRecords() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var json = GetBody(context); var recordIds = JsonConvert.DeserializeObject(JArray.Parse(json).ToString()); @@ -3974,7 +3986,7 @@ private void SearchRecords() var records = Array.Empty(); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var recordsArray = WexflowServer.WexflowEngine.GetRecords(keyword); List recordsList = []; @@ -4018,7 +4030,7 @@ private void SearchRecords() approversList.Add(a); } } - r.Approvers = approversList.ToArray(); + r.Approvers = [.. approversList]; // Versions var versions = WexflowServer.WexflowEngine.GetVersions(record.GetDbId()); @@ -4036,10 +4048,10 @@ private void SearchRecords() }; versionsList.Add(v); } - r.Versions = versionsList.ToArray(); + r.Versions = [.. versionsList]; recordsList.Add(r); } - records = recordsList.ToArray(); + records = [.. recordsList]; } await context.Response.WriteAsync(JsonConvert.SerializeObject(records)); @@ -4063,7 +4075,7 @@ private void GetRecordsCreatedBy() var records = Array.Empty(); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var recordsArray = WexflowServer.WexflowEngine.GetRecordsCreatedBy(createdBy.GetDbId()); List recordsList = []; @@ -4107,7 +4119,7 @@ private void GetRecordsCreatedBy() approversList.Add(a); } } - r.Approvers = approversList.ToArray(); + r.Approvers = [.. approversList]; // Versions var versions = WexflowServer.WexflowEngine.GetVersions(record.GetDbId()); @@ -4125,10 +4137,10 @@ private void GetRecordsCreatedBy() }; versionsList.Add(v); } - r.Versions = versionsList.ToArray(); + r.Versions = [.. versionsList]; recordsList.Add(r); } - records = recordsList.ToArray(); + records = [.. recordsList]; } await context.Response.WriteAsync(JsonConvert.SerializeObject(records)); @@ -4155,7 +4167,7 @@ private void SearchRecordsCreatedByOrAssignedTo() var records = Array.Empty(); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var recordsArray = WexflowServer.WexflowEngine.GetRecordsCreatedByOrAssignedTo(createdBy != null ? createdBy.GetDbId() : string.Empty, assignedTo != null ? assignedTo.GetDbId() : string.Empty, keyword); List recordsList = []; @@ -4199,7 +4211,7 @@ private void SearchRecordsCreatedByOrAssignedTo() approversList.Add(a); } } - r.Approvers = approversList.ToArray(); + r.Approvers = [.. approversList]; // Versions var versions = WexflowServer.WexflowEngine.GetVersions(record.GetDbId()); @@ -4217,10 +4229,10 @@ private void SearchRecordsCreatedByOrAssignedTo() }; versionsList.Add(v); } - r.Versions = versionsList.ToArray(); + r.Versions = [.. versionsList]; recordsList.Add(r); } - records = recordsList.ToArray(); + records = [.. recordsList]; } await context.Response.WriteAsync(JsonConvert.SerializeObject(records)); @@ -4244,7 +4256,7 @@ private void HasNotifications() var res = false; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { res = WexflowServer.WexflowEngine.HasNotifications(assignedTo.GetDbId()); } @@ -4268,7 +4280,7 @@ private void MarkNotificationsAsRead() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var json = GetBody(context); var notificationIds = JsonConvert.DeserializeObject(JArray.Parse(json).ToString()); @@ -4299,7 +4311,7 @@ private void MarkNotificationsAsUnread() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var json = GetBody(context); var notificationIds = JsonConvert.DeserializeObject(JArray.Parse(json).ToString()); @@ -4331,7 +4343,7 @@ private void DeleteNotifications() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var json = GetBody(context); var notificationIds = JsonConvert.DeserializeObject(JArray.Parse(json).ToString()); @@ -4365,7 +4377,7 @@ private void SearchNotifications() var notifications = Array.Empty(); var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var notificationsArray = WexflowServer.WexflowEngine.GetNotifications(assignedTo.GetDbId(), keyword); List notificationList = []; @@ -4384,7 +4396,7 @@ private void SearchNotifications() }; notificationList.Add(n); } - notifications = notificationList.ToArray(); + notifications = [.. notificationList]; } await context.Response.WriteAsync(JsonConvert.SerializeObject(notifications)); @@ -4449,7 +4461,7 @@ private void Notify() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var assignedToUsername = context.Request.Query["a"].ToString(); var message = context.Request.Query["m"].ToString(); @@ -4482,7 +4494,7 @@ private void NotifyApprovers() var password = auth.Password; var user = WexflowServer.WexflowEngine.GetUser(username); - if (user.Password.Equals(password) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) + if (user.Password.Equals(password, StringComparison.Ordinal) && (user.UserProfile == Core.Db.UserProfile.SuperAdministrator || user.UserProfile == Core.Db.UserProfile.Administrator)) { var recordId = context.Request.Query["r"].ToString(); var message = context.Request.Query["m"].ToString(); diff --git a/src/netcore/Wexflow.Tasks.ApproveRecord/ApproveRecord.cs b/src/netcore/Wexflow.Tasks.ApproveRecord/ApproveRecord.cs index b27a0243..14cce7f6 100644 --- a/src/netcore/Wexflow.Tasks.ApproveRecord/ApproveRecord.cs +++ b/src/netcore/Wexflow.Tasks.ApproveRecord/ApproveRecord.cs @@ -25,7 +25,7 @@ public class ApproveRecord : Task public string OnStopped { get; } public bool DeleteWorkflowOnApproval { get; } - private static readonly char[] separator = new[] { ',' }; + private static readonly char[] separator = [',']; public ApproveRecord(XElement xe, Workflow wf) : base(xe, wf) { @@ -735,7 +735,7 @@ private Task[] GetTasks(string evt) } } - return tasks.ToArray(); + return [.. tasks]; } private static void Send(string host, int port, bool enableSsl, string user, string password, string to, string from, string subject, string body) diff --git a/src/netcore/Wexflow.Tasks.CsvToSql/CsvToSql.cs b/src/netcore/Wexflow.Tasks.CsvToSql/CsvToSql.cs index d5696601..fd818979 100644 --- a/src/netcore/Wexflow.Tasks.CsvToSql/CsvToSql.cs +++ b/src/netcore/Wexflow.Tasks.CsvToSql/CsvToSql.cs @@ -98,7 +98,7 @@ private bool ConvertCsvToSql(string csvPath, string sqlPath, string tableName, s sw.Write($"'{value}'"); } - if (!values.Last().Equals(value)) + if (!values.Last().Equals(value, StringComparison.Ordinal)) { sw.Write(", "); } diff --git a/src/netcore/Wexflow.Tasks.FileSystemWatcher/FileSystemWatcher.cs b/src/netcore/Wexflow.Tasks.FileSystemWatcher/FileSystemWatcher.cs index 15381c62..83f3f096 100644 --- a/src/netcore/Wexflow.Tasks.FileSystemWatcher/FileSystemWatcher.cs +++ b/src/netcore/Wexflow.Tasks.FileSystemWatcher/FileSystemWatcher.cs @@ -22,7 +22,7 @@ public class FileSystemWatcher : Task public static bool SafeMode { get; private set; } public static List CurrentLogs { get; private set; } - private static readonly char[] separator = new[] { ',' }; + private static readonly char[] separator = [',']; public FileSystemWatcher(XElement xe, Workflow wf) : base(xe, wf) { @@ -290,7 +290,7 @@ private Task[] GetTasks(string evt) } } - return tasks.ToArray(); + return [.. tasks]; } private void ClearFiles() diff --git a/src/netcore/Wexflow.Tasks.FilesJoiner/FilesJoiner.cs b/src/netcore/Wexflow.Tasks.FilesJoiner/FilesJoiner.cs index e1556773..ea99cb6e 100644 --- a/src/netcore/Wexflow.Tasks.FilesJoiner/FilesJoiner.cs +++ b/src/netcore/Wexflow.Tasks.FilesJoiner/FilesJoiner.cs @@ -67,7 +67,7 @@ public override TaskStatus Run() foreach (var file in GetFiles()) { - if (JoinFiles(file.FileName, file.Files.ToArray())) + if (JoinFiles(file.FileName, [.. file.Files])) { atLeastOneSucceed = true; } diff --git a/src/netcore/Wexflow.Tasks.FilesLoaderEx/FilesLoaderEx.cs b/src/netcore/Wexflow.Tasks.FilesLoaderEx/FilesLoaderEx.cs index ec39ae28..4a3a8faa 100644 --- a/src/netcore/Wexflow.Tasks.FilesLoaderEx/FilesLoaderEx.cs +++ b/src/netcore/Wexflow.Tasks.FilesLoaderEx/FilesLoaderEx.cs @@ -151,7 +151,7 @@ private void AddFiles(IEnumerable files) private static string[] GetFilesRecursive(string dir) { - return Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories).OrderBy(f => f).ToArray(); + return [.. Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories).OrderBy(f => f)]; } private static void RemoveRange(List items, IEnumerable remove) diff --git a/src/netcore/Wexflow.Tasks.Ftp/PluginFTP.cs b/src/netcore/Wexflow.Tasks.Ftp/PluginFTP.cs index f1ba77e4..a0ac62b6 100644 --- a/src/netcore/Wexflow.Tasks.Ftp/PluginFTP.cs +++ b/src/netcore/Wexflow.Tasks.Ftp/PluginFTP.cs @@ -62,7 +62,7 @@ public override FileInf[] List() client.Disconnect(); - return files.ToArray(); + return [.. files]; } public static FileInf[] ListFiles(FtpClient client, int taskId) @@ -79,7 +79,7 @@ public static FileInf[] ListFiles(FtpClient client, int taskId) } } - return files.ToArray(); + return [.. files]; } public override void Upload(FileInf file) diff --git a/src/netcore/Wexflow.Tasks.Ftp/PluginFTPS.cs b/src/netcore/Wexflow.Tasks.Ftp/PluginFTPS.cs index cc3620b9..29d57e0a 100644 --- a/src/netcore/Wexflow.Tasks.Ftp/PluginFTPS.cs +++ b/src/netcore/Wexflow.Tasks.Ftp/PluginFTPS.cs @@ -80,7 +80,7 @@ public override FileInf[] List() client.Disconnect(); - return files.ToArray(); + return [.. files]; } public override void Upload(FileInf file) diff --git a/src/netcore/Wexflow.Tasks.Ftp/PluginSFTP.cs b/src/netcore/Wexflow.Tasks.Ftp/PluginSFTP.cs index 412fafb7..acc361cd 100644 --- a/src/netcore/Wexflow.Tasks.Ftp/PluginSFTP.cs +++ b/src/netcore/Wexflow.Tasks.Ftp/PluginSFTP.cs @@ -48,7 +48,7 @@ public override FileInf[] List() client.Disconnect(); } - return files.ToArray(); + return [.. files]; } public override void Upload(FileInf file) diff --git a/src/netcore/Wexflow.Tasks.MailsSender/MailsSender.cs b/src/netcore/Wexflow.Tasks.MailsSender/MailsSender.cs index 13f2eb4f..1345ba48 100644 --- a/src/netcore/Wexflow.Tasks.MailsSender/MailsSender.cs +++ b/src/netcore/Wexflow.Tasks.MailsSender/MailsSender.cs @@ -195,7 +195,7 @@ from f in QueryFiles(lf, xSelectFile) files.AddRange(qf); } } - return files.ToArray(); + return [.. files]; } } } diff --git a/src/netcore/Wexflow.Tasks.RedditListComments/RedditListComments.cs b/src/netcore/Wexflow.Tasks.RedditListComments/RedditListComments.cs index 79b93864..11f99d73 100644 --- a/src/netcore/Wexflow.Tasks.RedditListComments/RedditListComments.cs +++ b/src/netcore/Wexflow.Tasks.RedditListComments/RedditListComments.cs @@ -59,7 +59,11 @@ public override TaskStatus Run() new XAttribute("author", SecurityElement.Escape(comment.Author) ?? throw new InvalidOperationException()), new XAttribute("upvotes", comment.UpVotes), new XAttribute("downvotes", comment.DownVotes), new XCData(comment.BodyHTML)); - if (xdoc.Root == null) throw new InvalidOperationException(); + if (xdoc.Root == null) + { + throw new InvalidOperationException(); + } + xdoc.Root.Add(xcomment); } diff --git a/src/netcore/Wexflow.Tasks.RedditListPosts/RedditListPosts.cs b/src/netcore/Wexflow.Tasks.RedditListPosts/RedditListPosts.cs index 8a8dd82e..f839ae73 100644 --- a/src/netcore/Wexflow.Tasks.RedditListPosts/RedditListPosts.cs +++ b/src/netcore/Wexflow.Tasks.RedditListPosts/RedditListPosts.cs @@ -60,7 +60,11 @@ public override TaskStatus Run() new XAttribute("title", SecurityElement.Escape(post.Title) ?? throw new InvalidOperationException()), new XAttribute("upvotes", post.UpVotes), new XAttribute("downvotes", post.DownVotes)); - if (xdoc.Root == null) throw new InvalidOperationException(); + if (xdoc.Root == null) + { + throw new InvalidOperationException(); + } + xdoc.Root.Add(xpost); } diff --git a/src/netcore/Wexflow.Tasks.Rmdir/Rmdir.cs b/src/netcore/Wexflow.Tasks.Rmdir/Rmdir.cs index 6d4a22ab..584af5dc 100644 --- a/src/netcore/Wexflow.Tasks.Rmdir/Rmdir.cs +++ b/src/netcore/Wexflow.Tasks.Rmdir/Rmdir.cs @@ -65,7 +65,7 @@ public override TaskStatus Run() return new TaskStatus(status, false); } - private void RmdirRec(string folder) + private static void RmdirRec(string folder) { foreach (var file in Directory.GetFiles(folder)) { diff --git a/src/netcore/Wexflow.Tasks.Tar/Tar.cs b/src/netcore/Wexflow.Tasks.Tar/Tar.cs index 1efe6096..d5e41f9c 100644 --- a/src/netcore/Wexflow.Tasks.Tar/Tar.cs +++ b/src/netcore/Wexflow.Tasks.Tar/Tar.cs @@ -61,7 +61,7 @@ private bool CreateTar() foreach (var file in files) { - using (Stream inputStream = File.OpenRead(file.Path)) + using (var inputStream = File.OpenRead(file.Path)) { var fileSize = inputStream.Length; diff --git a/src/netcore/Wexflow.Tasks.VimeoListUploads/VimeoListUploads.cs b/src/netcore/Wexflow.Tasks.VimeoListUploads/VimeoListUploads.cs index 326ea529..55c148a8 100644 --- a/src/netcore/Wexflow.Tasks.VimeoListUploads/VimeoListUploads.cs +++ b/src/netcore/Wexflow.Tasks.VimeoListUploads/VimeoListUploads.cs @@ -48,7 +48,11 @@ public override TaskStatus Run() , new XAttribute("status", SecurityElement.Escape(d.Status) ?? throw new InvalidOperationException()) )); } - if (xdoc.Root == null) throw new InvalidOperationException(); + if (xdoc.Root == null) + { + throw new InvalidOperationException(); + } + xdoc.Root.Add(xvideos); xdoc.Save(xmlPath); Files.Add(new FileInf(xmlPath, Id)); diff --git a/src/netcore/Wexflow.Tasks.YouTubeListUploads/YouTubeListUploads.cs b/src/netcore/Wexflow.Tasks.YouTubeListUploads/YouTubeListUploads.cs index 47efc809..3492462f 100644 --- a/src/netcore/Wexflow.Tasks.YouTubeListUploads/YouTubeListUploads.cs +++ b/src/netcore/Wexflow.Tasks.YouTubeListUploads/YouTubeListUploads.cs @@ -121,7 +121,11 @@ private async System.Threading.Tasks.Task ListUploads() xchannels.Add(xchannel); } - if (xdoc.Root == null) throw new InvalidOperationException(); + if (xdoc.Root == null) + { + throw new InvalidOperationException(); + } + xdoc.Root.Add(xchannels); xdoc.Save(xmlPath); Files.Add(new FileInf(xmlPath, Id)); diff --git a/src/netcore/Wexflow.Tasks.YouTubeSearch/YouTubeSearch.cs b/src/netcore/Wexflow.Tasks.YouTubeSearch/YouTubeSearch.cs index d972d443..f75e052c 100644 --- a/src/netcore/Wexflow.Tasks.YouTubeSearch/YouTubeSearch.cs +++ b/src/netcore/Wexflow.Tasks.YouTubeSearch/YouTubeSearch.cs @@ -104,7 +104,11 @@ private async System.Threading.Tasks.Task Search() InfoFormat("Channels:\n{0}\n", string.Join("\n", channels)); InfoFormat("Playlists:\n{0}\n", string.Join("\n", playlists)); - if (xdoc.Root == null) throw new InvalidOperationException(); + if (xdoc.Root == null) + { + throw new InvalidOperationException(); + } + xdoc.Root.Add(xvideos); xdoc.Root.Add(xchannels); xdoc.Root.Add(xplaylists);