Exemplo n.º 1
0
        internal async Task <string> DeleteNsgRule(CloudHostedInstance instance, string rule)
        {
            string url;

            if (GetDeploymentEnvironmentTypeInfo(instance.EnvironmentId) == DeploymentEnvironmentType.MicrosoftManagedServiceFabric)
            {
                url = $"{LcsUrl}/EnvironmentServicingV2/SFDeleteNetworkSecurityRules/{LcsProjectId}";
            }
            else
            {
                url = $"{LcsUrl}/Environment/DeleteNetworkSecurityRules/{LcsProjectId}";
            }
            var parameters = $"lcsEnvironmentId={instance.EnvironmentId}&rulesToDelete%5B%5D={rule}";

            using (_stringContent = new StringContent(parameters, Encoding.UTF8, "application/x-www-form-urlencoded"))
            {
                SetRequestVerificationToken($"{LcsUrl}/V2");
                var result = await _httpClient.PostAsync(url, _stringContent);

                result.EnsureSuccessStatusCode();
                var responseBody = result.Content.ReadAsStringAsync().Result;
                var response     = JsonConvert.DeserializeObject <Response>(responseBody);
                if (response.Success)
                {
                    return($"Successfully deleted firewall rule {rule} for instance {instance.DisplayName}");
                }
                else
                {
                    return($"Could not delete firewall rule {rule} for instance {instance.DisplayName}");
                }
            }
        }
Exemplo n.º 2
0
        internal async Task <bool> AddNsgRule(CloudHostedInstance instance, string ruleName, string ipOrCidr)
        {
            string parameters, url;

            if (GetDeploymentEnvironmentTypeInfo(instance.EnvironmentId) == DeploymentEnvironmentType.MicrosoftManagedServiceFabric)
            {
                parameters = $"lcsEnvironmentId={instance.EnvironmentId}&newRuleName={ruleName}&newRuleIpOrCidr={ipOrCidr}&newRuleService=AzureSQL";
                url        = $"{LcsUrl}/EnvironmentServicingV2/SFAddNetworkSecurityRule/{LcsProjectId}";
            }
            else
            {
                parameters = $"lcsEnvironmentId={instance.EnvironmentId}&newRuleName={ruleName}&newRuleIpOrCidr={ipOrCidr}&newRuleService=RDP";
                url        = $"{LcsUrl}/Environment/AddNetworkSecurityRule/{LcsProjectId}";
            }
            using (_stringContent = new StringContent(parameters, Encoding.UTF8, "application/x-www-form-urlencoded"))
            {
                SetRequestVerificationToken($"{LcsUrl}/V2");
                var result = await _httpClient.PostAsync(url, _stringContent);

                result.EnsureSuccessStatusCode();
                var responseBody = result.Content.ReadAsStringAsync().Result;
                var response     = JsonConvert.DeserializeObject <Response>(responseBody);
                return(response.Success);
            }
        }
Exemplo n.º 3
0
        internal string ApplyPackage(CloudHostedInstance instance, DeployablePackage package)
        {
            StringBuilder log = new StringBuilder();

            package.LcsEnvironmentId = instance.EnvironmentId;
            var validationResponse = ValidateSandboxServicing(package);

            if (validationResponse.Success && !string.IsNullOrEmpty(validationResponse.Data.ToString()))
            {
                string platformRelease;
                try
                {
                    var releaseVersion = JsonConvert.DeserializeObject <ValidateSandboxServicingData>(validationResponse.Data.ToString());
                    platformRelease = releaseVersion.PlatformRelease;
                }
                catch
                {
                    platformRelease = validationResponse.Data.ToString();
                }
                log.AppendLine($"{instance.DisplayName}: Package deployment validation successful.");
                var deploymentResponse = StartSandboxServicing(package, platformRelease);
                log.AppendLine($"{instance.DisplayName}: {deploymentResponse.Message}");
                log.AppendLine();
            }
            else
            {
                log.AppendLine($"{instance.DisplayName}: Package deployment validation failed.");
                log.AppendLine($"{instance.DisplayName}: {validationResponse.Message}");
                log.AppendLine();
            }

            SetLastActivity();

            return(log.ToString());
        }
