コード例 #1
0
        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 });
        }
コード例 #2
0
        async public Task<JsonResult> GenerateVMConfig(QuickCreateModel model)
        {
            VMManager vmm = GetVMM();

            if (await vmm.IsServiceNameAvailable(serviceName).ConfigureAwait(continueOnCapturedContext:false) == false)
            {
                return Json(new { Status=OperationStatus.Failed});
            }
            

            XDocument vm = vmm.NewAzureVMConfig(vmName,model.Machine_Size , model.OS, GetOSDiskMediaLocation(model.OSLabel), true, isVmImage, ImageName, ImagePath);
            if (!isVmImage)
            {
                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, isVmImage).ConfigureAwait(continueOnCapturedContext:false);
                }
                else
                {
                    requestID_createDeployment = "";
                }

                return Json(new { Status = result.Status, ServiceName = serviceName , VMName = vmName});
        }