using FileFlows.Plugin;
using FileFlows.Plugin.Attributes;
namespace BasicNodes.File;
///
/// Flow element that sets the working file
///
public class SetWorkingFile : Node
{
///
public override int Inputs => 1;
///
public override int Outputs => 1;
///
public override FlowElementType Type => FlowElementType.Process;
///
public override string Icon => "fas fa-file-invoice-dollar";
///
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/set-working-file";
///
/// Gets or sets the file to set as the working file
///
[TextVariable(1)]
public string File { get; set; }
///
/// Gets or sets if the old temporary working file should not be deleted
///
[Boolean(2)]
public bool DontDeletePrevious { get; set; }
///
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;
}
}