Example #1
0
        /// <summary>
        /// Validate the coordinateSystem filename
        /// </summary>
        public static BusinessCenterFile ValidateBusinessCentreFile(BusinessCenterFile businessCenterFile)
        {
            if (businessCenterFile == null)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(82),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(82)));
            }
            ProjectDataValidator.ValidateFileName(businessCenterFile.Name);

            if (string.IsNullOrEmpty(businessCenterFile.Path) || businessCenterFile.Path.Length < 5)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(83),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(83)));
            }
            // Validates the BCC file path. Checks if path contains / in the beginning and NOT at the and of the path. Otherwise add/remove it.
            if (businessCenterFile.Path[0] != '/')
            {
                businessCenterFile.Path = businessCenterFile.Path.Insert(0, "/");
            }
            if (businessCenterFile.Path[businessCenterFile.Path.Length - 1] == '/')
            {
                businessCenterFile.Path = businessCenterFile.Path.Remove(businessCenterFile.Path.Length - 1);
            }

            if (string.IsNullOrEmpty(businessCenterFile.FileSpaceId) || businessCenterFile.FileSpaceId.Length > 50)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(84),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(84)));
            }

            return(businessCenterFile);
        }
Example #2
0
        public void ValidateCreateProjectV5Request_CheckBusinessCentreFile()
        {
            var bcf = BusinessCenterFile.CreateBusinessCenterFile(_businessCenterFile.FileSpaceId, _businessCenterFile.Path,
                                                                  _businessCenterFile.Name, _businessCenterFile.CreatedUtc);

            bcf.Path = "BC Data/Sites/Chch Test Site/";

            var resultantBusinessCenterFile = ProjectDataValidator.ValidateBusinessCentreFile(bcf);

            Assert.Equal("/BC Data/Sites/Chch Test Site", resultantBusinessCenterFile.Path);

            bcf = BusinessCenterFile.CreateBusinessCenterFile(_businessCenterFile.FileSpaceId, _businessCenterFile.Path,
                                                              _businessCenterFile.Name, _businessCenterFile.CreatedUtc);
            bcf.Path = "";
            var ex = Assert.Throws <ServiceException>(() => ProjectDataValidator.ValidateBusinessCentreFile(bcf));

            Assert.NotEqual(-1, ex.GetContent.IndexOf("2083", StringComparison.Ordinal));

            bcf = BusinessCenterFile.CreateBusinessCenterFile(_businessCenterFile.FileSpaceId, _businessCenterFile.Path,
                                                              _businessCenterFile.Name, _businessCenterFile.CreatedUtc);
            bcf.Name = "";
            ex       = Assert.Throws <ServiceException>(() => ProjectDataValidator.ValidateBusinessCentreFile(bcf));
            Assert.NotEqual(-1, ex.GetContent.IndexOf("2002", StringComparison.Ordinal));

            bcf = BusinessCenterFile.CreateBusinessCenterFile(_businessCenterFile.FileSpaceId, _businessCenterFile.Path,
                                                              _businessCenterFile.Name, _businessCenterFile.CreatedUtc);
            bcf.FileSpaceId = null;
            ex = Assert.Throws <ServiceException>(() => ProjectDataValidator.ValidateBusinessCentreFile(bcf));
            Assert.NotEqual(-1, ex.GetContent.IndexOf("2084", StringComparison.Ordinal));

            ex = Assert.Throws <ServiceException>(() => ProjectDataValidator.ValidateBusinessCentreFile(null));
            Assert.NotEqual(-1, ex.GetContent.IndexOf("2082", StringComparison.Ordinal));
        }
Example #3
0
 public ProjectValidationTBCTests()
 {
     AutoMapperUtility.AutomapperConfiguration.AssertConfigurationIsValid();
     _businessCenterFile = new BusinessCenterFile
     {
         FileSpaceId = "u3bdc38d-1afe-470e-8c1c-fc241d4c5e01",
         Path        = "/BC Data/Sites/Chch Test Site",
         Name        = "CTCTSITECAL.dc",
         CreatedUtc  = DateTime.UtcNow.AddDays(-0.5)
     };
 }
Example #4
0
        public CreateProjectTBCExecutorTests()
        {
            AutoMapperUtility.AutomapperConfiguration.AssertConfigurationIsValid();
            _boundaryLL = new List <TBCPoint> {
                new TBCPoint(-43.5, 172.6), new TBCPoint(-43.5003, 172.6), new TBCPoint(-43.5003, 172.603), new TBCPoint(-43.5, 172.603)
            };

            _checkBoundaryString = "POLYGON((172.6 -43.5,172.6 -43.5003,172.603 -43.5003,172.603 -43.5,172.6 -43.5))";
            _businessCenterFile  = new BusinessCenterFile {
                FileSpaceId = "u3bdc38d-1afe-470e-8c1c-fc241d4c5e01", Path = "/BC Data/Sites/Chch Test Site", Name = "CTCTSITECAL.dc", CreatedUtc = DateTime.UtcNow.AddDays(-0.5)
            };
        }