Exemplo n.º 4
0
        internal string GetDiagEnvironmentId(CloudHostedInstance instance)
        {
            var result = _httpClient.GetAsync($"{LcsUrl}/Environment/GetDiagEnvironmentId/{LcsProjectId}?environmentId={instance.EnvironmentId}&_={DateTimeOffset.Now.ToUnixTimeSeconds()}").Result;

            result.EnsureSuccessStatusCode();
            var responseBody = result.Content.ReadAsStringAsync().Result;
            var response     = JsonConvert.DeserializeObject <Response>(responseBody);

            SetLastActivity();

            return(response.Success && response.Data != null?response.Data.ToString() : null);
        }
Exemplo n.º 5
0
        internal ActionDetails GetOngoingActionDetails(CloudHostedInstance instance)
        {
            var result = _httpClient.GetAsync($"{LcsUrl}/Environment/GetOngoingActionDetails/{LcsProjectId}?environmentId={instance.EnvironmentId}").Result;

            result.EnsureSuccessStatusCode();
            var responseBody = result.Content.ReadAsStringAsync().Result;
            var response     = JsonConvert.DeserializeObject <Response>(responseBody);

            return(!response.Success
                    ? null
                    : response.Data == null ? null : JsonConvert.DeserializeObject <ActionDetails>(response.Data.ToString()));
        }
Exemplo n.º 6
0
        internal async Task <bool> StartStopDeployment(CloudHostedInstance instance, string action)
        {
            var parameters = $"{action}=&ActivityId={instance.ActivityId}&ProductName={WebUtility.UrlEncode(instance.ProductName)}&TopologyName={instance.TopologyName}&TopologyInstanceId={instance.InstanceId}&AzureSubscriptionId={instance.AzureSubscriptionId}&EnvironmentGroup=0";

            using (_stringContent = new StringContent(parameters, Encoding.UTF8, "application/x-www-form-urlencoded"))
            {
                SetRequestVerificationToken($"{LcsUrl}/V2");
                var result = await _httpClient.PostAsync($"{LcsUrl}/DeploymentPortal/StartStopDeployment/{LcsProjectId}", _stringContent);

                result.EnsureSuccessStatusCode();
                var responseBody = result.Content.ReadAsStringAsync().Result;
                return(responseBody == "true");
            }
        }
Exemplo n.º 7
0
        internal async Task <bool> DeleteEnvironment(CloudHostedInstance instance)
        {
            var parameters = $"delete=&ActivityId={instance.ActivityId}&ProductName={WebUtility.UrlEncode(instance.ProductName)}&TopologyName={instance.TopologyName}&TopologyInstanceId={instance.InstanceId}&AzureSubscriptionId={instance.AzureSubscriptionId}&EnvironmentGroup=0&EnvironmentId={instance.EnvironmentId}&PreserveCustomerSignOff=false";

            using (_stringContent = new StringContent(parameters, Encoding.UTF8, "application/x-www-form-urlencoded"))
            {
                SetRequestVerificationToken($"{LcsUrl}/V2");
                var result = await _httpClient.PostAsync($"{LcsUrl}/Environment/DeleteEnvironment/{LcsProjectId}", _stringContent);

                result.EnsureSuccessStatusCode();
                var responseBody = result.Content.ReadAsStringAsync().Result;
                var response     = JsonConvert.DeserializeObject <Response>(responseBody);
                return(response.Success);
            }
        }
