Contact Me

Contact Us
For an informal discussion

Everyone's business is different. Our business is software - ask where we can help.
eMail: john at appsolo.com

Archive for August, 2010

Catching CLR runtime errors in Silverlight

Saturday, August 28th, 2010

image thumb4 Catching CLR runtime errors in SilverlightDebugging Silverlight apps is fraught with problems. Often the error message is unhelpful and then there are the misleading ones (‘Page not found’ anyone?). One way to improve your diagnostic skills is to have VS catch CLR run-time errors. This seemingly isn’t enabled by default so press CTRL-ALT-E (for Error) and tick the ‘Thrown’ column for Command Language Runtime exceptions.

As an example, I had difficulty figuring out why a change to my shared ResourceDictionary was causing a problem. With the CLR exception handling enabled, you can see clearly where the problem lay. Without the CLR exception handling, well, nothing but a hung load page.

Silverlight Debugging Issues

Saturday, August 21st, 2010

image thumb3 Silverlight Debugging Issues

Occasionally, a bug manifests itself when debugging a Silverlight app. The problem is that breakpoints set are not triggering a halt in execution. In the code window, the familiar red circle symbol has an exclamation mark over it with the error:

“The breakpoint will not currently be hit. No symbols have been loaded for this document”

After a lot of searching the solution that worked for me was to attach the VS Debugger to the correct process. Choose Debug..Attach to Process in VS and select the correct Silverlight process. Opposite, you’ll see a number of tabs representing the distinct processes that my browser (Chrome) is using – remember, Chrome sandboxes each tab for safety.

Once you click ‘Attach’, the debug symbols are loaded and breakpoints will fire.

 

IsBusyIndicator Bug

Thursday, August 12th, 2010

 IsBusyIndicator BugDuring testing, I noticed excessive CPU usage when working on a particular Silverlight page. It seems particular to two pages but on navigating to others, the problem disappeared, re-appearing on return either of the two pages. Fast forward 5 hours of investigation taking me to xPerf (a performance analysis tool from MS that curiously is buried inside the Windows SDK taking a hour to find!). It told me nothing more than I could see with Task Manager – though it gave a pretty graph of the problem. Google swallowed about an hour of that seeing if the problem were out there. But I still didn’t know what exactly was causing the problem since there were a few elements at play on each page. Cross-comparing, it turned out that the two pages had DomainDataSources in common so naturally (first mistake) that seemed as good a place as any to start.

image thumb2 IsBusyIndicator Bug It wasn’t. There’s a lot to DomainDataSources but ultimately the fault wasn’t there. I used a DomainContext Query call in its place to see if getting the data was at fault – nope. Then the DataForm – really like this control so hoped it wasn’t the culprit. Nope. Okay, now there was nothing left on one of the pages so what gives? Turns out, that page wasn’t to blame. However, in my app, the Home pages loads first (duh) and then I navigate to the Admin page where the problem manifests. So I decided to ‘avoid’ the Home page and open directly on the problem ‘Admin’ page. And this time, no CPU hogging! Seemingly, the problem emanated from the Home page but didn’t manifest until the Admin page. Sneaky.

In the end, the Home page had something peculiar to it – a couple BusyIndicator controls from the Silverlight Toolkit. Some more investigation showed that, well, it didn’t work – you think? I played with templating it since it wasn’t so much the BusyIndicator control that was at fault but the progress bar animation within it. In the end, I took it out – amazing how templating even the simplest of controls takes >100 lines of XAML. Heck, I’m not pulling much data so it would never be seen.

So, progress for over 5 hours work – zilch, nada. Thanks MS – surely a known issue dating back over a year is worthy of some attention?

Dataforms and RIA Services

Tuesday, August 10th, 2010

image thumb1 Dataforms and RIA ServicesInitially, I didn’t take to the DataForm control but it’s growing on me. In our current app, we need to perform standard CRUD on users of the system. The client UI can be seen opposite.

The UI structure is that of a ListBox and DataForm. Both controls pull their data from a DomainDataSource which helps with sorting. The controls also keep in sync thanks to this common DataContext.

