Official Forum Flame Form


<lol> This is hilarious! :) Here is a simple check off list for flaming forums. I’m not a flamer, but I’ve got to try using this sometime when it would be appropriate. The checks are from its original post.

Official Forum Flame
==============================================
Dear:
[ ] Clueless Newbie
[X] Loser
[ ] Spammer
[ ] Nerd
[ ] Vet
[X] Other: Troll

You Are Being Flamed Because
[ ] You bumped a thread from the last page.
[ ] You started an off-topic thread.
[ ] You posted a "YOU ALL SUCK" message.
[ ] You don't know which forum to post in.
[ ] You posted false information (or lack thereof).
[ ] You posted something totally uninteresting.
[X] You want to sue a company for your bad experience.
[ ] You doubleposted.
[X] You posted a message all written in CAPS (oR aLtErNaTe CaPs).
[ ] You posted a X > Y thread.
[ ] I don't like your tone of voice.
[X] You said/suggested something incredibly stupid.

To Repent, You Must:
[X] Give up your AOL Internet account
[X] Jump into a bathtub while holding your monitor
[ ] Actually post something relevant
[ ] Apologize to everybody on this forum
[ ] Go stand in the middle of a freeway

In Closing, I'd Like to Say:
[X] Get a life
[ ] Never post again
[ ] I pity your dog
[ ] I think your IQ must be 6
[X] Take your crap somewhere else
[ ] Do us all a favor and jump into some industrial equipment
[ ] Go play Dress-Up Barbie Online
[ ] All of the above 

Reverse Enum Lookup

Sometimes you may have the string name of an enumeration identifier, and want its enum type. For example, you write a enum identifier as a string to a file and want to read it back and obtain the original enumeration type. This takes place when you serialize a class to an XML file and deserialize it back using XmlSerializer.

private enum Direction {North, South, East, West}; private Direction ParseDirection(string name) { return (Direction) Enum.Parse(typeof(Direction), name, true); }

Obtaining Indented XML as a String

Using XmlDocument.Save(string file) produces a file with nicely indented elements. XmlDocument.OuterXml returns a string without any formatting. If you want a nicely formatted string (to display to the user, write to console, etc), without directly writing to a file, you must use the XmlTextWriter.

The using statements in the method makes sure the resorces are disposed of sooner than later. Here is the code to return a string of formatted XML from an XmlDocument. Download Example Code (requires Visual Studio 2005)

using System.IO; using System.Xml; public static string FormatXML(XmlDocument doc) { // Create a stream buffer that can be read as a string using (StringWriter sw = new StringWriter()) // Create a specialized writer for XML code using (XmlTextWriter xtw = new XmlTextWriter(sw)) { // Set the writer to use indented (hierarchical) elements xtw.Formatting = System.Xml.Formatting.Indented; // Write the XML document to the stream doc.WriteTo(xtw); // Return the stream as a string return sw.ToString(); } }

Creating Quick Tests in C#

Update on 5/2/07:  This post has nothing to do with Unit Testing (it was written before I was aware of unit testing) but has to do with write little bits of code to try new stuff out.  It is also only for VS03.  For the current version (VS05), see this post: CoadNet VS Project Templates, Quick Code + Console App for C# in VS05

CoadTools Quick Test C# Project Template (setup .msi) for Visual Studio .NET 2003

Introduction
Very often I need to test a tidbit of code, do some research on a class, etc. In fact, I was creating several times as many quick code test projects as any other project need. I used to start a Console application, change it to a Windows Application, but still needed to add namespaces, etc. So I created a custom “New Project” template for Visual Studio .NET 2003. To use, just install, load VS.NET, choose “New Project”/”Visaul C# Projects”/”Quick Test”, and you’re good to go.

The Goal
The main goal was to minimize the time to test code. Just start VS.NET, choose the “Quick Test” project, and type code. I wanted to send output to the Trace (VS.NET Ouput Window) and have the most common namespaces already included. You can easily modify the template after it is installed to suite your own needs.

Compare and Contrast
A popular tool is Snippet Compiler, which is a stand-alone mini-IDE for testing code. This is a great tool, especially if you do not own VS.NET 2003. When testing, I find that I want the full VS.NET environment, which I’m most familiar with and productive in, and to perform quick MSDN help lookup and take advantage of the full debugging interface. Just a simple custom “New Project” template like this provides all these objectives in a simple manor.

Saving Code
When creating a new quick test project, I usually just store the project in “C:\Temp\Test”. This way I keep my tests for future reference and they are out of the way.

Leave Feedback
This is completely free. All I ask is that you leave a feedback comment. :)

