mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-29 18:20:24 -06:00
FF-1612: New flow element Set Working File
This commit is contained in:
65
BasicNodes/File/SetWorkingFile.cs
Normal file
65
BasicNodes/File/SetWorkingFile.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using FileFlows.Plugin;
|
||||
using FileFlows.Plugin.Attributes;
|
||||
|
||||
namespace BasicNodes.File;
|
||||
|
||||
/// <summary>
|
||||
/// Flow element that sets the working file
|
||||
/// </summary>
|
||||
public class SetWorkingFile : Node
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override int Inputs => 1;
|
||||
/// <inheritdoc />
|
||||
public override int Outputs => 1;
|
||||
/// <inheritdoc />
|
||||
public override FlowElementType Type => FlowElementType.Process;
|
||||
/// <inheritdoc />
|
||||
public override string Icon => "fas fa-file-invoice-dollar";
|
||||
/// <inheritdoc />
|
||||
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/set-working-file";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the file to set as the working file
|
||||
/// </summary>
|
||||
[TextVariable(1)]
|
||||
public string File { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the old temporary working file should not be deleted
|
||||
/// </summary>
|
||||
[Boolean(2)]
|
||||
public bool DontDeletePrevious { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
var file = args.ReplaceVariables(File ?? string.Empty, stripMissing: true);
|
||||
if (string.IsNullOrWhiteSpace(file))
|
||||
{
|
||||
args.FailureReason = "No file set";
|
||||
args.Logger?.ELog(args.FailureReason);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (args.FileService.FileExists(file))
|
||||
{
|
||||
args.Logger?.ILog("Setting new working file to: " + file);
|
||||
args.Logger?.ILog("Dont Delete Previous Temporary Working File: " + DontDeletePrevious);
|
||||
args.SetWorkingFile(file, DontDeletePrevious);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.FileService.DirectoryExists(file))
|
||||
{
|
||||
args.Logger?.ILog("Setting new working file to folder: " + file);
|
||||
args.Logger?.ILog("Dont Delete Previous Temporary Working File: " + DontDeletePrevious);
|
||||
args.SetWorkingFile(file, DontDeletePrevious);
|
||||
return 1;
|
||||
}
|
||||
|
||||
args.FailureReason = $"File or Folder '{file}' does not exist";
|
||||
args.Logger?.ELog(args.FailureReason);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -356,6 +356,19 @@
|
||||
"Value-Help": "The value of the variable to set."
|
||||
}
|
||||
},
|
||||
"SetWorkingFile": {
|
||||
"Label": "Set Working File",
|
||||
"Description": "Updates the current working file to the one specified.",
|
||||
"Outputs": {
|
||||
"1": "Working File Set"
|
||||
},
|
||||
"Fields": {
|
||||
"File": "File",
|
||||
"File-Description": "The path to the new working file or folder.",
|
||||
"DontDeletePrevious": "Don't Delete Previous",
|
||||
"DontDeletePrevious-Help": "If the previous *temporary* working file should *not* be deleted.\nOnly temporary files will be deleted, files that have been created by FileFlows into the runners temporary directory."
|
||||
}
|
||||
},
|
||||
"Sleep": {
|
||||
"Description": "Pauses the flow",
|
||||
"Outputs": {
|
||||
|
||||
Reference in New Issue
Block a user