Including Unreferenced Assemblies Into ClickOnce Deployment

October 29, 2009 22:43 by Alec Bryte

Many modern modular application products consist of the main application and several plug-ins. it has become popular to utilize the Unity Framework and Prism for WPF, which allows decoupling of the parts of the application from one another. The plug-ins are loaded at runtime using reflection. Usually the main application has the list of plug-in modules to load defined in its configuration file. Naturally the main application does not need to know of the existence of a particular plug-in or its internal structure until the execution time.

In such Visual Studio solution it makes sense not to add the plug-in projects or assemblies as references to the main application. However this presents the challenge when one needs to deploy the application with the plug-ins via ClickOnce. The ClickOnce architecture doesn’t allow one to include arbitrary files that are not part of the project.

It turns out there is no real harm in adding a project reference or a DLL reference to the main project. It’s true that during the compile time, the referenced assembly is passed to the compiler as the /r:MyReferencedAssembly.dll. However the compiler is smart enough to recognize that the main project makes no use of any of the classes inside the child assembly, and the reference is simply ignored.

For example, in the following screenshots, I used Red Gate’s .NET reflector to show that even though I added a reference to the project called MyPlugIn, the compiled assembly does not have any reference to it.

image

image

I hope this article saves time for another perfectionist developer like me :)


Code Generation Using Templates in Visual Studio 2008 and Higher

September 30, 2009 11:58 by Alec Bryte

If you've ever worked with CodeSmith or any other code generation toolkits, now you can enjoy the same functionality out of the box with Visual Studio 2008 or higher. The code name for it is T4, which stands for Text Template Transformation Toolkit.

The functionality is there but has been poorly documented in 2008 and the UI support is somewhat underdeveloped. This however has been fixed in Visual Studio 2010.

For more information, see Oleg Sych's blog entries on the topic.
http://www.olegsych.com/tag/code-generation/

In addition, there are some videos for it in Kevin Dietz's blog.
http://www.kevindietz.com/2009/03/27/UsingVisualStudio2008T4CodeGenerator.aspx

Finally, Scott Hanselman's blog entry
http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx


Padding Images using GDI+

September 9, 2009 15:07 by Alec Bryte

Recently I had to poke around in the good ol’ WinForms code and add some spacing to the images posted onto a form. I wrote a simple helper method for adding that extra space (padding) around the image. Here it is:

 

public static Image PadImage(Image source, int left, int top, int right, int bottom)
{
    Bitmap bmp = new Bitmap(source.Width + left + right, source.Height + top + bottom);
    Graphics g = Graphics.FromImage(bmp);
    g.DrawImage(source, left, top);
    g.Dispose();
    return bmp;
}

WPF Proportional Panel

January 16, 2009 12:59 by Alec Bryte

Standard Layout

Windows Presentation Framework provides a great flexibility when it comes to the layout. There are several Panel controls a developer may use to position elements, and they include:

  • Canvas - for absolute positioning of elements using (X,Y) coordinates. Useful for drawing custom graphics
  • Grid - most commonly used layout control. Allows dividing area into rows and cells and automatic alignment of controls placed inside the cells.
  • StackPanel - ideal for placing several controls next to each other, horizontally or vertically
  • DockPanel - aligns elements to a particular edge and allows an element to stretch and fill the remainder of the space

Custom Layout

All WPF panels are derived from Panel public class, which means one can create his own custom panel implementation.

In my case, I needed to create a special type of a panel that would resize the child elements based on a given percentage value. For example, assume two elements are in the panel positioned horizontally and the first one has a value of 20%, while the second one is 80%. The width of the first element would be 20% of the total available width, and the remainder would be the 80% of the width taken by the second element.

Here is an example with 4 elements:

ProportionalPanelDemo

Notice how the elements have their widths proportional to their percentage values.

