protected virtual string ValidatePath(string label, string path, Action onError, bool pathIsRequired) { if (!pathIsRequired && string.IsNullOrWhiteSpace(path)) { return string.Empty; } var errors = new List<IActionableErrorInfo>(); RuleSet fileActivityRuleSet = new RuleSet(); IsValidExpressionRule isValidExpressionRule = new IsValidExpressionRule(() => path, DataListSingleton.ActiveDataList.Resource.DataList); fileActivityRuleSet.Add(isValidExpressionRule); errors.AddRange(fileActivityRuleSet.ValidateRules(label, onError)); string pathValue; path.TryParseVariables(out pathValue, onError, variableValue: ValidUriSchemes[0] + "://temp"); if (errors.Count == 0) { IsStringEmptyOrWhiteSpaceRule isStringEmptyOrWhiteSpaceRuleUserName = new IsStringEmptyOrWhiteSpaceRule(() => path) { LabelText = label, DoError = onError }; IsValidFileNameRule isValidFileNameRule = new IsValidFileNameRule(() => path) { LabelText = label, DoError = onError }; fileActivityRuleSet.Add(isStringEmptyOrWhiteSpaceRuleUserName); fileActivityRuleSet.Add(isValidExpressionRule); errors.AddRange(fileActivityRuleSet.ValidateRules(label, onError)); } UpdateErrors(errors); return pathValue; }
protected virtual string ValidateArchivePassword(string password, string label, Action onError, bool contentIsRequired = true) { var errors = new List<IActionableErrorInfo>(); RuleSet fileActivityRuleSet = new RuleSet(); IsValidExpressionRule isValidExpressionRule = new IsValidExpressionRule(() => password, DataListSingleton.ActiveDataList.Resource.DataList); fileActivityRuleSet.Add(isValidExpressionRule); errors.AddRange(fileActivityRuleSet.ValidateRules(label, onError)); UpdateErrors(errors); return password; }
void ValidateUserNameAndPassword(string userNameValue, string userNameLabel, Action onUserNameError, string passwordValue, string passwordLabel, Action onPasswordError) { var errors = new List<IActionableErrorInfo>(); var credentialUserRuleSet = new RuleSet(); var dataListViewModel = DataListSingleton.ActiveDataList; if(dataListViewModel != null) { var isValidExpressionRule = new IsValidExpressionRule(() => userNameValue, dataListViewModel.Resource.DataList); credentialUserRuleSet.Add(isValidExpressionRule); errors.AddRange(credentialUserRuleSet.ValidateRules(userNameLabel, onUserNameError)); var credentialPasswordRuleSet = new RuleSet(); isValidExpressionRule = new IsValidExpressionRule(() => passwordValue, dataListViewModel.Resource.DataList); credentialPasswordRuleSet.Add(isValidExpressionRule); errors.AddRange(credentialPasswordRuleSet.ValidateRules(passwordLabel, onPasswordError)); } if(errors.Count == 0) { var isStringEmptyOrWhiteSpaceRuleUserName = new IsStringEmptyOrWhiteSpaceRule(() => userNameValue) { LabelText = userNameLabel, DoError = onUserNameError }; var userNameBlankError = isStringEmptyOrWhiteSpaceRuleUserName.Check(); var isStringEmptyOrWhiteSpaceRulePassword = new IsStringEmptyOrWhiteSpaceRule(() => passwordValue) { LabelText = passwordLabel, DoError = onPasswordError }; var passwordBlankError = isStringEmptyOrWhiteSpaceRulePassword.Check(); if (userNameBlankError == null && passwordBlankError != null) { errors.Add(passwordBlankError); } else { if (passwordBlankError == null && userNameBlankError != null) { errors.Add(userNameBlankError); } } } UpdateErrors(errors); }