Exemplo n.º 1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            //NOTE...IMPORTANT!:
            //This is an example of how-to-change-the-configuration.
            //You should maintain in your code just 1 (one) ValidatorEngine,
            //see SharedEngine: http://nhibernate.info/blog/2009/02/26/diving-in-nhibernate-validator.html

            ValidatorEngine ve = vvtor.ValidatorEngine;

            ve.Clear();

            //Configuration of NHV. You can also configure this stuff using xml, outside of the code
            XmlConfiguration nhvc = new XmlConfiguration();

            nhvc.Properties[Environment.ApplyToDDL]            = "false";
            nhvc.Properties[Environment.AutoregisterListeners] = "false";
            nhvc.Properties[Environment.ValidatorMode]         = GetMode();
            nhvc.Mappings.Add(new MappingConfiguration("NHibernate.Validator.Demo.Winforms", null));
            ve.Configure(nhvc);

            Customer customer = GetCustomerFromUI();

            if (ve.IsValid(customer))
            {
                listBox1.Items.Clear();
                Send();
            }
            else
            {
                InvalidValue[] values = ve.Validate(customer);
                FillErrorsOnListBox(values);
            }
        }
Exemplo n.º 2
0
        protected override void Configure(NHibernate.Cfg.Configuration configuration)
        {
            // The ValidatorInitializer and the ValidateEventListener share the same engine

            // Initialize the SharedEngine
            fortest = new NHibernateSharedEngineProvider();
            Cfg.Environment.SharedEngineProvider = fortest;
            ValidatorEngine ve = Cfg.Environment.SharedEngineProvider.GetEngine();

            ve.Clear();

            XmlConfiguration nhvc = new XmlConfiguration();

            nhvc.Properties[Cfg.Environment.ApplyToDDL]               = "true";
            nhvc.Properties[Cfg.Environment.AutoregisterListeners]    = "true";
            nhvc.Properties[Cfg.Environment.ValidatorMode]            = "UseAttribute";
            nhvc.Properties[Cfg.Environment.MessageInterpolatorClass] = typeof(PrefixMessageInterpolator).AssemblyQualifiedName;

            var enversConf = new FluentConfiguration();

            enversConf.Audit <Address>();
            configuration.IntegrateWithEnvers(enversConf);

            ve.Configure(nhvc);

            ValidatorInitializer.Initialize(configuration);
        }
Exemplo n.º 3
0
        protected override void Configure(NHibernate.Cfg.Configuration configuration)
        {
            Environment.SharedEngineProvider = new NHibernateSharedEngineProvider();
            vtor = Environment.SharedEngineProvider.GetEngine();
            vtor.Clear();
            var nhvc = new XmlConfiguration();
            nhvc.Properties[Environment.ApplyToDDL] = "false";
            nhvc.Properties[Environment.AutoregisterListeners] = "true";
            nhvc.Properties[Environment.ValidatorMode] = "UseAttribute";
            vtor.Configure(nhvc);

            configuration.Initialize();
        }
        protected override void Configure(NHibernate.Cfg.Configuration configuration)
        {
            Environment.SharedEngineProvider = new NHibernateSharedEngineProvider();
            vengine = Environment.SharedEngineProvider.GetEngine();
            vengine.Clear();
            XmlConfiguration nhvc = new XmlConfiguration();

            nhvc.Properties[Environment.ApplyToDDL]            = "false";
            nhvc.Properties[Environment.AutoregisterListeners] = "true";
            nhvc.Properties[Environment.ValidatorMode]         = "UseAttribute";
            vengine.Configure(nhvc);

            ValidatorInitializer.Initialize(configuration);
        }
Exemplo n.º 5
0
        protected override void Configure(Configuration configuration)
        {
            // The ValidatorInitializer and the ValidateEventListener share the same engine

            // Initialize the SharedEngine
            fortest = new NHibernateSharedEngineProvider();
            Cfg.Environment.SharedEngineProvider = fortest;
            ValidatorEngine ve = Cfg.Environment.SharedEngineProvider.GetEngine();

            ve.Clear();
            XmlConfiguration nhvc = new XmlConfiguration();

            nhvc.Properties[Cfg.Environment.ApplyToDDL]               = "true";
            nhvc.Properties[Cfg.Environment.AutoregisterListeners]    = "true";
            nhvc.Properties[Cfg.Environment.ValidatorMode]            = "UseAttribute";
            nhvc.Properties[Cfg.Environment.MessageInterpolatorClass] = typeof(PrefixMessageInterpolator).AssemblyQualifiedName;
            ve.Configure(nhvc);
            ve.IsValid(new AnyClass());            // add the element to engine for test

            ValidatorInitializer.Initialize(configuration);
        }