Calendar

<<  mars 2010  >>
lumamejevesadi
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

View posts in large calendar
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

(juillet 3, 2009 08:30)

Recently, I was playing with WatiN to do some integration and web testing, and I have "discovered" the concept of session merging in the browsers.

What is this ? By default, the browsers (Internet Explorer, Firefox, ...) are sharing the session information of a website (for instance the authentication information) between its tabs and different instances. What does implies in practice ? Just launch one instance of your favorite browser and log into an application (mail, ...). Then launch another instance (for instance another process) of the same browser and go to the same website. You should be logged in, even if you had not checked the magic checkbox "Remember me". Why are they doing this ? Just because many websites expect this behavior. Just imagine how surfing would behave without session merging in an application when it open popups ?

Just note that all website do NOT manage their authentication in the same way, and so, some of them may not be affected by session merging.

So, that's a feature ok. But when you do some web testing and that you would like to launch several browser logged in with different users to check simultaneous actions or things like that, this feature can be very very annoying.

But Internet Explorer 8 has added a new feature, that allow you to surf in a new session, meaning you just deactivate explicitely the session merging. How to do that ? Simple:

  • either from an existing Internet Explorer windows, juts use the menu File / New Session
  • from command line, use IExplore.exe -nomerge

What about in COM ?

Let's go back to my testing session. I was manipulating the DLL "Interop.SHDocVw.dll" to drive my browser and to create a new instance of Internet Explorer, I was just using the syntax new InternetExplorerClass. So how can I use this feature using the COM component ? Well, so far, I haven't found any way to do that directly so I'm waiting for your comments ! :-)

Anyway, I am using a workaround, that has been highly inspired of the source code of WatiN, just updating it to take into account the notion of session merging, and giving enough time to Internet Explorer to start.

To make this compile, you will need two references:

  • Interop.SHDocVw.dll : The COM wrapper exposing the Internet Explorer's classes
  • WatiN.Core.dll : The DLL of WatiN to be able to use the very nice TryFuncUntilTimeOut class and to collect the running instances of IE using the ShellWindows2 class
using System;
using System.Diagnostics;
using SHDocVw;
using WatiN.Core.Native.InternetExplorer;
using WatiN.Core.UtilityClasses;
 
namespace ClassLibrary1
{
   public class IEFactory
   {
      /// <summary>
      /// Start Internet Explorer without session merging
      /// </summary>
      /// <returns>The IE process</returns>
      private Process StartIEProcess()
      {
         string argument = "-nomerge about:blank";
         var process = Process.Start("IExplore.exe", argument);
         if ( process == null )
            throw new InvalidOperationException("The IExplore.exe process can't be started");
 
         return process;
      }
 
      /// <summary>
      /// Start a new instance of Internet Explorer and attach it to a IWebBrowser2 object
      /// </summary>
      /// <returns>The COM object corresponding to the running instance</returns>
      public IWebBrowser2 DemarreInstanceCOM()
      {
         //1. Let's count the current number of IE instances
         int count = new ShellWindows2().Count;
 
         //2. Start the process
         Process process = StartIEProcess();
 
         //3. Let's find the handle of the new running IE
         //   We will try for a maximum of 5 seconds, with trial every 100ms 
         //   if we had not been successful
         var getWindowHandle = new TryFuncUntilTimeOut(5) { SleepTime = 100 };
         int windowHandle = getWindowHandle.Try<int>(() => process.MainWindowHandle.ToInt32());
 
         //4. If we got the handle, let's get the browser
         var allBrowsers = new ShellWindows2();
         if ( windowHandle != 0 )
         {
            foreach ( var browser in allBrowsers )
               if ( ( (IWebBrowser2)browser ).HWND == windowHandle )
                  return browser as IWebBrowser2;
         }
         //5. Otherwise, let's take the first instance on a blank page
         else
         {
            //for that we'll wait until a new instance of IE is running
            var action = new TryFuncUntilTimeOut(5) { SleepTime = 100 };
            action.Try<bool>(() => new ShellWindows2().Count > count);
 
            foreach ( var browser in new ShellWindows2() )
               if ( ( (IWebBrowser2)browser ).LocationURL == "about:blank" )
                  return browser as IWebBrowser2;
         }
 
         //6. We had not been able to start the instance
         throw new InvalidOperationException("Internet Explorer could not be started");
      }
   }
}

Other information ?

Here is the link to the blog I have found explaining about session merging : http://blogs.msdn.com/ie/archive/2009/05/06/session-cookies-sessionstorage-and-ie8.aspx

(juin 12, 2009 08:51)

Recently I have been in the need of extracting  kind of a "call tree" of some functions of my code.

More exactly, it was not such the call tree, but I was needing to be able to list of methods being called by a given entry point, and then seeing the size of each tree.

NDepend can very easily give this information. Let's see how !

