Example #1
0
        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"));
        }
Example #2
0
        public ActionResult DownloadAllDatasetFiles(int?id)
        {
            string currentUserId = User.Identity.GetUserId();

            if (currentUserId == null)
            {
                return(RedirectToAction("Register", "Account"));
            }
            ApplicationUser user = db.Users.Find(currentUserId);

            if (currentUserId != null && !user.EmailConfirmed)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Dataset dataset = datasetRepository.Get((int)id);

            if (dataset == null)
            {
                return(HttpNotFound());
            }

            if (!securityService.HasAccess((int)id, currentUserId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            string[]   fileName = Directory.GetFiles(Server.MapPath(datasetService.getPath(dataset.DatasetID)));
            FileStream file     = new FileStream(fileName[0], FileMode.Open, FileAccess.Read);
            int        len      = (int)(file.Length);

            Byte[] datasetFile = new Byte[len];
            file.Read(datasetFile, 0, len);
            file.Close();
            dataset.NumberOfDownloads += 1;
            datasetRepository.Edit(dataset);
            datasetRepository.SaveChanges();

            return(File(datasetFile, "text/csv", "Dataset" + DateTime.Now + ".csv"));
        }
Example #3
0
        // GET: KarmaLego
        public ActionResult Index(int?id)
        {
            string currentUserId = User.Identity.GetUserId();

            if (currentUserId == null)
            {
                return(RedirectToAction("Register", "Account"));
            }
            ApplicationUser user = db.Users.Find(currentUserId);

            if (currentUserId != null && !user.EmailConfirmed)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Dataset         dataset     = db.Datasets.Find(id);
            ApplicationUser currentUser = db.Users.FirstOrDefault(y => y.Id == currentUserId);

            if (dataset == null)
            {
                return(HttpNotFound());
            }
            if (currentUser.Id != "4b67ae3b-8854-40a2-9751-8021070bf5ba")
            {
                if (dataset == null || (dataset.Owner != null && dataset.OwnerID != currentUserId && dataset.Visibility == "Private" && !securityService.HasAccess(dataset.DatasetID, currentUserId)))
                {
                    return(HttpNotFound());
                }
            }
            foreach (var disc in dataset.Discretizations)
            {
                string discPath = discretizationService.getPath(datasetService.getPath(disc.DatasetID), disc.DiscretizationID);
                foreach (var kl in disc.KarmaLegos)
                {
                    string klResultPath = kl.DownloadPath;
                    klResultPath += @"\kl-result.txt";
                    if (System.IO.File.Exists(klResultPath))
                    {
                        kl.IsReady = "Ready";
                    }
                    else
                    {
                        kl.IsReady = "In Progress";
                    }
                    db.Entry(kl).State = EntityState.Modified;
                }
            }
            db.SaveChanges();

            List <Discretization> discretizations = dataset.Discretizations;
            // Discretistation.FileHandler fileHandler = new Discretistation.FileHandler();
            List <KarmaLego>           karmaLegos = new List <KarmaLego>();
            Dictionary <int, string[]> klClasses  = new Dictionary <int, string[]>();

            foreach (var discretization in discretizations)
            {
                foreach (var kl in discretization.KarmaLegos)
                {
                    karmaLegos.Add(kl);
                }
            }
            foreach (var kl in karmaLegos)
            {  // if(new Discretistation.FileHandler().IsFileExists(kl.DownloadPath)== "Ready" && kl.Fold  == 1)
               //    {
               //        klClasses[kl.KarmaLegoID] = fileHandler.GetClasses(kl.DownloadPath + "/KARMALEGOV");
               //    }
                if (kl.IsReady == "Ready" && kl.Fold == 1)
                {
                    klClasses[kl.KarmaLegoID] = karmaLegoService.getClasses(kl.DownloadPath);
                }
                else
                {
                    klClasses[kl.KarmaLegoID] = new string[] { "" };
                }
            }
            return(View(new KarmaLegoIndexViewModel()
            {
                Discretizations = discretizations,
                KarmaLegos = karmaLegos,
                Classes = klClasses,
                Dataset = dataset
            }));
        }