public ActionResult GetDiscretizations(int id) { Discretization disc = discretizationRepository.Get(id); string path = discretizationService.getPath(datasetService.getPath(disc.DatasetID), id); string fullPath = Server.MapPath(path); string tmp = fullPath + "\\tmp"; Directory.CreateDirectory(tmp); string archive = fullPath + "\\Discretizations.zip"; foreach (string file in Directory.GetFiles(fullPath)) { System.IO.File.Copy(file, Path.Combine(tmp, Path.GetFileName(file))); } ZipFile.CreateFromDirectory(tmp, archive); Directory.Delete(tmp, true); FileStream files = new FileStream(archive, FileMode.Open, FileAccess.Read); int len = (int)(files.Length); Byte[] content = new Byte[len]; files.Read(content, 0, len); files.Close(); System.IO.File.Delete(archive); return(File(content, ".zip", "Discretizations" + DateTime.Now.ToShortDateString() + ".zip")); }
public string Download(DatasetIndexViewModel datasetIndexViewModel) { var datasetsRecords = datasetIndexViewModel.DatasetsRecords; var discretizationsRecords = datasetIndexViewModel.DiscretizationsRecords; var karmaLegoRecords = datasetIndexViewModel.KarmaLegoRecords; var discretistationFileHandler = new Discretistation.FileHandler(); Dictionary <int, string> idToParameters = new Dictionary <int, string>(); Dictionary <int, bool> idToRawFlag = new Dictionary <int, bool>(); DatasetService datasetService = new DatasetService(datasetRepository); List <string> allParamsToSend = new List <string>(); if (datasetsRecords != null) { foreach (var datasetRecord in datasetsRecords) { Dataset dataset = datasetRepository.Get(Int32.Parse(datasetRecord)); allParamsToSend.Add(dataset.Path); dataset.NumberOfDownloads += 1; datasetRepository.Edit(dataset); datasetRepository.SaveChanges(); } } if (discretizationsRecords != null) { foreach (var discretizationsRecord in discretizationsRecords) { var discretization = discretizationRepository.Get(Int32.Parse(discretizationsRecord)); var dataset = discretization.Dataset; var datasetPath = dataset.Path; allParamsToSend.Add(discretization.DownloadPath); } } if (karmaLegoRecords != null) { foreach (var karmaLegoRecord in karmaLegoRecords) { var kl = db.KarmaLegos.Find(Int32.Parse(karmaLegoRecord)); var discretization = kl.Discretization; var datasetPath = discretization.Dataset.Path; allParamsToSend.Add(kl.DownloadPath); } } var allParamsToSendString = String.Join(" ", allParamsToSend); return(allParamsToSendString); }