VS.NET 2003 “New Project” Dialog w/ Quick Test Project

Code Template in VS.NET, Fully Customizable

Screen captures have been brought to you by SnagIt. This is my first use of SnagIt, a powerful screen capture utility, and it is fantastic! Extremely easy to use (a big plus for me) and it includes additional editing tools.

Property Event Pattern

Introduction
Since the advent of .NET, one of my most frequent and useful patterns is using an event to notify change in state. Applying this pattern has reduced overall code, improved reliability, and made maintenance and expansion easier.

Why? The Context
Without events, spaghetti code occurs real quickly when one method changes state that other code is dependant on without notifying that the change is made. This is one of the most frequent causes of coding errors (bugs) in mid-to-large applications that I have seen. Events go a long way in solve this issue.

This should be obvious with public properties that can be changed externally, but must be acted upon by the owner. Such as the Text property on a label, when changed, the label must be redrawn.

Common Example
This is used extensively on Windows Forms components. Almost every property has an associated change event. TextChanged for the Text property, EnableChanged for the Enabled property and so on.

Internally Critical
This pattern becomes more subtle but critical with internal members. In larger applications, for clarity, I wrap most all class variables in properties with change events. If the class is designed to be inherited, this becomes all the more important as you can not rely on derived classes to notify your code when they change state.

The Solution

  • Subscribe to Events
    Code that depends on a class’ state can subscribe to the appropriate change event to receive notification of when that state changes to take appropriate action.

  • Event Triggers
    The “Event Triggers” allow easy triggering of the event and allow derived classes the option of first notification (before the event occurs).

  • Internal Access Through Properties
    Even internal members should access the variable through the property to ensure that notification occurs. In other words, members should not access the class variable directly, only through the property.

#region Public Events public event EventHandler DevicePortChanged; #endregion #region Property Variables private int m_DevicePort; #endregion #region Public Properties public int DevicePort { get {return m_DevicePort;} set { int saved = m_DevicePort; m_DevicePort = value; if (saved != value) OnDevicePortChanged(EventArgs.Empty); } } #endregion #region Event Triggers protected virtual void OnDevicePortChanged(EventArgs e) { if (DevicePortChanged != null) DevicePortChanged(this, e); } #endregion

References

.Text Upgrade on MVP Site

Susan Bradley just updated (6/11/04) msmvps.com to .Text v0.95.2004.102. We’re still working out the kinks, but it is coming along!

So if your agregate news reader shows double post entries (like my RSS Bandit), you know why. If you’re using RSS Bandit, just follow these steps to restore normality.

  1. Close RSS Bandit
  2. Edit “C:\Documents and Settings\[UserName]\Application Data\RssBandit\feedlist.xml”
  3. Search for “msmvps.com/coad”
  4. Delete all elements inside of the “stories-recently-viewed” element.
  5. Delete the Cache\msmvps.com* (or Cache\www.msmvps.com*) files.
  6. Load RSS Bandit, it will automatically download and recache the posts.

Associating a File Extension and Context Menus with an Application in the Registry

You can easily assign a file extension to open with your application in the registry.