The DataForm has a lot to offer. Here’s a quick list of the jobs it handles in this example:

  • AutoEdit set to true means the DataForm lets me edit a selected Author right away.
  • DataField element of a DataForm lets me customise the appearance of the fields – in this case, the Photo field is rendered with a border and doubles as a Button to duplicate the functionality of the ‘Load Image’ Button.
  • CommandButtons (note top right corner) make add, remove and navigation commands available.
  • AutoCommit (set false here) saves changes without explicit ‘Save’ clicking.
  • Say I edit Bill’s password opposite; the ‘Save’ Button enables to support persisting (see caveat below). If however, I continue editing and change password back to ‘Bill’ as per the original value, then the DataForm notices that there really isn’t any change and again disables the ‘Save’ Button. Similar for ‘Reject’ Button. Note also, the custom words used by these Buttons.

The caveat mentioned above has to do with a change introduced to RIA Services in July CTP ‘09. I’m not the best guy to explain the thinking behind the change but the upshot is that changes made using the DataForm while handled properly, do not persist to the backing store. The ‘last mile’ needs to be handled manually with a call to SubmitChanges(). For example, to delete a record:

private void dataForm_DeletingItem(object sender, System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = true;
            // Cancel DataForm's attempt at delete for all cases since DomainDataSource.Data doesn't accommodate changes
            if (MessageBox.Show("Are you sure you want to delete this author?", "Confirm Deletion", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                // Uses DataView to ensure DataForm's currentItem is deleted
                authorDomainDataSource.DataView.Remove(dataForm.CurrentItem);
                authorDomainDataSource.SubmitChanges();
            }
        }

This does muddy the water somewhat but the DataForm is still useful. It also integrates well with metadata added to the DomainService. In the above example, note the little ‘i’ icon next to some fields. These are brought across from the DomainService to the DomainContext which is the basis for the DomainDataSource and from there displayed on screen.

Also, custom validation class added on the web service side are respected by the DataForm. The ‘Save’ Button for example is disabled if there are validation errors. All in all, a reasonably competent way to provide basis CRUD operations on data sources.

RIA stored procedures and Scalar Function mapping

Monday, August 2nd, 2010

This one nearly drove me nuts. But thanks to this Post its solved. When returning a value from a stored procedure in RIA Entity Framework, I could not get the right combination of type conversions between the Entity Domain Model (EDM) Code and the Domain service functions. The solution to my problem was this.

Stored Procedure…..

 

   1: BEGIN

   2:     -- SET NOCOUNT ON added to prevent extra result sets from

   3:     -- interfering with SELECT statements.

   4:     SET NOCOUNT ON;

   5:     DECLARE @mArc int;

   6:     SELECT @mArc = max(ArcID) from dbo.Arc as int;

   7:     SELECT @mArc;

   8: END

 

I am using a reference to a record in a database that has an identity column. I need to get the Max Arc Id which is a newly added record and put it’s reference into a node table that maintains a point of reference to the Arc. This I’m doing this in Entity Framework. As per the Microsoft instructions further explained in the post mentioned above you import the stored procedure and set up a Function Import in the EDM. But the problem is that if you use return in the Stored procedure then the query does not return a workable scalar (it returns –1). So you have to have a select statement at the end of the SP instead of a return and then set up a Scalar return type in the properties of your Function Import as explained in the the above post. 

   1: [Invoke]

   2:         public System.Nullable<int> GetArcMax()

   3:         {

   4:             System.Nullable<int> val = ObjectContext.getMaxArc().SingleOrDefault() ; 

   5:             if (val.HasValue)

   6:                 return val.Value;

   7:             else return null;

   8:             // have to do this in the DB as the only the Arcs associated with the current Key should be loaded

   9:             //if (this.ObjectContext.Arcs.Count<Arc>() == 0)

  10:             //    return 0;

  11:             //     else return this.ObjectContext.Arcs.Max(a => a.ArcID);

  12:         }

Note you have to be careful using Aggregate functions in EF unless you all the records from the database loaded in the current Domain context. I’ve commented out the code that was used prior. Thanks to Anonymous for the Select idea post.

Finally the code to use this in the Domain Context of the EF

   1: [Invoke]

   2:         public  void AddNewNodeMaster(int K)

   3:         {

   4:             int CurrentMax = GetMaxMasterNodeID(K);

   5:             this.ObjectContext.NodeMasters.AddObject(new NodeMaster() { NodeID = CurrentMax + 1, TaxKeyID = K, MasterDescription = "Question Set Description to be filled" });

   6:             // When you add a new MasterNode you need to add a default node and Arc

   7:             this.ObjectContext.Arcs.AddObject(new Arc() { ArcDescription = "Not Set", ArcLabel = "Not Set" });

   8:             this.ObjectContext.SaveChanges(); // new Max does not get updated in DB until changes are submitted - see new GetArcMax

   9:             System.Nullable<int> NextArcId = this.GetArcMax(); // have to check for nullable otherwise it will throw an error is no arcs at all in DB

  10:             if (NextArcId != null)

  11:             {

  12:                 this.ObjectContext.Nodes.AddObject(new Node() { NodeID = CurrentMax + 1, ArcID = NextArcId.Value, TaxKeyID = K });

  13:                 this.ObjectContext.SaveChanges();

  14:             }

  15:         }

Visual Studio Extensions

Sunday, August 1st, 2010

solutionnavigator Visual Studio Extensionstrans Visual Studio ExtensionsVS2010 is a decent IDE. Couple it with Win7 and you can really get some work done. Throw in an unhealthy grasp of keyboard shortcuts and you’re firing on all trans Visual Studio Extensionstrans Visual Studio Extensionscylinders. Then if you’re still stalling on real work and want some more turbo-charging, check out the Visual Studio Gallery of extensions. There’s the handy VS Color Theme Editor to throw some colour into your editing. I like Noah Richards ItalicComments which well, do I have to tell you?

And then there’s the heavy duty add-in – Productivity Power Tools by MS. Thankfully, you can turn on/off individual tweaks that are part of this extension. I like Solution Navigator – think of it as like Solution Explorer, on steroids. Don’t forget to use CTRL-W, F to invoke it (sad, isn’t it?). Especially useful is the way you can select parts of your solution (say, the Web project) as ‘root’ and effect all searches against that part alone.

The Quick Access panel (see top of screenshot opposite) behaves like the search box in Blend – great at avoiding the horrible Find panel that seems perpetually to be off-screen. And, CTRL-3 calls up Quick Access!

Other bits – you can now pin particular windows to ensure they stay open. Braces are automatically matched. Tab window behaviour is improved. You can even colour-code tabs according to their Project or even a regex!?

And the piece de resistance – a much improved Add Reference dialog – Life is good. My favourite though is the highlighting of the current line – no more searching for that pesky cursor.

All in all, a useful set of tweaks for a good price – free.

Source Control

Sunday, August 1st, 2010

image thumb Source ControlOur current job has grown to a respectable size and it’s time to look at source control. To date, we’ve been happy with the Dropbox shuffle. But being more grown-up about proper versioning, it was time to examine the possibilities.

Seems SVN and Git are leading players, so too CVS (an older standard and used by sourceforge). The notion behind these revision control systems is to provide a mechanism to monitor current and historical versions of files, typically source code. Around these standards, online services have developed to provide storage for distributed development efforts. Keen to keep costs to a minimum (this project is a loss leader!), there are a number of free (or nearly) providers. I plumbed for Assembla. They give 2Gb (though under review) and permit private projects. If you’re working on open source, codeplex (from Microsoft) is a good alternative. Other providers seem limited at <200Mb which with maintaining unlimited versions (even of source code) would seem inadequate in the short term.

Choosing an online host for your repository (lingo for your online project unit) is one part of the solution. Next you need a means of interacting with the repository. There are two options here: shell extension to Explorer or integration into Eclipse or (in our case) Visual Studio. Right now, I’m playing with the integrated AnkhSVN from Collabnet which plays nice with VS2010. TortoiseSVN is popular as a shell extension and seems very intuitive. Both are free.

Setup is pretty straightforward. I began by creating a free private account at Assembla. This gives you a URL address for your repository. Now install AnkhSVN as a plugin to VS2010. Right clicking on your solution lets you add it to the online repository at the URL you received. Then Commit your solution to the newly created repository – this uploads local files to the repository for others to check out. As you can see from the screen shot, the tick marks indicate the local source is in synch with the online repository.

1 pages

latest news

UI Flow

Posted on Tuesday, 16th April, 2013

Often, we use wire-framing or mock-up tools (like the good guys at Balsamiq) to help communicate design ideas between developers as well as to clients. However, there is a need for something more efficient to aid communication of possible user interface flows through our emerging application. This communication is for internal use typically and doesn’t [...]

Testimonials

Excellent design skills

Posted on Sunday, 2nd May, 2010

We at Taxonomy.ie are happy to be associated with Appsolo and look forward to further work together.

follow me

twitter facebook delicious

AppsoloLtd. VAT No. IE97548691 - Copyright © 2010.