Sunday, May 30, 2010

StatLight V1.0 & V1.1 Released (Silverlight Testing Automation Tool)

About a week ago (May 21st 2010) I uploaded the v1.0 release of StatLight. You can review the list of changes on the StatLight v1.0 release page.

I knew once I marked it v1.0, I would probably have updates to it & sure enough… Microsoft’s Jeff Wilcox released a new version of the Microsoft.Silverlight.Testing.

I also incorporated some work done by Justin who recently released a version of the UnitDriven framework.

So there’s now a v1.1 build out.

Happy Silverlight Testing!

Saturday, May 22, 2010

Silverlight – DataBind to an Anonymous type (Who knew?)

I searched the web for the idea first. I was certain somebody had blogged about this before, and just wanted to quickly confirm it’s truth. Unfortunately all I came across were work-a-rounds and people telling you it’s not possible. So hopefully this post will help the next guy.

Since anonymous types are generated in an assembly as internal types, by default, if you try to DataBind to an anonymous type, you’ll probably receive a binding error much like the following.

System.Windows.Data Error: 
Cannot get 'Age' value (type 'System.Int32') from '{ Name = World, Age = 23 }' (type '<>f__AnonymousType0`2[System.String,System.Int32]').
BindingExpression: Path='Age' DataItem='{ Name = World, Age = 23 }' (HashCode=-172495608);
target element is 'System.Windows.Controls.TextBlock' (Name='');
target property is 'Text' (type 'System.String')..
System.MethodAccessException: Attempt by method 'System.Windows.CLRPropertyListener.get_Value()'
to access method '<>f__AnonymousType0`2<System.__Canon,System.Int32>.get_Age()' failed.

at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj,...
at System.RuntimeMethodHandle.PerformSecurityCheck(Object obj,...
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, Bind...
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, Bind...
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, ...
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, ...
at System.Windows.CLRPropertyListener.get_Value()
at System.Windows.PropertyAccessPathStep.ConnectToPropertyInSo...


Turns out, it _IS_ possible to DataBind to an anonymous type in Silverlight.



All you have to do is expose your privates. Placing the following into your AssemblyInfo.cs will give the built in bindings the ability DataBind to your object(s).





[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("System.Windows")]



 



I’m not going to say whether this is or is not a good idea, and I’m sure there’s many ways to abuse it.



Don’t inhale too much of this stuff.

Saturday, May 15, 2010

Silverlight Profiling PowerShell helper.

I was playing around with some Silverlight profiling the other night to see if I could find any obvious issues with my open source project StatLight and wound up writing a little script in PowerShell I hoped someone might find helpful.

But I didn’t know you could profile a Silverlight app.

I didn’t until I started doing some digging online. Now, the Silverlight profiling story (at least from what I’ve seen/tried) is not near the easy of say Redgate ANTS Performance Profiler. However, it’s do-able. (And with this helper script – hopefully a little simpler?)

How can I profile a Silverlight Application?

I would recommend you read the following blog, which explains one way of doing it very well.

http://blogs.msdn.com/profiler/archive/2010/04/26/vs2010-silverlight-4-profiling.aspx

So… what’s this script for?

If you read the blog above, or have done this before, then you probably noticed that there was quite a series of commands you had to execute before you could wind up with a performance report.

I threw together a quick little PowerShell script in an attempt to automate smooth out the process.

Hot do I use it?

  1. Download the script & save it somewhere. http://github.com/staxmanade/Scripts/blob/master/SilverlightProfiler.ps1
  2. Open the PowerShell console. cd to the directory your xap/assemblies are stored.
    (EX: {myProject}\Bin\Debug\ )
  3. Execute:
    {pathToScript}\SilverlightProfiler.ps1 -urlPath "{myProject}\Bin\Debug\TestPage.html"
  4. When your done profiling press enter to signal that your done.

    Once complete, it will print the location your profiling report was saved. You can then open it with Visual Studio.
Couple of disclaimers.
  • Some paths are hard-coded to my x86 machine.
  • I had troubles running the built in visual studio .bat files (from powershell) that are supposed to set the environment variables. So I extracted out what vars I could find to make it work.
  • I’m not a profiling expert – just hacked this together to get it to work for me.

I hope this is useful, and if you know of a better way, I’m always interested in hearing your feedback.

 

Copyright 2008 All Rights Reserved - Revolution Theme - by Brian Gardner. Converted into Blogger Template by Bloganol dot com