Write File


Node Information
Writes given content (usually string) to the specified file.
General Information
• This node doesn't have other available options.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Write IN RUN MULTIPLE FALSE FALSE
Path IN String ONE FALSE FALSE
Content IN String ONE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.IO.File
{
    [IsNode("Write File")]
    public class FileWrite : Node
    {
        Port run = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE,  "Write");
        Port path = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "Path");
        Port content = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "Content");
        public string Content
        {
            set { content.Value = value.ToString(); UpdateResults(); }
            get {return GetRuntimeValue(content);}
        }
        public string FilePath
        {
            set { path.Value = value.ToString(); }
            get { return GetRuntimeValue(path); }
        }
        public FileWrite()
        {
            this.Name = "Write File";
            this.NodeType = KGraph.NodeType.Method;
            AddPort(run);
            AddPort(path);
            AddPort(content);
            Information = "Writes given content (usually string) to the specified file.";
        }
        public override string Code()
        {
            string filepath = string.Empty;
            string cntnt = string.Empty;
            if (path.IsConnected) { filepath = GetValue(path); }
            else { filepath = "@" + q + FilePath + q; }
            if (content.IsConnected) { cntnt = GetValue(content); }
            else { cntnt = "@" + q + Content + q; }
            string code = "System.IO.File.WriteAllText(" + filepath + "," + cntnt + ");";
            return code;
        }
    }
}