Monday, January 19, 2009

Well this is a trick that most of your know already. Anyway for those who does not know this and for those who actually have a Dual Core and Quad Core machines, you could use all these processors on Windows right from the Boot process. Here is how you do it.

Go to Windows Run (Windows + R) and type in msconfig.

Now in the application launched, go to the Boot tab.

Click on the advanced options and you should see something like this.

My machine has two cores so I could check the Number of Processors and set the number to 2.

Tuesday, January 13, 2009

The trick is to place a rectangle first, with the color of your choice. Then place another rectangle, with half the height on the top of this one and then give it a LinearGradientBrush, but half the height and place it on the top portion of the first rectangle. I would share more information on this, once my friend Ashish actually teaches me how to do this kind of stuff. Anyway, the XAML for this one is shown below.

With information from both the videos, I made a lot of notes on paper but I am having trouble implementing the same ideas to an application of mine. Anyway I hope to resolve this issue with time and I just need a quick start. In that process, I have looked at some slides by Noyes from a talk on Prism. The following is my observations (which might be incorrect) and notes on CompositeWPF and as well as on Model-View-ViewModel pattern in WPF.

A composite WPF application has the following parts

Container – PRISM uses Unity Container by default. But it allows the developer to use any container of their choice. The Container is used to perform dependency injection (inversion-of-control). My understanding of dependency injection is – Project X would not refer to Project Y and yet be able to load Y at runtime. This makes both X and Y as loosely coupled as possible. By inversion-of-control, we mean that the control of generation of objects and dependent objects is moved from the host object to the container.

Bootstrapper – Bootstrapper is a class (derives from UnityBootstrapper in CompositeWPF) that is used to manage the startup of the Shell program or the main window. The Bootstrapper also performs configurations as required – configuration of the container, configure the regions mapping using regions-mapping-adapter, creates the shell, initializes the modules. An instance of BootStrapper is created and Run() is called from the Initialize() method of the App.xaml. When bootstrapper is used, we remove the StartupUri from the App.xaml. The bootstrapper is not a required component but is recommended. I usually go with any thing that is recommended.

Shell – A Shell is a WPF Window – the main Window. This is the window that would be instantiated and shown from the Bootstrapper class. Shell knows nothing about the modules and is just the UI Container for the application (the root UI element).

Modules – A module is an independent and loosely coupled unit of the composite application. It might be a GUI module with WPF Views inside the module or might just be a service module which provides the required services used by the application. One major addition that PRISM brings to WPF with CompositeWPF is the ability to load modules as and when required instead of referencing to the modules. This makes the application to be capable of extensions (like the Eclipse – the most popular extensible application). Some of the module loaders are StaticModuleLoader, DirectoryModuleLoader, etc.

Views – Views reside in module. View is the visual aspect of the application. When we talk about views, i think it would be a good time to talk slightly about MV-VM pattern. In the MV-VM pattern, the code-behind or the View is kept very clean. Not much code would be written and the view goes through the ViewModel to interact with the Model. Model would have no idea about the View and View only deals with the ViewModel. View updates the model from the ViewModel using Two-way databinding, an excellent feature of WPF. In Jason’s talk, he actually mentions that a clean MV-VM implementation is one in whose View, the controls would not be required to have x:Name specified. I like this litmus test in particular since it is the most easiest way to ensure the MV-VM being followed. Composite View is a view that is composed other views and it is responsible for composing itself of the the child views. It might have content of its own.

Services – Model are the data objects which are displayed/modified via the Views. But these objects are to be created using a service. For example, InternetQuoteService generates Quote objects to give to the QuoteManager application. Services also sit in the modules and typically follow the singleton instance model.

So why do we need to use CompositeWPF (CAL or PRISM or shit)?

Look at the baseline architecture of the Composite Application Library.

If you would not use CAL, then you have the additional burden to implement all the portions that is in BLUE. And you should not forget that the design that you come up might not actually be a great design and using CAL helps you take advantage from the experience of the architects in the patterns & practices team. To summarize, the CAL provides the following services:

Logging

Region Managers

Event Aggregators

Module Enumerators

Module Loaders

The Unity API

First of all, I read this amazing article on Dependency Injection/IoC and Unity which I unfortunately lost the link to. (remember I formatted my laptop). Anyway , get a good link and understand what dependency injection is and then you need to know that the unity api has the following important methods.

Register – tell the container that it is responsible for creating this object.

Resolve – fetch an object from container which was Register-ed.

BuildUp – inject dependencies into the existing object

Configure – Register based on the configuration information.

I would be writing more on my experiences and I feel I have invested a lot of time, just trying to understand the LOB aspect of WPF applications. I know how the UI should look in our application but want to do it the correct way from the beginning. Hopefully, I would have the basic structure for the application ready, as soon as possible.