Example #5
0
        public TestSupport()
        {
            SetFirstEventDate();
            SetLastEventDate();
            SetProjectUid();
            SetCustomerUid();

            _boundaryLL = new List <TBCPoint>
            {
                new TBCPoint(-43.5, 172.6),
                new TBCPoint(-43.5003, 172.6),
                new TBCPoint(-43.5003, 172.603),
                new TBCPoint(-43.5, 172.603)
            };

            _businessCenterFile = new BusinessCenterFile {
                FileSpaceId = "u3bdc38d-1afe-470e-8c1c-fc241d4c5e01", Name = "CTCTSITECAL.dc", Path = "/BC Data/Sites/Chch Test Site"
            };
        }
Example #6
0
        /// <summary>
        /// get file content from TCC
        ///     note that is is intended to be used for small, DC files only.
        ///     If/when it is needed for large files,
        ///           e.g. surfaces, you should use a smaller buffer and loop to read.
        /// </summary>
        public static async Task <byte[]> GetFileContentFromTcc(BusinessCenterFile businessCentreFile,
                                                                ILogger log, IServiceExceptionHandler serviceExceptionHandler, IFileRepository fileRepo)
        {
            Stream memStream = null;
            var    tccPath   = $"{businessCentreFile.Path}/{businessCentreFile.Name}";

            byte[] coordSystemFileContent = null;
            int    numBytesRead           = 0;

            try
            {
                log.LogInformation(
                    $"GetFileContentFromTcc: getBusinessCentreFile fielspaceID: {businessCentreFile.FileSpaceId} tccPath: {tccPath}");
                memStream = await fileRepo.GetFile(businessCentreFile.FileSpaceId, tccPath).ConfigureAwait(false);

                if (memStream != null && memStream.CanRead && memStream.Length > 0)
                {
                    coordSystemFileContent = new byte[memStream.Length];
                    int numBytesToRead = (int)memStream.Length;
                    numBytesRead = memStream.Read(coordSystemFileContent, 0, numBytesToRead);
                }
                else
                {
                    serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError,
                                                                  80, $" isAbleToRead: {memStream != null && memStream.CanRead} bytesReturned: {memStream?.Length ?? 0}");
                }
            }
            catch (Exception e)
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 79, e.Message);
            }
            finally
            {
                memStream?.Dispose();
            }

            log.LogInformation(
                $"GetFileContentFromTcc: numBytesRead: {numBytesRead} coordSystemFileContent.Length {coordSystemFileContent?.Length ?? 0}");
            return(coordSystemFileContent);
        }
Example #7
0
        /// <summary>
        /// Get the FileCreated and Updated UTCs
        ///    and checks that the file exists.
        /// </summary>
        /// <returns></returns>
        public static async Task <DirResult> GetFileInfoFromTccRepository(BusinessCenterFile sourceFile,
                                                                          ILogger log, IServiceExceptionHandler serviceExceptionHandler, IFileRepository fileRepo)
        {
            DirResult fileEntry = null;

            try
            {
                log.LogInformation(
                    $"GetFileInfoFromTccRepository: GetFileList filespaceID: {sourceFile.FileSpaceId} tccPathSource: {sourceFile.Path} sourceFile.Name: {sourceFile.Name}");

                var dirResult = await fileRepo.GetFileList(sourceFile.FileSpaceId, sourceFile.Path, sourceFile.Name);

                log.LogInformation(
                    $"GetFileInfoFromTccRepository: GetFileList dirResult: {JsonConvert.SerializeObject(dirResult)}");


                if (dirResult == null || dirResult.entries.Length == 0)
                {
                    serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 94, "fileRepo.GetFileList");
                }
                else
                {
                    fileEntry = dirResult.entries.FirstOrDefault(f =>
                                                                 !f.isFolder && (string.Compare(f.entryName, sourceFile.Name, true, CultureInfo.InvariantCulture) == 0));
                    if (fileEntry == null)
                    {
                        serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 94,
                                                                      "fileRepo.GetFileList");
                    }
                }
            }
            catch (Exception e)
            {
                serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 94, "fileRepo.GetFileList",
                                                              e.Message);
            }

            return(fileEntry);
        }
Example #8
0
        public UtilityTestsV5()
        {
            AutoMapperUtility.AutomapperConfiguration.AssertConfigurationIsValid();

            _boundaryLL = new List <TBCPoint>
            {
                new TBCPoint(-43.5, 172.6),
                new TBCPoint(-43.5003, 172.6),
                new TBCPoint(-43.5003, 172.603),
                new TBCPoint(-43.5, 172.603)
            };

            _checkBoundaryString = "POLYGON((172.6 -43.5,172.6 -43.5003,172.603 -43.5003,172.603 -43.5,172.6 -43.5))";

            _businessCenterFile = new BusinessCenterFile
            {
                FileSpaceId = "u710e3466-1d47-45e3-87b8-81d1127ed4ed",
                Path        = "/BC Data/Sites/Chch Test Site",
                Name        = "CTCTSITECAL.dc",
                CreatedUtc  = DateTime.UtcNow.AddDays(-0.5)
            };

            _customerUid = Guid.NewGuid().ToString();
        }