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); } } }
public WorkAreaViewModel(NodeTypesManager _nodeTypes) { Scheme = new Main.Sceme.Scheme("test"); Nodes = new ObservableCollection <NodeViewModel>(); Connections = new ObservableCollection <object>(); NodeTypes = _nodeTypes; }
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; }
public MainWindow() { _scene = new Main.Sceme.Scheme("scene1"); InitializeComponent(); SetLanguageDictionary(); }
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); }
/// <summary> /// Deserialize object /// </summary> public void Load(Stream stream, NodeTypesManager _nodeTypes) { this.Connections.Clear(); this.Nodes.Clear(); XmlDocument doc = new XmlDocument(); doc.Load(stream); Scheme = new Main.Sceme.Scheme(doc.DocumentElement.Attributes["name"].Value); List <Tuple <string, string> > _connectionsToCreate = new List <Tuple <string, string> >(); // First create all nodes foreach (XmlNode t in doc.DocumentElement.ChildNodes) { string nodeName = t.Attributes["name"].Value; string nodeType = t.Attributes["nodeType"].Value; string x = t.Attributes["x"].Value; string y = t.Attributes["y"].Value; var node = CreateNode(NodeTypes.GetNodeType(nodeType), Convert.ToDouble(x), Convert.ToDouble(y), false, nodeName); foreach (XmlNode z in t.ChildNodes) { string portName = z.Name; string value = z.Attributes["value"] == null ? null : z.Attributes["value"].Value; string connected = z.Attributes["connected"] == null ? null : z.Attributes["connected"].Value; if (connected != null) { _connectionsToCreate.Add(new Tuple <string, string>(nodeName + "+" + portName, connected)); } else { // We can set const value here InputPortViewModel port = node.InputPorts.FirstOrDefault((u) => u.PortName == portName); if (port.Port.DataType == typeof(bool)) { port.Val = Convert.ToBoolean(value); continue; } if (port.Port.DataType == typeof(int)) { port.Val = Convert.ToInt32(value); continue; } throw new ArgumentException(string.Format("{0} can't be desirialized", value.GetType())); } } } // Create connections (all nodes are created before) foreach (Tuple <string, string> conn in _connectionsToCreate) { string firstPortNode = conn.Item1.Split('+')[0]; string firstPort = conn.Item1.Split('+')[1]; string secondPortNode = conn.Item2.Split('+')[0]; string secondPort = conn.Item2.Split('+')[1]; PortViewModel first = Nodes.FirstOrDefault((r) => r.Name == firstPortNode).InputPorts.FirstOrDefault((u) => u.PortName == firstPort); if (first == null) { first = Nodes.FirstOrDefault((r) => r.Name == firstPortNode).OutputPorts.FirstOrDefault((u) => u.PortName == firstPort); } PortViewModel second = Nodes.FirstOrDefault((r) => r.Name == secondPortNode).InputPorts.FirstOrDefault((u) => u.PortName == secondPort); if (second == null) { second = Nodes.FirstOrDefault((r) => r.Name == secondPortNode).OutputPorts.FirstOrDefault((u) => u.PortName == secondPort); } CreateConnection(first, second); } }