<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="http://syndication.webwiz.co.uk/rss_namespace/">
 <channel>
  <title>DevForce Community Forum : Crazy idea making custom verifications</title>
  <link>http://www.ideablade.com/forum/</link>
  <description>This is an XML content feed of; DevForce Community Forum : DevForce 2010 : Crazy idea making custom verifications</description>
  <pubDate>Wed, 13 May 2026 03:47:59 -700</pubDate>
  <lastBuildDate>Fri, 03 Aug 2012 15:22:03 -700</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 9.69</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>www.ideablade.com/forum/RSS_post_feed.asp?TID=3566</WebWizForums:feedURL>
  <image>
   <title>DevForce Community Forum</title>
   <url>http://www.ideablade.com/forum/forum_images/IdeaBlade_logo_tm.png</url>
   <link>http://www.ideablade.com/forum/</link>
  </image>
  <item>
   <title>Crazy idea making custom verifications :   Ward,Nice to see you replying...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3566&amp;PID=14139#14139</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1264" rel="nofollow">katit</a><br /><strong>Subject:</strong> 3566<br /><strong>Posted:</strong> 03-Aug-2012 at 3:22pm<br /><br />Ward,<div>&nbsp;</div><div>Nice to see you replying :)</div><div>&nbsp;</div><div>Yes, your suggestion will help me clear out last "stinky" piece from my code. I think I got this thing under control. Everything lives in my BaseViewModel so it's hidden from individual VMs. Here is bullet point for my entity saving/validations:</div><div>&nbsp;</div><div>1. I run async validations on save only, not on each property set.</div><div>2. I run async validations in parallel (hello Coroutine)</div><div>3. I run save process in series (hello Coroutine)</div><div>4. Exception in process stops processing</div><div>5. Whole process covered with IsBusy so&nbsp;I do block toolbar and show indication of something going on in my View</div><div>&nbsp;</div><div>Here is "Save" routine in BaseViewModel. </div><div>&nbsp;</div><div><table width="99%"><tr><td class="BBquote"></div><div>private void DoSave(Action onSuccess)<br>{<br>&nbsp;&nbsp;&nbsp; this.IsBusy = true;<br>&nbsp;&nbsp;&nbsp; Coroutine.Start(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.SaveStepsIterator,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; args =&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.IsBusy = false;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (args.HasError)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; args.MarkErrorAsHandled();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DisplayErrorMessage("Error while saving record!", args.Error, true, false, true);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</div><div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // This need to be called if all operations completed successfuly<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (this.ValidationErrors.Count == 0) onSuccess();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<br>}</div><div>private IEnumerable&lt;INotifyCompleted&gt; SaveStepsIterator()<br>{<br>&nbsp;&nbsp;&nbsp; if (!this.OnBeforeIdeaBladeValidation()) yield break;</div><div>&nbsp;&nbsp;&nbsp; this.CurrentItem.EntityAspect.ValidationErrors.Clear();<br>&nbsp;&nbsp;&nbsp; this.CurrentItem.EntityAspect.VerifierEngine.Execute(this.CurrentItem);<br>&nbsp;&nbsp;&nbsp; if (this.ValidationErrors.Count &gt; 0) yield break;</div><div>&nbsp;&nbsp;&nbsp; // Run Async validations<br>&nbsp;&nbsp;&nbsp; this.TemporaryAsyncVerifiers = new List&lt;Verifier&gt;();<br>&nbsp;&nbsp;&nbsp; var asyncValidationsOperation = Coroutine.StartParallel(this.AsyncValidationsBundle);<br>&nbsp;&nbsp;&nbsp; yield return asyncValidationsOperation; // ------------------ SUSPEND WAIT FOR ASYNC VALIDATIONS TO COMPLETE</div><div>&nbsp;&nbsp;&nbsp; // Add all verifiers popylated by async validations to engine, run verification and clean engine<br>&nbsp;&nbsp;&nbsp; foreach (var verifier in this.TemporaryAsyncVerifiers) this.CurrentItem.EntityAspect.VerifierEngine.AddVerifier(verifier);<br>&nbsp;&nbsp;&nbsp; this.CurrentItem.EntityAspect.VerifierEngine.Execute(this.CurrentItem);<br>&nbsp;&nbsp;&nbsp; foreach (var verifier in this.TemporaryAsyncVerifiers) this.CurrentItem.EntityAspect.VerifierEngine.RemoveVerifier(verifier);</div><div>&nbsp;&nbsp;&nbsp; if (this.ValidationErrors.Count &gt; 0) yield break;</div><div>&nbsp;&nbsp;&nbsp; // Save record<br>&nbsp;&nbsp;&nbsp; yield return this.Repository.SubmitEntityManagerChanges(); // ---------------------- SUSPEND WAIT FOR SAVE TO COMPLETE<br>}</div><div></td></tr></table></div><div>&nbsp;</div><div><strong>this.TemporaryAsyncVerifiers</strong> is a stinky part about my code which I will be able to fix by manually injecting results</div><div>&nbsp;</div><div>Here is validators implemented in actual ViewModel. I think it looks decent, will be even cleaner after I make changes:</div><div>&nbsp;</div><div><table width="99%"><tr><td class="BBquote"></div><div>public override IEnumerable&lt;INotifyCompleted&gt; AsyncValidationsBundle()<br>{<br>&nbsp;&nbsp;&nbsp; var userRepository = this.Repository as IUserRepository;</div><div>&nbsp;&nbsp;&nbsp; // Validate user name to make sure no duplicates<br>&nbsp;&nbsp;&nbsp; var checkUserNameOperation = userRepository.CheckForDuplicateUserName(this.CurrentItem.UserName, this.CurrentItem.UserKey);<br>&nbsp;&nbsp;&nbsp; checkUserNameOperation.Completed += (sender, args) =&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (args.Results.Any()) this.TemporaryAsyncVerifiers.Add(this.GetDummyVerifier("User with same user name already exist.", MEMUser.PropertyMetadata.UserName.Name));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br>&nbsp;&nbsp;&nbsp; yield return checkUserNameOperation;</div><div>&nbsp;&nbsp;&nbsp; // Validate user email to make sure no duplicates<br>&nbsp;&nbsp;&nbsp; var checkEmailAddressOperation = userRepository.CheckForDuplicateEmailAddress(this.CurrentItem.EmailAddress, this.CurrentItem.UserKey);<br>&nbsp;&nbsp;&nbsp; checkEmailAddressOperation.Completed += (sender, args) =&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (args.Results.Any())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var userName = args.Results.FirstOrDefault();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!string.IsNullOrEmpty(userName))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.TemporaryAsyncVerifiers.Add(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.GetDummyVerifier(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string.Format("User '{0}' has same email address. Email address must be unique", userName),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MEMUser.PropertyMetadata.EmailAddress.Name));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br>&nbsp;&nbsp;&nbsp; yield return checkEmailAddressOperation;<br>}</div><div></td></tr></table></div><div>&nbsp;</div><div>Basically I add those "always failing" dummy verifiers to TemporaryAsyncVerifiers. This was my only problem.</div><div>&nbsp;</div><div>Now everything snaps together nicely. Coroutines do good job also I really want to learn Rx one day :)</div>]]>
   </description>
   <pubDate>Fri, 03 Aug 2012 15:22:03 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3566&amp;PID=14139#14139</guid>
  </item> 
  <item>
   <title>Crazy idea making custom verifications : Hi katitI can&amp;#039;t be sure of...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3566&amp;PID=14137#14137</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=482" rel="nofollow">WardBell</a><br /><strong>Subject:</strong> 3566<br /><strong>Posted:</strong> 03-Aug-2012 at 12:25pm<br /><br />Hi katit<div><br></div><div>I can't be sure of all of your needs. I confess to be leery of async validations and I am not as familiar with DevForce validation as I once was.</div><div><br></div><div>If I understand, you want to run an async validation for an entity only in a certain environment (e.g., a particular data entry screen). You don't want to do so whenever the property changes; just when the property changes in that environment.</div><div><br></div><div>You also want to leverage the entity's implementation of INotifyDataErrorInfo to project validation error conditions into the UI.</div><div><br></div><div>I think you can achieve this in a more simple way than you are proposing. In particular, I would avoid interacting with the VerifierEngine and would instead manipulate the entity's ValidationErrors collection</div><div><br></div><div>Following your plan, you will run your validation logic asynchronously at the ViewModel level. When the validation returns, you can update the entity's ValidationErrors collection directly. DevForce will raise OnErrorsChanged which should cause the View to update its display of the bound property.</div><div><br></div><div>For example</div><div>- user enters serial number</div><div>- you run async validation method</div><div>- that method returns, indicating that the entered serial number is a duplicate</div><div>- you construct a suitable DevForce VerifierResult with the message and error status</div><div>- add this to the entity's ValidationErrors</div><div>- that raises OnErrorsChanged</div><div>- the UI displays the error</div><div>- the user enters a different serial number</div><div><div>- you run async validation method again</div><div>- that method returns, indicating that the entered serial number is available</div><div>- you remove the "Duplicate Serial Number" VerifierResult that you previously created from the collection</div><div>&nbsp; &#091;alternatively, if you don't want to remember it, you can search the collection for the custom VerifierResult of this type&#093;</div><div>- remove this VerifierResult from the entity's ValidationErrors</div><div>- that raises OnErrorsChanged</div><div>- the UI clears the error display</div></div><div><br></div><div>When the user leaves the screen, you have to decide manually what to do about VerifierResults that you have added. You'll also have to figure out what to do about async validation methods that have not yet returned ... both before you let the user hit save and before letting them abandon the screen (cancel).</div><div><br></div><div>I assume you've already worked out those details for yourself.</div><div><br></div><div>Here's an obvious code snippet to add/remove VRs to an entity's ValidationErrors</div><div><br></div><div><pre style="font-family: C&#111;nsolas; font-size: 19px; : white; -: initial initial; -repeat: initial initial; "><span style="color:blue;">using</span>&nbsp;IbEm&nbsp;&nbsp;&nbsp;=&nbsp;IdeaBlade.EntityModel;<span style="color: blue; ">using</span><span style=": white; ">&nbsp;IbVal&nbsp;&nbsp;=&nbsp;IdeaBlade.Validation;</span></pre><pre style="font-family: C&#111;nsolas; font-size: 19px; : white; -: initial initial; -repeat: initial initial; "><span style="color:blue;">public</span>&nbsp;<span style="color:blue;">static</span>&nbsp;<span style="color:blue;">void</span>&nbsp;AddErrorToEntity(IbEm.<span style="color:#2b91af;">IEntity</span>&nbsp;entity&nbsp;,&nbsp;IbVal.<span style="color:#2b91af;">VerifierResult</span>&nbsp;error){&nbsp;&nbsp;&nbsp;&nbsp;entity.EntityAspect.ValidationErrors.Add(error);}<span style="color:blue;">public</span>&nbsp;<span style="color:blue;">static</span>&nbsp;<span style="color:blue;">void</span>&nbsp;RemoveErrorFromEntity(IbEm.<span style="color:#2b91af;">IEntity</span>&nbsp;entity,&nbsp;IbVal.<span style="color:#2b91af;">VerifierResult</span>&nbsp;error){&nbsp;&nbsp;&nbsp;&nbsp;entity.EntityAspect.ValidationErrors.Remove(error);}</pre></div><div>I haven't tested this. I'm merely suggesting a direction for you to pursue.</div><div><br></div><div>Let us know how this works out.</div><div><br></div><div><br></div>]]>
   </description>
   <pubDate>Fri, 03 Aug 2012 12:25:09 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3566&amp;PID=14137#14137</guid>
  </item> 
  <item>
   <title>Crazy idea making custom verifications :   I&amp;#039;m still battling verification...</title>
   <link>http://www.ideablade.com/forum/forum_posts.asp?TID=3566&amp;PID=14128#14128</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://www.ideablade.com/forum/member_profile.asp?PF=1264" rel="nofollow">katit</a><br /><strong>Subject:</strong> 3566<br /><strong>Posted:</strong> 01-Aug-2012 at 4:02pm<br /><br />I'm still battling verification aspects with Silverlight.<div>&nbsp;</div><div>1. IB verification engine works good for sync verifications (I call them static)</div><div>2. IB verification works good to bubble errors via INotifyDataErrorInfo</div><div>&nbsp;</div><div>But&nbsp;I need to make what I call "dynamic" verifications. I tried different ways and it is working somewhat but there is issues with those. </div><div>&nbsp;</div><div>My implementation is here: <a href="http://www.ideablade.com/forum/forum_posts.asp?TID=2985&amp;title=my-async-verifier-implementati&#111;n" target="_blank">http://www.ideablade.com/forum/forum_posts.asp?TID=2985&amp;title=my-async-verifier-implementation</a></div><div>&nbsp;</div><div>This works great when user fills out a form, I make async verifications and store verified values. Then when user hit's save - all values verified and all is well.</div><div>&nbsp;</div><div>It doesn't work when user opens existing record, make change and hit's save. If there is fields requiring this async verification I need to "wait" for all verifiers to finish async operations which is tricky...</div><div>&nbsp;</div><div>Plus, I'm realizing that if I get into verifying graphs it may get out of control and I can see how I don't wan't to validate childs for example.</div><div>&nbsp;</div><div>So, I think that it is best to do all async and data-driven validations (for example check that serial is not duplicated in database) at view model level. This way same entity may be validated on data entry form but won't be validated when used elsewhere. This is what I want.</div><div>&nbsp;</div><div>Now I have another issue. If I bind directly to entity property - IB need to raise INotifyDataErrorInfo in order to get nice validation red borders, etc.</div><div>&nbsp;</div><div><div>Essentialy I want to do validations manually and then plug results into verification engine so it tells my bindings about it.</div><div> </div><div>1. At ViewModel level create coroutines to run validations in parallel, this will be my functions on ViewModel.</div><div>2. I will run validations before "Save" operation.</div><div>3. When my validations complete and if there is failures  - I will do VerifierEngine.AddVerifier() for each failed one and add custom verifier that will fail with my error message</div><div>4. Call VerifierEngine.Execute so it finds those errors and bubbles to UI</div><div>5. Call VerifierEngine.RemoveVerifier.. to clean up</div><div>&nbsp;</div><div>Does this sound like a good strategy?</div><div>&nbsp;</div><div>I have 1 EntityManager per view, therefore I should be able to control verifiers without a problem.</div></div>]]>
   </description>
   <pubDate>Wed, 01 Aug 2012 16:02:27 -700</pubDate>
   <guid isPermaLink="true">http://www.ideablade.com/forum/forum_posts.asp?TID=3566&amp;PID=14128#14128</guid>
  </item> 
 </channel>
</rss>