Пример #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);
        }
Пример #2
0
        /// <summary>
        /// Validate the Upsert request i.e. that the parameters are as expected.
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="importedFile"></param>
        public static ImportedFileTbc ValidateUpsertImportedFileRequest(Guid projectUid,
                                                                        ImportedFileTbc importedFile)
        {
            if (projectUid == Guid.Empty)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(5),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(5)));
            }

            if (!Enum.IsDefined(typeof(ImportedFileType), importedFile.ImportedFileTypeId))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(30),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(30)));
            }

            if (!(importedFile.ImportedFileTypeId >= ImportedFileType.Linework && importedFile.ImportedFileTypeId <= ImportedFileType.Alignment))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(31),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(31)));
            }

            ProjectDataValidator.ValidateBusinessCentreFile(importedFile);


            if (importedFile.ImportedFileTypeId == ImportedFileType.Linework &&
                (importedFile.LineworkFile == null ||
                 !Enum.IsDefined(typeof(DxfUnitsType), importedFile.LineworkFile.DxfUnitsTypeId))
                )
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(75),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(75)));
            }

            if (importedFile.ImportedFileTypeId == ImportedFileType.SurveyedSurface &&
                (importedFile.SurfaceFile == null ||
                 importedFile.SurfaceFile.SurveyedUtc < DateTime.UtcNow.AddYears(-30) || importedFile.SurfaceFile.SurveyedUtc > DateTime.UtcNow.AddDays(2))
                )
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(33),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(33)));
            }

            if (importedFile.ImportedFileTypeId == ImportedFileType.Alignment &&
                importedFile.AlignmentFile == null)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(95),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(95)));
            }

            var fileExtension = Path.GetExtension(importedFile.Name).ToLower();

            if (!(
                    (importedFile.ImportedFileTypeId == ImportedFileType.Linework && fileExtension == ".dxf") ||
                    (importedFile.ImportedFileTypeId == ImportedFileType.DesignSurface && fileExtension == ".ttm") ||
                    (importedFile.ImportedFileTypeId == ImportedFileType.SurveyedSurface && fileExtension == ".ttm") ||
                    (importedFile.ImportedFileTypeId == ImportedFileType.Alignment && fileExtension == ".svl")
                    ))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(32),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(32)));
            }

            return(importedFile);
        }