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);
        }
 public void IsValidExpressionRule_Check_VariableIsEmptyString_RaisesNoError()
 {
     //------------Setup for test--------------------------
     var validator = new IsValidExpressionRule(() => "", "<ADL><rec><field1/></rec><var1/></ADL>");
     //------------Execute Test---------------------------
     var result = validator.Check();
     //------------Assert Results-------------------------
     Assert.IsNull(result);
 }
 public void IsValidExpressionRule_Check_MalformedVariable_RaisesAnError()
 {
     //------------Setup for test--------------------------
     var validator = new IsValidExpressionRule(() => "h]]", "<ADL><rec><field1/></rec><var1/></ADL>");
     //------------Execute Test---------------------------
     var errorInfo = validator.Check();
     //------------Assert Results-------------------------
     Assert.IsNotNull(errorInfo);
     Assert.AreEqual("The - Invalid expression: opening and closing brackets don't match.", errorInfo.Message);
 }
 public void IsValidExpressionRule_Check_InvalidVariable_RaisesError()
 {
     //------------Setup for test--------------------------
     var validator = new IsValidExpressionRule(() => "[[res#]]", "<ADL><rec><field1/></rec><var1/></ADL>");
     //------------Execute Test---------------------------
     var errorInfo = validator.Check();
     //------------Assert Results-------------------------
     Assert.IsNotNull(errorInfo);
     Assert.AreEqual("The - Variable name [[res#]] contains invalid character(s)", errorInfo.Message);
 }
        public void IsValidExpressionRule_Check_VariableIsEmptyString_RaisesNoError()
        {
            //------------Setup for test--------------------------
            var validator = new IsValidExpressionRule(() => "", "<ADL><rec><field1/></rec><var1/></ADL>", new VariableUtils());
            //------------Execute Test---------------------------
            var result = validator.Check();

            //------------Assert Results-------------------------
            Assert.IsNull(result);
        }
        public void IsValidExpressionRule_Check_MalformedVariable_RaisesAnError()
        {
            //------------Setup for test--------------------------
            var validator = new IsValidExpressionRule(() => "h]]", "<ADL><rec><field1/></rec><var1/></ADL>", new VariableUtils());
            //------------Execute Test---------------------------
            var errorInfo = validator.Check();

            //------------Assert Results-------------------------
            Assert.IsNotNull(errorInfo);
            Assert.AreEqual(Warewolf.Resource.Errors.ErrorResource.IsValidExpressionRuleErrorTest, errorInfo.Message);
        }
        public void IsValidExpressionRule_Check_MalformedVariable_RaisesAnError()
        {
            //------------Setup for test--------------------------
            var validator = new IsValidExpressionRule(() => "h]]", "<ADL><rec><field1/></rec><var1/></ADL>");
            //------------Execute Test---------------------------
            var errorInfo = validator.Check();

            //------------Assert Results-------------------------
            Assert.IsNotNull(errorInfo);
            Assert.AreEqual("The - Invalid expression: opening and closing brackets don't match.", errorInfo.Message);
        }
예제 #8
0
        IRuleSet GetRuleSet(string propertyName, string datalist)
        {
            var ruleSet = new RuleSet();

            switch (propertyName)
            {
            case "EmailSource":
                ruleSet.Add(new IsNullRule(() => EmailSource));
                break;

            case "FromAccount":
                var fromExprRule = new IsValidExpressionRule(() => FromAccount, datalist, "*****@*****.**");
                ruleSet.Add(fromExprRule);
                ruleSet.Add(new IsValidEmailAddressRule(() => fromExprRule.ExpressionValue));
                break;

            case "Password":
                ruleSet.Add(new IsRequiredWhenOtherIsNotEmptyRule(() => Password, () => FromAccount));
                break;

            case "To":
                var toExprRule = new IsValidExpressionRule(() => To, datalist, "*****@*****.**");
                ruleSet.Add(toExprRule);
                ruleSet.Add(new IsValidEmailAddressRule(() => toExprRule.ExpressionValue));
                break;

            case "Cc":
                var ccExprRule = new IsValidExpressionRule(() => Cc, datalist, "*****@*****.**");
                ruleSet.Add(ccExprRule);
                ruleSet.Add(new IsValidEmailAddressRule(() => ccExprRule.ExpressionValue));
                break;

            case "Bcc":
                var bccExprRule = new IsValidExpressionRule(() => Bcc, datalist, "*****@*****.**");
                ruleSet.Add(bccExprRule);
                ruleSet.Add(new IsValidEmailAddressRule(() => bccExprRule.ExpressionValue));
                break;

            case "Attachments":
                var attachmentsExprRule = new IsValidExpressionRule(() => Attachments, datalist, @"c:\test.txt");
                ruleSet.Add(attachmentsExprRule);
                ruleSet.Add(new IsValidFileNameRule(() => attachmentsExprRule.ExpressionValue));
                break;

            case "Recipients":
                ruleSet.Add(new HasAtLeastOneRule(() => To, () => Cc, () => Bcc));
                break;

            case "SubjectAndBody":
                ruleSet.Add(new HasAtLeastOneRule(() => Subject, () => Body));
                break;
            }
            return(ruleSet);
        }
        public void IsValidExpressionRule_Check_InvalidVariable_RaisesError()
        {
            //------------Setup for test--------------------------
            var validator = new IsValidExpressionRule(() => "[[res#]]", "<ADL><rec><field1/></rec><var1/></ADL>", new VariableUtils());
            //------------Execute Test---------------------------
            var errorInfo = validator.Check();

            //------------Assert Results-------------------------
            Assert.IsNotNull(errorInfo);
            Assert.AreEqual("Variable name [[res#]] contains invalid character(s). Only use alphanumeric _ and - ", errorInfo.Message);
        }
