예제 #1
0
        public new ActionResult ViewData()
        {
            ConvertersController obj = new ConvertersController();

            ViewBag.Results = obj.commaSeparatedValues(HttpContext.Session.GetString("Data"));
            return(View());
        }
예제 #2
0
        //Download Results
        public ActionResult Download(string type)
        {
            var info = JsonConvert.DeserializeObject <ExtractInfo>(HttpContext.Session.GetString("info"));

            if (type.Equals("ASCII"))
            {
                string filename               = "results" + Guid.NewGuid().ToString() + ".txt";
                ConvertersController obj      = new ConvertersController();
                string[]             datacsvs = obj.spaceSeparatedValues(HttpContext.Session.GetString("Data"));
                string dataString             = "";
                foreach (string s in datacsvs)
                {
                    dataString = dataString + s + Environment.NewLine;
                }
                var data = Encoding.UTF8.GetBytes(dataString);
                if (info.saveDownload)
                {
                    HttpContext.Session.SetString("type", type);
                    HttpContext.Session.SetString("dataString", dataString);
                    return(RedirectToAction("Create", "ArchivesDwnds"));
                }
                else
                {
                    return(File(data, "text/txt", filename));
                }
            }
            else if (type.Equals("NetCDF"))
            {
                string        directoryPath = DownloadDatafromWebApi("NetCDF", info.saveDownload);
                string        result        = RemoveDirtyCharsFromString(directoryPath);
                string        path          = Path.GetFullPath(result);
                DirectoryInfo dir1          = new DirectoryInfo(path);

                FileInfo[] DispatchFiles = dir1.GetFiles();
                if (DispatchFiles.Length > 0)
                {
                    foreach (FileInfo aFile in DispatchFiles)
                    {
                        byte[] doc = System.IO.File.ReadAllBytes(Path.Combine(dir1.FullName, aFile.Name));
                        if (info.saveDownload)
                        {
                            HttpContext.Session.SetString("type", type);
                            HttpContext.Session.SetString("URI", Path.Combine(dir1.FullName, aFile.Name));
                            return(RedirectToAction("Create", "ArchivesDwnds"));
                        }
                        else
                        {
                            return(File(doc, "application/netcdf", "result.nc"));
                        }
                    }
                    return(File("Data not found", "text/txt", "Result.txt"));
                }
                else
                {
                    return(File("Data not found", "text/txt", "Result.txt"));
                }
            }
            else if (type.Equals("HDF5"))
            {
                string directoryPath = DownloadDatafromWebApi("HDF5", info.saveDownload);
                string result        = RemoveDirtyCharsFromString(directoryPath);
                string path          = Path.GetFullPath(result);


                DirectoryInfo dir1          = new DirectoryInfo(path);
                FileInfo[]    DispatchFiles = dir1.GetFiles();
                if (DispatchFiles.Length > 0)
                {
                    foreach (FileInfo aFile in DispatchFiles)
                    {
                        byte[] doc = System.IO.File.ReadAllBytes(Path.Combine(dir1.FullName, aFile.Name));
                        if (info.saveDownload)
                        {
                            HttpContext.Session.SetString("type", type);
                            HttpContext.Session.SetString("URI", Path.Combine(dir1.FullName, aFile.Name));
                            return(RedirectToAction("Create", "ArchivesDwnds"));
                        }
                        else
                        {
                            return(File(doc, "application/hdf5", "result.h5"));
                        }
                    }
                    return(File("Data not found", "text/txt", "Result.txt"));
                }
                else
                {
                    return(File("Data not found", "text/txt", "Result.txt"));
                }
            }
            else
            {
                string filename               = "results" + Guid.NewGuid().ToString() + ".csv";
                ConvertersController obj      = new ConvertersController();
                string[]             datacsvs = obj.commaSeparatedValues(HttpContext.Session.GetString("Data"));
                string dataString             = "";
                foreach (string s in datacsvs)
                {
                    dataString = dataString + s + Environment.NewLine;
                }
                var data = Encoding.UTF8.GetBytes(dataString);
                if (info.saveDownload)
                {
                    HttpContext.Session.SetString("type", type);
                    HttpContext.Session.SetString("dataString", dataString);
                    return(RedirectToAction("Create", "ArchivesDwnds"));
                }
                else
                {
                    return(File(data, "text/csv", filename));
                }
            }
        }