public async Task<string> GetVMLabel(string imgName)
        {
            string Label;
            VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]);
            imageList = await vmm.GetAzureVMImages();
            imageList.TryGetValue(imgName, out Label);
            label = Label;
            return label;

        }
Ejemplo n.º 2
0
        public async Task<ActionResult> Index()
        {
            VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]);
            imageList = await vmm.GetAzureVMImages();
            List<string> imageListRest = new List<string>();
            //imageListRest.Add(imageList[184]);
            //imageListRest.Add(imageList[185]);
            //imageListRest.Add(imageList[186]);
            //imageListRest.Add(imageList[187]);
            var imgLst = new List<SelectListItem>();
            foreach (KeyValuePair<string, string> entry in imageList)
            {
                imgLst.Add(new SelectListItem { Value = entry.Key, Text = entry.Value });
            }

            TempData["OS"] = imgLst;

            return View();
        }
        public async Task<JsonResult> Getimages()
        {
            VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]);
            var swr = new StringWriter();
            imageList = await vmm.GetAzureVMImages();
            List<string> imageListRest = new List<string>();
            //imageList.TryGetValue("")
            //imageListRest.Add(;
            //imageListRest.Add(imageList[185]);
            //imageListRest.Add(imageList[186]);
            //imageListRest.Add(imageList[187]);
            var imgLst = new List<SelectListItem>();
            foreach (KeyValuePair<string, string> entry in imageList)
            {
                imgLst.Add(new SelectListItem{ Value =entry.Key, Text =entry.Value});
            }

            TempData["OS"] = imgLst;

            return Json(new { Status = 0, MessageTitle = "Success" });
        }
Ejemplo n.º 4
0
        async private Task<bool> CreateVM(string serviceName, string vmName, string password, string Machine_Size, string OS)
        {
            VMManager vmm = new VMManager(SubscriptionID, CertThumbPrint);

            if (await vmm.IsServiceNameAvailable(serviceName).ConfigureAwait(continueOnCapturedContext: false) == false)
            {
                return false;
            }

            XDocument vm = vmm.NewAzureVMConfig(vmName, Machine_Size, OS, GetOSDiskMediaLocation(vmName), true);

            vm = vmm.NewWindowsProvisioningConfig(vm, vmName, password);
            vm = vmm.NewNetworkConfigurationSet(vm);
            vm = vmm.AddNewInputEndpoint(vm, "web", "TCP", 80, 80);
            vm = vmm.AddNewInputEndpoint(vm, "rdp", "TCP", 3389, 3389);

            var builder = new StringBuilder();
            var settings = new XmlWriterSettings()
            {
                Indent = true
            };
            using (var writer = XmlWriter.Create(builder, settings))
            {
                vm.WriteTo(writer);
            }

            String requestID_cloudService = await vmm.NewAzureCloudService(serviceName, "West US", String.Empty).ConfigureAwait(continueOnCapturedContext: false);

            OperationResult result = await vmm.PollGetOperationStatus(requestID_cloudService, 5, 120).ConfigureAwait(continueOnCapturedContext: false); ;
            String requestID_createDeployment;
            if (result.Status == OperationStatus.Succeeded)
            {
                // VM creation takes too long so we'll check it later
                requestID_createDeployment = await vmm.NewAzureVMDeployment(serviceName, vmName, String.Empty, vm, null).ConfigureAwait(continueOnCapturedContext: false);
            }
            else
            {
                requestID_createDeployment = "";
            }
            return true;
        }
Ejemplo n.º 5
0
        async void checkLabEndTime_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);
                //Log exception message

            }
            SqlCommand closeLabs = new SqlCommand("Select * from Labs where ((datediff(minute, end_time, getdate())) = 0) ", conn);
            SqlDataReader closeLabsReader = closeLabs.ExecuteReader();
            if (closeLabsReader != null)
            {
                try
                {
                    while (closeLabsReader.Read())
                    {
                        string labName = closeLabsReader.GetString(1);
                        int labID = closeLabsReader.GetInt32(0);                        
                        SqlCommand VMList = new SqlCommand("Select * from LabVMs where Lab_ID = " + labID, conn);
                        SqlDataReader VMListReader = VMList.ExecuteReader();
                        while (VMListReader.Read())
                        {
                            SqlCommand updateLabsStatus = new SqlCommand("update labs set status='Deleting' where id = " + labID, conn);
                            updateLabsStatus.ExecuteNonQuery();

                            string serviceName = VMListReader.GetString(1);
                            SqlCommand closeParticipantList = new SqlCommand("Delete from LabParticipants where LabID = " + labID, conn);
                            SqlDataReader closeParticipantReader = closeParticipantList.ExecuteReader();

                            SqlCommand closeLabConfigOb = new SqlCommand("Delete from LabConfigurations where LabID = " + labID, conn);
                            SqlDataReader closeLabConfigReader = closeLabConfigOb.ExecuteReader();

                            SqlCommand deleteVMPath = new SqlCommand("Delete from LabVMs where Lab_ID = " + labID, conn);
                            deleteVMPath.ExecuteNonQuery();

                            SqlCommand deleteLabsStatus = new SqlCommand("Delete from Labs where id = " + labID, conn);
                            deleteLabsStatus.ExecuteNonQuery();
                            
                            VMManager vmm = new VMManager(SubscriptionID, CertThumbPrint);
                            string status = await vmm.DeleteQCVM(serviceName).ConfigureAwait(continueOnCapturedContext: false);
                        }
                    }
                }
                catch (Exception exc)
                {
                    //Log Exception
                   // Log.Write(EventKind.Critical, Log.FormatExceptionInfo(exc), null);
                }
            }
        }
 async public Task<JsonResult> CaptureQCVM(int id, string ImageName)
 {
     VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]);
     ApplicationDbContext db = new ApplicationDbContext();
     var cloudService = db.QuickCreates.Where(l => l.ID == id).FirstOrDefault();
     await vmm.ShutDownVM(cloudService.ServiceName, cloudService.Name);
     VirtualMachineCaptureVMImageParameters param = new VirtualMachineCaptureVMImageParameters();
     param.VMImageLabel = "NewVmImage";
     param.VMImageName = "NewVmImage";
     param.OSState = "Specialized";
     System.Threading.CancellationToken token = new System.Threading.CancellationToken(false);
     await vmm.CaptureVM(cloudService.ServiceName, cloudService.Name, param.VMImageName);
     await vmm.RebootVM(cloudService.ServiceName, cloudService.Name);
     return Json(new { Status = 0 });
 }
 async public Task <JsonResult> DeleteQCVM(int id)
 {           
     VMManager vmm = new VMManager(ConfigurationManager.AppSettings["SubcriptionID"], ConfigurationManager.AppSettings["CertificateThumbprint"]);
     ApplicationDbContext db = new ApplicationDbContext();
     var cloudService = db.QuickCreates.Where(l => l.ID == id ).FirstOrDefault();
     await vmm.DeleteQCVM(cloudService.ServiceName);
     db.QuickCreates.Remove(cloudService);
     db.SaveChanges();
     return Json(new { Status = 0 });
 }