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
                };

                fileActivityRuleSet.Add(isStringEmptyOrWhiteSpaceRuleUserName);
                errors.AddRange(fileActivityRuleSet.ValidateRules(label, onError));

                var pathBlankError = isStringEmptyOrWhiteSpaceRuleUserName.Check();
                if (pathBlankError != null)
                {
                    errors.Add(new ActionableErrorInfo(onError)
                    {
                        ErrorType = ErrorType.Critical, Message = label + " must have a value"
                    });
                }
                else
                {
                    Uri uriResult;
                    var isValid = Uri.TryCreate(pathValue, UriKind.Absolute, out uriResult)
                            ? ValidUriSchemes.Contains(uriResult.Scheme)
                            : File.Exists(pathValue);

                    if (!isValid)
                    {
                        errors.Add(new ActionableErrorInfo(onError)
                        {
                            ErrorType = ErrorType.Critical, Message = "Please supply a valid " + label
                        });
                    }
                }
            }

            UpdateErrors(errors);
            return(pathValue);
        }
        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, new VariableUtils());
                credentialUserRuleSet.Add(isValidExpressionRule);
                errors.AddRange(credentialUserRuleSet.ValidateRules(userNameLabel, onUserNameError));
                var credentialPasswordRuleSet = new RuleSet();
                isValidExpressionRule = new IsValidExpressionRule(() => passwordValue, dataListViewModel.Resource.DataList, new VariableUtils());
                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);
        }
Пример #3
0
        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 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;
        }
        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);
        }