コード例 #1
0
        public Mvc.ActionResult <ProjectConfigurationModel> UpdateProjectConfiguration(string projectTrn, string projectConfigurationType, [Mvc.FromBody] ProjectConfigurationFileRequestModel projectConfigurationFileRequest)
        {
            ProjectConfigurationModel projectConfigurationModel = null;

            if (_projectConfigFilesMap.ContainsKey(projectTrn) && _projectConfigFilesMap[projectTrn].ContainsKey(projectConfigurationType))
            {
                projectConfigurationModel = _projectConfigFilesMap[projectTrn][projectConfigurationType];
                if (!string.IsNullOrEmpty(projectConfigurationFileRequest.MachineControlFilespaceId))
                {
                    projectConfigurationModel.FileName         = _fileSpaceIdNameMap[projectConfigurationFileRequest.MachineControlFilespaceId];
                    projectConfigurationModel.FileDownloadLink = $"{_baseUrl}/another_fake_download_signed_url";
                }
                if (!string.IsNullOrEmpty(projectConfigurationFileRequest.SiteCollectorFilespaceId))
                {
                    projectConfigurationModel.SiteCollectorFileName         = _fileSpaceIdNameMap[projectConfigurationFileRequest.SiteCollectorFilespaceId];
                    projectConfigurationModel.SiteCollectorFileDownloadLink = $"{_baseUrl}/another_fake_download_signed_url";
                }
            }

            Logger.LogInformation($"{nameof(UpdateProjectConfiguration)}: projectTrn {projectTrn} projectConfigurationType {projectConfigurationType} projectConfigurationFileRequest {JsonConvert.SerializeObject(projectConfigurationFileRequest)} projectConfigurationModel {JsonConvert.SerializeObject(projectConfigurationModel)}");
            if (projectConfigurationModel == null)
            {
                return(NotFound());
            }
            return(Ok(projectConfigurationModel));
        }
