Skip to content

Commit

Permalink
General cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Jul 21, 2024
1 parent c6d3e1e commit 0a75988
Show file tree
Hide file tree
Showing 19 changed files with 175 additions and 125 deletions.
22 changes: 18 additions & 4 deletions src/net/Wexflow.Server/WexflowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -2984,7 +2996,9 @@ private XElement SwitchCasesToBlockly(Core.ExecutionGraph.Graph graph, Case @cas
}

private Core.ExecutionGraph.Node GetStartupNode(IEnumerable<Core.ExecutionGraph.Node> nodes)
=> nodes.FirstOrDefault(n => n.ParentId == Core.Workflow.START_ID);
{
return nodes.FirstOrDefault(n => n.ParentId == Core.Workflow.START_ID);
}

/// <summary>
/// Returns status count.
Expand Down
6 changes: 5 additions & 1 deletion src/net/Wexflow.Tasks.VimeoListUploads/VimeoListUploads.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
214 changes: 113 additions & 101 deletions src/netcore/Wexflow.Server/WexflowService.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/netcore/Wexflow.Tasks.ApproveRecord/ApproveRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/netcore/Wexflow.Tasks.CsvToSql/CsvToSql.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(", ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class FileSystemWatcher : Task
public static bool SafeMode { get; private set; }
public static List<string> CurrentLogs { get; private set; }

private static readonly char[] separator = new[] { ',' };
private static readonly char[] separator = [','];

public FileSystemWatcher(XElement xe, Workflow wf) : base(xe, wf)
{
Expand Down Expand Up @@ -290,7 +290,7 @@ private Task[] GetTasks(string evt)
}
}

return tasks.ToArray();
return [.. tasks];
}

private void ClearFiles()
Expand Down
2 changes: 1 addition & 1 deletion src/netcore/Wexflow.Tasks.FilesJoiner/FilesJoiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/netcore/Wexflow.Tasks.FilesLoaderEx/FilesLoaderEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ private void AddFiles(IEnumerable<FileInf> 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<FileInf> items, IEnumerable<FileInf> remove)
Expand Down
4 changes: 2 additions & 2 deletions src/netcore/Wexflow.Tasks.Ftp/PluginFTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override FileInf[] List()

client.Disconnect();

return files.ToArray();
return [.. files];
}

public static FileInf[] ListFiles(FtpClient client, int taskId)
Expand All @@ -79,7 +79,7 @@ public static FileInf[] ListFiles(FtpClient client, int taskId)
}
}

return files.ToArray();
return [.. files];
}

public override void Upload(FileInf file)
Expand Down
2 changes: 1 addition & 1 deletion src/netcore/Wexflow.Tasks.Ftp/PluginFTPS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public override FileInf[] List()

client.Disconnect();

return files.ToArray();
return [.. files];
}

public override void Upload(FileInf file)
Expand Down
2 changes: 1 addition & 1 deletion src/netcore/Wexflow.Tasks.Ftp/PluginSFTP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override FileInf[] List()
client.Disconnect();
}

return files.ToArray();
return [.. files];
}

public override void Upload(FileInf file)
Expand Down
2 changes: 1 addition & 1 deletion src/netcore/Wexflow.Tasks.MailsSender/MailsSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ from f in QueryFiles(lf, xSelectFile)
files.AddRange(qf);
}
}
return files.ToArray();
return [.. files];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 5 additions & 1 deletion src/netcore/Wexflow.Tasks.RedditListPosts/RedditListPosts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/netcore/Wexflow.Tasks.Rmdir/Rmdir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion src/netcore/Wexflow.Tasks.Tar/Tar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 5 additions & 1 deletion src/netcore/Wexflow.Tasks.YouTubeSearch/YouTubeSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0a75988

Please sign in to comment.