Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,UserName,FileName,Date,Path,ImgDown,FileType")] ArchivesDownload archivesDwnd)
        {
            if (id != archivesDwnd.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(archivesDwnd);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ArchivesDwndExists(archivesDwnd.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(archivesDwnd));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ID,UserName,FileName,Date,Path,ImgDown,FileType")] ArchivesDownload archivesDwnd)
        {
            var type = HttpContext.Session.GetString("type");

            if (type.Equals("Image"))
            {
                ArchivesDownload aD = new ArchivesDownload();
                aD.Date     = DateTime.Now;
                aD.UserName = HttpContext.Session.GetString("userName");

                aD.ImgDown = true;
                if (archivesDwnd.FileName == "")
                {
                    aD.FileName = "AVISTEDImage";
                }
                else
                {
                    aD.FileName = archivesDwnd.FileName;
                }
                aD.FileType = type;
                aD.Path     = HttpContext.Session.GetString("URI");
                _context.Add(aD);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            if (type.Equals("NetCDF") || type.Equals("HDF5"))
            {
                ArchivesDownload aD = new ArchivesDownload();
                aD.Date     = DateTime.Now;
                aD.UserName = HttpContext.Session.GetString("userName");
                aD.FileType = type;
                aD.ImgDown  = false;
                if (archivesDwnd.FileName == "")
                {
                    aD.FileName = "AVISTEDImage";
                }
                else
                {
                    aD.FileName = archivesDwnd.FileName;
                }
                aD.Path = HttpContext.Session.GetString("URI");
                _context.Add(aD);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            else
            {
                string randomlyGeneratedFolderNamePart = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());

                string timeRelatedFolderNamePart = DateTime.Now.Year.ToString()
                                                   + DateTime.Now.Month.ToString()
                                                   + DateTime.Now.Day.ToString()
                                                   + DateTime.Now.Hour.ToString()
                                                   + DateTime.Now.Minute.ToString()
                                                   + DateTime.Now.Second.ToString()
                                                   + DateTime.Now.Millisecond.ToString();

                string processRelatedFolderNamePart = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
                string copypath = _configuration["AppSettings:Save_Downloads"];
                string temporaryDirectoryName = Path.Combine(copypath
                                                             , timeRelatedFolderNamePart
                                                             + processRelatedFolderNamePart
                                                             + randomlyGeneratedFolderNamePart);
                Directory.CreateDirectory(temporaryDirectoryName);
                ArchivesDownload aD = new ArchivesDownload();
                aD.Date     = DateTime.Now;
                aD.UserName = HttpContext.Session.GetString("userName");

                aD.ImgDown = false;
                // string filename = "data";
                if (type.Equals("ASCII"))
                {
                    aD.FileType = type;
                    if (archivesDwnd.FileName == "")
                    {
                        aD.FileName = "result";
                    }
                    else
                    {
                        aD.FileName = archivesDwnd.FileName;
                    }
                    string fileUri = Path.Combine(temporaryDirectoryName, archivesDwnd.FileName + ".txt");
                    string data    = HttpContext.Session.GetString("dataString");
                    System.IO.File.WriteAllText(fileUri, data);
                    aD.Path = fileUri;
                    //var status = saveDownloadinDatabase(fileName, fileUri, 1);
                }
                else
                {
                    aD.FileType = type;

                    if (archivesDwnd.FileName == "")
                    {
                        aD.FileName = "result";
                    }
                    else
                    {
                        aD.FileName = archivesDwnd.FileName;
                    }
                    string fileUri    = Path.Combine(temporaryDirectoryName, archivesDwnd.FileName + ".csv");
                    string dataString = HttpContext.Session.GetString("dataString");
                    //var data = Encoding.UTF8.GetBytes(dataString);
                    System.IO.File.WriteAllText(fileUri, dataString);
                    aD.Path = fileUri;
                    //var status = saveDownloadinDatabase(fileName, fileUri, 1);
                }
                _context.Add(aD);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
        }