public void Serialize_MoreEntitiesWithMoreErrors_DeserializedIsSame() { var errors1 = new[] { new ValidationError("UserName", "error1"), new ValidationError("UserEmail", "error2") }; var entityErrors1 = new DataValidationResult(new EntryDouble(new User(1)), errors1); var errors2 = new[] { new ValidationError("RoleName", "error3"), new ValidationError("AccessRights", "error4") }; var entityErrors2 = new DataValidationResult(new EntryDouble(new Role(2)), errors2); DataValidationException e = new DataValidationException(string.Empty, new[] { entityErrors1, entityErrors2 }); using (Stream s = new MemoryStream()) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(s, e); s.Position = 0; // Reset stream position e = (DataValidationException)formatter.Deserialize(s); } DataValidationResult[] actual = e.ValidationErrors.ToArray(); AssertAreEqual(entityErrors1, actual[0]); AssertAreEqual(entityErrors2, actual[1]); }
private static MessageStatus GetMessageStatus(IMessageConverter converter, DataValidationException invalidDataException) { StorageExceptionHandler.LogException(converter, invalidDataException); SmtpResponse exceptionSmtpResponse = StorageExceptionHandler.GetExceptionSmtpResponse(converter, invalidDataException, true, converter.IsOutbound ? AckReason.OutboundInvalidDirectoryData : AckReason.InboundInvalidDirectoryData); return(new MessageStatus(MessageAction.NDR, exceptionSmtpResponse, invalidDataException)); }
public void AddGameCommand_GuestNameIsNull_ShowsExceptionMessageAndAborts() { // Arrange // Instantiate class under test. var viewModel = new GamesWindowViewModel(_sharedService, _controlService, _gameFinderWindow) { // Set up needed infrastructure of class under test. GuestName = null, HostName = "Host" }; // Set up needed infrastructure of class under test. var seasonID = (int)WpfGlobals.SelectedSeason; A.CallTo(() => _sharedService.FindTeamSeason(viewModel.GuestName, seasonID)).Returns(null); A.CallTo(() => _sharedService.FindTeamSeason(viewModel.HostName, seasonID)).Returns(null); // Act viewModel.AddGameCommand.Execute(null); // Assert var ex = new DataValidationException(WpfGlobals.Constants.BothTeamsNeededErrorMessage); A.CallTo(() => _sharedService.ShowExceptionMessage(A <DataValidationException> .That.IsEqualTo(ex))) .MustHaveHappenedOnceExactly(); A.CallTo(() => _controlService.AddGame(A <Game> .Ignored)).MustNotHaveHappened(); A.CallTo(() => _controlService.GetGames((int)WpfGlobals.SelectedSeason, null, null)).MustNotHaveHappened(); }
public IValueConfigurationExpression <Data, Value> PreValidate(Expression <Func <Value, bool> > expression, string exceptionMessage) { DataValidationException exception = new DataValidationException(typeof(Data).Name, _name, exceptionMessage); _preValidate = new Tuple <Expression <Func <Value, bool> >, DataValidationException>(expression, exception); return(this); }
public Question AddQuestion(List <Answer> answers, int?eventId, string text) { DataValidationException.ThrowIfTrue(answers.Count(x => x.IsCorrect) != 1, "Only one correct answer allowed"); Question question = new Question(answers, eventId, text); _questions.Add(question); return(question); }
/// <summary> /// Extension method that generates problem details for the exception. /// </summary> /// <param name="source">The exception to map to a <see cref="ProblemDetails"/></param> /// <param name="controller">The base controller the exception occured in. </param> /// <param name="type">Optional parameter that sets the URL for the human readable explanation for the status code. Default value is set to https://httpstatuses.com/403 </param> /// <param name="status">Optional parameter that sets the return status code for the problem. Default value is set to 403.</param> /// <param name="title">Optional parameter that sets the title for the problem. Default value is set to Forbidden.</param> /// <returns>Instance of the problem details.</returns> public static ProblemDetails GetProblemDetails(this DataValidationException source, ControllerBase controller, string type = "https://httpstatuses.com/400", int?status = 400, string title = "Bad Request") { return(new ProblemDetails { Type = type, Status = status, Title = title, Instance = controller?.HttpContext?.Request?.Path, Detail = source?.Message }); }
private void UpdateMisconfiguredCopyStatusEntry(DatabaseCopyStatusEntry status, DatabaseCopy databaseCopy) { status.Status = CopyStatus.Misconfigured; ValidationError[] array = databaseCopy.ValidateRead(); if (array.Length > 0) { Exception ex = new DataValidationException(array[0]); status.m_extendedErrorInfo = new ExtendedErrorInfo(ex); status.m_errorMessage = ex.Message; } }
internal ExchangePrincipal CreateExchangePrincipal() { ExchangePrincipal result = null; try { OwaDiagnostics.TracePfd(18057, "Creating new ExchangePrincipal", new object[0]); if (ExTraceGlobals.CoreTracer.IsTraceEnabled(TraceType.DebugTrace)) { string text = null; using (WindowsIdentity current = WindowsIdentity.GetCurrent()) { text = current.Name; } if (string.IsNullOrEmpty(text)) { text = "<n/a>"; } string arg = this.SafeGetRenderableName(); ExTraceGlobals.CoreTracer.TraceDebug <string, string>(0L, "Using accout {0} to bind to ExchangePrincipal object for user {1}", text, arg); } result = this.InternalCreateExchangePrincipal(); } catch (ObjectNotFoundException ex) { bool flag = false; DataValidationException ex2 = ex.InnerException as DataValidationException; if (ex2 != null) { PropertyValidationError propertyValidationError = ex2.Error as PropertyValidationError; if (propertyValidationError != null && propertyValidationError.PropertyDefinition == MiniRecipientSchema.Languages) { OWAMiniRecipient owaminiRecipient = this.FixCorruptOWAMiniRecipientCultureEntry(); if (owaminiRecipient != null) { try { result = ExchangePrincipal.FromMiniRecipient(owaminiRecipient, RemotingOptions.AllowCrossSite); flag = true; } catch (ObjectNotFoundException) { } } } } if (!flag) { throw ex; } } return(result); }
public async Task TryCheckout(CheckoutDto dto) { await Execute(async() => { using (UnitOfWork db = new UnitOfWork()) { CheckPointEntity checkPoint = await db.GetRepo <CheckPointEntity>().Get(dto.CheckPointId.Value); AccountEntity account = await db.GetRepo <AccountEntity>().Get(dto.AccountId.Value); if (dto.CurrentManufactoryId.Value != checkPoint.Manufactory1Id && dto.CurrentManufactoryId.Value != checkPoint.Manufactory2Id) { DataValidationException exception = new DataValidationException(); exception.Add( typeof(CheckoutDto), nameof(CheckoutDto.CurrentManufactoryId), $"{nameof(CheckoutDto.CurrentManufactoryId)} must be one of manufactories associated with check point" ); throw exception; } CheckPointEventEntity checkPointEvent = new CheckPointEventEntity() { account_id = account.id, check_point_id = checkPoint.id, is_direct = checkPoint.Manufactory1Id == dto.CurrentManufactoryId.Value, timespan = DateTime.Now }; ManufactoryEntity targetManufactory = checkPointEvent.is_direct ? checkPoint.Manufactory2 : checkPoint.Manufactory1; NotPermittedException ex = null; if (account.Roles.SelectMany(r => r.ManufactoryPermissions).Any(m => m.id == targetManufactory.id)) { checkPointEvent.log = $"Checkout to Manufactory #{targetManufactory.id} via Check Point ${checkPoint.id} by Account #{account.id}: SUCCESS"; } else { checkPointEvent.log = $"Checkout to Manufactory #{targetManufactory.id} via Check Point ${checkPoint.id} by Account #{account.id}: ACCESS DENIED"; ex = new NotPermittedException(checkPointEvent.log); } await db.GetRepo <CheckPointEventEntity>().Create(checkPointEvent); await db.Save(); if (ex != null) { throw ex; } } }); }
public DataValidationException Validate(object data) { DataValidationException exception = null; foreach (IValidator ValueConfig in ValueConfigs) { exception = ValueConfig.Validate(data as Data); if (exception != null) { return(exception); } } return(exception); }
protected override void InternalValidate() { base.InternalValidate(); if (base.HasErrors) { return; } ADOwaVirtualDirectory dataObject = this.DataObject; if (dataObject.ExchangeVersion.IsOlderThan(ADOwaVirtualDirectory.MinimumSupportedExchangeObjectVersion)) { base.WriteError(new TaskException(Strings.ErrorSetOlderVirtualDirectory(dataObject.Identity.ToString(), dataObject.ExchangeVersion.ToString(), ADOwaVirtualDirectory.MinimumSupportedExchangeObjectVersion.ToString())), ErrorCategory.InvalidArgument, null); } if (dataObject.WebReadyFileTypes != null) { foreach (string text in dataObject.WebReadyFileTypes) { if (!dataObject.WebReadyDocumentViewingSupportedFileTypes.Contains(text.ToLower())) { PropertyValidationError error = new PropertyValidationError(DataStrings.ConstraintViolationValueIsNotInGivenStringArray(string.Join(",", dataObject.WebReadyDocumentViewingSupportedFileTypes.ToArray()), text), ADOwaVirtualDirectorySchema.WebReadyFileTypes, dataObject.WebReadyFileTypes); DataValidationException exception = new DataValidationException(error); base.WriteError(exception, ErrorCategory.InvalidArgument, this.DataObject.Identity); } } } if (dataObject.WebReadyMimeTypes != null) { foreach (string text2 in dataObject.WebReadyMimeTypes) { if (!dataObject.WebReadyDocumentViewingSupportedMimeTypes.Contains(text2.ToLower())) { PropertyValidationError error2 = new PropertyValidationError(DataStrings.ConstraintViolationValueIsNotInGivenStringArray(string.Join(",", dataObject.WebReadyDocumentViewingSupportedMimeTypes.ToArray()), text2), ADOwaVirtualDirectorySchema.WebReadyMimeTypes, dataObject.WebReadyMimeTypes); DataValidationException exception2 = new DataValidationException(error2); base.WriteError(exception2, ErrorCategory.InvalidArgument, this.DataObject.Identity); } } } if (dataObject.InstantMessagingType == InstantMessagingTypeOptions.Msn && !Datacenter.IsMultiTenancyEnabled()) { base.WriteError(new TaskException(Strings.ErrorMsnIsNotSupportedInEnterprise), ErrorCategory.InvalidArgument, null); } if (base.Fields.Contains("AdfsAuthentication") && this.DataObject.AdfsAuthentication) { ADEcpVirtualDirectory adecpVirtualDirectory = WebAppVirtualDirectoryHelper.FindWebAppVirtualDirectoryInSameWebSite <ADEcpVirtualDirectory>(this.DataObject, base.DataSession); if (adecpVirtualDirectory == null || !adecpVirtualDirectory.AdfsAuthentication) { base.WriteError(new TaskException(Strings.CannotConfigureAdfsOwaWithoutEcpFirst), ErrorCategory.InvalidOperation, null); } } }
private async Task <Tout> ProtectedExecute <Tout>(Func <Task <Tout> > task) { try { return(await task()); } catch (DatabaseActionValidationException ex) { DataValidationException dataValidationException = new DataValidationException(); PropertyInfo[] properties = ex.EntityType?.GetProperties(); foreach (ValidationResult validationResult in ex.Errors) { TypeMap modelToEntityMap = ModelEntityMapper.Mapper.ConfigurationProvider.GetAllTypeMaps().FirstOrDefault( map => typeof(ModelBase).IsAssignableFrom(map.SourceType) && map.DestinationType.Equals(ex.EntityType) ); if (validationResult.MemberNames.Count() == 0) { InvalidFieldInfo info = new InvalidFieldInfo(modelToEntityMap?.SourceType, null, validationResult.ErrorMessage); dataValidationException.InvalidFieldInfos.Add(info); } foreach (string invalidFieldName in validationResult.MemberNames) { string realPropertyName = properties?.FirstOrDefault( property => property.GetCustomAttribute <ColumnAttribute>()?.Name == invalidFieldName )?.Name ?? invalidFieldName; PropertyMap foundPropertyMap = modelToEntityMap?.PropertyMaps.FirstOrDefault( map => map.DestinationMember.Name == realPropertyName ); InvalidFieldInfo info = new InvalidFieldInfo( modelToEntityMap?.SourceType, foundPropertyMap.SourceMember.Name, validationResult.ErrorMessage ); dataValidationException.InvalidFieldInfos.Add(info); } } throw dataValidationException; } catch (EntityNotFoundException ex) { throw new NotFoundException(ex.NotFoundSubject); } }
private void ValidateStorageCells(IEnumerable <StorageCellEntity> storageCells, int?pipelineId) { DataValidationException validationException = new DataValidationException(); IEnumerable <StorageCellEntity> usedStorageCells = storageCells.Where( storageCell => storageCell.pipeline_id != null && storageCell.pipeline_id != pipelineId ); foreach (StorageCellEntity usedStorageCell in usedStorageCells) { validationException.Add( typeof(PipelineDto), nameof(PipelineDto.Connections), $"Storage cell #{usedStorageCell.id} is already used in some pipeline" ); } if (validationException.InvalidFieldInfos.Count != 0) { throw validationException; } }
private void ValidatePipelineItems(IEnumerable <PipelineItemEntity> pipelineItems, int?pipelineId) { DataValidationException validationException = new DataValidationException(); IEnumerable <PipelineItemEntity> usedPipelineItems = pipelineItems.Where( pipelineItem => pipelineItem.pipeline_id != null && pipelineItem.pipeline_id != pipelineId ); foreach (PipelineItemEntity usedPipelineItem in usedPipelineItems) { validationException.Add( typeof(PipelineDto), nameof(PipelineDto.Connections), $"Pipeline item #{usedPipelineItem.id} is already used in some pipeline" ); } if (validationException.InvalidFieldInfos.Count != 0) { throw validationException; } }
public static Collection <ResponseError> GetResponseErrorsFromException(Exception ex) { Collection <ResponseError> responseErrors = new Collection <ResponseError>(); if (ex != null) { Type exceptionType = ex.GetType(); if (exceptionType == typeof(DataValidationException) || exceptionType == typeof(CartValidationException)) { // Convert the validation results in the exception to response errors. // Convert the exception to response error. DataValidationException serverException = (DataValidationException)ex; responseErrors = CreateResponseErrorsFromFailures(serverException.ValidationResults, failure => new ResponseError(failure.ErrorResourceId, failure.LocalizedMessage)); responseErrors.Add(new ResponseError(serverException.ErrorResourceId, serverException.LocalizedMessage)); } else if (exceptionType == typeof(PaymentException)) { // Convert the payment SDK errors in the exception to response errors. // Convert the exception to response error. PaymentException serverException = ex as PaymentException; responseErrors = CreateResponseErrorsFromFailures(serverException.PaymentSdkErrors, error => new ResponseError(error.Code, error.Message)); responseErrors.Add(new ResponseError(serverException.ErrorResourceId, serverException.LocalizedMessage)); } else if (typeof(RetailProxyException).IsAssignableFrom(exceptionType)) { // Convert the exception to response error. RetailProxyException serverException = (RetailProxyException)ex; responseErrors.Add(new ResponseError(serverException.ErrorResourceId, serverException.LocalizedMessage)); } } if (!responseErrors.Any()) { responseErrors.Add(new ResponseError(Utilities.GenericErrorMessage, "Sorry something went wrong, we cannot process your request at this time. Please try again later.")); } return(responseErrors); }
internal ExchangePrincipal CreateExchangePrincipal() { ExchangePrincipal exchangePrincipal = null; try { if (ExTraceGlobals.CoreTracer.IsTraceEnabled(TraceType.DebugTrace)) { string text = null; using (WindowsIdentity current = WindowsIdentity.GetCurrent()) { text = current.Name; } if (string.IsNullOrEmpty(text)) { text = "<n/a>"; } string arg = this.SafeGetRenderableName(); ExTraceGlobals.CoreTracer.TraceDebug <string, string>(0L, "Using accout {0} to bind to ExchangePrincipal object for user {1}", text, arg); } exchangePrincipal = this.InternalCreateExchangePrincipal(); } catch (AdUserNotFoundException innerException) { throw new OwaADUserNotFoundException(this.SafeGetRenderableName(), null, innerException); } catch (ObjectNotFoundException ex) { bool flag = false; DataValidationException ex2 = ex.InnerException as DataValidationException; if (ex2 != null) { PropertyValidationError propertyValidationError = ex2.Error as PropertyValidationError; if (propertyValidationError != null && propertyValidationError.PropertyDefinition == MiniRecipientSchema.Languages) { OWAMiniRecipient owaminiRecipient = this.FixCorruptOWAMiniRecipientCultureEntry(); if (owaminiRecipient != null) { try { exchangePrincipal = ExchangePrincipal.FromMiniRecipient(owaminiRecipient); ExTraceGlobals.CoreTracer.TraceDebug <SecurityIdentifier>(0L, "OwaIdentity.CreateExchangePrincipal: Got ExchangePrincipal from MiniRecipient for Sid: {0}", this.UserSid); flag = true; } catch (ObjectNotFoundException) { } } } } if (!flag) { ExTraceGlobals.CoreTracer.TraceDebug <SecurityIdentifier, ObjectNotFoundException>(0L, "OwaIdentity.CreateExchangePrincipal: Fail to create ExchangePrincipal for Sid: {0}. Cannot recover from exception: {1}", this.UserSid, ex); throw ex; } } if (exchangePrincipal == null) { ExTraceGlobals.CoreTracer.TraceDebug <SecurityIdentifier>(0L, "OwaIdentity.CreateExchangePrincipal: Got a null ExchangePrincipal for Sid: {0}", this.UserSid); } return(exchangePrincipal); }
/// <summary> /// Shows a DataValidationException message. /// </summary> /// <param name="ex">The exception for which a message will be shown</param> public void ShowExceptionMessage(DataValidationException ex) { ShowExceptionMessage(ex, "DataValidationException"); }
private void ValidatePlan(AuthorizedDto <SetupPlanDto> plan) { DataValidationException dataValidationException = new DataValidationException(); if (plan.Data.CompanyPlanPoints.Any(point => (point.Id.HasValue && point.FakeId.HasValue) || (!point.Id.HasValue && !point.FakeId.HasValue))) { dataValidationException.Add( typeof(CompanyPlanPointDto), nameof(CompanyPlanPointDto.FakeId), $"One of fields '{nameof(CompanyPlanPointDto.FakeId)}' and '{nameof(CompanyPlanPointDto.Id)}' must be specified" ); } bool manufactoryPointsInvalid = plan.Data.Manufactories.Any( manufactory => manufactory.ManufactoryPlanPoints.Any( point => (point.CompanyPlanPointId.HasValue && point.FakeCompanyPlanPointId.HasValue) || (!point.CompanyPlanPointId.HasValue && !point.FakeCompanyPlanPointId.HasValue) ) ); if (manufactoryPointsInvalid) { dataValidationException.Add( typeof(ManufactoryPlanPointDto), nameof(ManufactoryPlanPointDto.FakeCompanyPlanPointId), $"One of fields '{nameof(ManufactoryPlanPointDto.FakeCompanyPlanPointId)}' and '{nameof(ManufactoryPlanPointDto.CompanyPlanPointId)}' must be specified" ); } bool checkPointsInvalid = plan.Data.CheckPoints.Any( checkPoint => (checkPoint.CompanyPlanUniquePoint1Id.HasValue && checkPoint.FakeCompanyPlanUniquePoint1Id.HasValue) || (!checkPoint.CompanyPlanUniquePoint1Id.HasValue && !checkPoint.FakeCompanyPlanUniquePoint1Id.HasValue) || (checkPoint.CompanyPlanUniquePoint2Id.HasValue && checkPoint.FakeCompanyPlanUniquePoint2Id.HasValue) || (!checkPoint.CompanyPlanUniquePoint2Id.HasValue && !checkPoint.FakeCompanyPlanUniquePoint2Id.HasValue) ); if (checkPointsInvalid) { dataValidationException.Add( typeof(CheckPointDto), nameof(CheckPointDto.FakeCompanyPlanUniquePoint1Id), $"One of fields '{nameof(CheckPointDto.FakeCompanyPlanUniquePoint1Id)}' and '{nameof(CheckPointDto.CompanyPlanUniquePoint1Id)}' must be specified" ); dataValidationException.Add( typeof(CheckPointDto), nameof(CheckPointDto.FakeCompanyPlanUniquePoint2Id), $"One of fields '{nameof(CheckPointDto.FakeCompanyPlanUniquePoint2Id)}' and '{nameof(CheckPointDto.CompanyPlanUniquePoint2Id)}' must be specified" ); } bool enterLeavePointsInvalid = plan.Data.EnterLeavePoints.Any( enterLeavePoint => (enterLeavePoint.CompanyPlanUniquePoint1Id.HasValue && enterLeavePoint.FakeCompanyPlanUniquePoint1Id.HasValue) || (!enterLeavePoint.CompanyPlanUniquePoint1Id.HasValue && !enterLeavePoint.FakeCompanyPlanUniquePoint1Id.HasValue) || (enterLeavePoint.CompanyPlanUniquePoint2Id.HasValue && enterLeavePoint.FakeCompanyPlanUniquePoint2Id.HasValue) || (!enterLeavePoint.CompanyPlanUniquePoint2Id.HasValue && !enterLeavePoint.FakeCompanyPlanUniquePoint2Id.HasValue) ); if (enterLeavePointsInvalid) { dataValidationException.Add( typeof(EnterLeavePointDto), nameof(EnterLeavePointDto.FakeCompanyPlanUniquePoint1Id), $"One of fields '{nameof(EnterLeavePointDto.FakeCompanyPlanUniquePoint1Id)}' and '{nameof(EnterLeavePointDto.CompanyPlanUniquePoint1Id)}' must be specified" ); dataValidationException.Add( typeof(EnterLeavePointDto), nameof(EnterLeavePointDto.FakeCompanyPlanUniquePoint2Id), $"One of fields '{nameof(EnterLeavePointDto.FakeCompanyPlanUniquePoint2Id)}' and '{nameof(EnterLeavePointDto.CompanyPlanUniquePoint2Id)}' must be specified" ); } if (dataValidationException.InvalidFieldInfos.Count != 0) { throw dataValidationException; } int[] realCompanyPlanPointIds = plan.Data.CompanyPlanPoints.Where(point => point.Id.HasValue).Select(point => point.Id.Value).ToArray(); int[] fakeCompanyPlanPointIds = plan.Data.CompanyPlanPoints.Where(point => point.FakeId.HasValue).Select(point => point.FakeId.Value).ToArray(); foreach (ManufactoryDto manufactory in plan.Data.Manufactories) { int[] realManufactoryCompanyPlanPointIds = manufactory.ManufactoryPlanPoints.Where(point => point.CompanyPlanPointId.HasValue) .Select(point => point.CompanyPlanPointId.Value).ToArray(); int[] fakeManufactoryCompanyPlanPointIds = manufactory.ManufactoryPlanPoints.Where(point => point.FakeCompanyPlanPointId.HasValue) .Select(point => point.FakeCompanyPlanPointId.Value).ToArray(); if (realManufactoryCompanyPlanPointIds.Intersect(realCompanyPlanPointIds).Count() != realManufactoryCompanyPlanPointIds.Length) { dataValidationException.Add( typeof(ManufactoryPlanPointDto), nameof(ManufactoryPlanPointDto.CompanyPlanPointId), "company_plan_point_id provided for manufactory is not presented in company_plan_points collection" ); } if (fakeManufactoryCompanyPlanPointIds.Intersect(fakeCompanyPlanPointIds).Count() != fakeManufactoryCompanyPlanPointIds.Length) { dataValidationException.Add( typeof(ManufactoryPlanPointDto), nameof(ManufactoryPlanPointDto.CompanyPlanPointId), "fake_company_plan_point_id provided for manufactory is not presented in company_plan_points collection" ); } if (realManufactoryCompanyPlanPointIds.Distinct().Count() != realManufactoryCompanyPlanPointIds.Length) { dataValidationException.Add( typeof(ManufactoryDto), nameof(ManufactoryDto.ManufactoryPlanPoints), "company_plan_point_id's for one manufactory must be unique" ); } if (fakeManufactoryCompanyPlanPointIds.Distinct().Count() != fakeManufactoryCompanyPlanPointIds.Length) { dataValidationException.Add( typeof(ManufactoryDto), nameof(ManufactoryDto.ManufactoryPlanPoints), "fake_company_plan_point_id's for one manufactory must be unique" ); } if (manufactory.ManufactoryPlanPoints.Length < 3) { dataValidationException.Add( typeof(ManufactoryDto), nameof(ManufactoryDto.ManufactoryPlanPoints), "at least 3 company_plan_poin_id's must be specified for a manufactory" ); } } int[] realCheckPointCompanyPlanPointIds = plan.Data.CheckPoints .Where(point => point.CompanyPlanUniquePoint1Id.HasValue).Select(point => point.CompanyPlanUniquePoint1Id.Value) .Union(plan.Data.CheckPoints.Where(point => point.CompanyPlanUniquePoint2Id.HasValue).Select(point => point.CompanyPlanUniquePoint2Id.Value)) .ToArray(); int[] fakeCheckPointCompanyPlanPointIds = plan.Data.CheckPoints .Where(point => point.FakeCompanyPlanUniquePoint1Id.HasValue).Select(point => point.FakeCompanyPlanUniquePoint1Id.Value) .Union(plan.Data.CheckPoints.Where(point => point.FakeCompanyPlanUniquePoint2Id.HasValue).Select(point => point.FakeCompanyPlanUniquePoint2Id.Value)) .ToArray(); if (realCheckPointCompanyPlanPointIds.Intersect(realCompanyPlanPointIds).Count() != realCheckPointCompanyPlanPointIds.Length) { dataValidationException.Add( typeof(CheckPointDto), $"{nameof(CheckPointDto.CompanyPlanUniquePoint1Id)} or {nameof(CheckPointDto.CompanyPlanUniquePoint2Id)}", "company_plan_point_id provided for check point is not presented in company_plan_points collection" ); } if (fakeCheckPointCompanyPlanPointIds.Intersect(fakeCompanyPlanPointIds).Count() != fakeCheckPointCompanyPlanPointIds.Length) { dataValidationException.Add( typeof(CheckPointDto), $"{nameof(CheckPointDto.FakeCompanyPlanUniquePoint1Id)} or {nameof(CheckPointDto.FakeCompanyPlanUniquePoint2Id)}", "fake_company_plan_point_id provided for check point is not presented in company_plan_points collection" ); } int[] realEnterLeavePointCompanyPlanPointIds = plan.Data.EnterLeavePoints .Where(point => point.CompanyPlanUniquePoint1Id.HasValue).Select(point => point.CompanyPlanUniquePoint1Id.Value) .Union(plan.Data.EnterLeavePoints.Where(point => point.CompanyPlanUniquePoint2Id.HasValue).Select(point => point.CompanyPlanUniquePoint2Id.Value)) .ToArray(); int[] fakeEnterLeavePointCompanyPlanPointIds = plan.Data.EnterLeavePoints .Where(point => point.FakeCompanyPlanUniquePoint1Id.HasValue).Select(point => point.FakeCompanyPlanUniquePoint1Id.Value) .Union(plan.Data.EnterLeavePoints.Where(point => point.FakeCompanyPlanUniquePoint2Id.HasValue).Select(point => point.FakeCompanyPlanUniquePoint2Id.Value)) .ToArray(); if (realEnterLeavePointCompanyPlanPointIds.Intersect(realCompanyPlanPointIds).Count() != realEnterLeavePointCompanyPlanPointIds.Length) { dataValidationException.Add( typeof(EnterLeavePointDto), $"{nameof(EnterLeavePointDto.CompanyPlanUniquePoint1Id)} or {nameof(EnterLeavePointDto.CompanyPlanUniquePoint2Id)}", "company_plan_point_id provided for enter/leave point is not presented in company_plan_points collection" ); } if (fakeEnterLeavePointCompanyPlanPointIds.Intersect(fakeCompanyPlanPointIds).Count() != fakeEnterLeavePointCompanyPlanPointIds.Length) { dataValidationException.Add( typeof(EnterLeavePointDto), $"{nameof(EnterLeavePointDto.FakeCompanyPlanUniquePoint1Id)} or {nameof(EnterLeavePointDto.FakeCompanyPlanUniquePoint2Id)}", "fake_company_plan_point_id provided for enter/leave point is not presented in company_plan_points collection" ); } if (dataValidationException.InvalidFieldInfos.Count != 0) { throw dataValidationException; } Dictionary <int, bool> realCompanyPlanPointUsed = realCompanyPlanPointIds.ToDictionary(id => id, id => false); Dictionary <int, bool> fakeCompanyPlanPointUsed = fakeCompanyPlanPointIds.ToDictionary(id => id, id => false); (bool isCheckPoint, int?real1, int?real2, int?fake1, int?fake2)[] companyPlanPointIds = plan.Data.CheckPoints.Select(
public CoordinatesParser() { _defaultException = new DataValidationException("Incorect coordinates."); }