Let's start with code

Let's write some code that we'll use to validate our results. We'll start with a very basic set of class that will call each other:

namespace ClassLibrary1
{
   public class SecondClass
   {
      public void DoInSecondClass()
      {
         this.PrivateMethod();
      }
 
      public void DoInSecondClass_NoPrivate() { }
      private void PrivateMethod() { }
   }
 
   public class TopClass
   {
      public void Do()
      {
         this.FirstMethod();
         this.SecondMethod();
      }
 
      private void FirstMethod()
      {
         SecondClass obj = new SecondClass();
         obj.DoInSecondClass_NoPrivate();
      }
 
      private void SecondMethod()
      {
         SecondClass obj = new SecondClass();
         obj.DoInSecondClass();
      }
   }
}

Let's create our NDepend project

Our project is very basic but should be enough to validate our results. So now, we will create our NDepend project to start collecting (and validating) our metrics.

  • Start NDepend
  • Click on "Home / Start" and choose "New Project"
  • Give a project name ("NDepend Test" for instance) and the location where you want to store it
  • In the Code to Analyse tab, click on Add assemblies of a Visual Studio Solution and select the project you have just created.
  • In the Report tab, click on Select All

And here you are, ready to start the analysis ! Just click on Run Analysis and wait for NDepend to prompt the report.

Let's dig into the called method

We now want to find all the methods called by our entry point.

At the end of the analysis, NDepend pops up the report in your favorite browser. However, we'll close it for now and we will search our entry point in the Class Browser. To do that, either use the Show Menu button in the menu, or the hotkey ctrl + alt + C.

Just select the method you want, right-click on it, and select Who I use indirectly and then SELECT METHODS WHERE ...


Click on the image to enlarge

What happens here ? NDepend will generate for us a CQL Query. A CQL Query is written using the CQL language, a SQL-like language that allows us to run queries against our code to extract some information, statistics, .... Here we are using the following query :

SELECT METHODS WHERE IsUsedBy "ClassLibrary1.TopClass.Do()" ORDER BY DepthOfIsUsedBy

When we look to the result, it looks pretty good, unless that we do not have the number of line of code. Easy. We can just update the CQL Query like that :

SELECT METHODS WHERE IsUsedBy "ClassLibrary1.TopClass.Do()" ORDER BY DepthOfIsUsedBy, NbLinesOfCode

and here the result we get :

Of course the last column is visible only because we have altered the query to add another ORDER BY clause

Any graphical representation ?

It would be very nice to be able to extract a visual call tree with all the methods we have here in the CQL result. And of course, this can be done easily. Just go to the CQL Query Result page and right clic on the line marked 8 methods matched. Then you can choose Export 8 methods matched to Graph


Click on the image to enlarge

Antyhing missing ?

What we have here is pretty cool to find quickly information and in our case the dependencies between methods. Anyway, there is a functionality that could be nice to be added on the graph. We may start viewing a graph not from a CQL Query result, but from a list of assemblies. And thus it could be interesting to be able to :

  • From a graph of assemblies dependencies : doing a zoom meaning double-clicking on an assembly to see the type dependencies of that assembly
  • On a type, being able to do a zoom, meaning double-clicking on the type to see the method dependencies of that type
  • On a mehtod being able to right-clic to add to the graph or the callers, or the callees

Conclusion

 Anyway, even if some functionalities could be added to the tool, NDepend is a very interesting tool, easy to learn and very powerful - especially due to the CQL language.

Give it a try, and comment about our use !

(juin 12, 2009 08:40)

A few months ago, Patrick Smacchia offered me a professional licence of NDepend so I can try it on my current projects.

I was already knowing NDepend as being a reference tool for analysing code, extracting metrics, ... but I never had the opportunity to really trying it. But I was so far from the truth !

Unfortunately, I have had very hard months with many things to do (day to day job, articles, conferences, ...) and I have had to postpone so many times my trials.

But better late than never ! It's now on my top priority list and all the trials I now do with the tool show me the extarodinary possibilities of the tool. I will explain in a next post what was my first use of NDepend.

Ready for a try ? Just download a trial version of the tool and have fun !

(juin 5, 2009 08:58)

As I explained some time ago, I was writing an article about Continuous Integration in the Microsoft.NET world for the (french-speaking) website http://www.developpez.com/.

The article has been phased as follows :

