protected async Task CreateBuildEngineProjectAsync(Project project)
        {
            var buildEngineProject = new BuildEngineProject
            {
                UserId        = project.Owner.Email,
                GroupId       = project.Group.Abbreviation,
                AppId         = project.Type.Name,
                LanguageCode  = project.Language,
                PublishingKey = project.Owner.PublishingKey,
                ProjectName   = project.Name
            };
            ProjectResponse projectResponse = null;

            if (SetBuildEngineEndpoint(project.Organization))
            {
                projectResponse = BuildEngineApi.CreateProject(buildEngineProject);
            }
            if ((projectResponse != null) && (projectResponse.Id != 0))
            {
                // Set state to active?
                project.WorkflowProjectId = projectResponse.Id;
                await ProjectRepository.UpdateAsync(project);

                var monitorJob = Job.FromExpression <BuildEngineProjectService>(service => service.ManageProject(project.Id));
                RecurringJobManager.AddOrUpdate(GetHangfireToken(project.Id), monitorJob, "* * * * *");
            }
            else
            {
                // TODO: Send Notification
                // Throw Exception to force retry
                throw new Exception("Create project failed");
            }
        }
Esempio n. 2
0
        public void CreateTestProject()
        {
            var client  = new BuildEngineApi(BaseUrl, ApiAccessKey);
            var project = new Project
            {
                UserId        = this.UserId,
                GroupId       = this.GroupId,
                AppId         = "scriptureappbuilder",
                LanguageCode  = "eng",
                ProjectName   = Guid.NewGuid().ToString(),
                PublishingKey = this.PublishingKey
            };

            var response = client.CreateProject(project);

            Assert.NotNull(response);
            Assert.NotEqual(0, response.Id);
            Assert.Equal(project.UserId, response.UserId);
            Assert.Equal(project.GroupId, response.GroupId);
            Assert.Equal(project.AppId, response.AppId);
            Assert.Equal(project.LanguageCode, response.LanguageCode);
            Assert.Equal("initialized", response.Status);
            Assert.Null(response.Result);
            Assert.Null(response.Error);
            Assert.Null(response.Url);
            Assert.NotEqual(DateTime.MinValue, response.Created);
            Assert.NotEqual(DateTime.MinValue, response.Updated);
        }
Esempio n. 3
0
        protected async Task CreateBuildEngineProjectAsync(Project project, PerformContext context)
        {
            var buildEngineProject = new BuildEngineProject
            {
                AppId        = project.Type.Name,
                LanguageCode = project.Language,
                ProjectName  = project.Name,
                StorageType  = "s3"
            };
            ProjectResponse projectResponse = null;

            if (SetBuildEngineEndpoint(project.Organization))
            {
                projectResponse = BuildEngineApi.CreateProject(buildEngineProject);
            }
            if ((projectResponse != null) && (projectResponse.Id != 0))
            {
                // Set state to active?
                project.WorkflowProjectId = projectResponse.Id;
                if (projectResponse.Status == "completed")
                {
                    if (projectResponse.Result == "SUCCESS")
                    {
                        await ProjectCompletedAsync(project, projectResponse);
                    }
                    else
                    {
                        await ProjectCreationFailedAsync(project, projectResponse);
                    }
                    return;
                }
            }
            if (IsFinalRetry(context))
            {
                var messageParms = new Dictionary <string, object>()
                {
                    { "projectName", project.Name }
                };
                await SendNotificationSvc.SendNotificationToOrgAdminsAndOwnerAsync(project.Organization, project.Owner,
                                                                                   "projectFailedUnableToCreate",
                                                                                   messageParms);
            }
            // Throw Exception to force retry
            throw new Exception("Create project failed");
        }
        protected async Task CreateBuildEngineProjectAsync(Project project, PerformContext context)
        {
            var buildEngineProject = new BuildEngineProject
            {
                UserId        = project.Owner.Email,
                GroupId       = project.Group.Abbreviation,
                AppId         = project.Type.Name,
                LanguageCode  = project.Language,
                PublishingKey = project.Owner.PublishingKey,
                ProjectName   = project.Name
            };
            ProjectResponse projectResponse = null;

            if (SetBuildEngineEndpoint(project.Organization))
            {
                projectResponse = BuildEngineApi.CreateProject(buildEngineProject);
            }
            if ((projectResponse != null) && (projectResponse.Id != 0))
            {
                // Set state to active?
                project.WorkflowProjectId = projectResponse.Id;
                await ProjectRepository.UpdateAsync(project);

                var monitorJob = Job.FromExpression <BuildEngineProjectService>(service => service.ManageProject(project.Id, null));
                RecurringJobManager.AddOrUpdate(GetHangfireToken(project.Id), monitorJob, "* * * * *");
            }
            else
            {
                if (IsFinalRetry(context))
                {
                    var messageParms = new Dictionary <string, object>()
                    {
                        { "projectName", project.Name }
                    };
                    await SendNotificationSvc.SendNotificationToOrgAdminsAndOwnerAsync(project.Organization, project.Owner,
                                                                                       "projectFailedUnableToCreate",
                                                                                       messageParms);
                }
                // Throw Exception to force retry
                throw new Exception("Create project failed");
            }
        }
Esempio n. 5
0
        public void CreateS3Project()
        {
            var client  = new BuildEngineApi(BaseUrl, ApiAccessKey);
            var project = new Project
            {
                AppId        = "scriptureappbuilder",
                LanguageCode = "eng",
                ProjectName  = Guid.NewGuid().ToString(),
                StorageType  = "s3"
            };
            var response = client.CreateProject(project);

            Assert.NotNull(response);
            Assert.NotEqual(0, response.Id);
            Assert.Equal(project.AppId, response.AppId);
            Assert.Equal(project.LanguageCode, response.LanguageCode);
            Assert.Equal("completed", response.Status);
            Assert.Equal("SUCCESS", response.Result);
            // URL is like this with a GUID at the end s3://dem-stg-aps-projects/scriptureappbuilder/eng-5-ebb7a893-b4af-4b14-9bdf-e91d60c0f766
            var projectNamePart = project.AppId + "/" + project.LanguageCode + "-" + response.Id.ToString() + "-";

            Assert.Contains(projectNamePart, response.Url);
        }