예제 #10
0
        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, 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);
        }
        public void IsValidExpressionRule_Check_VariableExpressionIsValid_ReturnsNoError()
        {
            //------------Setup for test--------------------------
            const string trueString = "True";
            const string noneString = "None";
            var          datalist   = string.Format("<DataList><var Description=\"{0}\" IsEditable=\"\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString);

            var rule = new IsValidExpressionRule(() => "[[a]]", datalist, new VariableUtils())
            {
                LabelText = "MyVar"
            };
            //------------Execute Test---------------------------
            var errorInfo = rule.Check();

            //------------Assert Results-------------------------
            Assert.IsNull(errorInfo);
        }
예제 #13
0
        public override IRuleSet GetRuleSet(string propertyName, string datalist)
        {
            RuleSet ruleSet = new RuleSet();

            if (IsEmpty())
            {
                return(ruleSet);
            }
            switch (propertyName)
            {
            case "Input":
                if (!string.IsNullOrEmpty(InputVariable))
                {
                    var inputExprRule = new IsValidExpressionRule(() => InputVariable, datalist, "0");
                    ruleSet.Add(inputExprRule);
                }
                else
                {
                    ruleSet.Add(new IsStringEmptyRule(() => InputVariable));
                }
                break;

            case "At":
                if (MergeType == MergeTypeIndex)
                {
                    var atExprRule = new IsValidExpressionRule(() => At, datalist, "1");
                    ruleSet.Add(atExprRule);

                    ruleSet.Add(new IsStringEmptyRule(() => atExprRule.ExpressionValue));
                    ruleSet.Add(new IsPositiveNumberRule(() => atExprRule.ExpressionValue));
                }
                break;

            case "Padding":
                if (!string.IsNullOrEmpty(Padding))
                {
                    var paddingExprRule = new IsValidExpressionRule(() => Padding, datalist, "0");
                    ruleSet.Add(paddingExprRule);

                    ruleSet.Add(new IsSingleCharRule(() => paddingExprRule.ExpressionValue));
                }
                break;
            }
            return(ruleSet);
        }
예제 #14
0
        public void IsValidExpressionRule_Check_RecordsetHasANegativeIndex_ReturnsAnError()
        {
            //------------Setup for test--------------------------
            const string trueString = "True";
            const string noneString = "None";
            var          datalist   = string.Format("<DataList><var Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString);

            var rule = new IsValidExpressionRule(() => "[[rec(-1).set]]", datalist)
            {
                LabelText = "MyRecSet"
            };
            //------------Execute Test---------------------------
            var errorInfo = rule.Check();

            //------------Assert Results-------------------------
            Assert.IsNotNull(errorInfo);
            Assert.AreEqual(Warewolf.Resource.Errors.ErrorResource.IsValidExpressionRuleIndexZeroErrorTest, errorInfo.Message);
        }
        public void IsValidExpressionRule_Check_VaribaleExpressionHasSpecialCharacter_ReturnsAnError()
        {
            //------------Setup for test--------------------------
            const string trueString = "True";
            const string noneString = "None";
            var          datalist   = string.Format("<DataList><var Description=\"{0}\" IsEditable=\"\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString);

            var rule = new IsValidExpressionRule(() => "[[a$]]", datalist, new VariableUtils())
            {
                LabelText = "MyVar"
            };
            //------------Execute Test---------------------------
            var errorInfo = rule.Check();

            //------------Assert Results-------------------------
            Assert.IsNotNull(errorInfo);
            Assert.AreEqual("MyVar - Variable name [[a$]] contains invalid character(s). Only use alphanumeric _ and - ", errorInfo.Message);
        }
        public void IsValidExpressionRule_Check_VariableExpressionHasAnUnderscore_ReturnsAnError()
        {
            //------------Setup for test--------------------------
            const string trueString = "True";
            const string noneString = "None";
            var          datalist   = string.Format("<DataList><var Description=\"{0}\" IsEditable=\"\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString);

            var rule = new IsValidExpressionRule(() => "[[a_b]]", datalist, new VariableUtils())
            {
                LabelText = "MyVar"
            };
            //------------Execute Test---------------------------
            var errorInfo = rule.Check();

            //------------Assert Results-------------------------
            Assert.IsNotNull(errorInfo);
            Assert.AreEqual("MyVar -  [[a_b]] does not exist in your variable list", errorInfo.Message);
        }
        public void IsValidExpressionRule_Check_RecordsetHasAnInvalidIndex_ReturnsAnError()
        {
            //------------Setup for test--------------------------
            const string trueString = "True";
            const string noneString = "None";
            var          datalist   = string.Format("<DataList><var Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString);

            var rule = new IsValidExpressionRule(() => "[[rec(**).set]]", datalist, new VariableUtils())
            {
                LabelText = "MyRecSet"
            };
            //------------Execute Test---------------------------
            var errorInfo = rule.Check();

            //------------Assert Results-------------------------
            Assert.IsNotNull(errorInfo);
            Assert.AreEqual("MyRecSet - Recordset index (**) contains invalid character(s)", errorInfo.Message);
        }
        IRuleSet GetRuleSet(string propertyName, string datalist)
        {
            var ruleSet = new RuleSet();

            switch (propertyName)
            {
            case "EmailSource":
                ruleSet.Add(new IsNullRule(() => SourceRegion.SelectedSource));
                break;

            case "To":
                var toExprRule = new IsValidExpressionRule(() => To, datalist, "*****@*****.**");
                ruleSet.Add(toExprRule);
                ruleSet.Add(new IsValidEmailAddressRule(() => toExprRule.ExpressionValue));
                break;

            case "Cc":
                var ccExprRule = new IsValidExpressionRule(() => Cc, datalist, "*****@*****.**");
                ruleSet.Add(ccExprRule);
                ruleSet.Add(new IsValidEmailAddressRule(() => ccExprRule.ExpressionValue));
                break;

            case "Bcc":
                var bccExprRule = new IsValidExpressionRule(() => Bcc, datalist, "*****@*****.**");
                ruleSet.Add(bccExprRule);
                ruleSet.Add(new IsValidEmailAddressRule(() => bccExprRule.ExpressionValue));
                break;

            case "Attachments":
                var attachmentsExprRule = new IsValidExpressionRule(() => Attachments, datalist, @"c:\test.txt");
                ruleSet.Add(attachmentsExprRule);
                ruleSet.Add(new IsValidFileNameRule(() => attachmentsExprRule.ExpressionValue));
                break;

            case "Recipients":
                ruleSet.Add(new HasAtLeastOneRule(() => To, () => Cc, () => Bcc));
                break;

            case "SubjectAndBody":
                ruleSet.Add(new HasAtLeastOneRule(() => Subject, () => Body));
                break;
            }
            return(ruleSet);
        }
예제 #19
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);
        }
예제 #20
0
        static void ValidateVariable(string fieldName, IDataListCompiler compiler, IDSFDataObject dataObject, out ErrorResultTO errors)
        {
            fieldName = DataListUtil.IsValueRecordset(fieldName) ? DataListUtil.ReplaceRecordsetIndexWithBlank(fieldName) : fieldName;
            var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), Dev2.DataList.Contract.enTranslationDepth.Shape, out errors).ToString();

            if (!string.IsNullOrEmpty(datalist))
            {
                var isValidExpr = new IsValidExpressionRule(() => fieldName, datalist)
                {
                    LabelText = fieldName
                };

                var errorInfo = isValidExpr.Check();
                if (errorInfo != null)
                {
                    errors.AddError(errorInfo.Message);
                }
            }
        }
예제 #21
0
        void ValidateInput(string datalist, ErrorResultTO allErrors, string input)
        {
            var splitIntoRegions = DataListCleaningUtils.FindAllLanguagePieces(input);

            foreach (var region in splitIntoRegions)
            {
                string region1     = region;
                var    isValidExpr = new IsValidExpressionRule(() => region1, datalist)
                {
                    LabelText = "Input1"
                };
                var errValid = isValidExpr.Check();
                if (errValid != null)
                {
                    var validationError = new ErrorResultTO();
                    validationError.AddError(errValid.Message);
                    allErrors.MergeErrors(validationError);
                }
            }
        }
예제 #22
0
        IRuleSet GetRuleSet(string propertyName)
        {
            var ruleSet = new RuleSet();

            switch (propertyName)
            {
            case "SourceString":
                if (!string.IsNullOrEmpty(SourceString) && !string.IsNullOrWhiteSpace(SourceString))
                {
                    var inputExprRule = new IsValidExpressionRule(() => SourceString, GetDatalistString(), "1");
                    ruleSet.Add(inputExprRule);
                }
                else
                {
                    ruleSet.Add(new IsStringEmptyOrWhiteSpaceRule(() => SourceString));
                }
                break;
            }
            return(ruleSet);
        }
        IRuleSet GetRuleSet(string propertyName)
        {
            var ruleSet = new RuleSet();

            switch (propertyName)
            {
            case "SourceString":
                ruleSet.Add(new IsStringEmptyOrWhiteSpaceRule(() => SourceString));

                if (!string.IsNullOrEmpty(SourceString) && !DataListUtil.IsEvaluated(SourceString))
                {
                    ruleSet.Add(new IsValidXmlRule(() => SourceString));
                }

                var outputExprRule = new IsValidExpressionRule(() => SourceString, GetDatalistString(), "1");
                ruleSet.Add(outputExprRule);

                break;
            }
            return(ruleSet);
        }
예제 #24
0
        public override IRuleSet GetRuleSet(string propertyName, string datalist)
        {
            var ruleSet = new RuleSet();

            if (IsEmpty())
            {
                return(ruleSet);
            }

            switch (propertyName)
            {
            case "OutputVariable":
                if (!string.IsNullOrEmpty(OutputVariable))
                {
                    var outputExprRule = new IsValidExpressionRule(() => OutputVariable, datalist, "0");
                    ruleSet.Add(outputExprRule);
                    ruleSet.Add(new IsValidExpressionRule(() => outputExprRule.ExpressionValue, datalist));
                }
                ruleSet.Add(new IsStringEmptyRule(() => OutputVariable));
                break;

            case "At":
                switch (SplitType)
                {
                case SplitTypeIndex:
                    var atIndexExprRule = new IsValidExpressionRule(() => At, datalist, "1");
                    ruleSet.Add(atIndexExprRule);
                    ruleSet.Add(new IsPositiveNumberRule(() => atIndexExprRule.ExpressionValue));
                    break;

                case SplitTypeChars:
                    var atCharsExprRule = new IsValidExpressionRule(() => At, datalist, ",");
                    ruleSet.Add(atCharsExprRule);
                    ruleSet.Add(new IsStringEmptyRule(() => atCharsExprRule.ExpressionValue));
                    break;
                }
                break;
            }
            return(ruleSet);
        }
예제 #25
0
        public override IRuleSet GetRuleSet(string propertyName, string datalist)
        {
            var ruleSet = new RuleSet();

            if (IsEmpty())
            {
                return(ruleSet);
            }

            switch (propertyName)
            {
            case "OutputVariable":
                var outputExprRule = new IsValidExpressionRule(() => OutputVariable, datalist, "1");
                ruleSet.Add(outputExprRule);
                ruleSet.Add(new IsValidExpressionRule(() => outputExprRule.ExpressionValue, datalist));

                if (!string.IsNullOrEmpty(XPath))
                {
                    ruleSet.Add(new IsStringEmptyRule(() => OutputVariable));
                }
                break;

            case "XPath":
                if (!string.IsNullOrEmpty(OutputVariable))
                {
                    ruleSet.Add(new IsStringEmptyRule(() => XPath));

                    if (!string.IsNullOrEmpty(XPath) && !DataListUtil.IsEvaluated(XPath))
                    {
                        ruleSet.Add(new IsValidXpathRule(() => XPath));
                    }
                }
                break;
            }
            return(ruleSet);
        }
예제 #26
0
        public override IRuleSet GetRuleSet(string propertyName, string datalist)
        {
            var ruleSet = new RuleSet();

            if(IsEmpty())
            {
                return ruleSet;
            }

            switch(propertyName)
            {
                case "OutputVariable":
                    var outputExprRule = new IsValidExpressionRule(() => OutputVariable,datalist, "1");
                    ruleSet.Add(outputExprRule);
                    ruleSet.Add(new IsValidExpressionRule(() => outputExprRule.ExpressionValue, datalist));

                    if(!string.IsNullOrEmpty(XPath))
                    {
                        ruleSet.Add(new IsStringEmptyRule(() => OutputVariable));
                    }
                    break;

                case "XPath":
                    if(!string.IsNullOrEmpty(OutputVariable))
                    {
                        ruleSet.Add(new IsStringEmptyRule(() => XPath));

                        if(!string.IsNullOrEmpty(XPath) && !DataListUtil.IsEvaluated(XPath))
                        {
                            ruleSet.Add(new IsValidXpathRule(() => XPath));
                        }
                    }
                    break;
            }
            return ruleSet;
        }
예제 #27
0
        public void IsValidExpressionRule_Check_RecordsetHasAnInvalidIndex_ReturnsAnError()
        {
            //------------Setup for test--------------------------
            const string trueString = "True";
            const string noneString = "None";
            var datalist = string.Format("<DataList><var Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString);

            var rule = new IsValidExpressionRule(() => "[[rec(**).set]]", datalist) { LabelText = "MyRecSet" };
            //------------Execute Test---------------------------
            var errorInfo = rule.Check();
            //------------Assert Results-------------------------
            Assert.IsNotNull(errorInfo);
            Assert.AreEqual("MyRecSet - Recordset index (**) contains invalid character(s)", errorInfo.Message);
        }
        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;

        }
        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;
        }
