/// <summary> /// GetJOVirtualMachine /// </summary> /// <param name="jobject"></param> /// <returns></returns> public JsonResult GetJOVirtualMachine(JObject jobject) { VM vm = new VM(); using (CADContext context = new CADContext()) { try { IVirtualMachine virtualMachine = GetVMFromAzure(jobject["vmid"].ToString()); if (virtualMachine != null) { vm = VirtualMashinesList.FindOrCreateVM(createLocalVMFromAzureVM(virtualMachine)); } } catch (Exception ex) { Log log = new Log(); log.name = ex.ToString(); log.timestamp = DateTime.UtcNow; context.Logs.Add(log); context.SaveChanges(); } } return(new JsonResult(new { data = vm })); }
/// <summary> /// GetVirtualMachinesByUser /// </summary> /// <param name="_currentUser"></param> /// <returns></returns> public JsonResult GetVirtualMachinesByUser(ClaimsPrincipal _currentUser) { List <VM> vMashines = new List <VM>(); using (var context = new CADContext()) { try { User currentUser = context.Users .Include(u => u.Dashboard) .ThenInclude(d => d.DashboardApplications) .FirstOrDefault(u => u.UserName == _currentUser.Identity.Name); if (currentUser?.Dashboard == null) { return(new JsonResult(new { data = "" })); } var dashboard = context.Dashboards.Include(d => d.DashboardApplications).FirstOrDefault(d => d.DashboardId == currentUser.Dashboard.DashboardId); if (currentUser.Dashboard.DashboardId != 0) { vMashines = VirtualMashinesList.GetVMs(currentUser.Dashboard.DashboardId); } } catch (Exception ex) { Log log = new Log(); log.name = ex.ToString(); log.timestamp = DateTime.UtcNow; context.Logs.Add(log); context.SaveChanges(); } } return(new JsonResult(new { data = vMashines })); }
public void UpdateAllVirtualMashines() { using (CADContext context = new CADContext()) { var vmList = context.VMs.AsNoTracking().ToList(); context.VMs.RemoveRange(vmList); context.SaveChanges(); } using (CADContext context = new CADContext()) { try { IAzure azure; foreach (var apps in context.Applications) { try { azure = GetAzureConnection(apps); var curVMList = azure.VirtualMachines.List(); VirtualMashinesList.UpdateVMList(curVMList, apps.AppId); azure = null; } catch { continue; } } } catch (Exception ex) { Log log = new Log(); log.name = ex.ToString(); log.timestamp = DateTime.UtcNow; context.Logs.Add(log); context.SaveChanges(); } } }
/// <summary> /// GetVirtualMachinesByAccessCode /// </summary> /// <param name="_accessCode"></param> /// <returns></returns> public List <VM> GetVirtualMachinesByAccessCode(string _accessCode) { Dashboard dashboard; List <VM> vMashines = new List <VM>(); using (var context = new CADContext()) { try { dashboard = context.Dashboards.Include(d => d.DashboardApplications).FirstOrDefault(d => d.DashboardAnonAccessCode == _accessCode); vMashines = VirtualMashinesList.GetVMs(dashboard.DashboardId); } catch (Exception ex) { Log log = new Log(); log.name = ex.ToString(); log.timestamp = DateTime.UtcNow; context.Logs.Add(log); context.SaveChanges(); } } return(vMashines); }