Exemplo n.º 8
0
        internal ServiceRestartResponseData RestartService(CloudHostedInstance instance, string serviceTorestart)
        {
            var parameters = $"lcsEnvironmentId={instance.EnvironmentId}&axServiceName={serviceTorestart}";

            using (_stringContent = new StringContent(parameters, Encoding.UTF8, "application/x-www-form-urlencoded"))
            {
                SetRequestVerificationToken($"{LcsUrl}/V2");
                var result = _httpClient.PostAsync($"{LcsUrl}/EnvironmentServicingV2/RestartService/{LcsProjectId}", _stringContent).Result;
                result.EnsureSuccessStatusCode();
                var responseBody = result.Content.ReadAsStringAsync().Result;
                var response     = JsonConvert.DeserializeObject <Response>(responseBody);
                return(!response.Success
                    ? null
                    : response.Data == null ? null : JsonConvert.DeserializeObject <ServiceRestartResponseData>(response.Data.ToString()));
            }
        }
Exemplo n.º 9
0
        internal BuildInfoDetails GetEnvironmentBuildInfoDetails(CloudHostedInstance instance, string environmentId)
        {
            var result = _httpClient.GetAsync(GetEnvironmentBuildInfoDetailsUrl(instance, environmentId.ToString())).Result;

            result.EnsureSuccessStatusCode();
            var responseBody = result.Content.ReadAsStringAsync().Result;
            var response     = JsonConvert.DeserializeObject <BuildInfoDetails>(responseBody);

            if (response != null)
            {
                response.BuildInfoTreeView.RemoveAll(x => x.ParentId == null);
            }

            SetLastActivity();

            return(response);
        }
Exemplo n.º 10
0
        internal List <DeployablePackage> GetPagedDeployablePackageList(CloudHostedInstance instance)
        {
            const int numberOfPackagesRequested = 50;
            int       numberOfPackagesReturned;
            var       packageList = new List <DeployablePackage>();
            var       pageNumber  = 0;

            SetRequestVerificationToken($"{LcsUrl}/V2");
            do
            {
                pageNumber++;
                var pagingParams = new PagingParameters()
                {
                    DynamicPaging = new DynamicPaging()
                    {
                        StartPosition  = pageNumber * numberOfPackagesRequested - numberOfPackagesRequested,
                        ItemsRequested = numberOfPackagesRequested
                    }
                };
                var pagingParamsJson = JsonConvert.SerializeObject(pagingParams, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.Auto
                });

                using (_stringContent = new StringContent(pagingParamsJson, Encoding.UTF8, "application/json"))
                {
                    var result = _httpClient.PostAsync(GetPagedDeployablePackageListUrl(instance), _stringContent).Result;
                    result.EnsureSuccessStatusCode();

                    var responseBody = result.Content.ReadAsStringAsync().Result;
                    var response     = JsonConvert.DeserializeObject <Response>(responseBody);
                    if (response.Success && response.Data != null)
                    {
                        var packages = JsonConvert.DeserializeObject <PackagesData>(response.Data.ToString()).Results;
                        numberOfPackagesReturned = packages.Count;
                        packageList.AddRange(packages);
                    }
                    else
                    {
                        numberOfPackagesReturned = 0;
                    }
                }
            }while (numberOfPackagesReturned == numberOfPackagesRequested);

            return(packageList);
        }
