Skip to content

Commit

Permalink
Added Read/Write Text File Commands
Browse files Browse the repository at this point in the history
  • Loading branch information
saucepleez committed Jun 18, 2018
1 parent f655086 commit 50c4d66
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
96 changes: 96 additions & 0 deletions taskt/Core/AutomationCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ namespace taskt.Core.AutomationCommands
[XmlInclude(typeof(SequenceCommand))]
[XmlInclude(typeof(StopTaskCommand))]
[XmlInclude(typeof(RunTaskCommand))]
[XmlInclude(typeof(WriteTextFileCommand))]
[XmlInclude(typeof(ReadTextFileCommand))]
[Serializable]
public abstract class ScriptCommand
{
Expand Down Expand Up @@ -3523,6 +3525,100 @@ public override string GetDisplayValue()


#endregion

#region Text File Commands
[Serializable]
[Attributes.ClassAttributes.Group("Text File Commands")]
[Attributes.ClassAttributes.Description("This command writes specified data to a text file")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
public class WriteTextFileCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the path to the file")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_FilePath { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the text to be written")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
public string v_TextToWrite { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please select overwrite option")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Append")]
[Attributes.PropertyAttributes.PropertyUISelectionOption("Overwrite")]
public string v_Overwrite { get; set; }
public WriteTextFileCommand()
{
this.CommandName = "WriteTextFileCommand";
this.SelectionName = "Write To File";
this.CommandEnabled = true;
}

public override void RunCommand(object sender)
{
//convert variables
var filePath = v_FilePath.ConvertToUserVariable(sender);
var outputText = v_TextToWrite.ConvertToUserVariable(sender);

//append or overwrite as necessary
if (v_Overwrite == "Append")
{
System.IO.File.AppendAllText(filePath, outputText);
}
else
{
System.IO.File.WriteAllText(filePath, outputText);
}

}

public override string GetDisplayValue()
{
return base.GetDisplayValue() + " [" + v_Overwrite + " to '" + v_FilePath + "']";
}
}
[Serializable]
[Attributes.ClassAttributes.Group("Text File Commands")]
[Attributes.ClassAttributes.Description("This command reads text data into a variable")]
[Attributes.ClassAttributes.ImplementationDescription("This command implements '' to achieve automation.")]
public class ReadTextFileCommand : ScriptCommand
{
[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please indicate the path to the file")]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowVariableHelper)]
[Attributes.PropertyAttributes.PropertyUIHelper(Attributes.PropertyAttributes.PropertyUIHelper.UIAdditionalHelperType.ShowFileSelectionHelper)]
public string v_FilePath { get; set; }

[XmlAttribute]
[Attributes.PropertyAttributes.PropertyDescription("Please define where the text should be stored")]
public string v_userVariableName { get; set; }


public ReadTextFileCommand()
{
this.CommandName = "ReadTextFileCommand";
this.SelectionName = "Read Text File";
this.CommandEnabled = true;
}

public override void RunCommand(object sender)
{
//convert variables
var filePath = v_FilePath.ConvertToUserVariable(sender);
//read text from file
var textFromFile = System.IO.File.ReadAllText(filePath);
//assign text to user variable
textFromFile.StoreInUserVariable(sender, v_userVariableName);
}

public override string GetDisplayValue()
{
return base.GetDisplayValue() + " [Read from '" + v_FilePath + "']";
}
}
#endregion

}


Expand Down
2 changes: 2 additions & 0 deletions taskt/UI/CustomControls/CustomControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ public static Dictionary<string, Image> UIImageDictionary()
uiImages.Add("BeginExcelDatasetLoopCommand", taskt.Properties.Resources.command_startloop);
uiImages.Add("BeginNumberOfTimesLoopCommand", taskt.Properties.Resources.command_startloop);
uiImages.Add("SequenceCommand", taskt.Properties.Resources.command_sequence);
uiImages.Add("ReadTextFileCommand", taskt.Properties.Resources.command_files);
uiImages.Add("WriteTextFileCommand", taskt.Properties.Resources.command_files);
return uiImages;
}
public static ImageList UIImageList()
Expand Down

0 comments on commit 50c4d66

Please sign in to comment.