Powerd by dasBlog RSS 2.0
 Saturday, January 12, 2008

Let this be my first post in my new Windows CE category. I have a feeling I will be writing more stuff about WinCE in the coming months. I wanted to jot down some notes from a couple of articles I read over at OpenNetCF for future review. Most of the high level concepts I already knew, but it's nice to get some details once in a while.

Data Caching

  • No performance gain in keeping the data connection open for the life of an application.
  • Cache reads are two orders of magnitude faster then a database read. As the article points out, this is interesting due to the fact that the database, and cached data were both stored in RAM.
  • Several of the reader comments were interesting
    • The first time a SqlCE Connection is opened, the database is loaded into shared memory
    • One option is to have a connection opened for the life of the application, but not to use it, this is just to keep the engine loaded. Then open/close connections in your DAL as you normally would. This was recommended by Steve Lasker, a member of the SQL CE dev team. Steve also points out that reusing a command object and changing the text code hurt more then help, as you can't take advantage of query plans. Reusing a command object can sometimes help with the garbage collector.
    • Another reader provided a example where it looks like he is doing an index scan and getting faster results then directly querying the database. It's hard to tell without running the sample code.

Garbage Collector

  • GC suspends all threads while it performs necessary actions, such as freeing and moving memory. Frequent GC's can have an adverse affect on performance.
  • Remote performance monitor, which I blogged about before, is a valuable tool. This article provides a good example of how to interpret some of the numbers.
  • Don't fear the GC, and take the time to understand what the numbers in remote performance monitor mean.

I'm also in search of a decent MVC and IoC framework for Windows CE. I'll probably be posting more on this later.

Saturday, January 12, 2008 9:25:34 PM UTC  #    Comments [0] - Trackback
Review For Future Projects | WinCE
 Sunday, January 06, 2008

I jumped back into some compact framework development this weekend, and it was the first time since I had installed VS 2008 RTM. I went to connect to one of my CE devices via Visual Studio 2005, and was unable to connect. I also tried the remote performance monitor power toy.

I finally went to check on what version of the CoreCon files I had installed, and noticed right away that there date modified was 11/7/2007. I coped these latest versions over to my CE device, and was able to connect again.

Sunday, January 06, 2008 8:23:01 PM UTC  #    Comments [0] - Trackback
Programming
 Wednesday, January 02, 2008

Damon Payne put up his goals for 2008 and I decided to post my own. This is the first time I've ever written down goals for a new year, so we'll see how well I actually follow thru on them. I guess that's a goal in and of itself, to report back on my progress throughout the year and write something up on December 31 2008.

Programming, Architecture and Professional Development

  • Continue to blog, increasing the quality of my posts (Work in Progress)
  • Read at least one book on programming and/or architecture. Apply what I learn to projects I am working on and blog about this. (Need to identify books)
  • Start working on one or more personal projects I have been kicking around. The main purpose of these projects is to apply learnings from numerous resources (articles, blogs, books etc), as well as try out new techniques/technologies (IoC, Asp.Net MVC, Linq, MS Sync Runtime) and tools (NDepend, VS Team System). (Work in Progress, need to setup proper home development environment)
  • Present at one Madison .Net User Group meeting, most likely on one of the above, or on a project from work. (Identify possible topics)

Investing

  • Learn the fundamentals of long term investing (Started)
  • Put in the proper time to research new investments (Work in Progress)

Personal Development

  • Continue with my studies of Martial Arts, and improve
  • Continue playing, and improve at Roller Hockey
  • Start learning Japanese

Stuff on the Periphery

  • Purchase a Katana and take classes on how to use it

I don't know, it may be too much, but only time will tell. Thankfully, there is allot of overlap, and I've some of the 2008 goals were "goals" from 2007.

Wednesday, January 02, 2008 2:09:57 AM UTC  #    Comments [0] - Trackback
General
 Tuesday, January 01, 2008

