public JsonResult SendMachineLink(int Participant_ID, int Lab_ID) { ApplicationDbContext db = new ApplicationDbContext(); LabParticipant participant = db.LabParticipants.Where(p => p.ID == Participant_ID && p.LabID == Lab_ID).FirstOrDefault(); Lab lab = db.Labs.Where(l => l.ID == Lab_ID).FirstOrDefault(); string UserName = User.Identity.Name; string link = "http://ijepai.azurewebsites.net/" + UserName + "/" + lab.Name + "/" + participant.Email_Address.Replace("@", "_"); Mailer mail = new Mailer("*****@*****.**", "Ijepai"); mail.Compose(link, participant.Email_Address); mail.SendMail(); return Json(new { Status = 0}); }
async void checkLabUptime_Elapsed(object sender, ElapsedEventArgs e) { try { if (conn.State != ConnectionState.Open) { conn.ConnectionString = ConnectionString; conn.Open(); } } catch (Exception ex) { //Log.Write(EventKind.Critical, Log.FormatExceptionInfo(ex), null); } SqlCommand labs = new SqlCommand("Select * from Labs where ((datediff(minute, start_time, getdate()) = -6) and (status = 'Scheduled'))", conn); SqlDataReader labsReader = labs.ExecuteReader(); if (labsReader != null) { try { while (labsReader.Read()) { string labName = labsReader.GetString(1); int labID = labsReader.GetInt32(0); SqlCommand UserNameCmd = new SqlCommand("Select * from AspNetUsers where Id='" + labsReader.GetString(7) + "'", conn); SqlDataReader UserNameReader = UserNameCmd.ExecuteReader(); UserNameReader.Read(); string UserName = UserNameReader.GetString(1); SqlCommand participantList = new SqlCommand("Select * from LabParticipants where LabID = " + labID, conn); SqlDataReader participantReader = participantList.ExecuteReader(); SqlCommand labConfigOb = new SqlCommand("Select * from LabConfigurations where LabID = " + labID, conn); SqlDataReader labConfigReader = labConfigOb.ExecuteReader(); labConfigReader.Read(); string MachineSize = labConfigReader.GetString(6); string OS = labConfigReader.GetString(4); String serviceName = string.Empty; while (participantReader.Read()) { string passPhrase = "th0bb@123"; SqlCommand updateLabsStatus = new SqlCommand("update labs set status='Provisioning' where id = " + labID, conn); updateLabsStatus.ExecuteNonQuery(); string email = participantReader.GetString(1); serviceName = CreateServiceName(labName, email); string encService = StringCipher.Encrypt(serviceName+ ".cloudapp.net",passPhrase); string encUserName = StringCipher.Encrypt("administrator",passPhrase); string encPassword = StringCipher.Encrypt(password,passPhrase); string machineLink = "http://vmengine.azurewebsites.net/?" + StringCipher.initVector + "/" + "LB" + "/" + encService + "/" + encUserName + "/" + encPassword; Mailer mail = new Mailer("*****@*****.**", "Ijepai"); mail.Compose(machineLink, email); bool status = await CreateVM(serviceName, "VM1", password, MachineSize, OS).ConfigureAwait(continueOnCapturedContext: false); mail.SendMail(); } SqlCommand updateLabsStatusRunning = new SqlCommand("update labs set status='Available' where id = " + labID, conn); updateLabsStatusRunning.ExecuteNonQuery(); SqlCommand addVMPath = new SqlCommand("insert into LabVMs VALUES ('" + labID + "','" + serviceName + "')", conn); addVMPath.ExecuteNonQuery(); } } catch (Exception exc) { //Log.Write(EventKind.Critical, Log.FormatExceptionInfo(exc), null); //Log Exception } } }
async public Task<JsonResult> QuickCreate(QuickCreateModel model) { ApplicationDbContext db = new ApplicationDbContext(); model.ApplicationUserID = User.Identity.GetUserId(); var user = db.Users.Where(u => u.Id == model.ApplicationUserID).FirstOrDefault(); model.RecepientEmail = model.RecepientEmail ?? user.Email_Address; vmName = model.Name; await GetVMLabel(model.OS); model.OSLabel = label; model.ServiceName = serviceName; var status = GenerateVMConfig(model); db.QuickCreates.Add(model); db.SaveChanges(); string passPhrase = "th0bb@123"; string encService = StringCipher.Encrypt(serviceName + ".cloudapp.net", passPhrase); string encUserName = StringCipher.Encrypt("administrator", passPhrase); string encPassword = StringCipher.Encrypt(password, passPhrase); string link = "http://vmengine.azurewebsites.net/?" +StringCipher.initVector +"/" + "QC"+ "/"+ encService + "/" + encUserName + "/" + encPassword; Mailer mail = new Mailer("*****@*****.**", "Ijepai"); mail.Compose(link, model.RecepientEmail); mail.SendMail(); return Json(new { Status = 0, VMName = vmName, ServiceName = serviceName }); }