Esempio n. 1
0
            public async Task<bool> TryInitializeAsync(string id)
            {
                Console.WriteLine("Retrieving Resource: " + id);
                Resource = await ResourceController.GetResource(id);
                if (Resource == null)
                    return false;

                if (string.IsNullOrEmpty(Resource.SubscriptionId))
                {
                    //need to create a VM
                    Console.WriteLine("Creating VM");
                    this.IsCreating = true;

                    Subscription = await ResourceController.GetAvailabeDeploymentSubscription();
                    ServiceName = await ResourceController.GetCloudServiceName(Resource);
                }
                else
                {
                    Console.WriteLine("Retrieving Subscription: " + Resource.SubscriptionId);
                    Subscription = await ResourceController.GetSubscription(Resource.SubscriptionId);
                    ServiceName = Resource.CloudServiceName;
                }


                Provisioning = new ProvisioningController(Subscription.AzureManagementThumbnail, Subscription.AzureSubscriptionID);
                return true;
            }
        public async Task<IActionResult> GetRdp(string groupId, string resourceId)
        {
            ScampResource res = await _resourceRepository.GetResource(resourceId);
            if (res == null)
                return new HttpStatusCodeResult(404); // not found

            // can user preform this action
            if (!(await CanManageResource(res, ResourceAction.Undefined)))
                return new HttpStatusCodeResult(403); // request denied, invalid permission

            ScampSubscription sub = await _settingsRepository.GetSubscription(res.SubscriptionId);
            var provisioningController = new ProvisioningController(sub.AzureManagementThumbnail, sub.AzureSubscriptionID);


            //Response.ContentType = "application/x-rdp";
            Response.Headers.Add("content-disposition", new string[] { "attachment; filename =" + res.CloudServiceName + ".rdp" });

            byte[] bytes = await provisioningController.GetRdpAsync(res.Name, res.CloudServiceName);
            var encoding = new System.Text.UTF8Encoding();
            var sRes = encoding.GetString(bytes);
            return new ObjectResult(sRes) { StatusCode = 200 };
        }