Exemplo n.º 11
0
        internal int GetBuildInfoEnvironmentId(CloudHostedInstance instance)
        {
            var result = _httpClient.GetAsync(GetEnvironmentBuildInfoIdUrl(instance)).Result;

            result.EnsureSuccessStatusCode();
            var responseBody = result.Content.ReadAsStringAsync().Result;
            var environments = JsonConvert.DeserializeObject <List <BuildInfoEnvironment> >(responseBody);

            SetLastActivity();

            if (environments != null && environments.Count > 0)
            {
                return(environments.First().Value);
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 12
0
        internal List <ActionDetails> GetEnvironmentHistoryDetails(CloudHostedInstance instance)
        {
            const int historyItemsCount = 40;

            var pagingParams = new PagingParameters()
            {
                DynamicPaging = new DynamicPaging()
                {
                    StartPosition  = 0,
                    ItemsRequested = historyItemsCount
                }
            };
            var pagingParamsJson = JsonConvert.SerializeObject(pagingParams, new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.Auto
            });

            using (_stringContent = new StringContent(pagingParamsJson, Encoding.UTF8, "application/json"))
            {
                SetRequestVerificationToken($"{LcsUrl}/V2");
                var result = _httpClient.PostAsync($"{LcsUrl}/Environment/GetEnvironmentHistoryDetails/{LcsProjectId}?environmentId={instance.EnvironmentId}&_={DateTimeOffset.Now.ToUnixTimeSeconds()}", _stringContent).Result;
                result.EnsureSuccessStatusCode();
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    MissingMemberHandling = MissingMemberHandling.Ignore
                };

                var responseBody = result.Content.ReadAsStringAsync().Result;
                var response     = JsonConvert.DeserializeObject <Response>(responseBody);
                if (response.Success)
                {
                    var data = JsonConvert.DeserializeObject <EnvironmentHistoryDetailsData>(response.Data.ToString(), settings);
                    if (data != null)
                    {
                        return(data.Results);
                    }
                }
                return(null);
            }
        }
