AT&T Mobile Users - Keep Your Phone Off Abroad

June 20, 2010 11:06 by Alec Bryte

Guys,

I've recently visited Aruba for 5 days. When I got my cell phone bill, it was $100 more than usual. The statement contained $1.99/minute charges for the roaming phone calls.

What surprised me was that many of the $1.99 charges I got were for the phone calls I DID NOT PICK UP. Everytime I got an incoming call from a BLOCKED phone number, I just ignored it and let it ring.

It turned out I still got charged for those "conversations."

When I called the AT&T support they said it was by design and that I would charge for those calls anyway because I was connected to the other network. Their suggestion was for me to keep my phone off at all times.

Next time I'm definitely renting a phone in a foreign country.


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/