public GrafoPlus abrirGrafo(string nome) { GrafoLinqDataContext dt = new GrafoLinqDataContext(); try { tb_Grafo grafoAberto = dt.tb_Grafos.First(g => g.nome == nome); GrafoPlus grafo = new GrafoPlus(); grafo.width = grafoAberto.width; grafo.height = grafoAberto.height; grafo.idGrafo = grafoAberto.id_grafo; foreach (tb_Vertice vertice in grafoAberto.tb_Vertices) { grafo.inserirVertice(vertice.nome, vertice.posX, vertice.posY, vertice.id_vertice); } var arestasDoGrafo = from a in dt.tb_Arestas where a.tb_Vertice.tb_Grafo.nome == nome select a; VerticePlus origem, destino; foreach (tb_Aresta aresta in arestasDoGrafo) { origem = ((VerticePlus)grafo.vertices.Find(o => ((VerticePlus)o).idVertice == aresta.id_origem)); destino = ((VerticePlus)grafo.vertices.Find(d => ((VerticePlus)d).idVertice == aresta.id_destino)); grafo.inserirAresta(origem, destino, aresta.peso); } return(grafo); } catch (Exception ex) { throw ex; } return(null); }
public GrafoPlus abrirGrafoPlus(string nome) { GrafoLinqDataContext dt = new GrafoLinqDataContext(); try { tb_Grafo grafoAberto = dt.tb_Grafos.First(g => g.nome == nome); GrafoPlus grafo = new GrafoPlus(); grafo.width = grafoAberto.width; grafo.height = grafoAberto.height; grafo.idGrafo = grafoAberto.id_grafo; foreach (tb_Vertice vertice in grafoAberto.tb_Vertices) { grafo.vertices.Add(new VerticePlus(vertice.nome, vertice.id_vertice, vertice.posX, vertice.posY)); } var arestasDoGrafo = from a in dt.tb_Arestas where a.tb_Vertice.tb_Grafo.nome == nome select a; foreach (tb_Aresta aresta in arestasDoGrafo) { grafo.arestas.Add(new ArestaPlus(aresta.peso, aresta.id_aresta, aresta.id_origem, aresta.id_destino)); } return(grafo); } catch (Exception ex) { throw ex; } return(null); }
public string criarGrafo(string nome) { JavaScriptSerializer js = new JavaScriptSerializer(); GrafoPlus grafo; try { grafo = new GrafoPlus(nome); grafo.criarGrafo(); } catch (Exception ex) { return(js.Serialize(new GrafoWSErro(ex))); } return(js.Serialize(new Retorno())); }
public string abrirGrafo(string nomeGrafo) { JavaScriptSerializer js = new JavaScriptSerializer(); GrafoPlus grafo; try { grafo = new GrafoPlus(nomeGrafo); grafo.abrirGrafoPlus(); } catch (Exception ex) { return(js.Serialize(new GrafoWSErro(ex))); } return(js.Serialize(grafo)); }
public string menorCaminho(string nome, int idOrigem, int idDestino) { JavaScriptSerializer js = new JavaScriptSerializer(); GrafoPlus grafo; try { grafo = new GrafoPlus(nome); grafo.abrirGrafo(); } catch (Exception ex) { return(js.Serialize(new GrafoWSErro(ex))); } return(js.Serialize(grafo)); }