Example #1
0
        public bool Execute(ILeadEntity leadEntity)
        {
            // Create an array that specifies the types of the parameters
            // TODO this needs to be A LOT more if going this way!
            // Type[] validatorArgList = GetArgumentTypes("ILeadEntity");

            // leadEntity will be input parameter for the validators
            object[] argObjects = new object[] { leadEntity };

            // Select all the validators from the database
            var validatorMethodName = String.Empty;

            using (var db = new ValidatorContext())
            {
                foreach (var validator in db.Validators)
                {
                    validatorMethodName = validator.ClassName;
                    Console.WriteLine($"{validatorMethodName} | {validator.ClassName}");
                    //Invoke the Method within the Class
                    var valid = (bool)classType.InvokeMember(validatorMethodName, BindingFlags.InvokeMethod, null, null, argObjects);
                    Console.WriteLine($"Returned {valid}");
                }
            }


            Console.WriteLine($"Invoked validators in {validatorClassName}.");
            Console.ReadKey();

            return(true);
        }
Example #2
0
        public List <ValidatorClassAndAssemblyData> LeadCollectorValidatorClassAndAssemblyList()
        {
            var classAndAssemblyList = new List <ValidatorClassAndAssemblyData>();

            // Create the className List
            using (var context = new ValidatorContext())
            {
                int    prevAssemblyId = 0; //Initialize to force first lookup for ControlAssemblyId
                string assemblyName   = String.Empty;
                foreach (var leadCollectorValidator in context.LeadCollectorValidators)
                {
                    // Select the validator
                    var validator = context.Validators.FirstOrDefault(v => v.ValidatorId == leadCollectorValidator.ValidatorId);

                    // Select different Assembly if different from prev - Most Validators in same assembly
                    if (validator != null && validator.ControlAssemblyId != prevAssemblyId)
                    {
                        assemblyName = context.ControlAssemblies.Where(a => a.ControlAssemblyId == validator.ControlAssemblyId).Select(a => a.AssemblyName)
                                       .SingleOrDefault();
                        prevAssemblyId = validator.ControlAssemblyId;
                    }

                    if (validator != null)
                    {
                        classAndAssemblyList.Add(new ValidatorClassAndAssemblyData(validator.ClassName, assemblyName));
                    }
                }
                return(classAndAssemblyList);
            }
        }