示例#1
0
        public async Task <bool> StopVirtualMachine(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 shutdownRequest = new ShutdownRoleRequest(this.client);
            await shutdownRequest.Submit(roleIdentifier);

            return(true);
        }
示例#2
0
        public async Task <BinaryContent> GetRemoteDesktopConnection(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 path = string.Format("services/hostedservices/{0}/deployments/{1}/roleinstances/{2}/ModelFile?FileType=RDP", cloudServiceName, deployment.Name, name);

            return(await this.client.GetBinaryResponseAsync(path));
        }
示例#3
0
        private async Task <IEnumerable <VirtualMachineInfo> > GetVirtualMachinesForServiceAsync(HostedService hostedService)
        {
            try
            {
                var getProductionDeploymentRequest = new GetProductionDeploymentRequest(this.client);
                var deployment = await getProductionDeploymentRequest.Submit(hostedService.ServiceName);

                if (deployment != null)
                {
                    return(this.GetVirtualMachinesForDeployment(deployment, hostedService));
                }
            }
            catch (AzureManagementException ex)
            {
                if (!string.Equals(ex.Code, "ResourceNotFound", StringComparison.OrdinalIgnoreCase))
                {
                    throw;
                }

                // ignore if deployment was not found
            }

            return(null);
        }