If you are into CompositeWPF and are looking for someone to discuss ideas or for any other general discussion, you can reach me at krishna.bhargav@hotmail.com

For about one and half month, I was very much involved with the WPF community on MSDN. At that time, I had around 50 visitors everyday, which to my standards is a pretty leap. If you look at the graph that compares the visitors, you notice a decent hike in the number of visitors.

Notice the region with highest number of visitors between October 2008 and December 2008 which was when I was very active on MSDN community. Then I stopped my activity since I went lazy and then my visitors dropped – which makes sense.

So fellow bloggers, if you want visitors, then be active on the community. My numbers are not high but at least they were doubled with my participation on MSDN community.

I use Windows Live Writer to write the blog posts and it is one tool that I always have it installed. Since I write developer posts, sometimes I need to post code snippets and this would be easier if we use one of the many code-formatting plug-ins that are available. But personally, I prefer the Code snippet plug-in. You can get it here. Just look at how nicely the code is formatted.

By default, your code snippet can look something like this.

1:publicclass TestClass

2: {

3:publicstring TestProperty { get; set;}

4:

5:publicstring AnotherProperty

6: {

7: get

8: {

9:return"Nothing";

10: }

11: }

12:

13:publicstaticvoid RunProgram(string item)

14: {

15:int i = 200;

16:if(i==0x23 && item == "krishna bhargava")

17: Console.WriteLine("This program is crap");

18: }

19: }

You can notice that the source code snippet is cut-off and the scrollbar should be used. Personally, I believe that this annoys the user to great extent. Readers like to glance at the code and derive their own conclusions, without actually reading it thoroughly. Thus, it is good to have source code listed something like shown below.

1:publicclass TestClass

2: {

3:publicstring TestProperty { get; set;}

4:

5:publicstring AnotherProperty

6: {

7: get

8: {

9:return"Nothing";

10: }

11: }

12:

13:publicstaticvoid RunProgram(string item)

14: {

15:int i = 200;

16:if(i==0x23 && item == "krishna bhargava")

17: Console.WriteLine("This program is crap");

18: }

19: }

You can do that by going into the source mode and modifying the style on the container div. The source code is placed inside a div when the plug-in I mentioned is used. In the style attribute of the container div, remove the property height: 253px; (the height might vary or might not be present) and also remove the max-height property. You can otherwise change the max-height property to something you like so that you can still limit the size of the source code section. Also removing "overflow: true” property allows you to remove the scrollbar altogether.

Anyway, if you are looking for source code plug-in for Windows Live Writer and if you like the code formatting displayed on this page, then you should get the plug-in.

Formatting problem in Blogspot.

If you try to use the code snippet plug-in in Blogger hosted blogs, then the source code could look something like shown above. This is because the blogspot engine somehow inserts <br/> tags between each lines making them look very ugly. You can fix this by going to the blogger dashboard of your account –> Layout –> Edit HTML. Scroll down until you see some styles being listed. Somewhere in between, insert the following CSS style:

Thursday, January 08, 2009

I am writing my first blog post for the year 2009 from Windows 7 BETA, which was made available today to MSDN subscribers. I was more than excited to have it installed on my laptop (Dell XPS, 1 GB RAM). And I would like to share some of my experiences with the OS over here.

Installation

Like many said, it is not blazingly fast. It was pretty decent since the initial copying files took longer than expected and the actual GUI based installation was faster. I assume, more files than required were copied during the initialization of the set up. Overall, it went on pretty smooth and I think within 30 minutes I had my machine up and running. I do not exactly remember how long it took me to install Vista, but Windows 7 is pretty fast (though not as fast as in the reviews, may be my HDD is old and is too slow for that).

Initial Look.

Few interesting things – for me – the wall paper looks awesome – a fish floating on the desktop.

Notice the build number, since it is BETA. The installation keys are not available on the MSDN subscribers page at the time of this writing, so I have not yet activated my copy of Windows.

Startup, Shutdown and Restart

Start-up was fast – much faster than what Vista gave me. Moreover, I enabled the option to use both the cores on my machine during the BOOT process (using msconfig). I think it has decent effect on the boot performance. I wanted to try No Gui Boot but haven’t had the heart to take the risk.

Shutdown – I initially had few issues shutting the system down. It was not responding for a while, but the last few times I tried, it went on smooth. I think it has to do something with me starting the machine up in safe mode and then restarting the machine. But when it works, it is fast.

Restart – pretty fast.

New Taskbar

