public override void DialogCommand() { var visualStudioService = ApplicationController.ResolveType(typeof(IVisualStudioService)) as IVisualStudioService; if (visualStudioService == null) { throw new NullReferenceException("visualStudioService"); } var packageSettings = ApplicationController.ResolveType(typeof(XrmPackageSettings)) as XrmPackageSettings; if (packageSettings == null) { throw new NullReferenceException("packageSettings"); } if (packageSettings.Solution == null) { throw new NullReferenceException("Solution is not populated in the package settings"); } //WARNING THIS FOLDER IS CLEARED BEFORE PROCESSING SO CAREFUL IF CHANGE DIRECTORY var folderPath = visualStudioService.SolutionDirectory + "/TempSolutionFolder"; var request = CreatePackageRequest.CreateForCreatePackage(folderPath, packageSettings.Solution); var uri = new UriQuery(); uri.AddObject(nameof(CreatePackageDialog.Request), request); ApplicationController.NavigateTo(typeof(VsixCreatePackageDialog), uri); }
/// <summary> /// Create a Package /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/238/packages__experimental_/create_a_package.html"</para> /// </summary> public async Task <CreatePackageResponse> CreatePackage(Guid?guid, CreatePackageRequest value) { UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget); uriBuilder.Path = string.Format(CultureInfo.InvariantCulture, "/v3/apps/{0}/packages", guid); var client = this.GetHttpClient(); client.Uri = uriBuilder.Uri; client.Method = HttpMethod.Post; var authHeader = await BuildAuthenticationHeader(); if (!string.IsNullOrWhiteSpace(authHeader.Key)) { if (client.Headers.ContainsKey(authHeader.Key)) { client.Headers[authHeader.Key] = authHeader.Value; } else { client.Headers.Add(authHeader); } } client.ContentType = "application/x-www-form-urlencoded"; client.Content = ((string)JsonConvert.SerializeObject(value)).ConvertToStream(); var expectedReturnStatus = 201; var response = await this.SendAsync(client, expectedReturnStatus); return(Utilities.DeserializeJson <CreatePackageResponse>(await response.ReadContentAsStringAsync())); }
public void TestCreatePackageRequest() { string json = @"{ ""type"": ""docker"", ""data"": { ""image"": ""registry/image:latest"", ""credentials"": { ""user"": ""user name"", ""password"": ""very secret password"", ""email"": ""*****@*****.**"", ""login_server"": ""https://index.docker.io/v1"" }, ""store_image"": true } }"; CreatePackageRequest request = new CreatePackageRequest(); request.Type = "docker"; request.Data = TestUtil.GetJsonDictonary(@"{""image"":""registry/image:latest"",""credentials"":{""user"":""user name"",""password"":""very secret password"",""email"":""*****@*****.**"",""login_server"":""https://index.docker.io/v1""},""store_image"":true}"); string result = JsonConvert.SerializeObject(request, Formatting.None); Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result); }
public void CreatePackageTest() { using (ShimsContext.Create()) { MockClients clients = new MockClients(); string json = @"{ ""guid"": ""84120290-c0fd-4de6-bad5-baf52d968fd0"", ""type"": ""docker"", ""data"": { ""hash"": { ""type"": ""sha1"", ""value"": null }, ""error"": null, ""image"": ""registry/image:latest"", ""credentials"": { ""user"": ""user name"", ""email"": ""*****@*****.**"", ""password"": ""very secret password"", ""login_server"": ""https://index.docker.io/v1"" }, ""store_image"": true }, ""state"": ""READY"", ""created_at"": ""2016-07-07T09:17:16Z"", ""updated_at"": null, ""links"": { ""self"": { ""href"": ""/v3/packages/749fa305-e31b-4a77-b649-be9efabe82d9"" }, ""app"": { ""href"": ""/v3/apps/553def5a-3c79-4878-af65-8065994d9c5a"" } } }"; clients.JsonResponse = json; clients.ExpectedStatusCode = (HttpStatusCode)201; var cfClient = clients.CreateCloudFoundryClient(); Guid?guid = Guid.NewGuid(); CreatePackageRequest value = new CreatePackageRequest(); var obj = cfClient.PackagesExperimental.CreatePackage(guid, value).Result; Assert.AreEqual("84120290-c0fd-4de6-bad5-baf52d968fd0", TestUtil.ToTestableString(obj.Guid), true); Assert.AreEqual("docker", TestUtil.ToTestableString(obj.Type), true); Assert.AreEqual("READY", TestUtil.ToTestableString(obj.State), true); Assert.AreEqual("2016-07-07T09:17:16Z", TestUtil.ToTestableString(obj.CreatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.UpdatedAt), true); } }
public async Task <Uri> CreatePackage(CreatePackageRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var response = await Client.CreatePackage(request); return(await AcceptedLocationOrError(response)); }
public async Task <Uri> CreatePackage(CreatePackageRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } var message = await Client.CreatePackage(request); return(await message.UriOrError(HttpStatusCode.Accepted)); }
private void EnsurePackageEntryExistsInDatabase(CreatePackageRequest package) { var existingPackage = this.redisQuerier.Get(package.Name); if (existingPackage == null) { redisQuerier.Set(package.Name, new Package { Name = package.Name }); latestPackages.Update(SystemClock.Instance.GetCurrentInstant().Ticks, package.Name); } }
public Builder(IntegrationTestsFixture fixture, string projectId, int componentId) { _fixture = fixture; _request = new CreatePackageRequest { ProjectId = projectId, ComponentId = componentId, Description = $"package {Guid.NewGuid()}", ZipFile = TestProcessZipArchives.TestProcess, VariableUpdates = null }; }
public HttpStatusCodeResult Post([FromBody] CreatePackageRequest package) { var packageExists = nugetApi.GetPackage(package.Name); if (!packageExists) { return(new HttpStatusCodeResult(404)); } EnsurePackageEntryExistsInDatabase(package); packageCrawlerJobQueue.EnqueueJob(package.Name); return(new HttpStatusCodeResult(200)); }
public async Task CreatePackageAsync_InvalidProjectId_ShouldThrowArgumentNullException(string projectId) { // Arrange var title = Guid.NewGuid().ToString(); var createPackageRequest = new CreatePackageRequest(title); var packageApi = this.fixture.GetPackageApi(); // Act Func <Task> act = async() => await packageApi.CreatePackageAsync(projectId, createPackageRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public void TestCreatePackageRequest() { string json = @"{ ""type"": ""docker"", ""url"": ""docker://cloudfoundry/runtime-ci"" }"; CreatePackageRequest request = new CreatePackageRequest(); request.Type = "docker"; request.Url = "docker://cloudfoundry/runtime-ci"; string result = JsonConvert.SerializeObject(request, Formatting.None); Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result); }
public void CreatePackageTest() { using (ShimsContext.Create()) { MockClients clients = new MockClients(); string json = @"{ ""guid"": ""ea8759d4-00c1-45f9-bcaa-6f63cdb0097d"", ""type"": ""docker"", ""hash"": null, ""url"": ""docker://cloudfoundry/runtime-ci"", ""state"": ""READY"", ""error"": null, ""created_at"": ""2015-06-30T07:10:53Z"", ""updated_at"": null, ""_links"": { ""self"": { ""href"": ""/v3/packages/ea8759d4-00c1-45f9-bcaa-6f63cdb0097d"" }, ""app"": { ""href"": ""/v3/apps/guid-a19e1170-7a28-4ae4-b98e-69cce235f7a7"" } } }"; clients.JsonResponse = json; clients.ExpectedStatusCode = (HttpStatusCode)201; var cfClient = clients.CreateCloudFoundryClient(); Guid?guid = Guid.NewGuid(); CreatePackageRequest value = new CreatePackageRequest(); var obj = cfClient.Packages.CreatePackage(guid, value).Result; Assert.AreEqual("ea8759d4-00c1-45f9-bcaa-6f63cdb0097d", TestUtil.ToTestableString(obj.Guid), true); Assert.AreEqual("docker", TestUtil.ToTestableString(obj.Type), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Hash), true); Assert.AreEqual("docker://cloudfoundry/runtime-ci", TestUtil.ToTestableString(obj.Url), true); Assert.AreEqual("READY", TestUtil.ToTestableString(obj.State), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Error), true); Assert.AreEqual("2015-06-30T07:10:53Z", TestUtil.ToTestableString(obj.CreatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.UpdatedAt), true); } }
public async Task CreatePackageAsync_NullRequestModelTitle_ShouldThrowArgumentNullException() { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var createPackageRequest = new CreatePackageRequest(title: null); var packageApi = this.fixture.GetPackageApi(); // Act Func <Task> act = async() => await packageApi.CreatePackageAsync(existingProject.Id, createPackageRequest); // Assert await act.Should().ThrowAsync <ArgumentNullException>(); }
public async Task CreatePackageAsync_UnsuccessfulRequest_ShouldThrowFactroApiException() { // Arrange var projectId = Guid.NewGuid().ToString(); var createProjectRequest = new CreatePackageRequest(Guid.NewGuid().ToString()); var expectedResponse = new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, RequestMessage = new HttpRequestMessage { RequestUri = new Uri("http://www.mock-web-address.com"), }, }; var packageApi = this.fixture.GetPackageApi(expectedResponse); // Act Func <Task> act = async() => await packageApi.CreatePackageAsync(projectId, createProjectRequest); // Assert await act.Should().ThrowAsync <FactroApiException>(); }
public async Task CreatePackageAsync_ValidRequest_ShouldReturnCreatedPackage() { // Arrange var existingProject = new GetProjectPayload { Id = Guid.NewGuid().ToString(), }; var title = Guid.NewGuid().ToString(); var createPackageRequest = new CreatePackageRequest(title); var expectedPackage = new CreatePackageResponse { Title = title, }; var expectedResponseContent = new StringContent(JsonConvert.SerializeObject(expectedPackage, this.fixture.JsonSerializerSettings)); var expectedResponse = new HttpResponseMessage { Content = expectedResponseContent, }; var packageApi = this.fixture.GetPackageApi(expectedResponse); var createPackageResponse = default(CreatePackageResponse); // Act Func <Task> act = async() => createPackageResponse = await packageApi.CreatePackageAsync(existingProject.Id, createPackageRequest); // Assert await act.Should().NotThrowAsync(); createPackageResponse.Should().BeEquivalentTo(expectedPackage); }
public async Task <ActionResult> CreatePackageForOneCatering([FromBody] CreatePackageRequest request, [FromRoute] Guid cateringId) { if (!ModelState.IsValid) { return(BadRequest(new ApiErrorResponse() { ErrorType = "Bad Request", StatusCode = 400, Errors = ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage) })); } var catering = await cateringService.GetCateringByIdAsync(cateringId); if (catering == null) { return(NotFound(new ApiErrorResponse() { ErrorType = "Not Found", StatusCode = 404, Errors = new string[] { "Catering doesn't exist" } })); } var package = new Package { Name = request.Name, Serves = request.Serves, ServicePresentation = request.ServicePresentation, SetupTime = request.SetupTime, Description = request.Description, Price = request.Price, Menus = request.Menus.Select(m => new Menu { Name = m }).ToList(), Catering = catering, PackageOptions = request.PackageOptions.Select(o => new PackageOption { OptionsType = o.OptionsType, Title = o.Title, PackageOptionItems = o.PackageOptionItems.Select(i => new PackageOptionItem { Name = i }).ToList() }).ToList(), PackageRequirements = request.PackageRequirements.Select(r => new PackageRequirement { Name = r }).ToList() }; var created = await packageService.CreatePackageAsync(package); if (!created) { return(BadRequest(new ApiErrorResponse() { ErrorType = "Bad Request", StatusCode = 400, Errors = new[] { "Unable to create a package." } })); } var baseUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}"; var locationUrl = baseUrl + "/" + ApiRoutes.Packages.Get.Replace("{packageId}", package.Id.ToString()); var response = new CreatePackageSuccessResponse() { Id = package.Id }; return(Created(locationUrl, response)); }
public void VsixCreateAndDeployPackageTest() { //clear some stuff DeleteAll(Entities.account); DeleteAll(Entities.contact); var tempFolder = Path.Combine(TestingFolder, "TEMP"); if (Directory.Exists(tempFolder)) { FileUtility.DeleteFiles(tempFolder); FileUtility.DeleteSubFolders(tempFolder); } //create and account for the deployment package var account = CreateAccount(); var packageSettings = GetTestPackageSettings(); //set solution v2 prior to package create XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); var app = CreateAndLoadTestApplication <VsixCreatePackageModule>(); //run the dialog - including a redirect to enter the package settings first var originalConnection = HijackForPackageEntryRedirect(app); var dialog = app.NavigateToDialog <VsixCreatePackageModule, VsixCreatePackageDialog>(); VerifyPackageEntryRedirect(originalConnection, dialog); //okay no should be at the entry the create package details var packageEntry = dialog.Controller.UiItems.First() as ObjectEntryViewModel; //create package request var request = new CreatePackageRequest(); request.HideTypeAndFolder = true; request.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; app.EnterObject(request, packageEntry); //lets set explicit versions packageEntry.GetStringFieldFieldViewModel(nameof(CreatePackageRequest.ThisReleaseVersion)).Value = "3.0.0.0"; packageEntry.GetStringFieldFieldViewModel(nameof(CreatePackageRequest.SetVersionPostRelease)).Value = "4.0.0.0"; if (!packageEntry.Validate()) { throw new Exception(packageEntry.GetValidationSummary()); } packageEntry.SaveButtonViewModel.Invoke(); var createResponse = dialog.CompletionItem as ServiceResponseBase <DataImportResponseItem>; Assert.IsFalse(createResponse.HasError); //verify the files created in the solution package folder var folder = Directory.GetDirectories(Path.Combine(VisualStudioService.SolutionDirectory, "Releases")).First(); Assert.IsTrue(FileUtility.GetFiles(folder).First().EndsWith(".zip")); Assert.IsTrue(FileUtility.GetFolders(folder).First().EndsWith("Data")); Assert.IsTrue(FileUtility.GetFiles((FileUtility.GetFolders(folder).First())).Any()); //+ the solution version changed var solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("4.0.0.0", solution.GetStringField(Fields.solution_.version)); //delete for account for recreation during import XrmService.Delete(account); //Okay now lets deploy it var deployRequest = new DeployPackageRequest(); deployRequest.Connection = packageSettings.Connections.First(); //set the package folder selected in vidsual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioSolutionFolder(folder)); //run the deployment dialog var deployTestApplication = CreateAndLoadTestApplication <VsixDeployPackageModule>(); var deployResponse = deployTestApplication.NavigateAndProcessDialog <VsixDeployPackageModule, DeployPackageDialog, ServiceResponseBase <DataImportResponseItem> >(deployRequest); Assert.IsFalse(deployResponse.HasError); //verify the solution dpeloyed with updated version solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //account should be recreated account = Refresh(account); //Okay now lets just do the solution import it //set the solutoon version something XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); //set the solution zip selected in visual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioProjectItem(FileUtility.GetFiles(folder).First())); //run the dialog var importSolutionRequest = new ImportSolutionRequest(); importSolutionRequest.Connection = packageSettings.Connections.First(); var importSolutionApplication = CreateAndLoadTestApplication <ImportSolutionModule>(); var importSolutionResponse = importSolutionApplication.NavigateAndProcessDialog <ImportSolutionModule, ImportSolutionDialog, ImportSolutionResponse>(importSolutionRequest); Assert.IsFalse(importSolutionResponse.HasError); //verify the solution dpeloyed with updated version Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //Okay now lets just do the records import //delete for account for recreation during import XrmService.Delete(account); //set the xml files selected VisualStudioService.SetSelectedItems(FileUtility.GetFiles(FileUtility.GetFolders(folder).First()).Select(f => new FakeVisualStudioProjectItem(f))); //run the import records dialog var importRecordsRequest = new ImportRecordsRequest(); importRecordsRequest.Connection = packageSettings.Connections.First(); var importRecordsApplication = CreateAndLoadTestApplication <ImportRecordsModule>(); var importRecordsResponse = importRecordsApplication.NavigateAndProcessDialog <ImportRecordsModule, ImportRecordsDialog, ImportRecordsResponse>(importRecordsRequest); Assert.IsFalse(importRecordsResponse.HasError); //should be recreated account = Refresh(account); }
public void VsixCreateAndDeployPackageTest() { //clear some stuff DeleteAll(Entities.account); DeleteAll(Entities.contact); var tempFolder = Path.Combine(TestingFolder, "TEMP"); if (Directory.Exists(tempFolder)) { FileUtility.DeleteFiles(tempFolder); FileUtility.DeleteSubFolders(tempFolder); } //create and account for the deployment package var account = CreateAccount(); var packageSettings = GetTestPackageSettings(); //set solution v2 prior to package create XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); //run create package dialog var request = CreatePackageRequest.CreateForCreatePackage(tempFolder, packageSettings.Solution); request.ThisReleaseVersion = "3.0.0.0"; request.SetVersionPostRelease = "4.0.0.0"; request.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; var createTestApplication = CreateAndLoadTestApplication <VsixCreatePackageModule>(); var createResponse = createTestApplication.NavigateAndProcessDialog <VsixCreatePackageModule, VsixCreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(request); Assert.IsFalse(createResponse.HasError); //verify the files created in the solution package folder var folder = Directory.GetDirectories(Path.Combine(VisualStudioService.SolutionDirectory, "Releases")).First(); Assert.IsTrue(FileUtility.GetFiles(folder).First().EndsWith(".zip")); Assert.IsTrue(FileUtility.GetFolders(folder).First().EndsWith("Data")); Assert.IsTrue(FileUtility.GetFiles((FileUtility.GetFolders(folder).First())).Any()); //+ the solution version changed var solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("4.0.0.0", solution.GetStringField(Fields.solution_.version)); //delete for account for recreation during import XrmService.Delete(account); //Okay now lets deploy it var deployRequest = new DeployPackageRequest(); deployRequest.Connection = packageSettings.Connections.First(); //set the package folder selected in vidsual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioSolutionFolder(folder)); //run the deployment dialog var deployTestApplication = CreateAndLoadTestApplication <VsixDeployPackageModule>(); var deployResponse = deployTestApplication.NavigateAndProcessDialog <VsixDeployPackageModule, DeployPackageDialog, ServiceResponseBase <DataImportResponseItem> >(deployRequest); Assert.IsFalse(deployResponse.HasError); //verify the solution dpeloyed with updated version solution = XrmRecordService.Get(packageSettings.Solution.RecordType, packageSettings.Solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //account should be recreated account = Refresh(account); //Okay now lets just do the solution import it //set the solutoon version something XrmService.SetField(Entities.solution, new Guid(packageSettings.Solution.Id), Fields.solution_.version, "2.0.0.0"); //set the solution zip selected in visual studio VisualStudioService.SetSelectedItem(new FakeVisualStudioProjectItem(FileUtility.GetFiles(folder).First())); //run the dialog var importSolutionRequest = new ImportSolutionRequest(); importSolutionRequest.Connection = packageSettings.Connections.First(); var importSolutionApplication = CreateAndLoadTestApplication <ImportSolutionModule>(); var importSolutionResponse = importSolutionApplication.NavigateAndProcessDialog <ImportSolutionModule, ImportSolutionDialog, ImportSolutionResponse>(importSolutionRequest); Assert.IsFalse(importSolutionResponse.HasError); //verify the solution dpeloyed with updated version Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //Okay now lets just do the records import //delete for account for recreation during import XrmService.Delete(account); //set the xml files selected VisualStudioService.SetSelectedItems(FileUtility.GetFiles(FileUtility.GetFolders(folder).First()).Select(f => new FakeVisualStudioProjectItem(f))); //run the import records dialog var importRecordsRequest = new ImportRecordsRequest(); importRecordsRequest.Connection = packageSettings.Connections.First(); var importRecordsApplication = CreateAndLoadTestApplication <ImportRecordsModule>(); var importRecordsResponse = importRecordsApplication.NavigateAndProcessDialog <ImportRecordsModule, ImportRecordsDialog, ImportRecordsResponse>(importRecordsRequest); Assert.IsFalse(importRecordsResponse.HasError); //should be recreated account = Refresh(account); }
/// <summary> /// Pushes an application to the cloud. /// <remarks> /// This method is only available on the .NET 4.5 framework. /// Calling this method from a Windows Phone App or a Windows App will throw a <see cref="NotImplementedException"/>. /// </remarks> /// </summary> /// <exception cref="NotImplementedException"></exception> /// <param name="appGuid">Application guid</param> /// <param name="appPath">Path of origin from which the application will be deployed</param> /// <param name="stack">The name of the stack the app will be running on</param> /// <param name="buildpackGitUrl">Git URL of the buildpack</param> /// <param name="startApplication">True if the app should be started after upload is complete, false otherwise</param> /// <param name="diskLimit">Memory limit used to stage package</param> /// <param name="memoryLimit">Disk limit used to stage package</param> public async Task Push(Guid appGuid, string appPath, string stack, string buildpackGitUrl, bool startApplication, int memoryLimit, int diskLimit) { if (appPath == null) { throw new ArgumentNullException("appPath"); } IAppPushTools pushTools = new AppPushTools(appPath); int usedSteps = 1; // Step 1 - Check if application exists this.TriggerPushProgressEvent(usedSteps, "Checking if application exists"); GetAppResponse app = await this.Client.AppsExperimental.GetApp(appGuid); usedSteps += 1; // Step 2 - Create package CreatePackageRequest createPackage = new CreatePackageRequest(); createPackage.Type = "bits"; CreatePackageResponse packageResponse = await this.Client.PackagesExperimental.CreatePackage(appGuid, createPackage); Guid packageId = new Guid(packageResponse.Guid.ToString()); if (this.CheckCancellation()) { return; } usedSteps += 1; // Step 3 - Zip all needed files and get a stream back from the PushTools this.TriggerPushProgressEvent(usedSteps, "Creating zip package ..."); using (Stream zippedPayload = await pushTools.GetZippedPayload(this.Client.CancellationToken)) { if (this.CheckCancellation()) { return; } usedSteps += 1; // Step 4 - Upload zip to CloudFoundry ... this.TriggerPushProgressEvent(usedSteps, "Uploading zip package ..."); await this.Client.PackagesExperimental.UploadBits(packageId, zippedPayload); bool uploadProcessed = false; while (!uploadProcessed) { GetPackageResponse getPackage = await this.Client.PackagesExperimental.GetPackage(packageId); switch (getPackage.State) { case "FAILED": { throw new Exception(string.Format(CultureInfo.InvariantCulture, "Upload failed: {0}", getPackage.Data["error"])); } case "READY": { uploadProcessed = true; break; } default: continue; } if (this.CheckCancellation()) { return; } Task.Delay(500).Wait(); } usedSteps += 1; } // Step 5 - Stage application StagePackageRequest stagePackage = new StagePackageRequest(); stagePackage.Lifecycle = new Dictionary <string, dynamic>(); Dictionary <string, string> data = new Dictionary <string, string>(); data["buildpack"] = buildpackGitUrl; data["stack"] = stack; stagePackage.Lifecycle["data"] = data; stagePackage.Lifecycle["type"] = "buildpack"; stagePackage.MemoryLimit = memoryLimit; stagePackage.DiskLimit = diskLimit; StagePackageResponse stageResponse = await this.Client.PackagesExperimental.StagePackage(packageId, stagePackage); if (this.CheckCancellation()) { return; } usedSteps += 1; if (startApplication) { bool staged = false; while (!staged) { GetDropletResponse getDroplet = await this.Client.DropletsExperimental.GetDroplet(new Guid(stageResponse.Guid.ToString())); switch (getDroplet.State) { case "FAILED": { throw new Exception(string.Format(CultureInfo.InvariantCulture, "Staging failed: {0}", getDroplet.Error)); } case "STAGED": { staged = true; break; } default: continue; } if (this.CheckCancellation()) { return; } Task.Delay(500).Wait(); } // Step 6 - Assign droplet AssignDropletAsAppsCurrentDropletRequest assignRequest = new AssignDropletAsAppsCurrentDropletRequest(); assignRequest.DropletGuid = stageResponse.Guid; AssignDropletAsAppsCurrentDropletResponse assignDroplet = await this.AssignDropletAsAppsCurrentDroplet(appGuid, assignRequest); if (this.CheckCancellation()) { return; } usedSteps += 1; // Step 7 - Start Application StartingAppResponse response = await this.Client.AppsExperimental.StartingApp(appGuid); if (this.CheckCancellation()) { return; } usedSteps += 1; } // Step 8 - Done this.TriggerPushProgressEvent(usedSteps, "Application {0} pushed successfully", app.Name); }
public async Task <CreatePackageResponse> CreatePackageAsync(string projectId, CreatePackageRequest createPackageRequest) { if (string.IsNullOrWhiteSpace(projectId)) { throw new ArgumentNullException(nameof(projectId), $"{nameof(projectId)} can not be null, empty or whitespace."); } if (createPackageRequest == null) { throw new ArgumentNullException(nameof(createPackageRequest), $"{nameof(createPackageRequest)} can not be null."); } if (createPackageRequest.Title == null) { throw new ArgumentNullException(nameof(createPackageRequest), $"{nameof(createPackageRequest.Title)} can not be null."); } var requestRoute = PackageApiEndpoints.Base.Create(projectId); var requestString = JsonConvert.SerializeObject(createPackageRequest, this.jsonSerializerSettings); var requestContent = ApiHelpers.GetStringContent(requestString); var response = await this.httpClient.PostAsync(requestRoute, requestContent); if (!response.IsSuccessStatusCode) { throw new FactroApiException( "Could not create package.", response.RequestMessage.RequestUri.ToString(), response.StatusCode, response.Content == null ? null : await response.Content.ReadAsStringAsync()); } var responseContentString = await response.Content.ReadAsStringAsync(); var result = JsonConvert.DeserializeObject <CreatePackageResponse>( responseContentString, this.jsonSerializerSettings); return(result); }
public void DeploymentCreateAndDeployPackageModuleTest() { DeleteAll(Entities.account); DeleteAll(Entities.contact); var account = CreateAccount(); var solution = XrmRecordService.GetFirst("solution", XrmRecordService.GetPrimaryField("solution"), "Test Components"); Assert.IsNotNull(solution); FileUtility.DeleteFiles(TestingFolder); var createDeploymentPackageRequest = new CreatePackageRequest(); createDeploymentPackageRequest.FolderPath = new Folder(TestingFolder); createDeploymentPackageRequest.Solution = solution.ToLookup(); createDeploymentPackageRequest.ThisReleaseVersion = "3.0.0.0"; createDeploymentPackageRequest.SetVersionPostRelease = "4.0.0.0"; createDeploymentPackageRequest.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords, }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; var createApplication = CreateAndLoadTestApplication <CreatePackageModule>(); var response = createApplication.NavigateAndProcessDialog <CreatePackageModule, CreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(createDeploymentPackageRequest); Assert.IsFalse(response.HasError); Assert.IsTrue(FileUtility.GetFiles(TestingFolder).First().EndsWith(".zip")); Assert.IsTrue(FileUtility.GetFolders(TestingFolder).First().EndsWith("Data")); Assert.IsTrue(FileUtility.GetFiles((FileUtility.GetFolders(TestingFolder).First())).Any()); solution = XrmRecordService.Get(solution.Type, solution.Id); Assert.AreEqual("4.0.0.0", solution.GetStringField(Fields.solution_.version)); //delete for recreation XrmService.Delete(account); //Okay now lets deploy it var deployRequest = new DeployPackageRequest(); deployRequest.FolderContainingPackage = new Folder(TestingFolder); deployRequest.Connection = GetSavedXrmRecordConfiguration(); var deployApplication = CreateAndLoadTestApplication <DeployPackageModule>(); response = deployApplication.NavigateAndProcessDialog <DeployPackageModule, DeployPackageDialog, ServiceResponseBase <DataImportResponseItem> >(deployRequest); Assert.IsFalse(response.HasError); solution = XrmRecordService.Get(solution.Type, solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); //should be recreated account = Refresh(account); createDeploymentPackageRequest = new CreatePackageRequest(); createDeploymentPackageRequest.FolderPath = new Folder(TestingFolder); createDeploymentPackageRequest.Solution = solution.ToLookup(); createDeploymentPackageRequest.ThisReleaseVersion = "3.0.0.0"; createDeploymentPackageRequest.SetVersionPostRelease = "4.0.0.0"; createDeploymentPackageRequest.DeployPackageInto = GetSavedXrmRecordConfiguration(); createDeploymentPackageRequest.DataToInclude = new[] { new ExportRecordType() { RecordType = new RecordType(Entities.account, Entities.account), Type = ExportType.AllRecords }, new ExportRecordType() { RecordType = new RecordType(Entities.contact, Entities.contact), Type = ExportType.AllRecords } }; //error if already .zips on the folder FileUtility.WriteToFile(TestingFolder, "Fake.zip", "FakeContent"); createApplication = CreateAndLoadTestApplication <CreatePackageModule>(); try { createApplication.NavigateAndProcessDialog <CreatePackageModule, CreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(createDeploymentPackageRequest); Assert.Fail(); } catch (Exception ex) { Assert.IsFalse(ex is AssertFailedException); } FileUtility.DeleteFiles(TestingFolder); FileUtility.DeleteSubFolders(TestingFolder); response = createApplication.NavigateAndProcessDialog <CreatePackageModule, CreatePackageDialog, ServiceResponseBase <DataImportResponseItem> >(createDeploymentPackageRequest); Assert.IsFalse(response.HasError); solution = XrmRecordService.Get(solution.Type, solution.Id); Assert.AreEqual("3.0.0.0", solution.GetStringField(Fields.solution_.version)); }