public Graph_Handler() { this.graph = null; /*this.transport = new TSocket("localhost", 9090); * this.protocol = new TBinaryProtocol(transport); * this.client = new Thrift.TheGraph.Client(this.protocol); * * transport.Open();*/ InitializeComponent(); }
private void txt_Command_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)Keys.Enter) { string command = txt_Command.Text.ToLower(); txt_Command.Text = ""; txt_Console.Text += command + "\n"; if (command.Contains("draw")) { this.graph = client.G(true); pnl_Grafo.Refresh(); } else if (command.Contains("connect")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); if (this.transport != null && this.transport.IsOpen) { this.transport.Close(); } this.transport = new TSocket(values[0], int.Parse(values[1])); this.protocol = new TBinaryProtocol(transport); this.client = new Thrift.TheGraph.Client(this.protocol); transport.Open(); } else if (command.Contains("add-v")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); // int Name = int.Parse(values[0]); int Color = int.Parse(values[1]); // double P = double.Parse(values[2].Replace(".", ",")); // string Description = values[3]; try { var result = client.createVertex(new Thrift.vertex() { Name = Name, Color = Color, Weight = P, Description = Description }); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } else if (command.Contains("get-v")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); try { if (values.Length == 1) { int name = int.Parse(values[0]); var V = client.readV(name); txt_Console.Text += string.Format("Name = {0}\nColor={1}\nWeight={2}\nDescription={3}\n", V.Name, V.Color, V.Weight, V.Description); } if (values.Length == 3) { int V1 = int.Parse(values[0]); int V2 = int.Parse(values[1]); bool Directed = bool.Parse(values[2]); var LV = client.getVertex(new Thrift.edge() { V1 = V1, V2 = V2, Directed = Directed }); foreach (var V in LV) { txt_Console.Text += string.Format("Name = {0}\nColor={1}\nWeight={2}\nDescription={3}\n", V.Name, V.Color, V.Weight, V.Description); } } } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } else if (command.Contains("rem-v")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); // int Name = int.Parse(values[0]); try { client.deleteVertex(new Thrift.vertex() { Name = Name }); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } else if (command.Contains("update-v")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); // int Name = int.Parse(values[0]); int Color = int.Parse(values[1]); // double P = double.Parse(values[2].Replace(".", ",")); // string Description = values[3]; try { client.updateVertex(new Thrift.vertex() { Name = Name, Color = Color, Weight = P, Description = Description }); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } else if (command.Contains("add-e")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); // int V1 = int.Parse(values[0]); int V2 = int.Parse(values[1]); // double P = double.Parse(values[2].Replace(".", ",")); // bool Directed = bool.Parse(values[3]); // string Description = values[4]; try { client.createEdge(new Thrift.edge() { V1 = V1, V2 = V2, Weight = P, Directed = Directed, Description = Description }); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } else if (command.Contains("get-e")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); try { if (values.Length == 3) { // int V1 = int.Parse(values[0]); int V2 = int.Parse(values[1]); // bool Directed = bool.Parse(values[2]); var E = client.readE(V1, V2, Directed); txt_Console.Text += string.Format("V1={0}\nV2={1}\nDirected={2}\nWeight={3}\nDescription={4}\n", E.V1, E.V2, E.Directed, E.Weight, E.Description); } else if (values.Length == 1) { int Name = int.Parse(values[0]); var LE = client.getEdges(new Thrift.vertex() { Name = Name }); foreach (var E in LE) { txt_Console.Text += string.Format("V1={0}\nV2={1}\nDirected={2}\nWeight={3}\nDescription={4}\n", E.V1, E.V2, E.Directed, E.Weight, E.Description); } } } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } else if (command.Contains("rem-e")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); // int V1 = int.Parse(values[0]); int V2 = int.Parse(values[1]); bool Directed = bool.Parse(values[2]); try { client.deleteEdge(new Thrift.edge() { V1 = V1, V2 = V2, Directed = Directed }); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } else if (command.Contains("update-e")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); // int V1 = int.Parse(values[0]); int V2 = int.Parse(values[1]); // double P = double.Parse(values[2].Replace(".", ",")); // bool Directed = bool.Parse(values[3]); // string Description = values[4]; try { client.updateEdge(new Thrift.edge() { V1 = V1, V2 = V2, Weight = P, Directed = Directed, Description = Description }); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } else if (command.Contains("bfs")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); // int V1 = int.Parse(values[0]); int V2 = int.Parse(values[1]); // try { try{ var result = client.bfs(V2, new List <List <int> >() { new List <int>() { V1 } }, new List <int>()); txt_Console.Text += string.Join("-", result) + "\n"; } catch (Exception ex) { txt_Console.Text += "NÃO EXISTE CAMINHO\n"; } } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } else if (command.Contains("neighborhood")) { command = command.Remove(0, command.IndexOf("(")); command = command.Replace("(", "").Replace(")", ""); var values = command.Split(','); try { int Name = int.Parse(values[0]); var LV = client.getNeighborhood(new Thrift.vertex() { Name = Name }); foreach (var V in LV) { txt_Console.Text += string.Format("Name = {0}\nColor={1}\nWeight={3}\nDescription={2}\n", V.Name, V.Color, V.Weight, V.Description); } } catch (Exception exception) { MessageBox.Show(exception.ToString()); } } } }