示例#1
0
        public ActionResult ImportFiles()
        {
            IFileSystemRepo fsr = new FileSystemRepo();
            IStarSystemRepo ssr = new StarSystemRepo();
            var files = Request.Files.AllKeys.Select(fileName => Request.Files[fileName]).Where(file => file.ContentLength > 0).ToList();
            List<string> pathNames = new List<string>();
            foreach (var file in files)
            {
                var fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
                var virtualPath = "~/Content/netlogs/" + DateTime.Today.ToString("MMddyyyy");
                var subPath = Server.MapPath(virtualPath);
                if (!Directory.Exists(subPath))
                {
                    Directory.CreateDirectory(subPath);
                }
                var path = Path.Combine(subPath, fileName);
                try
                {
                    file.SaveAs(path);
                }
                catch (Exception e)
                {
                    continue;
                }

                fsr.SaveFileData(Path.Combine(virtualPath.Replace("~/", "/").Replace("\\", "/"), fileName), fileName);
                pathNames.Add(path);
            }
            foreach (var path in pathNames)
            {
                List<NetLog> nlList =
                    NetLogTranslator.RawNetLogToNetLogs(path)
                        .GroupBy(nl => nl.SystemName)
                        .Select(lst => lst.First()).ToList();
                foreach (var nl in nlList)
                {
                    var ssvm = new StarSystemViewModel
                    {
                        Name = nl.SystemName,
                        Uploader = User.Identity.Name
                    };
                    ssr.Create(ssvm);
                }
            }
            return Json(new { Message = string.Empty });
        }
示例#2
0
 // GET: Planet/Details/5
 public ActionResult Details(int id)
 {
     IPlanetRepo pr = new PlanetRepo();
     IStarSystemRepo ssr = new StarSystemRepo();
     IFileSystemRepo fsr = new FileSystemRepo();
     var planet = pr.GetById(id);
     planet.StarSystem = ssr.GetById(planet.StarSystem.Id);
     planet.PlanetImagePaths = new Dictionary<string, string>();
     foreach (var item in fsr.GetFileDataByPlanetId(id))
     {
         planet.PlanetImagePaths.Add(item.Path.Replace("\\", "/"), item.Name);
     }
     return View(planet);
 }
示例#3
0
 public ActionResult UploadFilesByPlanetId(int planetId)
 {
     IPlanetRepo pr = new PlanetRepo();
     var files = Request.Files.AllKeys.Select(fileName => Request.Files[fileName]).Where(file => file.ContentLength > 0).ToList();
     PlanetViewModel pvm = pr.GetById(planetId);
     if (User.Identity.Name != pvm.Uploader) return Json(new {Message = "You are not the original uploader of this Planet."});
     foreach (var file in files)
     {
         var fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
         var virtualPath = "~/Content/img/" + DateTime.Today.ToString("MMddyyyy");
         var subPath = Server.MapPath(virtualPath);
         if (!Directory.Exists(subPath))
         {
             Directory.CreateDirectory(subPath);
         }
         var path = Path.Combine(subPath, fileName);
         try
         {
             file.SaveAs(path);
         }
         catch (Exception e)
         {
             continue;
         }
         IFileSystemRepo fsr = new FileSystemRepo();
         fsr.SaveFileDataByPlanetId(
             Path.Combine(virtualPath.Replace("~/", "/").Replace("\\\\", "/"), fileName), fileName, planetId);
     }
     return Json(new { Message = string.Empty });
 }
示例#4
0
        public ActionResult UploadFiles()
        {
            var files = Request.Files.AllKeys.Select(fileName => Request.Files[fileName]).Where(file => file.ContentLength > 0).ToList();

            foreach (var file in files)
            {
                var fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
                var virtualPath = "~/Content/img/" + DateTime.Today.ToString("MMddyyyy");
                var subPath = Server.MapPath(virtualPath);
                if (!Directory.Exists(subPath))
                {
                    Directory.CreateDirectory(subPath);
                }
                var path = Path.Combine(subPath, fileName);
                try
                {
                    file.SaveAs(path);
                }
                catch (Exception e)
                {
                    continue;
                }
                IFileSystemRepo fsr = new FileSystemRepo();
                fsr.SaveFileData(Path.Combine(virtualPath.Replace("~/", "/").Replace("\\", "/"), fileName), fileName);
            }
            return Json(new { Message = string.Empty});
        }