public override void Validate() { var errors = new RulesException <ObjectFormat>(); base.Validate(errors); if (!string.IsNullOrWhiteSpace(NetFormatName) && IsSiteDotNet) { if (!Regex.IsMatch(NetFormatName, RegularExpressions.NetName)) { errors.ErrorFor(x => x.NetFormatName, TemplateStrings.NetNameInvalidFormat); } if (!PageTemplateRepository.ObjectFormatNetNameUnique(NetFormatName, ObjectId, Id)) { errors.ErrorFor(x => x.NetFormatName, TemplateStrings.NetNameNotUnique); } if (NetFormatName.Length > 255) { errors.ErrorFor(x => x.NetFormatName, TemplateStrings.NetNameMaxLengthExceeded); } } if (NetLanguageId != null) { if (string.IsNullOrWhiteSpace(CodeBehind)) { errors.ErrorFor(n => n.CodeBehind, ObjectFormatStrings.CodeBehindRequired); } } if (!errors.IsEmpty) { throw errors; } }
public override void Validate() { var errors = new RulesException <EntityPermission>(); base.Validate(errors); if (MemberType != UserMemberType && MemberType != GroupMemberType) { errors.ErrorForModel(EntityPermissionStrings.SystemError); } if (MemberType == UserMemberType && !UserId.HasValue) { errors.ErrorFor(m => m.UserId, EntityPermissionStrings.UserIsNotSelected); } if (MemberType == GroupMemberType && !GroupId.HasValue) { errors.ErrorFor(m => m.GroupId, EntityPermissionStrings.GroupIsNotSelected); } if (!errors.IsEmpty) { throw errors; } }
protected virtual RulesException Validate(RulesException errors) { SaveResults(errors, ValidationFactory.CreateValidator(GetType()).Validate(this)); ValidateSecurity(errors); ValidateUnique(errors); return(errors); }
private void ValidateWeight(RulesException <StatusType> errors) { if (StatusTypeRepository.GetWeightsBySiteId(SiteId, Id).Contains(Weight)) { errors.ErrorFor(n => n.Weight, StatusTypeStrings.WeightIsInUse); } }
public override void Validate() { var errors = new RulesException <Workflow>(); if (IsDefault) { var another = WorkflowRepository.AnotherDefaultExists(Id); if (another != 0) { errors.ErrorFor(w => w.IsDefault, string.Format(WorkflowStrings.WorkflowDefaultAlreadyExists, another)); } } WorkflowRules.ForEach(x => x.IsInvalid = false); base.Validate(errors); var workflowRulesArray = WorkflowRules.ToArray(); foreach (var rule in workflowRulesArray) { ValidateWorkflowRule(rule, errors); } if (!errors.IsEmpty) { throw errors; } }
public override void Validate() { var errors = new RulesException <Page>(); base.Validate(errors); if (!PageTemplateRepository.PageFileNameUnique(FileName, PageTemplate.Id, Id)) { errors.ErrorFor(x => x.FileName, TemplateStrings.NetNameNotUnique); } if (!string.IsNullOrWhiteSpace(CustomClass)) { if (!Regex.IsMatch(CustomClass, RegularExpressions.NetName)) { errors.ErrorFor(x => x.CustomClass, TemplateStrings.CustomClassInvalidFormat); } } if (!string.IsNullOrWhiteSpace(Folder)) { if (!Regex.IsMatch(Folder, RegularExpressions.RelativeWindowsFolderPath)) { errors.ErrorFor(x => x.Folder, TemplateStrings.FolderNameInvalidFormat); } } if (PageTemplate.SiteIsDotNet) { if (!string.IsNullOrWhiteSpace(CustomClass)) { if (!Regex.IsMatch(CustomClass, RegularExpressions.NetName)) { errors.ErrorFor(x => x.CustomClass, TemplateStrings.CustomClassInvalidFormat); } if (CustomClass.Length > 255) { errors.ErrorFor(x => x.CustomClass, TemplateStrings.CustomClassMaxLengthExceeded); } } if (!string.IsNullOrWhiteSpace(Folder)) { if (!Regex.IsMatch(Folder, RegularExpressions.RelativeWindowsFolderPath)) { errors.ErrorFor(x => x.Folder, TemplateStrings.FolderNameInvalidFormat); } if (Folder.Length > 255) { errors.ErrorFor(x => x.Folder, TemplateStrings.FolderNameMaxLengthExceeded); } } } if (!errors.IsEmpty) { throw errors; } }
protected override RulesException ValidateUnique(RulesException errors) { if (IsNew && !Repository.CheckUnique(this)) { errors.ErrorForModel(EntityPermissionStrings.PermissionIsNotUnique); } return(errors); }
public virtual void Validate() { var errors = new RulesException <EntityObject>(); Validate(errors); if (!errors.IsEmpty) { throw errors; } }
protected override RulesException Validate(RulesException errors) { base.Validate(errors); if (LockedByAnyoneElse) { errors.CriticalErrorForModel(string.Format(LockedByAnyoneElseMessage, LockedByDisplayName)); } return(errors); }
protected virtual RulesException ValidateUnique(RulesException errors) { if (!string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(EntityTypeCode)) { if (EntityObjectRepository.CheckNameUniqueness(this)) { errors.Error(UniquePropertyName, Name, PropertyIsNotUniqueMessage); } } return(errors); }
public override void Validate() { var errors = new RulesException <CustomAction>(); base.Validate(errors); if (Order < 0) { errors.ErrorFor(a => a.Order, CustomActionStrings.OrderIsNotInRange); } else if (Order > 0 && Action.EntityTypeId > 0 && !CustomActionRepository.IsOrderUnique(Id, Order, Action.EntityTypeId)) { var freeOrder = GetFreeOrder(Action.EntityTypeId); errors.ErrorFor(a => a.Order, string.Format(CustomActionStrings.OrderValueIsNotUniq, freeOrder)); } if (Action.IsInterface && Action.IsWindow) { if (!Action.WindowHeight.HasValue) { errors.ErrorFor(a => a.Action.WindowHeight, CustomActionStrings.WindowHeightIsNotEntered); } else if (!Action.WindowHeight.Value.IsInRange(100, 1000)) { errors.ErrorFor(a => a.Action.WindowHeight, string.Format(CustomActionStrings.WindowHeightIsNotInRange, 100, 1000)); } if (!Action.WindowWidth.HasValue) { errors.ErrorFor(a => a.Action.WindowWidth, CustomActionStrings.WindowWidthIsNotEntered); } else if (!Action.WindowWidth.Value.IsInRange(100, 1000)) { errors.ErrorFor(a => a.Action.WindowWidth, string.Format(CustomActionStrings.WindowWidthIsNotInRange, 100, 1000)); } } if (!UrlHelpers.IsValidUrl(Url)) { errors.ErrorFor(a => a.Url, string.Format(CustomActionStrings.UrlInvalidFormat)); } if (!UrlHelpers.IsValidUrl(IconUrl)) { errors.ErrorFor(a => a.IconUrl, string.Format(CustomActionStrings.IconUrlInvalidFormat)); } if (!errors.IsEmpty) { throw errors; } }
public override void Validate() { var errors = new RulesException <UserGroup>(); base.Validate(errors); // Группа не может иметь родительскую группу с параллельным Worfklow if (ParentGroup != null && ParentGroup.UseParallelWorkflow) { errors.ErrorFor(g => g.ParentGroup, UserGroupStrings.ParentCouldntUseWorkflow); } // Если группа с параллельным Worfklow, то она не может иметь потомков if (UseParallelWorkflow && ChildGroups.Any()) { errors.ErrorFor(g => g.UseParallelWorkflow, UserGroupStrings.GroupCouldntUseWorkflow); } // Если группа с параллельным Worfklow то проверить, не являеться ли родительская группа потомком группы Администраторы if (UseParallelWorkflow && ( IsAdministrators || ParentGroup != null && ParentGroup.IsAdminDescendant ) ) { errors.ErrorForModel(UserGroupStrings.GroupCouldntBeAdminDescendant); } // проверка на циклы if (!IsNew && ParentGroup != null) { if (UserGroupRepository.IsCyclePossible(Id, ParentGroup.Id)) { errors.ErrorFor(g => g.ParentGroup, UserGroupStrings.IsGroupCycle); } } // Группа с параллельным Worfklow не может содержать пользователей прямо или косвенно входящих в группу Администраторы AdminDescendantGroupUserValidation(errors); // Если группа является потомком группы "Администраторы", то она не может содержать пользователей входящих в группы использующие параллельный Workflow WorkflowGroupUsersInAdminDescendantValidation(errors); // Проверка на то, что нельзя удалять встроенных пользователей из встроенной группы BuiltInUsersRemovingValidation(errors); if (!errors.IsEmpty) { throw errors; } }
private static void ValidateWorkflowRule(WorkflowRule rule, RulesException errors) { if (rule.UserId == null && rule.GroupId == null) { errors.ErrorForModel(string.Format(WorkflowStrings.UserNotSelected, rule.StatusType.Name)); rule.IsInvalid = true; } if (rule.Description.Length > 2000) { errors.ErrorForModel(string.Format(WorkflowStrings.CommentToLong, rule.StatusType.Name)); rule.IsInvalid = true; } }
public void Validate() { var errors = new RulesException <FolderFile>(); if (NameChanged && File.Exists(FullName)) { errors.ErrorFor(s => s.Name, string.Format(LibraryStrings.FileExists, FullName)); } if (!errors.IsEmpty) { throw errors; } }
public static void Wrap(Exception ex) { var newEx = new RulesException(); var sb = new StringBuilder(ex.Message); while (ex.InnerException != null) { ex = ex.InnerException; sb.Append(" "); sb.Append(ex.Message); } newEx.ErrorForModel(sb.ToString()); throw newEx; }
/// <summary> /// Группа с параллельным Worfklow не может содержать пользователей прямо или косвенно входящих в группу Администраторы /// </summary> /// <param name="errors"></param> private void AdminDescendantGroupUserValidation(RulesException <UserGroup> errors) { if (UseParallelWorkflow && Users.Any()) { var adminDescendantUsersIDs = UserGroupRepository.SelectAdminDescendantGroupUserIDs(Users.Select(u => u.Id).ToArray(), Id); if (adminDescendantUsersIDs.Any()) { var logins = Users .Where(u => adminDescendantUsersIDs.Contains(u.Id)) .Select(u => u.LogOn); var message = string.Format(UserGroupStrings.GroupCouldntBindAdminDescendantUsers, string.Join(",", logins)); errors.ErrorForModel(message); } } }
private static void SaveResults(RulesException ex, IEnumerable <ValidationResult> validationResults) { if (validationResults != null) { foreach (var validationResult in validationResults) { if (validationResult.NestedValidationResults != null) { SaveResults(ex, validationResult.NestedValidationResults); } ex.Error(validationResult.Key, string.Empty, validationResult.Message); } } }
public override void Validate() { var errors = new RulesException <ContentGroup>(); if (IsDefault) { errors.ErrorForModel(ContentStrings.CannotUpdateDefaultGroup); } else { base.Validate(errors); } if (!errors.IsEmpty) { throw errors; } }
protected virtual RulesException ValidateSecurity(RulesException errors) { if (IsNew) { if (Parent != null && !Parent.IsUpdatable) { errors.CriticalErrorForModel(CannotAddBecauseOfSecurityMessage); } } else { if (!IsUpdatable) { errors.CriticalErrorForModel(CannotUpdateBecauseOfSecurityMessage); } } return(errors); }
public override void Validate() { WorkflowRules.ForEach(x => x.IsInvalid = false); var errors = new RulesException <Workflow>(); base.Validate(errors); var workflowRulesArray = WorkflowRules.ToArray(); foreach (var rule in workflowRulesArray) { ValidateWorkflowRule(rule, errors); } if (!errors.IsEmpty) { throw errors; } }
public override void Validate() { var errors = new RulesException <Db>(); base.Validate(errors); var duplicateNames = AppSettings.GroupBy(c => c.Key).Where(g => g.Count() > 1).Select(x => x.Key).ToArray(); var settings = AppSettings.ToArray(); for (var i = 0; i < settings.Length; i++) { settings[i].Validate(errors, i + 1, duplicateNames); } if (!errors.IsEmpty) { throw errors; } }
public override void Validate() { var errors = new RulesException <StatusType>(); if (string.IsNullOrEmpty(Color) && !string.IsNullOrEmpty(AltColor)) { errors.ErrorFor(n => n.Color, StatusTypeStrings.ColorMissed); } if (string.IsNullOrEmpty(AltColor) && !string.IsNullOrEmpty(Color)) { errors.ErrorFor(n => n.AltColor, StatusTypeStrings.AltColorMissed); } ValidateWeight(errors); base.Validate(errors); if (!errors.IsEmpty) { throw errors; } }
private static void ValidateUsing(AdditionalNamespace additionalNamespace, RulesException <PageTemplate> errors, int index) { if (string.IsNullOrWhiteSpace(additionalNamespace.Name)) { errors.ErrorForModel(string.Format(TemplateStrings.AdditionalNamespaceRequired, index)); additionalNamespace.Invalid = true; return; } if (additionalNamespace.Name.Length > 255) { errors.ErrorForModel(string.Format(TemplateStrings.AdditionalNamespaceLengthExceeded, index)); additionalNamespace.Invalid = true; } if (!Regex.IsMatch(additionalNamespace.Name, RegularExpressions.FullQualifiedNetName)) { errors.ErrorForModel(string.Format(TemplateStrings.AdditionalNamespaceInvalidFormat, index)); additionalNamespace.Invalid = true; } }
/// <summary> /// Проверка на то, что нельзя удалять встроенных пользователей из встроенной группы /// </summary> /// <param name="errors"></param> private void BuiltInUsersRemovingValidation(RulesException <UserGroup> errors) { if (BuiltIn) { var group = UserGroupRepository.GetPropertiesById(Id); if (group == null) { throw new ApplicationException(string.Format(UserGroupStrings.GroupNotFound, Id)); } var dbBuiltInUserIDs = group.Users.Where(u => u.BuiltIn).Select(u => u.Id); var builtInUserIDs = Users.Where(u => u.BuiltIn).Select(u => u.Id); var undindedBuiltInUserIDs = dbBuiltInUserIDs.Except(builtInUserIDs); if (undindedBuiltInUserIDs.Any()) { var logins = group.Users .Where(u => undindedBuiltInUserIDs.Contains(u.Id)) .Select(u => u.LogOn); var message = string.Format(UserGroupStrings.BuiltInUsersCouldntBeRemoved, string.Join(",", logins)); errors.ErrorForModel(message); } } }
public override void Validate() { var errors = new RulesException <PageTemplate>(); base.Validate(errors); if (SiteIsDotNet) { if (!Regex.IsMatch(NetTemplateName, RegularExpressions.NetName)) { errors.ErrorFor(x => x.NetTemplateName, TemplateStrings.NetNameInvalidFormat); } if (!PageTemplateRepository.PageTemplateNetNameUnique(NetTemplateName, SiteId, Id)) { errors.ErrorFor(x => x.NetTemplateName, TemplateStrings.NetNameNotUnique); } } if (!string.IsNullOrWhiteSpace(TemplateFolder)) { if (!Regex.IsMatch(TemplateFolder, RegularExpressions.RelativeWindowsFolderPath)) { errors.ErrorFor(x => x.TemplateFolder, TemplateStrings.FolderNameInvalidFormat); } } if (!string.IsNullOrWhiteSpace(CustomClassForPages)) { if (!Regex.IsMatch(CustomClassForPages, RegularExpressions.NetName)) { errors.ErrorFor(x => x.CustomClassForPages, TemplateStrings.CustomClassForPagesInvalidFormat); } } if (!string.IsNullOrWhiteSpace(TemplateCustomClass)) { if (!Regex.IsMatch(TemplateCustomClass, RegularExpressions.NetName)) { errors.ErrorFor(x => x.CustomClassForPages, TemplateStrings.CustomClassForTemplateInvalidFormat); } } if (!string.IsNullOrWhiteSpace(CustomClassForGenerics)) { if (!Regex.IsMatch(CustomClassForGenerics, RegularExpressions.NetName)) { errors.ErrorFor(x => x.CustomClassForGenerics, TemplateStrings.CustomClassForGenericsInvalidFormat); } } if (!string.IsNullOrWhiteSpace(CustomClassForContainers)) { if (!Regex.IsMatch(CustomClassForContainers, RegularExpressions.NetName)) { errors.ErrorFor(x => x.CustomClassForContainers, TemplateStrings.CustomClassForContainersInvalidFormat); } } if (!string.IsNullOrWhiteSpace(CustomClassForForms)) { if (!Regex.IsMatch(CustomClassForForms, RegularExpressions.NetName)) { errors.ErrorFor(x => x.CustomClassForForms, TemplateStrings.CustomClassForFormsInvalidFormat); } } if (Using.Length > 512) { errors.ErrorFor(x => x.Using, TemplateStrings.UsingTotalLengthExceeded); } var usingsArray = AdditionalNamespaceItems.ToArray(); for (var i = 0; i < usingsArray.Length; i++) { ValidateUsing(usingsArray[i], errors, i + 1); } if (!errors.IsEmpty) { throw errors; } }
public override void Validate() { var errors = new RulesException <QpPlugin>(); base.Validate(errors); if (!string.IsNullOrEmpty(LoadedContractInvalidMessage)) { errors.ErrorFor(n => ServiceUrl, $"{QpPluginStrings.LoadedContractInvalidMessage}: {LoadedContractInvalidMessage}"); } if (!string.IsNullOrEmpty(ParsedContractInvalidMessage)) { errors.ErrorFor(n => Contract, $"{QpPluginStrings.ParsedContractInvalidMessage}: {ParsedContractInvalidMessage}"); } if (!string.IsNullOrEmpty(ServiceUrl) && !UrlHelpers.IsValidWebFolderUrl(ServiceUrl)) { errors.ErrorFor(n => ServiceUrl, QpPluginStrings.ServiceUrlInvalidFormat); } if (ContractParsed) { if (string.IsNullOrEmpty(Contract)) { errors.ErrorFor(n => ServiceUrl, QpPluginStrings.ContractNotEntered); } else { if (string.IsNullOrEmpty(Code)) { errors.ErrorFor(n => ServiceUrl, QpPluginStrings.CodeNotEntered); } else { if (QpPluginRepository.CodeExists(this)) { errors.ErrorFor(n => Code, QpPluginStrings.CodeExists); } } if (string.IsNullOrEmpty(Version)) { errors.ErrorFor(n => ServiceUrl, QpPluginStrings.VersionNotEntered); } else { if (Version.Length > MaxVersionLength) { errors.ErrorFor(n => Version, String.Format(QpPluginStrings.VersionMaxLengthExceeded, null, MaxVersionLength)); } else if (OldVersion == Version) { errors.ErrorFor(n => Version, QpPluginStrings.VersionEqual); } } if (Fields.Any(n => String.IsNullOrEmpty(n.Name))) { errors.ErrorForModel(QpPluginStrings.FieldNameNotEntered); } if (Fields.Any(n => n.Name.Length > MaxFieldNameLength)) { errors.ErrorForModel(String.Format(QpPluginStrings.FieldNameMaxLengthExceeded, null, MaxFieldNameLength)); } if (Fields.GroupBy(n => n.Name.ToLower() + n.RelationType).Any(g => g.Count() > 1)) { errors.ErrorForModel(QpPluginStrings.FieldNameDuplicate); } } } if (!errors.IsEmpty) { throw errors; } }
protected virtual RulesException Validate(RulesException errors) { ValidateSecurity(errors); ValidateUnique(errors); return(errors); }