Verbal Description
The extension is added as a key under “HKEY_CLASSES_ROOT” with the (default) value set to the file’s type (a string arbitrarily assigned by yourself). Then you add a key with the file’s type also to “HKEY_CLASSES_ROOT” with its (default) value set to the file’s type description (that is shown in Exporer). Under the same key, add they keys “shell/open/command” with the (default) value being the program to execute. Use “%1″ with the quotes to pass the file’s name to your app. You can also assign an icon by adding a “DefaultIcon” key under the file’s type key. Then additional context menu items can be added by putting keys the [filetype]/shell/[MenuItem]/Command

Example Registry Entries

  • HKEY_CLASSES_ROOT\.npost = NovaBlog.Post
  • HKEY_CLASSES_ROOT\NovaBlog.Post = NovaBlog Article Posting
  • HKEY_CLASSES_ROOT\NovaBlog.Post\DefaultIcon = C:\Program Files\NovaBlog\NovaBlox.exe,0
  • HKEY_CLASSES_ROOT\NovaBlog.Post\shell\Open = &Open
  • HKEY_CLASSES_ROOT\NovaBlog.Post\shell\Open\Command = C:\Program Files\NovaBlog\NovaBlox.exe “%1″
  • HKEY_CLASSES_ROOT\NovaBlog.Post\shell\PostNow = &Post the Article Now
  • HKEY_CLASSES_ROOT\NovaBlog.Post\shell\PostNow\Command = C:\Program Files\NovaBlog\NovaBlox.exe /postnow “%1″

C# Code
Thankfully there is a Microsoft.Win32 namespace with classes for working with the registry. This is all there is to it!

// Created by Noah Coad, 6/11/04 using Microsoft.Win32; using System.Windows.Forms; public static void CreateRegEntries() { RegistryKey rkey = Registry.ClassesRoot; rkey.CreateSubKey(".npost").SetValue("", "NovaBlog.Post"); rkey = rkey.CreateSubKey("NovaBlog.Post"); rkey.SetValue("", "NovaBlog Article Post"); rkey.CreateSubKey("DefaultIcon").SetValue("", Application.ExecutablePath + ",0"); rkey = rkey.CreateSubKey("shell"); RegistryKey keycmd = rkey.CreateSubKey("Open"); keycmd.SetValue("", "&amp;Open"); keycmd.CreateSubKey("Command").SetValue("", "\"" + Application.ExecutablePath + "\" \"%1\""); keycmd = rkey.CreateSubKey("PostNow"); keycmd.SetValue("", "&amp;Post Article Now"); keycmd.CreateSubKey("Command").SetValue("", "\"" + Application.ExecutablePath + "\" /postnow \"%1\""); }

Ultra-Portable Laptop

Overview
I have received many inquiries in airports, conferences, classes, meetings, etc when I pull out my laptop and it is smaller than even the thinnest paper notebooks on the table. I’ve seen too many people not carry or use their portable computer because it was inconvenient, this defeats the purpose of a laptop. Even with my last Sony VAIO V505, which was only 4 lbs, I still found that I would leave it behind because it just wasn’t easy enough. Not so with this little system, it goes everywhere with me. This has been one of my most enjoyable, useful, and best investments.

Specifications

Sharp Actius MM10 (PDF)

Cost$1400
Weight2.10 lbs (0.95 kg)
Dimensions9.9″ x 8.2″ x 0.54″ (min.)/0.78″ (max)
Processor1 GHz Transmeta Crusoe
Memory256MB DDR SDRAM (fixed)
Video ControllerSMI Lynx3DM+ w/ 8MB
Display10.4″ XGA TFT LCD (1024×768)
Networking10/100 Ethernet & 802.11b Wireless
Hard Drive15GB
Pointing DeviceTouch-Pad
PCMCIAType II x 1, CardBus port supported
I/O PortsUSB 2.0 x 2, LAN, Audio output, VGA dongle cable connector, DC in, Cradle connection
Storage MediaExternal USB 2.0 CD Writer / DVD Reader Combo


