Esempio n. 1
0
        public ActionResult CrearProyectoArchivo(ProyectoArchivoViewModel newModel, HttpPostedFileBase topologiaCVS)
        {
            if (ModelState.IsValid)
            {
                int idProyecto = newModel.InsertProyecto();
                List<Tabla> tablaDatos = new List<Tabla>();
                StreamReader csvreader = new StreamReader(topologiaCVS.InputStream);    // Use the InputStream to get the actual stream sent.

                //Primera linea
                var line = csvreader.ReadLine();
                var values = line.Split(';');

                while (!csvreader.EndOfStream)
                {
                    Tabla row = new Tabla();
                    line = csvreader.ReadLine();
                    values = line.Split(';');

                    row.Hostname = values[0];
                    row.OSPFRouterID = values[1];
                    row.OSPFNeighborRouterID = values[2];
                    row.OSPFNeighborIP = values[3];
                    tablaDatos.Add(row);
                }
                Proyecto newProyecto = new Proyecto(idProyecto);
                newProyecto.GenerarTopologia(tablaDatos);

                string url = Url.Action("Editar", "Topologia", new { idProyecto = idProyecto });
                return Json(new { success = true, url = url });

                //return Json(new { success = true });
            }
            else
            {
                return PartialView(newModel);
            }
        }
Esempio n. 2
0
        public ActionResult CrearProyectoRP(ProyectoRaspberryViewModel newModel)
        {
            if (ModelState.IsValid)
            {
                int idProyecto = newModel.InsertProyecto();
                string answer = ConexionSSH.EjecutarOSPFDiscovery(newModel.cRaspberryIP, newModel.nPuerto, newModel.cRouterIP, newModel.cCommunityString);
                //string answer = ""; //ConexionSSH.EjecutarOSPFDiscovery(newModel.cRaspberryIP, newModel.nPuerto, newModel.cRouterIP, newModel.cCommunityString);

                List<Tabla> tablaDatos = new List<Tabla>();

                #region response
                /*
                answer = @"Hostname; OSPFRouterID; OSPFNeighborRouterID; OSPFNeighborIP\n\n" +
                           @"R6; 6.6.6.6; 5.5.5.5, 4.4.4.4; 10.0.4.5, 10.0.4.14\n\n" +
                           @"R5; 5.5.5.5; 1.1.1.1, 6.6.6.6, 4.4.4.4; 10.0.4.1, 10.0.4.6, 10.0.4.10\n\n" +
                           @"R4; 4.4.4.4; 3.3.3.3, 5.5.5.5, 6.6.6.6; 10.0.3.1, 10.0.4.9, 10.0.4.13\n\n" +
                           @"R4; 4.4.4.4; 3.3.3.3, 5.5.5.5, 6.6.6.6; 10.0.3.1, 10.0.4.9, 10.0.4.13\n\n" +
                           @"R1; 1.1.1.1; 2.2.2.2, 5.5.5.5; 10.0.1.2, 10.0.4.2\n\n" +
                           @"R3; 3.3.3.3; 2.2.2.2, 4.4.4.4; 10.0.2.1, 10.0.3.2\n\n" +
                           @"R3; 3.3.3.3; 2.2.2.2, 4.4.4.4; 10.0.2.1, 10.0.3.2\n\n" +
                           @"R3; 3.3.3.3; 2.2.2.2, 4.4.4.4; 10.0.2.1, 10.0.3.2\n\n" +
                           @"R3; 3.3.3.3; 2.2.2.2, 4.4.4.4; 10.0.2.1, 10.0.3.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"R2; 2.2.2.2; 1.1.1.1, 3.3.3.3; 10.0.1.1, 10.0.2.2\n\n" +
                           @"end of file\n";*/
                #endregion

                if (answer != "")
                {
                    string[] lines = answer.Split(new string[] { "\n\n" }, StringSplitOptions.None);
                    // TODO: Parsear el archivo CSV

                    List<string> templist = new List<string>();
                    templist = lines.ToList();
                    templist.RemoveAt(0);
                    templist.RemoveAt(templist.Count - 1);

                    foreach (var line in templist)
                    {
                        Tabla row = new Tabla();
                        var values = line.Split(';');

                        row.Hostname = values[0].Trim();
                        row.OSPFRouterID = values[1].Trim();
                        row.OSPFNeighborRouterID = values[2].Trim();
                        row.OSPFNeighborIP = values[3].Trim();
                        tablaDatos.Add(row);
                    }
                    Proyecto newModelP = new Proyecto(idProyecto);
                    newModelP.GenerarTopologia(tablaDatos);
                }
                //return RedirectToAction("Index");
                //return RedirectToAction("Editar", new { idProyecto = idProyecto });

                string url = Url.Action("Editar", "Topologia", new { idProyecto = idProyecto });
                return Json(new { success = true, url = url });
            }
            else
            {
                return PartialView(newModel);
            }
        }