コード例 #2
0
        public ActionResult GetProjectConfigurationBuilds(string projectName, string projectConfigurationName)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                return(BadRequest());
            }

            if (string.IsNullOrEmpty(projectConfigurationName))
            {
                return(BadRequest());
            }

            var projectConfigurationModel = new ProjectConfigurationModel(projectConfigurationName);

            List <ProjectConfigurationBuildViewModel> projectConfigurationBuildViewModels =
                _agentService.GetProjectConfigurationBuilds(
                    projectName,
                    projectConfigurationModel.ConfigurationName,
                    projectConfigurationModel.BranchName,
                    _maxProjectConfigurationBuildsCount)
                .Select(
                    pcb =>
                    new ProjectConfigurationBuildViewModel
            {
                Id           = pcb.Id,
                Number       = pcb.Number,
                StartDateStr = pcb.StartDate
            })
                .ToList();

            return
                (Json(
                     new { projectConfigurationBuilds = projectConfigurationBuildViewModels },
                     JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        public void GetProjectConfiguration()
        {
            var projectUid = new Guid("560c2a6c-6b7e-48d8-b1a5-e4009e2d4c97");
            var projectConfigurationModel = new ProjectConfigurationModel
            {
                FileName         = "MyTestFilename.dc",
                FileDownloadLink = "http//whatever",
                FileType         = ProjectConfigurationFileType.CALIBRATION.ToString(),
                CreatedAt        = DateTime.UtcNow.ToString(),
                UpdatedAt        = DateTime.UtcNow.ToString(),
                Size             = 66
            };
            string route       = $"/projects/{TRNHelper.MakeTRN(projectUid)}/configuration/CALIBRATION";
            var    expectedUrl = $"{baseUrl}{route}";

            mockServiceResolution.Setup(m => m.ResolveRemoteServiceEndpoint(
                                            It.IsAny <string>(), It.IsAny <ApiType>(), It.IsAny <ApiVersion>(), route, It.IsAny <IList <KeyValuePair <string, string> > >())).Returns(Task.FromResult(expectedUrl));

            MockUtilities.TestRequestSendsCorrectJson("Get a project calibration file", mockWebRequest, null, expectedUrl, HttpMethod.Get, projectConfigurationModel, async() =>
            {
                var client = ServiceProvider.GetRequiredService <ICwsProfileSettingsClient>();
                var result = await client.GetProjectConfiguration(projectUid, ProjectConfigurationFileType.CALIBRATION);

                Assert.NotNull(result);
                Assert.Equal(projectConfigurationModel.FileName, result.FileName);
                return(true);
            });
        }
コード例 #4
0
        public Mvc.ActionResult <ProjectConfigurationModel> GetProjectConfiguration(string projectTrn, string projectConfigurationType)
        {
            ProjectConfigurationModel projectConfigurationModel = null;

            if (_projectConfigFilesMap.ContainsKey(projectTrn) && _projectConfigFilesMap[projectTrn].ContainsKey(projectConfigurationType))
            {
                projectConfigurationModel = _projectConfigFilesMap[projectTrn][projectConfigurationType];
            }
            Logger.LogInformation($"{nameof(GetProjectConfiguration)}: projectTrn {projectTrn} projectConfigurationType {projectConfigurationType} projectConfigurationModel {JsonConvert.SerializeObject(projectConfigurationModel)}");

            if (projectConfigurationModel == null)
            {
                return(NotFound());
            }
            return(Ok(projectConfigurationModel));
        }
コード例 #5
0
        public Task <ProjectConfigurationModel> GetProjectConfiguration(Guid projectUid, ProjectConfigurationFileType projectConfigurationFileType, IHeaderDictionary customHeaders = null)
        {
            log.LogDebug($"{nameof(GetProjectConfiguration)} Mock: projectUid {projectUid} projectConfigurationFileType {JsonConvert.SerializeObject(projectConfigurationFileType)}");

            var projectConfigurationModel = new ProjectConfigurationModel
            {
                FileName         = "MyTestFilename.dc",
                FileDownloadLink = "http//whatever",
                FileType         = ProjectConfigurationFileType.CALIBRATION.ToString(),
                CreatedAt        = DateTime.UtcNow.ToString(),
                UpdatedAt        = DateTime.UtcNow.ToString(),
                Size             = 66
            };

            log.LogDebug($"{nameof(GetProjectConfiguration)} Mock: projectConfigurationModel {JsonConvert.SerializeObject(projectConfigurationModel)}");
            return(Task.FromResult(projectConfigurationModel));
        }
コード例 #6
0
        public ProjectConfigurationModel SaveProjectConfiguration(string projectTrn, string projectConfigurationType, [Mvc.FromBody] ProjectConfigurationFileRequestModel projectConfigurationFileRequest)
        {
            var projectConfigurationModel = new ProjectConfigurationModel
            {
                FileType                      = projectConfigurationType,
                FileName                      = !string.IsNullOrEmpty(projectConfigurationFileRequest.MachineControlFilespaceId) ? _fileSpaceIdNameMap[projectConfigurationFileRequest.MachineControlFilespaceId] : null,
                FileDownloadLink              = !string.IsNullOrEmpty(projectConfigurationFileRequest.MachineControlFilespaceId) ? $"{_baseUrl}/another_fake_download_signed_url" : null,
                SiteCollectorFileName         = !string.IsNullOrEmpty(projectConfigurationFileRequest.SiteCollectorFilespaceId) ? _fileSpaceIdNameMap[projectConfigurationFileRequest.SiteCollectorFilespaceId] : null,
                SiteCollectorFileDownloadLink = !string.IsNullOrEmpty(projectConfigurationFileRequest.SiteCollectorFilespaceId) ? $"{_baseUrl}/another_fake_download_signed_url" : null,
            };

            if (!_projectConfigFilesMap.ContainsKey(projectTrn))
            {
                _projectConfigFilesMap.Add(projectTrn, new Dictionary <string, ProjectConfigurationModel>());
            }
            if (!_projectConfigFilesMap[projectTrn].ContainsKey(projectConfigurationType))
            {
                _projectConfigFilesMap[projectTrn].Add(projectConfigurationType, projectConfigurationModel);
            }

            Logger.LogInformation($"{nameof(SaveProjectConfiguration)}: projectTrn {projectTrn} projectConfigurationType {projectConfigurationType} projectConfigurationFileRequest {JsonConvert.SerializeObject(projectConfigurationFileRequest)} projectConfigurationModel {JsonConvert.SerializeObject(projectConfigurationModel)}");
            return(projectConfigurationModel);
        }
コード例 #7
0
        public async Task CreateProjectV5TBCExecutor_HappyPath()
        {
            var request = CreateProjectV5Request.CreateACreateProjectV5Request
                              ("projectName", _boundaryLL, _businessCenterFile);
            var projectValidation = MapV5Models.MapCreateProjectV5RequestToProjectValidation(request, _customerUid.ToString());

            Assert.Equal(_checkBoundaryString, projectValidation.ProjectBoundaryWKT);
            var coordSystemFileContent = "Some dummy content";

            projectValidation.CoordinateSystemFileContent = System.Text.Encoding.ASCII.GetBytes(coordSystemFileContent);

            var createProjectResponseModel = new CreateProjectResponseModel()
            {
                TRN = _projectTrn
            };
            var project          = CreateProjectDetailModel(_customerTrn, _projectTrn, request.ProjectName);
            var projectList      = CreateProjectListModel(_customerTrn, _projectTrn);
            var cwsProjectClient = new Mock <ICwsProjectClient>();

            cwsProjectClient.Setup(pr => pr.CreateProject(It.IsAny <CreateProjectRequestModel>(), _customHeaders)).ReturnsAsync(createProjectResponseModel);
            cwsProjectClient.Setup(ps => ps.GetProjectsForCustomer(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CwsProjectType?>(), It.IsAny <ProjectStatus?>(), It.IsAny <bool>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(projectList);
            cwsProjectClient.Setup(ps => ps.GetMyProject(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(project);

            var httpContextAccessor = new HttpContextAccessor {
                HttpContext = new DefaultHttpContext()
            };

            httpContextAccessor.HttpContext.Request.Path = new PathString("/api/v5/projects");

            var productivity3dV1ProxyCoord = new Mock <IProductivity3dV1ProxyCoord>();

            productivity3dV1ProxyCoord.Setup(p =>
                                             p.CoordinateSystemValidate(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <HeaderDictionary>()))
            .ReturnsAsync(new CoordinateSystemSettingsResult());
            productivity3dV1ProxyCoord.Setup(p => p.CoordinateSystemPost(It.IsAny <Guid>(), It.IsAny <byte[]>(), It.IsAny <string>(),
                                                                         It.IsAny <HeaderDictionary>()))
            .ReturnsAsync(new CoordinateSystemSettingsResult());

            var dataOceanClient = new Mock <IDataOceanClient>();

            dataOceanClient.Setup(f => f.FolderExists(It.IsAny <string>(), It.IsAny <HeaderDictionary>())).ReturnsAsync(true);
            dataOceanClient.Setup(f => f.PutFile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Stream>(),
                                                 It.IsAny <HeaderDictionary>())).ReturnsAsync(true);

            var projectConfigurationModel = new ProjectConfigurationModel
            {
                FileName         = "some coord sys file",
                FileDownloadLink = "some download link"
            };
            var cwsProfileSettingsClient = new Mock <ICwsProfileSettingsClient>();

            cwsProfileSettingsClient.Setup(ps => ps.GetProjectConfiguration(It.IsAny <Guid>(), ProjectConfigurationFileType.CALIBRATION, _customHeaders))
            .ReturnsAsync((ProjectConfigurationModel)null);
            cwsProfileSettingsClient.Setup(ps => ps.SaveProjectConfiguration(It.IsAny <Guid>(), ProjectConfigurationFileType.CALIBRATION, It.IsAny <ProjectConfigurationFileRequestModel>(), _customHeaders))
            .ReturnsAsync(projectConfigurationModel);

            var authn = new Mock <ITPaaSApplicationAuthentication>();

            authn.Setup(a => a.GetApplicationBearerToken()).Returns("some token");

            var executor = RequestExecutorContainerFactory.Build <CreateProjectTBCExecutor>
                               (_loggerFactory, _configStore, ServiceExceptionHandler,
                               _customerUid.ToString(), _userUid.ToString(), null, _customHeaders,
                               productivity3dV1ProxyCoord.Object, httpContextAccessor: httpContextAccessor,
                               dataOceanClient: dataOceanClient.Object, authn: authn.Object,
                               cwsProjectClient: cwsProjectClient.Object,
                               cwsProfileSettingsClient: cwsProfileSettingsClient.Object);
            var result = await executor.ProcessAsync(projectValidation) as ProjectV6DescriptorsSingleResult;

            Assert.NotNull(result);
            Assert.False(string.IsNullOrEmpty(result.ProjectDescriptor.ProjectUid));
            Assert.True(result.ProjectDescriptor.ShortRaptorProjectId != 0);
            Assert.Equal(request.ProjectName, result.ProjectDescriptor.Name);
        }
コード例 #8
0
        private ActionResult DoDeployOrSimulate(bool isSimulation, string projectName, string projectConfigurationName, string projectConfigurationBuildId, string targetEnvironmentName, ProjectType?projectType, List <string> targetMachines = null)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                return(BadRequest());
            }

            if (string.IsNullOrEmpty(projectConfigurationName))
            {
                return(BadRequest());
            }

            if (string.IsNullOrEmpty(projectConfigurationBuildId))
            {
                return(BadRequest());
            }

            if (string.IsNullOrEmpty(targetEnvironmentName))
            {
                return(BadRequest());
            }

            if (!projectType.HasValue)
            {
                return(BadRequest());
            }

            try
            {
                Guid deploymentId = Guid.NewGuid();

                var projectConfigurationModel = new ProjectConfigurationModel(projectConfigurationName);

                var deploymentState =
                    new DeploymentState(
                        deploymentId,
                        UserIdentity,
                        projectName,
                        projectConfigurationModel.ConfigurationName,
                        targetEnvironmentName);

                _deploymentStateProvider.SetDeploymentState(
                    deploymentId,
                    deploymentState);

                _agentService.DeployAsync(
                    deploymentId,
                    _sessionService.UniqueClientId,
                    SecurityUtils.CurrentUsername,
                    CreateDeploymentInfo(
                        deploymentId,
                        isSimulation,
                        projectName,
                        projectConfigurationModel.ConfigurationName,
                        projectConfigurationBuildId,
                        targetEnvironmentName,
                        projectType.Value,
                        targetMachines));

                return(Json(new { Status = "OK" }));
            }
            catch (Exception exc)
            {
                return(HandleAjaxError(exc));
            }
        }
コード例 #9
0
        public static ProjectConfiguration FromJson(string jsonString)
        {
            var model = new ProjectConfigurationModel();

            return(model.FromJson(jsonString));
        }