Format Drive


Node Information
Formats the specified directory
General Information
• This node doesn't have other available options.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Format IN RUN MULTIPLE FALSE FALSE
Drive IN String ONE FALSE FALSE
Label IN String ONE FALSE FALSE
Done OUT RUN MULTIPLE FALSE FALSE
Type IN DriveFormat ONE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.IO.Drive
{
    [IsNode("Format")]
    public class FormatDrive : Node
    {
        Port run = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Format");
        Port drive = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "Drive");
        Port label = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "Label");
        Port formt = new Port(PortType.IN, typeof(DriveFormat), AcceptsLinks.ONE, "Type");
        Port runout = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "Done");
        public string Drive
        {
            set { drive.Value = value.ToString(); }
            get { return GetRuntimeValue(drive); }
        }
        public string Label
        {
            set { label.Value = value; }
            get { return GetRuntimeValue(label); }
        }
        public DriveFormat Format
        {
            set { Settings[0] = value.ToString(); }
            get { return (DriveFormat)Enum.Parse(typeof(DriveFormat), Settings[0]); }
        }
        public FormatDrive()
        {
            this.NodeType = KGraph.NodeType.Method;
            Dependency = DependencyLibraries.COMMANDLINE;
            this.Name = "Format Drive";
            Drive = string.Empty;
            Format = DriveFormat.FAT32;
            Label = string.Empty;
            AddPort(run);
            AddPort(drive);
            AddPort(label);
            AddPort(runout);
            formt.DataType = typeof(DriveFormat);
            AddPort(formt);
            Information = "Formats the specified directory";
        }
        public override string Code()
        {
            string code = string.Empty;
            string lbl = string.Empty;
            string drv = string.Empty;
            if (label.ConnectedPorts.Count == 0)
            {
                lbl = q + Label.Replace(@"\", string.Empty) + q;
            }
            else
            {
                lbl = GetValue(label);
            }
            if (drive.ConnectedPorts.Count == 0)
            {
                drv = q + Drive.Replace(@"\", string.Empty) + q;
            }
            else
            {
                drv = "(" + GetValue(drive) + ").ToString()" + ".Replace(@" + q + @"\" + q + ", string.Empty)";
            }
            code = "CMDExecute cmd = new CMDExecute();" + Environment.NewLine +
            "cmd.Execute(@" + q + "format " + q + " + " + drv + " + " + q + " /q /FS:" + Format.ToString() + " /y /v:" + q + " + " + lbl + ", 0, true, true);\r\n" +
            "cmd.CommandExecuted += delegate(object sender, int e)\r\n{\r\n" + GetValue(runout) + "};";
            return code;
        }
        public override void UpdateResults()
        {
            Code();
        }
    }
}