To achieve this behavior we will create a class ProportionalPanel derived from the original Panel class. There we need to override 2 important methods that take care of the layout logic: ArrangeOverride() and MeasureOverride(). Basically, when a panel renders elements, it first asks each child for its current size. It then uses the values to properly position the elements.

        protected override Size MeasureOverride(Size constraint)
        {
            [...]

            double totalProportion = 0.0;
            foreach (UIElement child in this.Children)
            {
                 totalProportion+= GetProportion(child);
            }
            foreach (UIElement child in this.Children)
            {
                if (Orientation == Orientation.Horizontal)
                {
                    childWidth = constraint.Width * (GetProportion(child) / totalProportion);
                    childHeight = constraint.Height;
                }
    [...]

Note that GetProportion() is implemented as an attached property. This allows setting Proportion values on elements inside our panel. Since we want to allow just about any element (TextBox, Grid, ComboBox, Rectangle) to be placed inside the panel, even a custom element, such elements won't have a Proportion property by default. Attached Properties is a new and a very powerful feature in WPF that allows extending of existing classes with custom properties.

Using Proportion attached property, we can set the value as follows:

<ctl:ProportionalPanel Orientation="Horizontal" >
    <TextBlock Text="Apples" ctl:ProportionalPanel.Proportion=".20" />
    <TextBlock Text="Oranges" ctl:ProportionalPanel.Proportion=".15" />
    [....]
</ctl:ProportionalPanel>

Complete Solution

Click below to download a working Visual Studio 2008 solution of the WPF Proportional Panel.
ProportionalPanelDemo.zip (27.24 kb)


Great .NET resource list

December 22, 2008 13:04 by Alec Bryte

If you're as crazy (in a good sense) about .NET technology as I am, check out http://www.dotnetkicks.com/. It has links on top of links to useful articles. Those include blog entries on cutting edge technologies like ASP.NET MVC, futures of the Entity Framework, C# 4.0 dynamic language extensions, cloud computing, etc.


Rocking the Stage at MiX08 with Rock Band for XBOX360

March 31, 2008 10:44 by Alec Bryte

We're in Vegas at the MiX Conference, what a rush. Rock Band is Microsoft's latest addition to the Guitar Hero series. Now it's a complete band with a lead guitar, a bass, drums and of course a vocalist.

The game rules are simple. Guitar players hit the right buttons on the controller, there are 3-8 buttons used depending on the level of difficulty. The drummer hits the right drums with the sticks. The singer - well, he has to actually sing the songs in the right tonality. The screen shows you if you're singing off key. PRETTY AWESOME! I was getting close to 97% accuracy on all the songs. Here's the list of those we did:

  • Enter Sandman by Metallica
  • Go With the Flow by Queens of the Stone Age
  • Wanted Dead or Alive by Bon Jovi
  • Learn to Fly by Foo Fighters
  • Black Hole Sun by Soundgarden
  • Dani California by Red Hot Chili Peppers
  • When You Were Young by The Killers
  • I'm So Sick by Flyleaf

Strangely enough at this conference guitars were the most popular choice followed by drums but no one really wanted to sing. That's great since I never pass a karaoke bar, no mater which country I'm in.

Me Rocking the MiX. Click for the full size image.

We rocked. The crowds cheered. I probably did about 10 songs in a row with different drummers and guitarists. Now I think I'm going to buy the set and do rock band parties in my apartment.

A word of advice to anyone who likes to sing: don't eat ice cream in between songs. Microsoft treated us with some tasty Häagen-Dazs, and for the rest of the day my voice sounded like a 1950s radio.


Improvising @ The Upright Citizens Brigade Theatre

December 7, 2007 15:50 by Alec Bryte

UCBT is the best place for comedy in New York City, and probably the world. Where else can you watch a hillarious show that is fully improvised, fun, and only costs $8. You can't beat that, especially in The Big Apple.

UCBT has been a major part of my life since early 2004, where I took their first class. Since then, I became a regular.

This photo was taken during the warm up for one of our shows, in one of their cold basements. Well, at least I was getting warmer. Thanks guys for hugging me.

Yep, we found that thing called "The Closure" and it sure helped us. The show was a blast.

 


Snowboarding @ Zermatt, Switzerland

September 10, 2006 17:05 by Alec Bryte

 

Here are some pictures from my Switzerland vacation. Where else can you find snow in August?

This is the Matterhorn mountain. There is a group of people who climb it almost every day. You can join them too.

  

The village looks great. Smaller hotels, plenty of rooms to rent. This is a pedestrian village, which means no gasoline cars allowed. You have to park your car in the nearby village and then take a train to Zermatt.

 

This is an interesting device - a drink mixing machine. Every bar has it and it doesn't require a bartender to posess any skills, just press the right button. Gin & Tonic = press A8.

It's the last week of August. The weather in the village is 15 degrees Celcius. You have to go 3000 meters up the mountain to get to the snow. There is a chain of gondolas that take you there.

In winter time you can take the same gondola up and then ski down aaaaall the way to the village. These are not your typical short slopes of the US East Coast. It might take you some time to get all the way down.

Once you've arrived at the top of the mountain by the gondola, there is a tunnel that takes you to the opposite side of the mountain top.

Beautiful view. Notice that there are no chair lifts. Only t-bars.


Paintball at High Velocity

March 26, 2006 20:37 by Alec Bryte

GET DOWN!!! There is an enemy shooting from each side.

Shooting people has always been fun; ask any experienced hit man. This time our team Rush-N-Kill was out hunting some fresh blood.

This is me, hiding behind enemy lines. A single wrong move, and you're dead.

We've been experimenting with different guns. This one is semi-automatic, battery powered. It takes time to get used to it but once you do, you wonder how in the world you'd ever manage without it.

Here's me again, this time with the regular (rental) gun. It usually works without glitches, so I kept alternating between guns.

My old buddy Diesel-.

Here's their website, in case you ever want to check it out:
http://www.highvelocitypaintball.com/


India Trip, Summer 2005

March 26, 2006 19:58 by Alec Bryte

Ohm... Shanti Shanti...
I'm south of India, city of Chennai (formely Madras), province Tamilnadu. Surprisingly enough, everyone here speaks enough English to communicate with outlanders. The native language is Tamil but most of the time you don't hear it, unless you're in a little village; or perhaps they all stop speaking it when they see a whitey.

I feel like a rock star. Surely, I'm the center of attention. Most people here have never seen a white person before. I bet they've never seen blond hair either. I don't know if I can handle all this popularity. Now I know what being a super hot woman in New York feels like. This is probably not going to change the way I look at super hot women, though.

On Partying...

There is a dozen of night clubs in Chennai. However, they all close down at 11pm. WTF??? At exactly 11pm the music stops, the lights are lit, and the bar is closed. Nobody really kicks you out at this point but 20 minutes later everyone wanders off anyway, thristy and craving more excitements. Fortunately, at this point everyone is unafficially invited to an afterparty - the party is at our office/hotel.

 

 

Back to Business

I'm here on a long business trip, which lasts about a month. There is a plethora of .NET developers to teach. What's really funny is that a lot of them are women. I always thought being a computer geek is a privelege of the male race but in this country many roles are reversed. If I'm in a bar talking to a local lady, chances are she's a programmer. You can tell it right away by the first words from their mouths. A classic example is "Do you play 'Dungeons and Dragons?' I love strategy video games." OK, maybe not the exact words but you get the picture.

On Whacky Food

If you are a New Yorker like myself, who is used to variety, you'll suffer greatly. Food out here is fairly basic; there is not much of a choice. Chinese, Japanese, Mexican, Italian? Forgetabout it. Be prepared to eat the same stuff every day.

Also, food is just too damn spicy. Asking the chef NOT to put hot stuff into your dish won't help you. The standard response is, "Sorry, my friend, this is just part of the food."

Here's me munching on a Dosa. It's filled with chili peppers. This picture was clearly taken before I took the first bite

 

 

On Culture

But enough of my bashing. There were interesting things to see, like this unfinished sphere in Auroville - The Town of No Religion. This is the only place in India where people don't practice any religion. I didn't meet many people around there so it was tough to make anything out of it but I liked the concept.

 

Here's another interesting thing - getting blessed by an elephant. One leans in and the elephant blesses him, i.e. lightly taps him with its trunk.

This particular elephant won't bless you unless you give it a coin.

There were also nice temples; unfortunately we weren't allowed to photograph. Gotta respect that...