Esempio n. 3
0
        public ActionResult SaveJsonNetwork(List<RouterJson> nodeDataArray, List<EnlaceJson> linkDataArray)
        {
            try
            {
                List<Router> listaRouters = nodeDataArray.ToModeList();
                List<Enlace> listaEnlaces = linkDataArray.ToModeList();
                int idProyecto = listaRouters.FirstOrDefault().idProyecto;
                Proyecto newModel = new Proyecto(idProyecto, listaRouters, listaEnlaces);

                newModel.InsertUpdateListaRouters();
                newModel.InsertUpdateListaEnlaces();
                return Json(new { success = true });
            }
            catch (Exception ex)
            {
                return Json(new { success = false });
            }
        }
Esempio n. 4
0
        public ActionResult LoadJsonNetwork(int idProyecto)
        {
            Proyecto temp = new Proyecto(idProyecto);

            //Transforma las listas en formato Json de GoJS
            var nodeDataArray = temp.listadoRouters.toJson();
            var linkDataArray = temp.listadoEnlaces.toJson();
            return Json(new { @class = "go.GraphLinksModel", nodeDataArray, linkDataArray },
                        JsonRequestBehavior.AllowGet);
        }
Esempio n. 5
0
 public ActionResult GetJsonTopologia(int idProyecto)
 {
     Proyecto temp = new Proyecto(idProyecto);
     //temp = null;
     //return Json(new { routers = temp }, JsonRequestBehavior.AllowGet);
     return Json(new { routers = temp.listadoRouters, enlaces = temp.listadoEnlaces }, JsonRequestBehavior.AllowGet);
 }
Esempio n. 6
0
 // GET: Topologia/Editar/5
 public ActionResult Editar(int idProyecto)
 {
     Proyecto newModel = new Proyecto(idProyecto);
     //ViewBag.idEnlace = "1";
     return View(newModel);
 }
Esempio n. 7
0
        public async Task<IHttpActionResult> PostFile()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var provider = await Request.Content.ReadAsMultipartAsync<InMemoryMultipartFormDataStreamProvider>(new InMemoryMultipartFormDataStreamProvider());

            //Debug.Write(provider.Contents.ToString());

            //access form data
            NameValueCollection formData = provider.FormData;

            //access files
            IList<HttpContent> files = provider.Files;

            string userName = formData.GetValues("cUserName")[0];
            string projectName = formData.GetValues("cFileName")[0];

            byte[] byteArray = await provider.Files[0].ReadAsByteArrayAsync();
            MemoryStream myStream = new MemoryStream(byteArray);

            //Proceso de parsing del archivo CSV
            List<Tabla> tablaDatos = new List<Tabla>();
            StreamReader csvreader = new StreamReader(myStream);

            //Debug.Write(csvreader.ReadToEnd());

            //Primera linea
            var line = csvreader.ReadLine();
            var values = line.Split(';');

            while (!csvreader.EndOfStream)
            {
                Tabla row = new Tabla();
                line = csvreader.ReadLine();
                if (line != "")
                {
                    values = line.Split(';');

                    row.Hostname = values[0];
                    row.OSPFRouterID = values[1];
                    row.OSPFNeighborRouterID = values[2];
                    row.OSPFNeighborIP = values[3];
                    tablaDatos.Add(row);
                }                
            }

            //Llama al SP para crear el nuevo proyecto en la DB
            Data.dsTopologiaTableAdapters.ProyectosTableAdapter Adapter = new Data.dsTopologiaTableAdapters.ProyectosTableAdapter();
            int idProyecto = (int)Adapter.CrearProyectoLocal(userName, projectName);

            //Creación del nuevo objeto de proyecto
            Proyecto newProyecto = new Proyecto(idProyecto);
            newProyecto.GenerarTopologia(tablaDatos);

            return Ok();
        }
Esempio n. 8
0
        /// <summary>
        /// Genera la lista de proyectos asociados a un usuario
        /// </summary>
        /// <param name="cUserName"></param>
        /// <returns></returns>
        public static List<Proyecto> GetListaProyectos(string cUserName)
        {
            List<Proyecto> listaProyectos = new List<Proyecto>();

            Data.dsTopologiaTableAdapters.ProyectosTableAdapter Adapter = new Data.dsTopologiaTableAdapters.ProyectosTableAdapter();
            Data.dsTopologia.ProyectosDataTable dt = Adapter.SeleccionarListaProyectos(null, cUserName);

            foreach(var dr in dt)
            {
                Proyecto temp = new Proyecto();
                temp.idProyecto = dr.idProyecto;
                temp.cUserName = dr.cUserName.Trim();
                temp.cTitulo = dr.cFileName.Trim();
                if (!dr.IsdtFechaCreacionNull())
                    temp.dtFechaCreacion = dr.dtFechaCreacion;
                if (!dr.IsdtFechaUltEdicionNull())
                    temp.dtFechaUltEdicion = dr.dtFechaUltEdicion;
                listaProyectos.Add(temp);
            }

            return listaProyectos;
        }