예제 #1
0
        public void PrintHelp(Main.Nodes.NodeTypesManager nodeTypes, EndPoint _remote)
        {
            Print("[HELP]", _remote);
            Print("+ create <type_name> -node_name", _remote);
            Print("<group_name> - group name which contains nodeType", _remote);
            Print("<type_name> - name of nodeType", _remote);
            Print("-node_name - name of node(optional)", _remote);
            Print("available node types:", _remote);
            foreach (Main.Nodes.NodeType t in nodeTypes.GetAll())
            {
                Print("     " + t.FullName, _remote);
            }

            Print("+ print -node_name", _remote);
            Print("-node_name - name of node(optional)", _remote);
            Print("Print information about node", _remote);

            Print("+ connect <node1>.<port1> <node2>.<port2>", _remote);
            Print("<node1> - name of first node to connect", _remote);
            Print("<port1> - name of first port to connect", _remote);
            Print("<node2> - name of second node to connect", _remote);
            Print("<port2> - name of second port to connect", _remote);

            Print("+ set <node>.<port>", _remote);
            Print("Set constant to input port", _remote);
            Print("<node> - name of node to set constant", _remote);
            Print("<port> - name of Input port to set constant", _remote);

            Print("**************", _remote);
        }
예제 #2
0
        static void Main(string[] args)
        {
            UDP_Server serv = new UDP_Server();

            List <Assembly> _assemblys = new List <Assembly>();

            _assemblys.Add(Assembly.LoadFrom(@"StandartNodes.dll"));
            Main.Nodes.NodeTypesManager nodeTypes = new Main.Nodes.NodeTypesManager(_assemblys);

            Main.Sceme.Scheme scheme = new Main.Sceme.Scheme("test");

            MyConsole cons = new MyConsole(serv);

            while (true)
            {
                EndPoint remote = new IPEndPoint(IPAddress.Any, 9050);
                var      comm   = serv.Listen(ref remote);
                if (comm != "")
                {
                    Parameters par = new Parameters(remote, comm, nodeTypes, cons, scheme, serv);
                    //ParameterizedThreadStart paramThread = new ParameterizedThreadStart(Handle);

                    /*Thread thread = new Thread(paramThread);
                     * thread.Start(par);*/
                    var t = BeginHandle(par, null, null);
                }
            }
        }
예제 #3
0
 public Parameters(EndPoint _remote, string _message, Main.Nodes.NodeTypesManager _nodeTypes, MyConsole _cons, Main.Sceme.Scheme _scheme, UDP_Server _serv)
 {
     remote    = _remote;
     message   = _message;
     nodeTypes = _nodeTypes;
     cons      = _cons;
     scheme    = _scheme;
     serv      = _serv;
 }
예제 #4
0
        public MainWindowViewModel()
        {
            List <Assembly> _assemblys = new List <Assembly>();

            _assemblys.Add(Assembly.LoadFrom(@"StandartNodes.dll"));
            _nodeTypes = new Main.Nodes.NodeTypesManager(_assemblys);

            WorkArea = new WorkAreaViewModel(_nodeTypes);

            NodeTypes = new NodeTypesListViewModel(_nodeTypes);

            MyConsole = new ConsViewModel();

            CalculateSchemeCommand = new SimpleCommand(CalculateSchemeExcecuted);
            ClearSchemeCommand     = new SimpleCommand(ClearSchemeExcecuted);
            SaveSchemeCommand      = new SimpleCommand(SaveSchemeExcecuted);
            LoadSchemeCommand      = new SimpleCommand(LoadSchemeExcecuted);
        }
        public NodeTypesListViewModel(Main.Nodes.NodeTypesManager _types)
        {
            NodeTypes = _types;
            Elements  = new ObservableCollection <IBundle>();
            List <Main.Nodes.NodeType> types = _types.GetAll();

            foreach (Main.Nodes.NodeType t in types)
            {
                // If nodeType is in root, lets just create it
                if (t.Bundles.Count == 0)
                {
                    Elements.Add(new TypeViewModel(t.Name, t));
                    continue;
                }
                // Try find first group (if it isn't exists, create it)
                TypeGroupViewModel cur = Elements.FirstOrDefault(x => x.Name == t.Bundles[0]) as TypeGroupViewModel;
                if (cur == null)
                {
                    cur = new TypeGroupViewModel(t.Bundles[0]);
                    Elements.Add(cur);
                }
                // Lets add other bundles
                foreach (string bundle in t.Bundles.Skip(1))
                {
                    // Create new TypeGroup if it isn't exists
                    var z = cur.Childs.FirstOrDefault(x => x.Name == bundle) as TypeGroupViewModel;
                    if (z == null)
                    {
                        z = new TypeGroupViewModel(bundle);
                        cur.Childs.Add(z);
                    }
                    cur = z;
                }
                // Lets add leaf(nodeType)
                cur.Childs.Add(new TypeViewModel(t.Name, t));
            }
        }
