示例#1
0
        public async Task <bool> StartVirtualMachine(string name, string cloudServiceName)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            if (string.IsNullOrEmpty(cloudServiceName))
            {
                throw new ArgumentNullException("cloudServiceName");
            }
            if (!ValidateVirtualMachineName(name))
            {
                throw new ArgumentException(Properties.Resources.Error_InvalidVirtualMachineName, "name");
            }
            if (!ValidateCloudServiceName(cloudServiceName))
            {
                throw new ArgumentException(Properties.Resources.Error_InvalidCloudServiceName, "name");
            }

            var getProductionDeploymentRequest = new GetProductionDeploymentRequest(this.client);
            var deployment = await getProductionDeploymentRequest.Submit(cloudServiceName);

            var roleIdentifier = new RoleIdentifier(cloudServiceName, deployment.Name, name);
            var startRequest   = new StartRoleRequest(this.client);
            await startRequest.Submit(roleIdentifier);

            return(true);
        }
示例#2
0
        /// <summary>
        /// Method use to Start the VM Role.
        /// </summary>
        /// <param name="serviceName">Name of the Service.</param>
        /// <param name="deploymentName">Deployment Name.</param>
        /// <param name="roleName">Role Name.</param>
        /// <returns>True/False</returns>
        public static bool StartVMRole(string serviceName, string deploymentName, string roleName)
        {
            bool result = false;
            string version = VMOperations.RoleVersionConstants.VER2012;
            string uriFormat = AzureFrameWork.Util.UrlConstants.StartStopVMRole;
            //Uri uri = new Uri(String.Format(uriFormat, subscriberID, serviceName, deploymentName, roleName));
            Uri uri = new Uri(String.Format(uriFormat, subscriberID, "autovm", "autovm13sep", roleName));
            StartRoleRequest startRoleRequest = new StartRoleRequest() { OperationType = "StartRoleOperation" };
            HttpWebRequest request = AzureFrameWork.Util.CreateWebRequest(uri, version, APIVersions.MethodType.POST.ToString(), startRoleRequest);

            HttpWebResponse response = null;
            TrustAllCert trust = new TrustAllCert();
            ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(trust.OnValidationCallback);

            try
            {
                response = (HttpWebResponse)request.GetResponse();
                if (response.StatusCode == HttpStatusCode.Accepted)
                    result = true;
            }
            catch (WebException ex)
            {
                // GetResponse throws a WebException for 400 and 500 status codes
                    response = (HttpWebResponse)ex.Response;
            }
                HttpStatusCode statusCode = response.StatusCode;
                if (response.ContentLength > 0)
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        XDocument responseBody = XDocument.Load(reader);
                    }
                }
            response.Close();
            return result;
        }