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()); }
internal Response ValidateSandboxServicing(DeployablePackage package) { var parameters = $"package[PackageId]={package.PackageId}&package[Name]={package.Name}&package[Description]={package.Description}&package[packageType]={package.PackageType}&package[ModifiedDate]={package.ModifiedDate}&package[ModifiedBy]={package.ModifiedBy}&package[Publisher]={package.Publisher}&package[LcsEnvironmentActionId]={package.LcsEnvironmentActionId}&package[LcsEnvironmentId]={package.LcsEnvironmentId}&package[FileAssetDisplayVersion]={package.FileAssetDisplayVersion}&package[PlatformVersion]={package.PlatformVersion}&package[AppVersion]={package.AppVersion}"; using (_stringContent = new StringContent(parameters, Encoding.UTF8, "application/x-www-form-urlencoded")) { SetRequestVerificationToken($"{LcsUrl}/V2"); var result = _httpClient.PostAsync($"{LcsUrl}/Environment/ValidateSandboxServicing/{LcsProjectId}", _stringContent).Result; result.EnsureSuccessStatusCode(); SetLastActivity(); var responseBody = result.Content.ReadAsStringAsync().Result; return(JsonConvert.DeserializeObject <Response>(responseBody)); } }