First Part (published on March 4th - available online here) - 43 pagesSecond Part (published on June 5th - available online here) - 62 pages
  • Quick introduction to continuous integration
    • Why do we want Continuous Integration
    • What is Continuous Integration
    • What do we call BVTs
  • Quick presentation of the tools needed for Continuous Integration (in the Microsoft.NET world)
    • MsTest
    • Static Code Analysis
    • MsBuild
    • TfsBuild
  • Unit Test : Writing unit tests with MsTest
    • Structure of a test class
    • Checking the correctness of a test
    • Testing the non public API
  • Unit Test : Executing tests with MsTest
    • Via Visual Studio 
    • Thru Command line
  • Unit Test : Configuring tests
    • Test Runs naming
    • Code Coverage
    • Deploying files
    • TimeOut
  • Unit Test : Managing the tests
    • Via the "Test View"
    • Via the "Test Editor"
  • Unit Test : Additional attributes
    • Behavioral attributes
    • Informational attributes
  • Static Code Analysis : Presentation
    • Activate the analysis
    • Running the analysis
    • Explication of the rule naming
    • Parameterizing the analysis
  • Static Code Analysis : Correcting the errors
    • Correcting one error
    • Correcting several errors
    • Grouping the rules suppression in a global file
  • Static Code Analysis : Limitations
  • Quick introdution to MsBuild
  • First steps with MsBuild - Writing a basic project file
    • Its structure
    • What is a task ? a target ?
    • Creating and executing a project file
  • Going further with MsBuild
    • Ensure the project file is valid
    • Properties and PropertyGroup
      • How to statically & dynamically create them ? To use them ?
      • Order of declaration
      • Updating the value
      • Delaying the creation of a PropertyGroup
    • Items and ItemGroup
      • Same detail as for Properties
    • Executing a project file in command line
      • Choosing the target to execute
      • Overriding properties
      • Playing with verbosity
    • Using .NET 3.5 tasks
    • Playing with Targets
      • Control the execution order
      • Explicit call of a target : 3 techniques and their differences
      • Passing input and output parameters to a target
  • Refactor a project file
    • .targets files
    • Importing files from Source Control
  • Create your own tasks
    • A simple one, with inputs (mandatory or not), with outputs
    • Raising errors
    • Debugging your task
  • Quick introduction to Team Foundation Server
  • TFS & Continuous Integration
    • Create, edit and execute a build
    • Parameter a build
    • Which target can you override ?
  • Managing TFS
    • Destroying, Undoing and listing files
    • Presentation of TFS Power Tools
  • Tips & Tricks

To read this article, just go to http://dotnet.developpez.com/ or directly to my webpage on this site : http://pedautreppe.developpez.com/.

Note that these article are available only in french for now, but do not hesitate to leave comments here if you think the content is interesting and that it could be interesting that I translate it.

(mars 22, 2009 21:06)

Hello,

Again for this day, I exclusively followed the Developper and Solution Architect track, but switched between the sessions related to Client & Web, Tools & Languages and Servers and Services. Definitely good sessions ans goof speakers. So many lessons to learn ! 


Session 1 : The Daily Scrum (by Joel Semeniuk and Stephen Forte)

I am now working for 3 years and a half, and so I try to follow all the agile related sessions to learn a maximum of things and compare other practitionners method implementation with mine. Some key points of this session:

  • The daily stand up meeting
    • The daily stand up meeting is not a status meeting
    • The scrum faster is a facilitater
    • Three questions to answer during the meeting :
      • What did you do yesterday ?
      • What will you do today ?
      • Is anything in your way ?
    • You should not attack anyone during the meeting --> See him after the meeting
  • An important question to answer : What is "done" meaning ?
  • Some book references :
  • The duration of sprint is fixed in advance, but all the sprint may not have the same length (we can plan in advance that the next spring will be longer or shorter, but once it has started, we do not re-schedule it)
  • There are three key parts in a project (Functionality, Cost and Schedule), and only two of them can be fixed

Session 2 : ASP.NET MVC for Smart People (By Scott Galloway)

I was already knowing quite well the model of ASP.NET MVC so this session didn't show lots of things new. However, some key information :

  • When creating a new MVC solution, the template will create among all:
    • a "Content" folder that will hold images, ...
    • a "Scripts" folder including JQuery 1.3.1
  • The template will create the controller and the associated views (on demand)
  • We can use the [OutputCache] attribute on a view
  • When doing some POST to the server, the controller works by default with the FormCollection. However, we can use the ModelBinding to replace this FormCollection by the currently typed object we are managing
  • The Model is a partial class and so we can "extend it" (creating another partial class) to add some validation. For that purpose, we can use the IDataErrorInfo interface
  • Two goals of the MVC framework
    • to have a tight control on the HTML markup
    • to have user and SEO (Search Engine Optimization) friendly URLs 

In my view, this framework is interesting, but I'm not totally convinced by its added value. More specifically if we note that

  • in ASP.NET 4.0 we'll be more free to manage the HTML markup (by avoiding to have long generated IDs)
  • we can already use the Routing namespace to get friendly URLs

I think it's currently generating extra work for limited added value. Well let's see and try !


Session 3 : Fastest to Market : RAD Web Applications with ASP.NET Dynamic Data and Entity Framework (By Ingo Rammer)

