protected override ValidationResult IsValid(object value, ValidationContext validationContext) { using (GenomeAssemblyDbContext context = new GenomeAssemblyDbContext()) { // Grab all the dawgtags. var userList = context.Users .Select(u => new { DawgTag = u.DawgTag }).ToList(); // Compare the dawgtags against the entered dawgtag. foreach (var u in userList) { if (u.DawgTag == Convert.ToInt32(value)) { return(new ValidationResult("That DawgTag is already associated with a user.")); } } return(ValidationResult.Success); } }
public ActionResult ViewJobs() { using (GenomeAssemblyDbContext db = new GenomeAssemblyDbContext()) { var jobList = from jobs in db.GenomeModels where jobs.CreatedBy.Equals(User.Identity.Name) select jobs; if (jobList.Count() > 0) { return(View(jobList.ToList())); } else { ViewBag.ShowJobList = false; return(View()); } } }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { // First check if the email address is a valid email address. EmailAddressAttribute emailFormat = new EmailAddressAttribute(); if (emailFormat.IsValid(value)) { // Check if the email has @siu.edu at the end of the email. if (Convert.ToString(value).Split('@')[1].Equals("siu.edu")) { // Check that the email is currently not in the database. using (GenomeAssemblyDbContext context = new GenomeAssemblyDbContext()) { // Grab all the emails. var userList = context.Users .Select(u => new { Email = u.Email }).ToList(); // Compare the emails against the entered email. foreach (var u in userList) { if (u.Email.Equals(value)) { return(new ValidationResult("That email is already associated with a user.")); } } return(ValidationResult.Success); } } else { return(new ValidationResult("The email address must be a valid SIU email address ending with @siu.edu.")); } } else { return(new ValidationResult(ErrorMessage)); } }
public ActionResult Create() { // TODO: Need policy-based authorization workaround for this...aka open up the parameter in the account model // and extending the authorize attribute to include it as a parameter to check all in one sweep. If time permits... using (GenomeAssemblyDbContext db = new GenomeAssemblyDbContext()) { string username = HttpContext.User.Identity.GetUserName(); var temp = from u in db.Users where u.UserName.Equals(username) select u.ClusterAccountVerified; // This should only ever be iterated through once. foreach (var acctStat in temp) { if (!acctStat) { return(RedirectToAction("CreateJobErrorCluster", "Error")); } } return(View(new GenomeModel())); } }
public ActionResult UnverifiedUser() { // While this shouldn't necessarily need to be run, there are instances where // this is necessary to make sure we don't show this page to anything but an unverified user. using (GenomeAssemblyDbContext db = new GenomeAssemblyDbContext()) { string username = HttpContext.User.Identity.GetUserName(); var temp = from u in db.Users where u.UserName.Equals(username) select u.Roles; // This should only ever be iterated through once. foreach (var uRole in temp) { if (!uRole.Equals(Helpers.CustomRoles.Unverified)) { return(RedirectToAction("Index", "Home")); } } } return(View()); }
/// <summary> /// Updates the status of a single job. But it does not perform the upload if that needs to happen. /// </summary> /// <param name="genomeModel">The model of the particular job.</param> protected internal static void UpdateStatus(GenomeModel genomeModel) { using (var client = new SshClient(CreatePrivateKeyConnectionInfo())) { try { client.Connect(); /// TODO: Modify the code to skip entire sections if they have already been completed. This will be based off the CURRENT STEP stored in the model data. using (GenomeAssemblyDbContext db = new GenomeAssemblyDbContext()) { bool continueUpdate = true; // Determines whether we will continue checking the job status. bool DEBUG_MODE = false; // Debug mode to skip some assembler steps. bool outOfRange = false; // If the overall step is out of bounds, then we set this to true to attempt a correction. ErrorHandling.error = ""; // Reset the errror flag. while (continueUpdate && ErrorHandling.NoError()) { // Depending on the current step, this switch will determine if the state of the job needs to change. switch (genomeModel.OverallCurrentStep) { // Queued step case 1: { if (DEBUG_MODE) { genomeModel.NextStep(); break; } if (LinuxCommands.IsProcessRunning(client, "conversionScript.sh")) { genomeModel.NextStep(); } // If a conversion was never run or if we missed it, then check if the job has already started. else if (LinuxCommands.JobRunningAlt(client, genomeModel.SSHUser)) { genomeModel.NextStep(); } else { continueUpdate = false; } break; } // Data conversion step case 2: { if (DEBUG_MODE) { genomeModel.NextStep(); break; } if (LinuxCommands.DirectoryHasFiles(client, Accessors.GetMasurcaOutputPath(genomeModel.Seed))) { genomeModel.NextStep(); } else { continueUpdate = false; } break; } // Running assemblers step case 3: { if (DEBUG_MODE) { genomeModel.NextStep(); break; } if (genomeModel.UseMasurca) { CheckMasurcaStep(client, genomeModel); } if (genomeModel.UseSGA) { } if (genomeModel.UseWGS) { } if (genomeModel.IsAssemblyFinished()) { genomeModel.NextStep(); } else { continueUpdate = false; } break; } // Data analysis step case 4: { // Until data analysis is implemented, we skip the step. genomeModel.NextStep(); break; //if (LinuxCommands.IsProcessRunning(client, "dataAnalysis.sh")) // continueUpdate = false; //else //{ // // Has it finished? // if (LinuxCommands.FileExists(client, Accessors.GetJobOutputPath(genomeModel.Seed) + "dataAnalysisResult")) // genomeModel.NextStep(); // else // LinuxCommands.RunDataAnalysis(client); //} //break; } // TODO: Create a more robust method in checking for a completed upload. Maybe connect to the FTP and compare file sizes and see if they are close. // Uploading Data step case 5: { //if (LinuxCommands.IsJobUploading(client, Accessors.USER_ROOT_JOB_DIRECTORY, Accessors.GetCompressedDataPath(genomeModel.Seed))) // continueUpdate = false; //else if (LinuxCommands.FileExists(client, Accessors.GetCompressedDataPath(genomeModel.Seed))) // genomeModel.NextStep(); //else //{ LinuxCommands.UploadJobData(client, Accessors.USER_ROOT_JOB_DIRECTORY, Accessors.GetCompressedDataPath(genomeModel.Seed) , Accessors.GetRelativeJobDirectory(genomeModel.Seed), Accessors.GetRemoteDownloadLocation(genomeModel.Seed), true, "yr"); continueUpdate = false; //} break; } // Completed step case 6: { continueUpdate = false; break; } default: { // If we have attempted a correction and failed, throw in the towel. if (outOfRange) { throw new IndexOutOfRangeException("The current step of the program is out of bounds after an attempted correction. The current step: " + genomeModel.OverallCurrentStep); } else { outOfRange = true; // Reset the state to default and have it run through the update method again. genomeModel.OverallCurrentStep = 1; genomeModel.OverallStatus = StepDescriptions.GetOverallStepList()[genomeModel.OverallCurrentStep].ToString(); } break; } } } } } // SSH Connection couldn't be established. catch (SocketException e) { ErrorHandling.error = "The SSH connection couldn't be established. " + e.Message; } // The SSH connection was dropped. catch (SshConnectionException e) { ErrorHandling.error = "The connection was terminated unexpectedly. " + e.Message; } } }
// // GET: /Manage/Index public async Task <ActionResult> Index(ManageMessageId?message) { ViewBag.StatusMessage = message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed." : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set." : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set." : message == ManageMessageId.Error ? "An error has occurred." : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added." : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed." : ""; var userId = User.Identity.GetUserId(); /// I really need to extend the Identity class to add a get for the verifiedclusteraccount rather than this. BUt it will do for now. using (GenomeAssemblyDbContext db = new GenomeAssemblyDbContext()) { string username = HttpContext.User.Identity.GetUserName(); bool verifiedClusterAccount = false; var usernameLookup = from u in db.Users where u.UserName.Equals(username) select u; var dawgTagLookup = from u in db.Users where u.UserName.Equals(username) select u.DawgTag; int dawgTag = 0; foreach (var user in dawgTagLookup) { dawgTag = user; } // This should only ever be iterated through once. foreach (var user in usernameLookup) { if (user.ClusterAccountVerified) { verifiedClusterAccount = true; } } var model = new IndexViewModel { HasPassword = HasPassword(), PhoneNumber = await UserManager.GetPhoneNumberAsync(userId), ClusterAccountVerified = verifiedClusterAccount, DawgTag = dawgTag, TwoFactor = await UserManager.GetTwoFactorEnabledAsync(userId), Logins = await UserManager.GetLoginsAsync(userId), BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId) }; var createdJobs = from j in db.GenomeModels where j.CreatedBy.Equals(username) select j; ViewBag.JobsCreated = createdJobs.Count().ToString(); var finishedJobs = from j in db.GenomeModels where j.CreatedBy.Equals(username) where !string.IsNullOrEmpty(j.DownloadLink) select j; ViewBag.JobsFinished = finishedJobs.Count().ToString(); if (createdJobs.Count() != 0) { ViewBag.JobsFinishedStat = Convert.ToString(100 * finishedJobs.Count() / createdJobs.Count()) + "%"; } else { ViewBag.JobsFinishedStat = "0%"; } return(View(model)); } }