Exemplo n.º 13
0
        internal NetworkSecurityGroup GetNetworkSecurityGroup(CloudHostedInstance instance)
        {
            try
            {
                string url;
                if (GetDeploymentEnvironmentTypeInfo(instance.EnvironmentId) == DeploymentEnvironmentType.MicrosoftManagedServiceFabric)
                {
                    url = $"{LcsUrl}/EnvironmentServicingV2/SFGetNetworkSecurityGroup/{LcsProjectId}?lcsEnvironmentId={instance.EnvironmentId}&_={DateTimeOffset.Now.ToUnixTimeSeconds()}";
                }
                else
                {
                    url = $"{LcsUrl}/Environment/GetNetworkSecurityGroup/{LcsProjectId}?lcsEnvironmentId={instance.EnvironmentId}&_={DateTimeOffset.Now.ToUnixTimeSeconds()}";
                }

                var result = _httpClient.GetAsync(url).Result;
                result.EnsureSuccessStatusCode();
                var responseBody = result.Content.ReadAsStringAsync().Result;
                var response     = JsonConvert.DeserializeObject <Response>(responseBody);
                if (!response.Success || response.Data == null)
                {
                    return(null);
                }
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    MissingMemberHandling = MissingMemberHandling.Ignore
                };
                var NSG = JsonConvert.DeserializeObject <NetworkSecurityGroup>(response.Data.ToString(), settings);

                SetLastActivity();

                return(NSG);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 14
0
        internal List <RDPConnectionDetails> GetRdpConnectionDetails(CloudHostedInstance instance)
        {
            var list = new List <RDPConnectionDetails>();

            //check RDP availability
            foreach (var vm in instance.Instances)
            {
                var result = _httpClient.GetAsync($"{LcsUrl}/DeploymentPortal/IsRdpResourceAvailable/{LcsProjectId}/?topologyInstanceId={instance.InstanceId}&virtualMachineInstanceName={vm.MachineName}&deploymentItemName={vm.ItemName}&azureSubscriptionId={instance.AzureSubscriptionId}&group=0&isARMTopology={instance.IsARMTopology}&nsgWarningDisplayed=true&_={DateTimeOffset.Now.ToUnixTimeSeconds()}").Result;
                result.EnsureSuccessStatusCode();
                var responseBody       = result.Content.ReadAsStringAsync().Result;
                var rdpPresentResponse = JsonConvert.DeserializeObject <Response>(responseBody);
                if (!rdpPresentResponse.Success)
                {
                    continue;
                }
                _httpClient.DefaultRequestHeaders.Remove("Accept");
                _httpClient.DefaultRequestHeaders.Remove("X-Requested-With");
                _httpClient.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
                _httpClient.DefaultRequestHeaders.Add("Upgrade-Insecure-Requests", "1");

                result = _httpClient.GetAsync($"{LcsUrl}/DeploymentPortal/IsRdpResourceAvailable/{LcsProjectId}/?topologyInstanceId={instance.InstanceId}&virtualMachineInstanceName={vm.MachineName}&deploymentItemName={vm.ItemName}&azureSubscriptionId={instance.AzureSubscriptionId}&group=0&isARMTopology={instance.IsARMTopology}&nsgWarningDisplayed=true&_={DateTimeOffset.Now.ToUnixTimeSeconds()}&isDownloadEnabled=True").Result;
                result.EnsureSuccessStatusCode();
                responseBody = result.Content.ReadAsStringAsync().Result;
                var line1 = responseBody.Split('\r', '\n').FirstOrDefault();
                if (line1 == null)
                {
                    continue;
                }
                var splited = line1.Split(':');

                _httpClient.DefaultRequestHeaders.Remove("Accept");
                _httpClient.DefaultRequestHeaders.Add("Accept", "*/*");
                _httpClient.DefaultRequestHeaders.Add("X-Requested-With", "XMLHttpRequest");
                _httpClient.DefaultRequestHeaders.Remove("Upgrade-Insecure-Requests");

                vm.Credentials = GetCredentials(instance.EnvironmentId, vm.ItemName);

                var localAdmin = vm.Credentials.Where(x => x.Key.Contains("Local admin")).ToDictionary(x => x.Key, x => x.Value);
                if (localAdmin.Count == 1)
                {
                    var adminUsername = localAdmin.First().Key.Split('\\')[1];
                    var adminDomain   = localAdmin.First().Key.Split('\\')[0].Split('-')[2];
                    var adminPassword = localAdmin.First().Value;
                    var rdp           = new RDPConnectionDetails
                    {
                        Address  = splited[2],
                        Port     = splited[3],
                        Domain   = adminDomain,
                        Username = adminUsername,
                        Password = adminPassword,
                        Machine  = vm.MachineName
                    };
                    list.Add(rdp);
                }
                var localUser = vm.Credentials.Where(x => x.Key.Contains("Local user")).ToDictionary(x => x.Key, x => x.Value);
                if (localUser.Count == 1)
                {
                    var userUsername = localUser.First().Key.Split('\\')[1];
                    var userDomain   = localUser.First().Key.Split('\\')[0].Split('-')[2];
                    var userPassword = localUser.First().Value;
                    var rdp          = new RDPConnectionDetails
                    {
                        Address  = splited[2],
                        Port     = splited[3],
                        Domain   = userDomain,
                        Username = userUsername,
                        Password = userPassword,
                        Machine  = vm.MachineName
                    };
                    list.Add(rdp);
                }
            }
            return(list);
        }
Exemplo n.º 15
0
 internal string GetPagedDeployablePackageListUrl(CloudHostedInstance instance)
 {
     return($"{LcsUrl}/Environment/GetPagedDeployablePackageList/{LcsProjectId}?lcsEnvironmentActionId=2&lcsEnvironmentId={instance.EnvironmentId}");
 }
Exemplo n.º 16
0
 internal string GetEnvironmentBuildInfoIdUrl(CloudHostedInstance instance)
 {
     return($"{LcsDiagUrl}/BuildInfo/GetEnvironments/{LcsProjectId}?lcsEnvironmentId={instance.EnvironmentId}&environmentId=0&_={DateTimeOffset.Now.ToUnixTimeSeconds()}");
 }
Exemplo n.º 17
0
 public string GetEnvironmentDetailsUrl(CloudHostedInstance instance)
 {
     return($"{LcsUrl}/V2/EnvironmentDetailsV3New/{LcsProjectId}?EnvironmentId={instance.EnvironmentId}&IsDiagnosticsEnabledEnvironment={instance.IsDiagnosticsEnabledEnvironment}");
 }