One of my favorite speaker for an interesting session even if Dynamci Data is not really new for me.

  • Some new templates are available, among them we can note "Dynamic Data Entities Web Site" to have a web site using Dynamic Data and entity Framework. Another template will use LINQ to SQL.
  • You will need to install the latest hot fixes of Entity Framework
  • In configuration : ScaffoldAllTables means that some CRUD (Create, Read, Update, Delete) interface will be generated for all the tables of database we are targeting. But we can decide to scaffold only the tables we want
  • Dynamic Data will fo automatic form generation
  • We can use Routing
    • Be careful, if the routing you specify creates URLs not finishing with .aspx, IIS Will not redirect to ASP.NET We need to change the HttpMapping to redirect all the URLs to aspnet_isapi.dll
  • We can use the [MetadataType] attribute to specify wich class will contain the definition of the attributes. This will be usefull if we want to add some extra attributes on the generated members of the entity framework model
    • Ingo has published on his blog a small tool to generate al the metadata type class based on a model. It is available here
    • We can use a [DataType] attribute to interecept the formatting of a column thru the Format method
    • It is not possible currently to reorder the columns, except if we use the IAutoFieldGenerator interface of classical ASP.NET 

The conclusion of Ingo ? Dynamic Data will never get used to generate a business web site where high performance is needed as everything is done here at runtime. Moreover, managing business rules thru this model could be tricky. However this could be very usefull to generate some maintenance pages very quickly.


Session 4 : ASP.NET 4.0 what is coming? How do I prepare my app? (By Scott Galloway)

No so many information to remember here. Let's just say that:

  • Lot's of snippets will now be available in the HTML code
  • Some web.config transformation files have been added. This will allow to change osme attributes dependent of the configuration we are using (development database versus production database for instance)
  • An OutputCacheProvider has been added, targeting "On Disk", "In Memory", or even "Azure"
  • We can now control more the client ids that will generated : a new ClientIdMode property is available on the controls:
    • static: the ids will "forget" the naming containers part and will restart to this point
    • predictable: we can use a pattern to generate the Ids as for instance the identity of a data row in a grid
  • Visual Studio 2010 will be shipped with JQuery and Ajax Control Toolkit

Session 5 : ASP.NET AJAX 4.0 (By Jurgen Postelmans)

Jurgen has posted the slides of his session on his blog on http://www.u2u.be/res/articles.aspx.

  • Jurgen has reinsisted on the fact that the UpdatePanel is doing an asynchronous POST to the server, sending all the data of the pages (view state included), and that the server will thus process all the page (running all the events Page_Load, ...) to send back the HTML of the parts to update (ie the panel itself AND the view state)
  • POX : Plain Old XML
  • If we want to use WCF from Javascript, we must declare our service using webHttpBinding and adding a behavior declaring enableWebScript
  • To view the WCF service proxy that can be used in the javascript, we can use the WCF service URL and adding at the end /js or /jsdebug. This URL can be simply referenced on the page where we wantr to use the service
  • In javascript, the OnSuccess and OnFailure method take three parameters : The data received (or the error), the context and the method name
  • To do some binding in our HTML, we must use the syntax:
    • {{expression}}
    • where "expression" can contain method call, variables, ...
  • A new client class DataView has been added
    • One method set_data to fill the dataview
    • The method render has been replaced by updated
  • ASP.NET AJAX recognize tthe CSS class sys_template and will remove it when rendering an object. This class should be reponsible of hiding one element (typically visibility=hidden and display=none)
  • The prerogative sys:activate="*" is used to define the elements (here all of them) where we allow the creation of a control we have referenced in an xml namespace
  • A class Sys.Observer has been added. The method remove must be used to inform a grid that we have removed an element. This class is similar to the .NET classes ObservableCollection and INotifyPropertyChanged

 Session 6 : Azure - A lap around cloud-hosted Services (By Ingo Rammer)

Last session of the TechDays, and last one about Azure. Some more information to get:

  • SQL Services is a high scalable database available in the cloud, that should support up to a peta bytes of data
  • A Web Role can be seen as equivalent of an ASP.NET application that has medium trust
  • The Development Fabric allow to debug a cloug computing project locally
  • Azure provides us with a Zero Downtime Environment
    • Two platform are available online : Production and Staging
    • A simple click will swith between these two platforms
  • A new SessionStateProvider has been provided to target Azure
  • A WebRole is done to perform Synchronous Operations, while a WorkerRole will be in charge of Asynchronous Operations
  • The WorkerRole is based on a queue
    • It's important to (explicitely) delete a message from the queue once it is processed. Otherwise, it could be treated by another worker role later
    • This process (without implicit deletion) has been done to counter a potential message loss if a server has a problem while processing it
  •  

Powered by BlogEngine.NET 1.2.0.0 | Theme by Pierre-Emmanuel Dautreppe