WordPress database error: [INSERT, UPDATE command denied to user '51213-2'@'10.10.20.64' for table 'wp_options']INSERT INTO `wp_options` (`option_name`, `option_value`, `autoload`) VALUES ('_transient_doing_cron', '1725758664.6659259796142578125000', 'yes') ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)
Silverlight, with is asynchronous philosophy provided the INotifyDataErrorInfo which performed the same thing but asyncrhonously.<\/p>\n It is a newinterface of WPF 4.5 and we will discover it in this post.<\/p>\n <\/p>\n Here is the definition of it: As you can see there is only 3 things inside:<\/p>\n As a note, if you return false in the HasErrors property, the binding will act as if there were no errors, even if they exists. <\/p>\n With the traditionnal IDataErrorInfo, you have to set to true the ValidatesOnDataErrors property on each binding to your object. There is nothing really new under the sun because this time you have to set the ValidatesOnNotifyDataErrors property to true<\/strong>. <\/p>\n In the linked demo project I create a form which display the properties of an object named ‘Person’. Here is how the validation with INotifyDataErrorInfo is enabled in the Binding: The binding will then register itself for the ErrorsChanged event of the binded Person. Eeach time this event is raised for the binded property, the controls will dress itself to display an error. As pointed out before, this is done only if the HasErrors is set to true.<\/strong><\/p>\n I have implemented a delay in the validation of the Person class. The validations occured after each set of any properties but it is delayed by ‘WaitSecondsBeforeValidation’ seconds.<\/p>\n I also maintain a dictionary of all the errors by property name and use it to provide them via the GetErros methods. The HasErrors property returns true if this any error exists in this dictionary. Here is the code for this basic implementation: public bool HasErrors private Dictionary private void Validate() private object _lock = new object(); if (String.IsNullOrEmpty(Name)) _errors[“Name”] = errorsForName; \/\/Validate Age if (Age <= 0)\n errorsForAge.Add(\"The age must be greater than zero.\");\n\n _errors[\"Age\"] = errorsForAge;\n if (errorsForAge.Count > 0) RaiseErrorsChanged(“Age”); Finally, I have created a RaiseErrorsChanged method which ease the raising of Validations event errors: The demo application can be found on this Dropbox folder<\/a>. Don’t forget to register yourself on dropbox using this link \ud83d\ude42<\/a>.<\/p>\n<\/a>Here is the first post of a serie about the new features of WPF 4.5<\/a>. Validation of data is often if not always necessary in modern applications. From a long time, WPF provided the IDataErrorInfo interfaces which permitted the automatic validation of your properties. <\/p>\n
What’s inside ?<\/h3>\n
\n<\/a><\/p>\n
\n
How to use it ?<\/h3>\n
\n[xml]
\n[csharp]public System.Collections.IEnumerable GetErrors(string propertyName)
\n{
\n List
\n _errors.TryGetValue(“Name”, out errorsForName);
\n return errorsForName;
\n}<\/p>\n
\n{
\n get { return _errors.Values.FirstOrDefault(l => l.Count > 0) != null; }
\n}<\/p>\n
\n new Dictionary
\n{
\n Task waitTask = new Task(() => Thread.Sleep(
\n TimeSpan.FromSeconds(WaitSecondsBeforeValidation)));
\n waitTask.ContinueWith((_) => RealValidation());
\n waitTask.Start();
\n}<\/p>\n
\nprivate void RealValidation()
\n{
\n lock (_lock)
\n {
\n \/\/Validate Name
\n List
\n if (!_errors.TryGetValue(“Name”, out errorsForName))
\n errorsForName = new List
\n else errorsForName.Clear();<\/p>\n
\n errorsForName.Add(“The name can’t be null or empty.”);<\/p>\n
\n if (errorsForName.Count > 0) RaiseErrorsChanged(“Name”);<\/p>\n
\n List
\n if (!_errors.TryGetValue(“Age”, out errorsForAge))
\n errorsForAge = new List
\n else errorsForAge.Clear();<\/p>\n
\n }
\n[\/csharp]<\/p>\n
\n[csharp] public event EventHandler
\n public void RaiseErrorsChanged(string propertyName)
\n {
\n EventHandler
\n if (handler == null) return;
\n var arg = new DataErrorsChangedEventArgs(propertyName);
\n handler.Invoke(this, arg);
\n }
\n[\/csharp]<\/p>\nDemo application<\/h3>\n