예제 #30
0
        public void IsValidExpressionRule_Check_VariableExpressionIsValid_ReturnsNoError()
        {
            //------------Setup for test--------------------------
            const string trueString = "True";
            const string noneString = "None";
            var datalist = string.Format("<DataList><var Description=\"{0}\" IsEditable=\"\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString);

            var rule = new IsValidExpressionRule(() => "[[a]]", datalist) { LabelText = "MyVar" };
            //------------Execute Test---------------------------
            var errorInfo = rule.Check();
            //------------Assert Results-------------------------
            Assert.IsNull(errorInfo);
        }
예제 #31
0
        // ReSharper restore RedundantOverridenMember

        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            IDSFDataObject       dataObject      = context.GetExtension <IDSFDataObject>();
            IDataListCompiler    compiler        = DataListFactory.CreateDataListCompiler();
            IDev2MergeOperations mergeOperations = new Dev2MergeOperations();
            ErrorResultTO        allErrors       = new ErrorResultTO();
            ErrorResultTO        errorResultTo   = new ErrorResultTO();
            Guid executionId = DataListExecutionID.Get(context);
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(true);

            toUpsert.IsDebug    = dataObject.IsDebugMode();
            toUpsert.ResourceID = dataObject.ResourceID;

            InitializeDebug(dataObject);
            try
            {
                CleanArguments(MergeCollection);

                if (MergeCollection.Count <= 0)
                {
                    return;
                }

                IDev2IteratorCollection iteratorCollection = Dev2ValueObjectFactory.CreateIteratorCollection();


                allErrors.MergeErrors(errorResultTo);
                Dictionary <int, List <IDev2DataListEvaluateIterator> > listOfIterators = new Dictionary <int, List <IDev2DataListEvaluateIterator> >();

                #region Create a iterator for each row in the data grid in the designer so that the right iteration happen on the data

                int dictionaryKey = 0;
                foreach (DataMergeDTO row in MergeCollection)
                {
                    IBinaryDataListEntry inputVariableExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.InputVariable, false, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);

                    IBinaryDataListEntry atExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.At, false, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);

                    IBinaryDataListEntry paddingExpressionEntry = compiler.Evaluate(executionId, enActionType.User, row.Padding, false, out errorResultTo);
                    allErrors.MergeErrors(errorResultTo);

                    var fieldName        = row.InputVariable;
                    var splitIntoRegions = DataListCleaningUtils.FindAllLanguagePieces(fieldName);
                    var datalist         = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errorResultTo).ToString();
                    if (!string.IsNullOrEmpty(datalist))
                    {
                        foreach (var region in splitIntoRegions)
                        {
                            var r           = DataListUtil.IsValueRecordset(region) ? DataListUtil.ReplaceRecordsetIndexWithBlank(region) : region;
                            var isValidExpr = new IsValidExpressionRule(() => r, datalist)
                            {
                                LabelText = fieldName
                            };

                            var errorInfo = isValidExpr.Check();
                            if (errorInfo != null)
                            {
                                row.InputVariable = "";
                                errorResultTo.AddError(errorInfo.Message);
                            }
                            allErrors.MergeErrors(errorResultTo);
                        }
                    }

                    allErrors.MergeErrors(errorResultTo);

                    if (dataObject.IsDebugMode())
                    {
                        DebugItem debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", (MergeCollection.IndexOf(row) + 1).ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugItemVariableParams(row.InputVariable, "", inputVariableExpressionEntry, executionId), debugItem);
                        AddDebugItem(new DebugItemStaticDataParams(row.MergeType, "With"), debugItem);
                        AddDebugItem(new DebugItemVariableParams(row.At, "Using", atExpressionEntry, executionId), debugItem);
                        AddDebugItem(new DebugItemVariableParams(row.Padding, "Pad", paddingExpressionEntry, executionId), debugItem);

                        //Old workflows don't have this set.
                        if (row.Alignment == null)
                        {
                            row.Alignment = string.Empty;
                        }

                        AddDebugItem(DataListUtil.IsEvaluated(row.Alignment) ? new DebugItemStaticDataParams("", row.Alignment, "Align") : new DebugItemStaticDataParams(row.Alignment, "Align"), debugItem);

                        _debugInputs.Add(debugItem);
                    }

                    IDev2DataListEvaluateIterator itr    = Dev2ValueObjectFactory.CreateEvaluateIterator(inputVariableExpressionEntry);
                    IDev2DataListEvaluateIterator atItr  = Dev2ValueObjectFactory.CreateEvaluateIterator(atExpressionEntry);
                    IDev2DataListEvaluateIterator padItr = Dev2ValueObjectFactory.CreateEvaluateIterator(paddingExpressionEntry);

                    iteratorCollection.AddIterator(itr);
                    iteratorCollection.AddIterator(atItr);
                    iteratorCollection.AddIterator(padItr);

                    listOfIterators.Add(dictionaryKey, new List <IDev2DataListEvaluateIterator> {
                        itr, atItr, padItr
                    });
                    dictionaryKey++;
                }

                #endregion

                #region Iterate and Merge Data
                if (!allErrors.HasErrors())
                {
                    while (iteratorCollection.HasMoreData())
                    {
                        int pos = 0;
                        foreach (var iterator in listOfIterators)
                        {
                            var val = iteratorCollection.FetchNextRow(iterator.Value[0]);
                            var at  = iteratorCollection.FetchNextRow(iterator.Value[1]);
                            var pad = iteratorCollection.FetchNextRow(iterator.Value[2]);

                            if (val != null)
                            {
                                if (at != null)
                                {
                                    if (pad != null)
                                    {
                                        if (MergeCollection[pos].MergeType == "Index")
                                        {
                                            if (string.IsNullOrEmpty(at.TheValue))
                                            {
                                                allErrors.AddError("The 'Using' value cannot be blank.");
                                            }

                                            int atValue;
                                            if (!Int32.TryParse(at.TheValue, out atValue) || atValue < 0)
                                            {
                                                allErrors.AddError("The 'Using' value must be a real number.");
                                            }
                                            if (pad.TheValue.Length > 1)
                                            {
                                                allErrors.AddError("'Padding' must be a single character");
                                            }
                                        }
                                        else
                                        {
                                            if (MergeCollection[pos].MergeType == "Chars" && string.IsNullOrEmpty(at.TheValue))
                                            {
                                                allErrors.AddError("The 'Using' value cannot be blank.");
                                            }
                                        }
                                        mergeOperations.Merge(val.TheValue, MergeCollection[pos].MergeType, at.TheValue, pad.TheValue, MergeCollection[pos].Alignment);
                                        pos++;
                                    }
                                }
                            }
                        }
                    }
                    if (!allErrors.HasErrors())
                    {
                        if (string.IsNullOrEmpty(Result))
                        {
                            AddDebugOutputItem(new DebugItemStaticDataParams("", ""));
                        }
                        else
                        {
                            var rule   = new IsSingleValueRule(() => Result);
                            var single = rule.Check();
                            if (single != null)
                            {
                                allErrors.AddError(single.Message);
                            }
                            else
                            {
                                toUpsert.Add(Result, mergeOperations.MergeData.ToString());
                                toUpsert.FlushIterationFrame();
                                compiler.Upsert(executionId, toUpsert, out errorResultTo);
                                allErrors.MergeErrors(errorResultTo);

                                if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                                {
                                    foreach (var debugOutputTo in toUpsert.DebugOutputs)
                                    {
                                        if (debugOutputTo.LeftEntry != null && debugOutputTo.TargetEntry != null)
                                        {
                                            AddDebugOutputItem(new DebugItemVariableParams(debugOutputTo));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                #endregion Iterate and Merge Data
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFDataMerge", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                #region Handle Errors

                if (allErrors.HasErrors())
                {
                    if (dataObject.IsDebugMode())
                    {
                        AddDebugOutputItem(new DebugItemStaticDataParams("", Result, ""));
                    }
                    DisplayAndWriteError("DsfDataMergeActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errorResultTo);
                    compiler.Upsert(executionId, Result, (string)null, out errorResultTo);
                }

                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }

                #endregion
            }
        }
예제 #32
0
        public void IsValidExpressionRule_Check_VariableExpressionHasAnUnderscore_ReturnsAnError()
        {
            //------------Setup for test--------------------------
            const string trueString = "True";
            const string noneString = "None";
            var datalist = string.Format("<DataList><var Description=\"{0}\" IsEditable=\"\" ColumnIODirection=\"{1}\" /><a Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /><rec Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" ><set Description=\"\" IsEditable=\"{0}\" ColumnIODirection=\"{1}\" /></rec></DataList>", trueString, noneString);

            var rule = new IsValidExpressionRule(() => "[[a_b]]", datalist) { LabelText = "MyVar" };
            //------------Execute Test---------------------------
            var errorInfo = rule.Check();
            //------------Assert Results-------------------------
            Assert.IsNotNull(errorInfo);
            Assert.AreEqual("MyVar -  [[a_b]] does not exist in your variable list", errorInfo.Message);
        }
예제 #33
0
        // ReSharper restore RedundantOverridenMember

        protected override void OnExecute(NativeActivityContext context)
        {
            _debugOutputs.Clear();
            _debugInputs.Clear();

            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false);

            toUpsert.IsDebug    = (dataObject.IsDebugMode());
            toUpsert.ResourceID = dataObject.ResourceID;

            InitializeDebug(dataObject);

            ErrorResultTO errors      = new ErrorResultTO();
            ErrorResultTO allErrors   = new ErrorResultTO();
            Guid          executionId = DataListExecutionID.Get(context);

            try
            {
                if (!errors.HasErrors())
                {
                    foreach (ActivityDTO t in FieldsCollection)
                    {
                        if (!string.IsNullOrEmpty(t.FieldName))
                        {
                            var fieldName = t.FieldName;
                            fieldName = DataListUtil.IsValueRecordset(fieldName) ? DataListUtil.ReplaceRecordsetIndexWithBlank(fieldName) : fieldName;
                            var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), enTranslationDepth.Shape, out errors).ToString();
                            if (!string.IsNullOrEmpty(datalist))
                            {
                                var isValidExpr = new IsValidExpressionRule(() => fieldName, datalist)
                                {
                                    LabelText = fieldName
                                };

                                var errorInfo = isValidExpr.Check();
                                if (errorInfo != null)
                                {
                                    t.FieldName = "";
                                    errors.AddError(errorInfo.Message);
                                }
                                allErrors.MergeErrors(errors);
                            }

                            string eval = t.FieldValue;

                            if (eval.StartsWith("@"))
                            {
                                eval = GetEnviromentVariable(dataObject, context, eval);
                            }

                            toUpsert.Add(t.FieldName, eval);
                        }
                    }

                    compiler.Upsert(executionId, toUpsert, out errors);
                    allErrors.MergeErrors(errors);

                    if (dataObject.IsDebugMode() && !allErrors.HasErrors())
                    {
                        AddDebugTos(toUpsert, executionId);
                    }
                    allErrors.MergeErrors(errors);
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error(e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfAssignActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    if (hasErrors)
                    {
                        AddDebugTos(toUpsert, executionId);
                    }
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
예제 #34
0
        public override IRuleSet GetRuleSet(string propertyName, string datalist)
        {
            var ruleSet = new RuleSet();
            if(IsEmpty())
            {
                return ruleSet;
            }

            switch(propertyName)
            {
                case "OutputVariable":
                    if (!string.IsNullOrEmpty(OutputVariable))
                    {
                        var outputExprRule = new IsValidExpressionRule(() => OutputVariable, datalist, "0");
                        ruleSet.Add(outputExprRule);
                        ruleSet.Add(new IsValidExpressionRule(() => outputExprRule.ExpressionValue, datalist));
                    }
                    break;

                case "At":
                    switch(SplitType)
                    {
                        case SplitTypeIndex:
                            var atIndexExprRule = new IsValidExpressionRule(() => At, datalist, "1");
                            ruleSet.Add(atIndexExprRule);
                            ruleSet.Add(new IsPositiveNumberRule(() => atIndexExprRule.ExpressionValue));
                            break;
                        case SplitTypeChars:
                            var atCharsExprRule = new IsValidExpressionRule(() => At, datalist, ",");
                            ruleSet.Add(atCharsExprRule);
                            ruleSet.Add(new IsStringEmptyRule(() => atCharsExprRule.ExpressionValue));
                            break;
                    }
                    break;
            }
            return ruleSet;
        }
예제 #35
0
        private IDev2Tokenizer CreateSplitPattern(ref string stringToSplit, IEnumerable <DataSplitDTO> args, IDataListCompiler compiler, Guid dlId, out ErrorResultTO errors)
        {
            Dev2TokenizerBuilder dtb = new Dev2TokenizerBuilder {
                ToTokenize = stringToSplit, ReverseOrder = ReverseOrder
            };

            errors = new ErrorResultTO();

            foreach (DataSplitDTO t in args)
            {
                var fieldName = t.OutputVariable;
                t.At = t.At ?? "";
                if (!string.IsNullOrEmpty(_datalistString))
                {
                    var isValidExpr = new IsValidExpressionRule(() => fieldName, _datalistString)
                    {
                        LabelText = fieldName
                    };

                    var errorInfo = isValidExpr.Check();
                    if (errorInfo != null)
                    {
                        errors.AddError(errorInfo.Message);
                        continue;
                    }
                }

                IBinaryDataListEntry entry;
                string error;
                switch (t.SplitType)
                {
                case "Index":
                    try
                    {
                        entry = compiler.Evaluate(dlId, enActionType.User, t.At, false, out errors);
                        string index    = DataListUtil.GetValueAtIndex(entry, 1, out error);
                        int    indexNum = Convert.ToInt32(index);
                        if (indexNum > 0)
                        {
                            dtb.AddIndexOp(indexNum);
                        }
                    }
                    catch (Exception ex)
                    {
                        errors.AddError(ex.Message);
                    }
                    break;

                case "End":
                    dtb.AddEoFOp();
                    break;

                case "Space":
                    dtb.AddTokenOp(" ", t.Include);
                    break;

                case "Tab":
                    dtb.AddTokenOp("\t", t.Include);
                    break;

                case "New Line":
                    if (stringToSplit.Contains("\r\n"))
                    {
                        dtb.AddTokenOp("\r\n", t.Include);
                    }
                    else if (stringToSplit.Contains("\n"))
                    {
                        dtb.AddTokenOp("\n", t.Include);
                    }
                    else if (stringToSplit.Contains("\r"))
                    {
                        dtb.AddTokenOp("\r", t.Include);
                    }
                    break;

                case "Chars":
                    if (!string.IsNullOrEmpty(t.At))
                    {
                        entry = compiler.Evaluate(dlId, enActionType.User, t.At, false, out errors);

                        string val    = DataListUtil.GetValueAtIndex(entry, 1, out error);
                        string escape = t.EscapeChar;
                        if (!String.IsNullOrEmpty(escape))
                        {
                            entry  = compiler.Evaluate(dlId, enActionType.User, t.EscapeChar, false, out errors);
                            escape = DataListUtil.GetValueAtIndex(entry, 1, out error);
                        }

                        dtb.AddTokenOp(val, t.Include, escape);
                    }
                    break;
                }
                _indexCounter++;
            }
            return(string.IsNullOrEmpty(dtb.ToTokenize) || errors.HasErrors() ? null : dtb.Generate());
        }
예제 #36
0
        // ReSharper restore RedundantOverridenMember


        /// <summary>
        /// The execute method that is called when the activity is executed at run time and will hold all the logic of the activity
        /// </summary>
        protected override void OnExecute(NativeActivityContext context)
        {
            _debugInputs  = new List <DebugItem>();
            _debugOutputs = new List <DebugItem>();
            _indexCounter = 0;
            IDSFDataObject    dataObject = context.GetExtension <IDSFDataObject>();
            IDataListCompiler compiler   = DataListFactory.CreateDataListCompiler();

            ErrorResultTO allErrors = new ErrorResultTO();
            ErrorResultTO errors;
            Guid          executionId = DataListExecutionID.Get(context);
            IDev2DataListUpsertPayloadBuilder <string> toUpsert = Dev2DataListBuilderFactory.CreateStringDataListUpsertBuilder(false);

            InitializeDebug(dataObject);

            try
            {
                CleanArgs();

                toUpsert.IsDebug = dataObject.IsDebugMode();

                foreach (var item in ConvertCollection)
                {
                    try
                    {
                        _indexCounter++;
                        // Travis.Frisinger - This needs to be in the ViewModel not here ;)
                        if (item.ToExpression == string.Empty)
                        {
                            item.ToExpression = item.FromExpression;
                        }
                        IsSingleValueRule.ApplyIsSingleValueRule(item.FromExpression, allErrors);
                        var fieldName = item.FromExpression;
                        fieldName = DataListUtil.IsValueRecordset(fieldName) ? DataListUtil.ReplaceRecordsetIndexWithBlank(fieldName) : fieldName;
                        var datalist = compiler.ConvertFrom(dataObject.DataListID, DataListFormat.CreateFormat(GlobalConstants._Studio_XML), Dev2.DataList.Contract.enTranslationDepth.Shape, out errors);
                        if (!datalist.IsNullOrEmpty())
                        {
                            var isValidExpr = new IsValidExpressionRule(() => fieldName, datalist.ToString())
                            {
                                LabelText = fieldName
                            };

                            var errorInfo = isValidExpr.Check();
                            if (errorInfo != null)
                            {
                                item.FromExpression = "";
                                errors.AddError(errorInfo.Message);
                            }
                            allErrors.MergeErrors(errors);
                        }

                        IBinaryDataListEntry tmp = compiler.Evaluate(executionId, enActionType.User, item.FromExpression, false, out errors);
                        if (dataObject.IsDebugMode())
                        {
                            AddDebugInputItem(item.FromExpression, tmp, executionId, item.FromType, item.ToType);
                        }
                        allErrors.MergeErrors(errors);
                        if (tmp != null)
                        {
                            IDev2DataListEvaluateIterator itr = Dev2ValueObjectFactory.CreateEvaluateIterator(tmp);

                            IBaseConverter        from   = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.FromType, typeof(enDev2BaseConvertType)));
                            IBaseConverter        to     = _fac.CreateConverter((enDev2BaseConvertType)Dev2EnumConverter.GetEnumFromStringDiscription(item.ToType, typeof(enDev2BaseConvertType)));
                            IBaseConversionBroker broker = _fac.CreateBroker(from, to);

                            // process result information
                            while (itr.HasMoreRecords())
                            {
                                IList <IBinaryDataListItem> cols = itr.FetchNextRowData();
                                foreach (IBinaryDataListItem c in cols)
                                {
                                    // set up live flushing iterator details
                                    if (c.IsDeferredRead)
                                    {
                                        if (toUpsert != null)
                                        {
                                            toUpsert.HasLiveFlushing      = true;
                                            toUpsert.LiveFlushingLocation = executionId;
                                        }
                                    }

                                    int indexToUpsertTo = c.ItemCollectionIndex;

                                    string val        = string.IsNullOrEmpty(c.TheValue) ? "" : broker.Convert(c.TheValue);
                                    string expression = item.ToExpression;

                                    if (DataListUtil.IsValueRecordset(item.ToExpression) && DataListUtil.GetRecordsetIndexType(item.ToExpression) == enRecordsetIndexType.Star)
                                    {
                                        expression = item.ToExpression.Replace(GlobalConstants.StarExpression, indexToUpsertTo.ToString(CultureInfo.InvariantCulture));
                                    }
                                    toUpsert.Add(expression, val);
                                    if (toUpsert != null && toUpsert.HasLiveFlushing)
                                    {
                                        toUpsert.FlushIterationFrame();
                                        toUpsert = null;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error("DSFBaseConvert", e);
                        allErrors.AddError(e.Message);
                    }
                    finally
                    {
                        if (allErrors.HasErrors())
                        {
                            toUpsert.Add(item.ToExpression, null);
                        }
                    }
                }

                if (toUpsert != null && toUpsert.HasLiveFlushing)
                {
                    try
                    {
                        toUpsert.FlushIterationFrame();
                    }
                    catch (Exception e)
                    {
                        Dev2Logger.Log.Error("DSFBaseConvert", e);
                        allErrors.AddError(e.Message);
                    }
                }
                else
                {
                    compiler.Upsert(executionId, toUpsert, out errors);
                    allErrors.MergeErrors(errors);
                }

                if (!allErrors.HasErrors() && toUpsert != null)
                {
                    var outIndex = 1;
                    foreach (var debugOutputTo in toUpsert.DebugOutputs)
                    {
                        var debugItem = new DebugItem();
                        AddDebugItem(new DebugItemStaticDataParams("", outIndex.ToString(CultureInfo.InvariantCulture)), debugItem);
                        AddDebugItem(new DebugItemVariableParams(debugOutputTo), debugItem);
                        _debugOutputs.Add(debugItem);
                        outIndex++;
                    }
                }
            }
            catch (Exception e)
            {
                Dev2Logger.Log.Error("DSFBaseConvert", e);
                allErrors.AddError(e.Message);
            }
            finally
            {
                // Handle Errors
                var hasErrors = allErrors.HasErrors();
                if (hasErrors)
                {
                    DisplayAndWriteError("DsfBaseConvertActivity", allErrors);
                    compiler.UpsertSystemTag(dataObject.DataListID, enSystemTag.Dev2Error, allErrors.MakeDataListReady(), out errors);
                }
                if (dataObject.IsDebugMode())
                {
                    DispatchDebugState(context, StateType.Before);
                    DispatchDebugState(context, StateType.After);
                }
            }
        }
예제 #37
0
        public override IRuleSet GetRuleSet(string propertyName, string datalist)
        {
            RuleSet ruleSet = new RuleSet();
            if (IsEmpty())
            {
                return ruleSet;
            }
            switch (propertyName)
            {
                case "Input":
                    if (!string.IsNullOrEmpty(InputVariable))
                    {
                        var inputExprRule = new IsValidExpressionRule(() => InputVariable, datalist, "0");
                        ruleSet.Add(inputExprRule);
                    }
                    else
                        ruleSet.Add(new IsStringEmptyRule(() => InputVariable));
                    break;
                case "At":
                    if (MergeType == MergeTypeIndex)
                    {
                        var atExprRule = new IsValidExpressionRule(() => At, datalist, "1");
                        ruleSet.Add(atExprRule);

                        ruleSet.Add(new IsStringEmptyRule(() => atExprRule.ExpressionValue));
                        ruleSet.Add(new IsPositiveNumberRule(() => atExprRule.ExpressionValue));
                    }
                    break;
                case "Padding":
                    if (!string.IsNullOrEmpty(Padding))
                    {
                        var paddingExprRule = new IsValidExpressionRule(() => Padding, datalist, "0");
                        ruleSet.Add(paddingExprRule);

                        ruleSet.Add(new IsSingleCharRule(() => paddingExprRule.ExpressionValue));
                    }
                    break;
            }
            return ruleSet;
        }
        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);
        }