File Search


Node Information
Searches the specified directory for files based on the given conditions.
General Information
• This node has other options, you can view them by clicking on the info button, this also means according to the node you might be able to add more ports than what is already listed.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Start IN RUN MULTIPLE FALSE FALSE
Stop IN RUN MULTIPLE FALSE FALSE
Directory IN String ONE FALSE FALSE
FileFound OUT RUN MULTIPLE FALSE FALSE
CurrentFile OUT String MULTIPLE FALSE FALSE
Complete OUT RUN MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.IO.File
{
    [IsNode("File Search")]
    public class FileSearch : Node
    {
        Port run = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Start");
        Port stop = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Stop");
        Port path = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "Directory");
        Port found = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "FileFound");
        Port curFile = new Port(PortType.OUT, typeof(string), AcceptsLinks.MULTIPLE, "CurrentFile");
        Port complete = new Port(PortType.OUT, typeof(RUN), AcceptsLinks.MULTIPLE, "Complete");
        Variable var1 = new Variable("KIO.Searcher", null, " new KIO.Searcher()");
        public FileSearch()
        {
            this.Dependency = DependencyLibraries.IOOPERATIONS;
            this.Name = "File Search";
            this.NodeType = NodeType.Method;
            AddPort(run);
            AddPort(stop);
            AddPort(path);
            AddPort(found);
            AddPort(curFile);
            AddPort(complete);
            Variables.Add(var1);
            OptionsAvilable = true;
            Information = "Searches the specified directory for files based on the given conditions.";
            CreateContextMenu();
        }
        public void CreateContextMenu()
        {
            InfoContextMenu = new System.Windows.Controls.ContextMenu();
            System.Windows.Controls.MenuItem setitem = new System.Windows.Controls.MenuItem();
            System.Windows.Controls.MenuItem getitem = new System.Windows.Controls.MenuItem();
            setitem.Header = "Set";
            getitem.Header = "Get";
            foreach (System.Windows.Controls.MenuItem item in GetTypePropertiesMenu(typeof(KIO.Searcher), true, true).Items)
            {
                System.Windows.Controls.MenuItem setmi = new System.Windows.Controls.MenuItem();
                setmi.Header = item.Header;
                setmi.Tag = item.Tag;
                setmi.Click += setmi_Click;
                setitem.Items.Add(setmi);
            }
            foreach (System.Windows.Controls.MenuItem item in GetTypePropertiesMenu(typeof(KIO.Searcher), true).Items)
            {
                System.Windows.Controls.MenuItem getmi = new System.Windows.Controls.MenuItem();
                getmi.Header = item.Header;
                getmi.Tag = item.Tag;
                getmi.Click += getmi_Click;
                getitem.Items.Add(getmi);
            }
            InfoContextMenu.Items.Add(setitem);
            InfoContextMenu.Items.Add(getitem);
        }
        void setmi_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            System.Windows.Controls.MenuItem mi = (System.Windows.Controls.MenuItem)sender;
            System.Reflection.PropertyInfo prp = (System.Reflection.PropertyInfo)mi.Tag;
            Port newport = new Port(PortType.IN, prp.PropertyType, AcceptsLinks.ONE, prp.Name, true);
            newport.IsRemovable = true;
            newport.Instructions = "init";
            AddPort(newport);
        }
        void getmi_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            System.Windows.Controls.MenuItem mi = (System.Windows.Controls.MenuItem)sender;
            System.Reflection.PropertyInfo prp = (System.Reflection.PropertyInfo)mi.Tag;
            Port newport = new Port(PortType.OUT, prp.PropertyType, AcceptsLinks.MULTIPLE, prp.Name, true);
            newport.IsRemovable = true;
            newport.Instructions = "init";
            AddPort(newport);
        }
        public override string Code()
        {
            string code = string.Empty;
            var1.Name = run.ID;
            foreach (var item in Ports.Where(p => p != path && p.PortType == PortType.IN && p.DataType != typeof(RUN)))
            {
                code += var1.Name + "." + item.Text + " = " + GetValue(item) + ";\r\n";
            }
            foreach (var item in Ports.Where(p => p.PortType == PortType.OUT && p.DataType != typeof(RUN)))
            {
                item.Instructions = var1.Name + "." + item.Text;
            }
            code += var1.Name + ".FileFound +=delegate(object sender, string e)\r\n{\r\n this.Invoke(new Action(()=> {" + GetValue(found) + "}));\r\n};\r\n";
            code += var1.Name + ".Complete +=delegate(object sender, EventArgs e)\r\n{\r\n this.Invoke(new Action(()=> {" + GetValue(complete) + "}));\r\n};\r\n";
            code += var1.Name + ".BackgroundSearch(" + GetValue(path) + ");";
            return code;
        }
        public override void UpdateResults()
        {
            Code();
        }
    }
}