Today's task, a somewhat detailed code analysis of one of our Windows CE projects. In addition to reviewing from a lead architect point of view (design and implementation), I also needed to take a look at general coding practices. For this I turned to the Code Analysis tool in Visual Studio, and NDepend.

I had remembered reading about NDepend on Scott's blog, and went back there to re-read his post. I highly recommend it, as it's a great quick start and introduction to NDepend. Scott also has a pod cast available, and the the NDepend web site has links to several video tutorials showing how to use it.

One thing I found lacking, was there were no support forums on the NDepend web site. I had a couple of issues getting my Compact Framework application to be property recognized by NDepend. The main issue, was NDepend was trying to use the full framework version of System.Data instead of the Compact Framework version. I noticed that there was an option when selecting assemblies to resolved missing ones (well, some it let me, others it didn't), and figured the resolved location was stored in the project configuration file. So I opened it up in note pad and sure enough, there were all the directory paths.

I removed all of the paths that were added by default, and added my own paths to my project. I also added paths to the SQL CE 3.5 directory, as well as the location of the compact framework dlls (See update below). Unfortunately I still had issues with NDpend detecting multiple dlls (System.Data and System.Windows.Forms) with the same name. I decided to remove the path statements for everything except my project. This resulted in warning about not being able to resolve dependencies, but the analysis completed.

There is allot of information presented, almost to the point of information overload. I highly recommend printing out and reviewing the NDepend placemat as a quick reference. I concentrated primarily on the metrics, which use NDepend's Code Query Language to identify possible problems. I found myself viewing all of the queries to figure out what they were looking at. The documentation of the queries is excellent, and each one includes a link to the NDepend web site which defines the metric is pretty good detail.

I am quite impressed with the amount of information that NDepend gave me about my project. There were/are a few usability issues, but they can be overcome. I hope that I can continue to find time to make use of this excellent tool. I spent some time watching the video tutorials, and they were very helpful. I've been trying to get a side project started at home to try out all the tools, techniques, patterns, etc that I don't have time for at work, and this will definitely find it's way onto my to do list. I think it will be very interesting to use this from the beginning and see how the different metrics change as I build out my project.

Update:

  • 1/2/2008 - After watching the videos, I discovered that when you are setting up your project in VisualNDepend, there is a screen that lest you add/remove directories in the application. This is much easier then editing the project file manually like I was initially doing.

Other Links:

Tuesday, January 01, 2008 6:01:14 PM UTC  #    Comments [0] - Trackback
Programming | Review For Future Projects | Tools
 Saturday, December 29, 2007

Yesterday, a co-worker of mine passed on a link for the Microsoft Sync Runtime, suggesting that we may be able to leverage it in the future in order to meet some requirements we have on our project.

Microsoft Sync Framework is a comprehensive synchronization platform that enables collaboration and offline access for applications, services and devices. It features technologies and tools that enable roaming, sharing, and taking data offline. Using Microsoft Sync Framework, developers can build sync ecosystems that integrate any application, with any data from any store using any protocol over any network. 

 

Reading thru the initial article, I was quite impressed, but it left out a key piece of information, how does the sync runtime work over the Internet. Not just the internet, but also any decent corporate network were clients do not have direct database access.

I made my way to an overview of the Sync Services for ADO.Net, which is what I would be most interested in (although syncing file systems has an interesting appeal as well), and they clearly showed the Internet cloud, but not really how the sync framework worked with it. I actually had to dig into the documentation, and finally found some details on how to get this to work on the Internet. If you read towards the bottom of the documentation, you can see that you implement a proxy on a middle tier.

On the middle tier, the service inherits from and exposes the same methods as ServerSyncProvider (the abstract class from which DbServerSyncProvider inherits). The methods are then executed by the application code over a direct connection to the server database. The results are routed through the middle tier and back to the client.

 

Basically the middle tier exposes the same interface that the client application would normally use if it could connect directly to the database. There was a link which gives a specific example of setting up a n-Tier environment and provides a good start. However, I could not find exactly what I was looking for, which was an example of using WCF as the transport mechanism. With WCF I could have 1 middle tier service with multiple end points configured, such as a Basic Http for Internet, and TCP for intranet. WCF also adds support for encryption and authentication, which I didn't see called out specifically in the sync runtime.

Other items of interest include, how to setup a database for different sync scenarios, and peer to peer synchronization.

All in all, the Sync runtime looks like a very promising framework for building disconnected applications. It will require some re-architecting for existing solutions, specifically the data store, but it might be worth it in the long run. I will be sure to post updates if I get a chance to play around with it at all. It is defiantly something that would save me some time on a side project I am hoping to start working on soon.

Saturday, December 29, 2007 7:59:47 PM UTC  #    Comments [0] - Trackback
Review For Future Projects
 Thursday, December 27, 2007

Just when I thought I was on a roll, my unit tests stopped working, all of them. At least when they all fail, and fail in the same way, you know it's not your code that's causing the issue. Switching to running the unit tests in debug showed that they were failing when I was trying to leave the service domain as part of my "database rollback" functionality (idea and code I based my work off of was from a 2004 MSDN article), which uses Enterprise Transactions. 

I had a previous issue with MS DTC and my unit tests, but this is different. No helpful messages in the event log (first place I looked this time) on my development server. My laptop, where I am running the unit tests from, have a couple of entries for DistributedCOM but they are kind of vague. I decided to jump over to dtctester and see what that showed.

It hung on "Enlisting Connection in Transaction" for at least 1 minute (I left to get a soda) before finishing. The most recent changes I've made to my development server are:

  • Upgrade to BizTalk 2006 R2
  • Install .Net Framework 3.5 RTM
  • Install Windows Server 2003 SP2

My bet is on a fix in SP2, or the SP2 installer resetting the MS DTC configuration. I found an excellent MSDN article on trouble shooting MS DTC in an effort to verify how I should have MSDTC configured, specifically the security settings. I noticed that mutual authentication was required, and from previous issues with DTC and the fact that my machines are not on a domain, I set this to no authentication and tried again, no go. I did find a new entry in the application event log on the dev server which seems to point with an issue on the dev server itself.

MS DTC is unable to communicate with MS DTC on a remote system.  MS DTC on the primary system established an RPC binding with MS DTC on the secondary system.  However, the secondary system did not create the reverse RPC binding to the primary MS DTC  system before the timeout period expired.  Please ensure that there is network connectivity between the two systems.  Error Specifics:d:\nt\com\complus\dtc\dtc\cm\src\iomgrsrv.cpp:1318, Pid: 2728
No Callstack,
CmdLine: C:\WINDOWS\system32\msdtc.exe

Nope, it wasn't the dev server. I decided to run dtctester on 2 other computers and they both passed. The first time I ran the tool on one of the computers, I got an error that was very similar. The only difference was the native error. On my laptop (Vista) the native error is -2147168242 and on the other computer it was -2147168220. The issue on the other computer was that I had not setup DTC for network communication.

 

So now I knew it was an issue with my laptop, which is running Vista. A couple of things I've done recently were:

  • Remove VS 2008 Beta 2 and all related components and install RTM
  • Install various updates from Windows Update
  • Installed VPN software
  • Was playing around with network settings trying to get wireless working at my parents over the holidays
  • Uninstalled and reinstalled newer version of VMWare

I know I had problems with the firewall before, so I turned off the Vista firewall, and success, dtctester passed. En-enabling the firewall caused the dtctester to fail again. In the simple firewall UI, distributed transaction coordinator was selected. I went back and looked at a post I wrote on our internal network, and I had mentioned that the VMWare network adapters change the zone that the firewall thinks you are in.

Well, I was in the public zone, and couldn't change it. There should have been a Customize option on the Network and Sharing center. I remembered that I had gone into Services, and disabled some that I "thought" I could do without. One of them was Network Location Awareness, which caused Network List Service to fail to start. Once those 2 were running, the firewall knew I was on the private network, and DTC worked again. My firewall exception was for the private network only.

Wow, that was a trip. 

Download MS DTC Tester: http://support.microsoft.com/default.aspx?scid=kb;en-us;293799

Thursday, December 27, 2007 11:20:13 PM UTC  #    Comments [0] - Trackback

So I was updating another computer from Visual Studio 2008 Beta 2 to RTM over Christmas and noticed something during the install process. You know, the install process, where they show pictures of people I never saw in my computer science classes, interviewed, or seen at any of development/industry events. Got to love marketing.

Back to what I saw though, the Sql Publishing Wizard. A quick Google search showed me this was previously an add in which has made it's way into Visual Studio 2008 as a default component. You can download and read about it on CodePlex. From the home page on the CodePlex, the Sql Publishing wizard supports two modes of operation:

  1. It generates a single SQL script file which can be used to recreate a database when the only connectivity to a server is through a web-based control panel with a script execution window.
  2. It connects to a web service provided by your hoster and directly creates objects on a specified hosted database

I tested out the single SQL script mode on our new database, which is quite complex and has challenged other scripting tools. I am extremely happy to report, that the single generate script reproduced our database perfectly. What's even better, is that it is an open source project, so you can make some changes, maybe add some schema object filters, or separate the objects into separate files.

Thursday, December 27, 2007 4:31:53 AM UTC  #    Comments [0] - Trackback
Sql

Inversion of Control (IoC) and Dependency Injection (DI) are two practices, patterns, techniques, that I have been very interested to take a look at in greater detail. I came across a tutorial (the tutorial) which goes over IoC and DI using the Castle Windsor Container (and Micro Container), part of the Castle Project. Two other similar implementations presented in the tutorial are Spring.NET and StructureMap, as well as Microsoft's ObjectBuidler DI framework. The ObjectBuilder framework is used in the Enterprise Library, and Composite UI Application Block (CAB), which is good enough for me to steer clear of it and try out the Windsor Container instead.

I have never really been impressed with the Enterprise Library, and the CAB seemed overly cumbersome. Granted, it has been over a year since I last looked at the CAB and EntLib in any great detail, so maybe things have gotten better. I know allot of people live and breath EntLib, but I'm trying to experience some other thoughts outside the typical Microsoft sphere, such as Alt.Net. Microsoft is starting to catch onto the Alt.Net movement especially with the introduction of the Asp.Net MVC framework, a topic for a future post.

Part I

So what exactly is inversion of control? It helps if you consider how an application is traditionally written and define what "control" means. "Control" can be thought of as adding references to various assemblies, declaring instances of specific specific classes by calling the appropriate constructor and passing in parameters. The tutorial refers to this as a "canonical programming process". Now if we take the opposite, or invert the control, then our application does not reference specifically assemblies and does not instantiate concrete classes. Instead your application makes use of interfaces or abstract classes and relies on a framework to instantiate the classes as needed. This is commonly referred to as the Hollywood Principle, and what post on design patterns would be complete without a link to Martin Fowler.

The tutorial talks about another design principle, which is the separation of concerns (SoC). Separation of Concerns states that a component should do only one task, and do it very well. In the tutorial's example application, the functionality to download HTML data should be separated from the logic to parse the HTML itself. By separating the two pieces and applying IoC, if a new, faster algorithm for parsing was written, it could be swapped out with the original with no modification to the application. Under a traditional model, you would have to edit the single class, change the parsing routine, and then recompile the class and application. Then what happens when management says, "well the first algorithm was slower, but it was written by the boss's nephew....".

The tutorial defines a component as: "... a small unit of reusable code. It should implement and expose just one service, and do it well. In practical terms, a component is a class that implements a service (interface). The interface is the contract of the service, which creates an abstraction layer so you can replace the service implementation without effort."

The power of an Inversion of Control framework does not become apparent until you have components with dependencies on other components, each with their own dependency. The Castle project refers to it's IoC as a container which is offered in two versions. The first exposes the core IoC functionality and is called the MicroKernel. In the simplest of terms, you add components by specifying a key (ID), type and assembly to load. You then ask the container for an instance, which it returns, loading all required dependencies. The 2nd version of the container, Windsor, extends the Micro Kernel and is used most often. It adds supports for generics to reduce casting and external configuration (app.config and web.config) options to name a few.

Part II:

  • Constructor, Setter, and Component Injection
    • Constructor arguments, and [property] setter arguments can be specified in the configuration file.
    • If more then one component of a service is specified, you can specify which component to use, using the ${ComponentName} syntax in the configuration file.
    • The name of the XML Elements in the configuration file should match a constructor parameter and property name.
  • Collections in the configuration file
    • Arrays, Dictionaries and Lists can be specified in the configuration file.
    • This allows you to pass in a collection of components and allow the parent container to decide which one to use.
    • Collections can be specified for constructor parameters and property setters.

Part III

  • Separation of configuration and data
    • The configuration file can get complex pretty fast, especially when you are specifying a large set of data for a collection.
    • Windsor allows you to work around this by moving the data to the top of the configuration file under a <properties /> section. Child elements can be referenced in the configuration section by using the #{ChildPropertyName}
    • The tutorial points out that the real power of this, lies in the fact that you can put the properties in a separate file.
  • Custom Converters
    • Windsor supports converting from strings (in the configuration file) to other types.
    • You need to implement AbstractTypeConvertor, and a new class inheriting from WindsorContainer to register your TypeConvertor
  • Decorator Pattern
    • The decorator pattern basically has you wrapping a component that implements IInterface, with another component that implements IInterface, taking the original component as a constructor parameter.
    • Once you have the new implementation, you can perform things like benchmarking around specific method calls.
    • Since everything is setup via the configuration file(s), there was no need to re-compile the main container.
  • Define and If
    • Windsor supports an IF/Else syntax in the configuration file
    • Windsor also supports using DEFINED variables, such as DEBUG. This is not the same as the compiler flags, you have to add your own DEFINE statements in the configuration file. this can be in either the main component configuration, or your properties configuration.

Party IV

  • Lifestyles
    • Windsor supports 4 object lifecycles
      • Singleton (Default) - Each call to Resolve returns the same instance
      • Transient - Each call to Resolve returns a new reference
      • Thread - Each thread gets a single instance
      • Pooled - Instances are retrieved from a pool. If there are no more available instances in the pool, a new one is created. All instances are created upon the container being instantiated. 
      • Custom
    • Specify the lifestyle using attributes (i.e. [Transient]), or via the configuration file
  • Facilities
    • From the official documentation (taken from the tutorial): Facilities augment the MicroKernel capabilities by integrating it with a different project or technology, or by implementing new semantics.
    • Built in facilities (Covered by the tutorial):
      • Factory - Allows you to use classes which implement an Interface but use the factory pattern
      • Startable - Components are "started" as soon as possible after the application is started, and stop when it's released. You can implement an IStartable interface, or, specify start and stop methods in the configuration file.
    • The logging facility is mentioned as one being worth while to investigate, but it's not covered.
  • Commission and Decommission
    • Implement the ICommission and IDecommission to specify code which should be run when the component is created and destroyed by the container. Depending on the lifestyle chosen, the actual time at which the decommission code is called varies, and without understanding this, you may get unexpected results.
  • IDisposable
    • If you implement IDispoable, the container will automatically call the dispose method when the component is no longer needed. 

Questions:

  • Is there a utility that can analyze an assembly, namespace and/or class and generate a skeleton configuration file?
    • The StructureMap lists some tools that make configuration file management easier.
  • Other ways to store configuration data. It would be great if you could load configuration, or the properties from a SQL data store.
    • StructureMap supports full programmatic configuration.

Conclusion:

I can't wait to try out the Micro Kernel and Windsor Container in a project. The flexibility is phenomenal, and the decorator pattern makes it extremely easy to extend functionality.  I only took a quick look at the StructureMap and Spring.Net, and they have some interesting features which need further investigation.

Thursday, December 27, 2007 4:10:24 AM UTC  #    Comments [0] - Trackback
Programming
 Tuesday, December 18, 2007

I thought I was missing something in SQL Management Studio, as I couldn't believe the functionality to export or script database diagrams wasn't included. I went off to Google to search for something, either how to script it myself, or some missing function.

First I came across this post, but wasn't to inclined to copy/paste the script and clean it up. I later came to find out it was for SQL 2000, and would not work in 2005 (good, saved some time there). I continued my search and found an article on Code Project that provided SQL scripts to do exactly what I needed. The scripts are actually 2005 updates of the 2000 scripts I found on my first search.

Even if my Google search fails, I need to remember to hit up Code Project, it's a wealth of information.

Tuesday, December 18, 2007 2:52:25 PM UTC  #    Comments [0] - Trackback
Sql

Compliments of ScottGu's blog, the World Of Warcraft add-in for Visual Studio is almost enough to make me go back and start playing again. Or, at least install WoW just to try this out.

Tuesday, December 18, 2007 2:12:14 AM UTC  #    Comments [0] - Trackback
Tools
 Monday, December 17, 2007

Stumbled across Volta by accident today. Volta is a prototype developer tool developed by Microsoft Labs.

What I got from the FAQ was that You to develop an entire application from the perspective of the client, as a single Tier, using out of the box tools like Visual Studio 2008. You then add declarations to your code which Volta will use to refractor your code (as a 2nd phase of compilation) into multiple tiers, targeting java script enabled browsers (IE and Fire Fox are supported), and traditional Windows Forms. Volta actually takes the default compiled MSIL, scans for the Volta declarations you added, and generates new MSIL which will run on your various Tiers.

I think it sounds like pretty exciting stuff (or I wouldn't have blogged it). However, I have a few questions/comments/thoughts.

  1. Volta is currently a CTP, and is referred to at least once as experimental. I would not want to develop any production code unless Volta was going to be actively developed.
  2. What options exist for tweaking the generated application, specifically on the client pieces. You always need to tweak something on the generated stuff, and then those tweaks are usually lost when you re-generate.
  3. How would Volta work with something like CSLA, which I use allot. CSLA provides a mechanism for running as 2 or 3 tier with a configuration file change.
  4. You can still do more with a WinForms application then a Web Application, even with things like java script and Ajax and Silver Light. Technologies like WPF add another layer of complexity as well. As with other things in the land of programming, it sounds like you would have to give up some performance and features you get with targeting a specific client environment, in exchange for a single code base.

If everyone else is using existing programming methodologies, targeting specific environments, reusing code where possible, they are going to have a better looking and performing application IMO. In the end, the customer doesn't care if you don't have to do as much work, they only care how the application looks and performs. You would have to save enough money by using Volta, that you could pass that savings onto the customer. I'm not sure how you could justify this for internal customers.

I have a backlog of technologies to take a look at, so I probably won't get to Volta any time soon. That might be a good thing, as by waiting, I will either give it more time to develop, or get dropped.

Monday, December 17, 2007 3:14:58 PM UTC  #    Comments [0] - Trackback
Review For Future Projects
Archive
<January 2008>
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2008
Adam Salvo
Sign In
Statistics
Total Posts: 146
This Year: 72
This Month: 3
This Week: 0
Comments: 8
Themes
All Content © 2008, Adam Salvo
DasBlog theme 'Business' created by Christoph De Baene (delarou)