The Review

  • Purpose
    This is definitely a secondary, travel computer, it is not ment to be a primary system. Using a synchronization program I found with my own custom written multi-threading overhead, I can very easily synchronize my files to/from the laptop anytime. Frequently I’ll just use the laptop to Remote Desktop to my main system when on the couch, front porch, or friend’s house and will get another 30% of battery life.
  • Summery
    Overall I love this thing! For its purpose, I’d give it a 4.5 star rating.
  • Size
    Oh my gosh, this is definitely one of the biggest advantages! It is just so thin and light-weight! If a laptop is not light and small enough to be carried, it is no good to me (since it is not truly portable). The case is just barely thick enough for the PCMCIA and USB ports!
  • Low Power
    Since it uses the low power Transmeta processor, it runs cool, doesn’t need a fan, and runs about 2.5 hours on the standard battery and 9 hours on the slightly larger battery.
  • Speed
    Even through it is 1 GHz, it still runs slow, but is fast enough to run WinXP Pro, IIS, Visual Studio, Office, and anything else I’ve thrown at it.
  • Storage
    The 15GB may seem small, but I can still keep 5GB free. It uses a specialized hard drive because just the normal laptop drives are actually thicker than the computer!
  • Memory
    The 256MB of RAM may also seem small, but remember, it is not for high-power work and actually works out just fine. It hibernates and resumes quite quickly, which is a big plus.
  • Removable Media
    I actual really like the fact that it does not have internal removable media (floppy or CD drives) which I find quite unnecessary most of the time and would just add useless bulk. They only thing I’ve really needed the external CD drive for was reloading the operating system. Everything else I do through the Internet, FTP, USB Sticks, virtual CD mounts, etc.
  • Docking Cradle
    It comes with a docking cradle that mounts its internal hard drive as a drive on the main PC, but I never ever use it. I just use folder shares and a wireless network and am set.
  • Keyboard
    The keyboard is small. No doubt about it; it takes getting used to. Fry’s Electronics (where I bought it) stopped carrying it because of too many returns by people saying the keyboard was too small. Once you get used to it, it is very efficient and I can actually type faster on it. So much so that I purchased a similar mini-laptop styled keyboard for my main system.
  • Networking
    The 10/100 Ethernet and 802.11b wireless work great! The wireless does not take as much power as I would expect. It does not have a modem built in, but comes with a v.92 PCMCIA modem which I find I rarely ever need anyways.

Comparison
It has been hard to compare this unit since finding something comparable in weight and size has been difficult until recently. Sony just announced their new VAIO X505 which is very similar.

The VAIO X505 costs twice as much ($3k), uses an Intel 1 GHz M, has 512MB RAM, 20GB HD, does not have built-in 802.11b wireless, does not include a CD/DVD drive ($400 more), uses an eraser head pointer (no touch pad), weighs slightly less (1.9 lbs), is about the same physical size, is the same size and resolution display (10.4″), and does not have the option of an extended life battery.

Conclusion
This is designed to be a secondary, travel, take your files with you, type of compuer. For that, dang, it is awesome! The size, weight, price, and features just can’t be beat (yet).

Favorite Bloggers

News/Blog Reading
RSS Bandit is a great aggregate news reader. It is writting entirely in C#, is easy to use, works like a charm, and is even open source so you can see how various components have been implemented. To add feeds, just right-click in IE on an XML or RSS icon in the blog (or the RSS links below) and choose “Subscribe in default aggregator”.

Favorite Bloggars (To Date)
Here is a list of the blogs I am currently subscribed to. As my list is modified over time I’ll repost this list of active bloggers. These are really great posters!

Jeffery PalermoRSSASP.NET Dude
Cyrus’ BlatherRSSVS IDE Team
Ted NewardRSS.NET & Java Author
Jean-Luc DavidRSS.NET MVP & Author
Erik PorterRSS.NET MVP
Eric GunnersonRSSC# Team
Duncan MackenzieRSSC# Team
C# Frequently Asked QuestionsRSSC# Team
Visual Studio 2005 Team SystemRSSOfficial VS TS News