예제 #6
0
        public bool ParseCommand(string command, Main.Nodes.NodeTypesManager nodeTypes, Main.Sceme.Scheme scheme, EndPoint _remote)
        {
            Regex reg   = new Regex(@"^create ([^ ]+)(?: -([^ ]+)){0,1}$");
            Match match = reg.Match(command);
            bool  flag  = false;

            if (match.Success)
            {
                flag = true;
                try
                {
                    string nodeName;
                    if (match.Groups[3].Value != "")
                    {
                        nodeName = match.Groups[3].Value;
                    }
                    else
                    {
                        nodeName = null;
                    }
                    var newNode = scheme.CreateNode(nodeTypes.GetNodeType(match.Groups[1].ToString()), nodeName);
                    PrintSuccess(string.Format("Node '{0}' created", newNode.Name), _remote);
                }
                catch (Exception e)
                {
                    PrintError(e.Message, _remote);
                }
            }

            reg   = new Regex(@"^print(?: -([^ ]+)){0,1}$");
            match = reg.Match(command);
            if (match.Success)
            {
                flag = true;
                try
                {
                    var nodes = scheme.Nodes;
                    foreach (Main.Nodes.Node node in nodes)
                    {
                        if (match.Groups[1].Value != "")
                        {
                            if (node.Name != match.Groups[1].Value)
                            {
                                continue;
                            }
                        }
                        Print(string.Format(">>'{0}' of type '{1}'", node.Name, node.NodeType.Name), _remote);
                        Print("inputs:", _remote);
                        var ports = node.PortManager.GetPorts(Main.Ports.PortType.Input);
                        foreach (Main.Ports.Port port in ports)
                        {
                            if (Main.Connections.ConnectionManager.Connected(port))
                            {
                                Main.Ports.Port _conenctedTo = Main.Connections.ConnectionManager.GetAllConnections(port)[0];
                                Print(string.Format("   {0} : connected to '{1}.{2}'",
                                                    port.Name, _conenctedTo.Parent.Name, _conenctedTo.Name), _remote);
                            }
                            else
                            {
                                Print(string.Format("   {0} : value = {1}", port.Name, Main.Values.ValueManager.GetVal(port)), _remote);
                            }
                        }
                        Print("outputs:", _remote);
                        var outputs = node.PortManager.GetPorts(Main.Ports.PortType.Output);
                        foreach (Main.Ports.Port port in outputs)
                        {
                            Print(string.Format("   {0} : value(calculated) = {1}", port.Name, Main.Values.ValueManager.GetVal(port)), _remote);
                        }
                    }
                }
                catch (Exception e)
                {
                    PrintError(e.Message, _remote);
                }
            }

            reg   = new Regex(@"^connect ([^ .]+).([^ .]+) ([^ .]+).([^ .]+)$");
            match = reg.Match(command);
            if (match.Success)
            {
                flag = true;
                try
                {
                    Main.Nodes.Node node1 = scheme.Nodes.Find((x) => x.Name == match.Groups[1].Value);
                    Main.Ports.Port port1 = node1.PortManager.GetPort(match.Groups[2].Value);
                    Main.Nodes.Node node2 = scheme.Nodes.Find((x) => x.Name == match.Groups[3].Value);
                    Main.Ports.Port port2 = node2.PortManager.GetPort(match.Groups[4].Value);
                    scheme.Connect(port1, port2);
                    PrintSuccess(string.Format("Conenction between '{0}.{1}' and '{2}.{3}' created",
                                               node1.Name, port1.Name, node2.Name, port2.Name), _remote);
                }
                catch (Exception e)
                {
                    PrintError(e.Message, _remote);
                }
            }

            reg   = new Regex(@"^set ([^ .]+).([^ .]+) (True|False|true|false)$");
            match = reg.Match(command);
            if (match.Success)
            {
                flag = true;
                try
                {
                    Main.Nodes.Node node1 = scheme.Nodes.Find((x) => x.Name == match.Groups[1].Value);
                    Main.Ports.Port port1 = node1.PortManager.GetPort(match.Groups[2].Value);
                    Main.Values.ValueManager.SetValue(port1, Convert.ToBoolean(match.Groups[3].Value));
                    PrintSuccess("Value changed", _remote);
                }
                catch (Exception e)
                {
                    PrintError(e.Message, _remote);
                }
            }

            reg   = new Regex(@"^help$");
            match = reg.Match(command);
            if (match.Success)
            {
                flag = true;
                PrintHelp(nodeTypes, _remote);
            }

            if (!flag)
            {
                PrintError("No such command", _remote);
            }
            return(true);
        }