The new taskbar has a lot of feel. I think the taskbar is moving towards the OS X style but the difference is that the taskbar is 100% of the width in the Windows 7. The shortcut WIN + T, gives a nice summary of windows on your desktop, just above the taskbar. You can maximize a window by pressing Win + Up Arrow or by simply moving the window to the top of the screen. This is more of an easter egg than intuitive.

Also in the image, you can see the list of new shortcuts for windows 7. Quick Launch is gone and is replaced with the task bar itself where you can pin your applications. On my task bar, the first one is IE, so WIN + 1 launches IE. This, I think, would be very useful once we get the feel of the shortcuts. The window arrangement is pretty sweet too – OS X like feature to hide all windows by moving the mouse to the bottom right corner and brining up the gadgets (this actually sets transparency of the windows to 0, so they are invisible and if you have any gadgets, they appear). The Show Desktopis now the little rectangle very next to the time. Click that button, you get your desktop.

Start menu

The start menu also behaves differently. Applications can also be pinned to start menu (just like in the case of task bar)

Notice the Pin to Taskbar and Pin to Start Menu options in the context menu of the files.

Notice the Context Menu has changed – it is now more like a preview window than context menu. You can also pin a window to task bar from here.

Powershell ISE

Great news for geeks is that Powershell along with the new IDE (Powershell ISE) comes pre-installed. The Powershell ISE is very good and I believe it is WPF based, given its smooth zooming functionality (Ctrl + +). Zoomed ISE is shown below.

You can run powershell commands as well as write PS scripts. It has debugging capabilities too. I remember seeing something like in PowerGUI or not sure if it is the same one that I saw few months back. But this tool looks promising.

Mounting ISO

I tried to make Daemon Tools work on Windows 7 but the SPTD driver that is required does not get installed on Windows 7. So I installed Virtual CloneDVD. Initially even this did not work – the software got installed successfully but failed to show any new drives inside the Explorer. But after I rebooted the machine into SAFE MODE, I could see the new drives added. Then I switched back to normal boot and it worked.

Installing Visual Studio 2008 SP1, Silverlight on Windows 7

I had no issues with installing the VS 2008 SP1, Resharper 4.1, Silverlight 2 Runtime and PowerCommands. So far, things are working as expected.

Themes

There are new theme packs to change the looks of the windows shell. Not all are up to my taste, so I decided to stick with the default one. But there are some good themes, if you did like to try.

The context menu on the desktop now includes Screen Resolution option.

Wireless

The Wireless settings were taken care at the beginning of the set up and it has been very good so far. The wireless repair, I read, is repaired automatically, if required.

UAC

The UAC is still on by default but the better news is that it does not block you from using other programs, if there are any running. It shows a shield like icon in the task bar and you get the UAC prompt when you click that. This is way better than the previous one in Vista.

ReadyBoost

ReadyBoost – using Flash Stick as paging cache to speed up paging is still present. I haven’t actually tried it to see if it made it any better.

Connecting to a projector

The image below shows the options (Win + P) and it looks sweet. This is way better and I am not sure if it is already present in Vista (haven’t used it before). Since I connect my machine to my HDTV, this is a really cool discovery for me.

Ribbon UI

Ribbon based UI, the one that came with Office 2007 is not everywhere. By this I mean, explorer does not have ribbon UI but Paint and Wordpad sure does.

Calculator

Calculator is improved – two more modes added (Programmer, Statistics). The Options are increased and shown in the image is the templates option. More on calculator later.

ANNOYANCES

There are some areas which I think needs certain improvements.

1. The wireless status icon color is deceiving. The color contrast between connection level and no connection is not good enough and when the connection is 100%, the icon appears as if there is no connection.

2. The shutdown that failed – it almost made my heart skip. I removed my Vista install, the one which I used for over 1.5 year to use this. So i was worried.

3. The taskbar is good but it does not display any text or name of the application. If you want to see the text, then you need to hover on the icon. I like visual information but little text would sometimes make more sense than the icons – at least in the beginning. Not many of us remember the icons of rarely used programs.

4. For some reason, my external HDD did not show up in the explorer when I connected it for the first time, during the first boot. It just worked fine from the next boot. No clue on why it happened.

OVERALL – 4/5

Excepting the annoyances listed, the experience so far is very good. The UX is improved vastly though most of the UI looks like Vista, it is the feel that has changed drastically. My system rating was 2.0 given my age old HDD on the laptop but on a 1 GB machine, the OS is very fast and I feel it is even better than XP. Performance is good – starts up fast, shuts down fast, reboots fast – that is great news for others, for me it does not matter since I hardly shut down my laptop. Users versed with Vista would find no issues working around the UI since the UI principles are the same. And since I liked it, I consider Windows 7 (even the BETA) to be worthy of trying out.

Though, the post is not exactly descriptive, I tried to show as many images as I can. I hope to cover more details in subsequent posts.