Allowing Remote Desktop Access to Windows XP, Step by Step

Way back in October of last year (https://arcanecode.wordpress.com/2006/10/09/remote-desktop-connection/ or http://shrinkster.com/mvr) I wrote about using the Remote Desktop tool.

A few people have had problems accessing their desktops, so I thought I’d provide some step by step instructions on how to allow your computer to be access via Remote Desktop.

First, open Control Panel.Then, open the User Accounts.

Click “Change the way users log on or off” and uncheck “Use the Welcome screen”. Click Apply Options.

[Picture of User Acct Screen]

Click on your account, and make sure it has a password. If not, click “Create a password”, then create one.

Close out the user accounts, then close out Control Panel.

Right click on the “My Computer” icon, and pick Properties.

Select the “Remote” tab.

Check the box on that reads “Allow users to connect remotely to this computer”.

[Pic of System Properties Remote tab]

Click Apply and OK, and you should now be able to access your computer via Remote Desktop. Just follow my instructions in the post I mentioned at the beginning of the message and you should be in good shape!

Developing From The Network

When developing, it’s nice to be able to save and run your projects from your corporate network. Network drives are typically backed up, where local hard drives are often not unless you take the time to do it yourself.

As part of it’s code security initiative, the .Net Framework protects us by not allowing us to run code from an “unsafe” location. Unfortunately .Net often sees company networks as locations that are not safe.

It’s easy enough to remedy, with a simple command that no one seems to know about. I finally lucked out and found a brief reference on Chris Sells blog. I’d like to expound on his entry slightly and go into a little detail about what’s going on.

First though, let me give you the command in case you are the type of person who just wants a quick fix:

First, navigate to your c:\windows\microsoft.net\framework\ directory. Now, if you are using .Net 1.1, drop into the v1.1.4322 folder, if you are using .Net 2.0, go into the v2.0.50727 directory. Now execute the command

caspol -q -machine -addgroup 1 -url file://z:/* FullTrust -name “Z Drive”

Make sure to type it in all as one single command, in case your reader has wrapped the line. The two things you need to note are the folder designation, z:/* and the name in quotes “Z Drive”. For the z:/* put the drive letter for the network drive you want to give permissions to. You can also add a folder if you want to narrow it down for security, such as z:/myprojects/* .

Inside the quotes you can put anything you want, I made it easy and named it Z Drive, but you could call it “Projects on Z” or “My Projects” or “Arcane is a wizard at this coding stuff”.

Now for those who are a bit more inquisitive, here’s a breakdown of the command line options.

-q     Runs in quiet mode, suppressing all of the normal “are you sure” prompts

-machine     The commands will apply to this computer.

-addgroup     This adds a new security group to your machine, with the name you enter in quotes.

1     is the parent group under which you are adding, use 1 for the base group on the machine.

-url file:     Indicates we are adding a url, in the form of a file spec. Normally caspol expects your adding a website or webservice you want to execute code from, using the file: spec gives us a work around to add a network drive.

FullTrust     Again, an obvious entry that sets the security level in addgroup.

-name     Obviously the name you want to give to your group. Following the –name place the name in double quotes, such as –name “Z Drive”

After issuing the command, you probably want to verify your new permissions have been set. To do so, use this command:

caspol –listgroups

This will list your security groups, with your newly named group (the name you put in quotes) at the bottom of the list. It should look something like:

1.7. Url – file://z:/*: FullTrust

Finally, if you want to find out more about the access security policy tool, use the command

caspol -?

To display screen after screen of help text.

And that’s how you can set it up so you can run your .Net applications from your company network.

Dictionaries in C#: OrderedDictionary

There are times in life when you’d like to have your cake and eat it too. With a hashtable, this means there are times when you want to use the keys to look things up, or iterate in a foreach using DictionaryEntry objects. There are other times though when it would be easiest to treat the collection as if it were an array, using a traditional for(int i=0; … type syntax.

The OrderedDictionary is what lets you have the best of both worlds. Using it, you can perform specific actions at a numeric index in the collection, or you can use the Dictionary Entry style of looping over the collection. Like the other specialized dictionaries I’ve mentioned in the latter part of this week, you will need a using System.Collections.Specialized reference.

Let’s take a look at an example.

      OrderedDictionary myOD = new OrderedDictionary();

 

      myOD.Add(“01”, “First”);

      myOD.Add(“02”, “Second”);

      myOD.Add(“03”, “Third”);

      myOD.Add(“04”, “Fourth”);

      myOD.Add(“05”, “Fifth”);

 

      // Reference the values array style

      for (int i = 0; i < myOD.Count; i++)

      {

        // Create a strongly typed variable to hold the

        // generic object in myOD[], then do a cast

        string valueString = (string) myOD[i];

        Console.WriteLine(valueString);

      }

 

      // Reference the values Dictionary style

      foreach(DictionaryEntry myDE in myOD)

      {

        Console.WriteLine(myDE.Value);

      }

 

Above you can see I used two different methods to iterate over my collection. In the first example, I used a for loop and a numeric index to retrieve each object (in this case a string) stored in the collection. Using a cast I convert it from the generic object type into a more strongly typed variable.

While it’s true I simply could have used Console.WriteLine(myOD[i].ToString()), you will not always be dealing with string data in your value. This example demonstrates how to do a simple conversion.

In the second loop, you can see code similar to what has been shown all week, using a DictionaryEntry object to iterate over the collection.

The other advantage to an OrderedDictionary is speed. When going over a large collection, reading the OrderedDictionary using the first example, the numeric index, is always going to be faster than using the dictionary style method.

When you need both the power of a collection, and the simple access of a numeric index, the OrderedDictionary is the collection of choice.

Dictionaries in C#: The HybridDictionary

So far we’ve looked at the HashTable collection, and determined that it’s the way to go for large collections. We’ve also taken a look at the ListDictionary, which is geared towards very small collections. But what if you don’t know how big your collection will be?

There are many situations where at design time you simply can not know what the final size of your collection will be. Sometimes it will depend on user input, what range of data the user selects for example. Other times it may be dependant on the data, how much is out there for you to use. There’s enough uncertainty in all our lives to get stressed out, so to keep us calm Microsoft has provided the HybridDictionary collection.

A HybridDictionary will self monitor itself. Initially, and while it remains small the HybridDictionary will internally keep itself as a ListDictionary. Once it exceeds a certain threshold, it will then convert it’s data into a HashTable. The nice part is you don’t have to care when, or what state it is currently in. All you have to know is the HybridDictionary is managing the memory most efficiently on your behalf.

Like it’s sibling the ListDictionary, the HybridDictionary will require a using System.Collections.Specialized reference. After that, it has the same interface as the HashTable and can be treated as such.

      HybridDictionary genders = new HybridDictionary();

 

      genders.Add(“M”, “Male”);

      genders.Add(“F”, “Female”);

 

The question many will ask “well why not just use a HybridDictionary all the time?” As with most things in life, there is a trade off. There is a some overhead associated with HybridDictionaries, as they have to constantly monitor their own size, then convert back and forth between ListDictionaries and HashTables as needed. In return, you get the best possible performance from your collection as it changes in size.

The moral of the story, when you know you have a small collection, use a ListDictionary. On the other hand, if you know with certainty your collection will be large, use a HashTable. But for all those other times when you just don’t know, the HybridDictionary is your answer.

The Hashtable Demystified

After reading yesterday’s post, one of my coworkers asked me “so what exactly is a hash and how does it work”. Fair question, in my post I concentrated more on how to use the dictionary than what it was, so it does deserve a little explanation.

When you enter a Key as part of the Key/Value pair, you use something human readable like “ArcaneCode”. While good for people, it’s very inefficient for the computer. Thus the .Net Framework runs your key through a sophisticated algorithm called a “hash”.

The output of this hash algorithm is a number, and that number is what the framework uses for the true key to your data. Thus “ArcaneCode” might produce a hash of 1234. It’s very fast for the computer to find your data when it can compare numbers, hence the usefulness of a hash.

The pseudo code below shows the general process a hash table goes through when retrieving your data.

  1. Key is passed in.
  2. Key is converted to a hash.
  3. The collection is searched for a matching hash.
  4. If found, the value in the dictionary associated with the hashed key is returned.

Hashes are unique, no two strings will ever yield the same hash value. Additionally, they are case sensitive. “ArcaneCode”, “ARCANECODE”, “arcanecode” and “aRCANEcODE” all produce different hash values.

The concept of hash tables are not unique to the .Net Framework, many languages have them, it’s just .Net hides the ugliness and makes them easy to use.

Dictionaries in C#: The Hashtable

About a week ago I began talking about collections in C#, and discussed two special cases, the Stack and the Queue. Another group of specialized collection classes are dictionaries. Dictionaries operate off of a key / value system, where you lookup your information, your value, based on a key you create. The key can be a string, number or other type of data, but it must be unique within the dictionary. Just like in your traditional printed dictionary, you can’t have two entries for the same key.

The most basic type of Dictionary is the Hashtable. The hashtable has the basic functionality for putting entries into the dictionary collection, getting a value based on a key, looping through them, and updating or removing them.

Getting data into the hashtable is pretty easy. First make sure to include a using reference to System.Collections, then simply create a hashtable variable, and finally call the Add method, passing in the key and value.  

      Hashtable myHash = new Hashtable();

 

      myHash.Add(“ArcaneCode”, “arcanecode.wordpress.com”);

 

To read or update the data stored in the value, you can treat the hashtable as if it were a simple array, using the key where you’d normally put the index.

 

      Console.WriteLine(myHash[“ArcaneCode”]);

      myHash[“ArcaneCode”] = “Here I’ve changed the value.”;

      Console.WriteLine(myHash[“ArcaneCode”]);

 

      Console.Read();

 

Hashtables are great for storing data where you have a good primary key you can quickly reference things by. In our example, I’ve stored strings as the value part of the key / value pair, but you can use any type of object for the value, including classes you create.

The examples so far assume you will always want to retrieve a single item out of your hashtable. However, we all know there are times when you will want to iterate over the entire collection. To do this, it’s necessary to understand how your key / value pair is storied.

In keeping with the spirit of OOP, what is actually stored in the hashtable collection is another object of type DictionaryEntry. The dictionary entry object has two essential properties, the Key and the Value, both of which are the generic object type. Here’s an example of how to loop over the myHash collection.

      // Clear out the previous items

      myHash.Clear();

 

      // Now add some new items.

      // Note we use an int as the key this time.

      myHash.Add(1, “Item one”);

      myHash.Add(2, “Item two”);

      myHash.Add(3, “Item three”);

 

      // Loop over the list, writing out the value

      foreach (DictionaryEntry myEntry in myHash)

      {

        Console.WriteLine(myEntry.Value);

      }

 

      Console.Read(); // Wait for user to press a key

 

Note we cycle through a list of DictionaryEntry objects, and each time through get the Value property. If we wanted to get the key, it would be a simple matter of replacing the Value property call with a call to Key.

If you are in a situation where you are not sure of the data types being used in the keys or the values, you should append a .ToString() after a reference to the Key or Value so as not to generate run time errors when displaying. In the above example, we’d have needed to use Console.WriteLine(myEntry.Key.ToString()); since our keys were integers (1, 2, and 3).

As you can see, the hashtable makes it easy to look up values when you have a specific key, yet at the same time is still flexible enough to allow you to iterate over your entire collection when you need to.

Saving All Attachments in Outlook

Back on January 3’rd, 2007 (https://arcanecode.wordpress.com/2007/01/03/enhancing-the-save-attachments-outlook-macro/ or http://shrinkster.com/mhm) I posted a useful macro that would save attachments on the selected items in a folder. Since then several have written asking for a version that would save all attachments for every item in a folder, whether it was selected or not.

UPDATE: Some users were having problems downloading the code, so I’ve posted it at: https://arcanecode.com/2011/07/16/revisting-the-outlook-save-all-attachments-macro/

I finally had a chance to experiment, and it turned out to be very easy. To create a version that saves attachments for all items, you only have to change three lines of code.

The first line is the name of the sub. I changed

Public Sub SaveAttachments()

To

Public Sub SaveAllAttachments()

Easy enough. Next, the variable declaration of

Dim Sel As Outlook.Selection

Has to be changed to

Dim Sel As Outlook.Items

The final change is to

Set Sel = Exp.Selection

It becomes

Set Sel = Exp.CurrentFolder.Items

And that’s it, it works. Let me explain what’s happening. In the original, I was cycling through the Selection collection of the Outlook Explorer object. The Selection is a special type of Items collection that holds what’s selected.

For our new macro we wanted all of the items in the current folder, not just what was selected. The first thing we had to do, after changing the sub’s name, was to change the data type of the Sel variable. I wanted to get away from the specific selection collection to the more generic items collection.

Then, all I had to do was have the Sel point to the Items collection of the current folder. Since both Selection and CurrentFolder.Items both support the Items interface, everything else just worked. That’s the power of OOP!

I’ve uploaded a new version of the file as Save All Attachments. It contains this version, the original SaveAttachements, and the GetOutputDirectory function. If you are installing this new, please don’t forget to set a reference to the Microsoft Scripting Runtime Library (scrrun.dll).

Select Tool, References from the VB Macros Editor. Scroll down until you find Microsoft Scripting Runtime, and check it. You’ll know it’s the right one when the file name is scrrun.dll.

[VB References Dialog]

I’ve tested this with messages stored in a variety of folders, including the Inbox. It’s based off the current folder, so it doesn’t seem to care where you are at. I’ve also gotten this to work with the calendar as well.

There you go, you now have a choice. Using my original macro you can save attachments for only the selected items in the current folder, or using this version you can save all attachments for all items in the current folder. I hope the folks who requested the change will find this fits their needs, enjoy!

 

Arcane Review: Why Software Sucks

I promised myself I wasn’t going to have a blog filled with a lot of book reviews. But having just finished “Why Software Sucks” by David S. Platt (http://www.amazon.com/Why-Software-Sucks-What-About/dp/0321466756/sr=8-1/qid=1172286512/ref=pd_bbs_sr_1/105-8037691-1992410?ie=UTF8&s=books or http://shrinkster.com/mdg), I find I can’t resist mentioning it.

David S. Platt is a software developer, author, and teacher at Harvard University Extension. However this book is not targeted at the experienced software developer, but instead at the average computer user. He gives the reader a basic knowledge of how software works, so they will know what is possible and what is not. Armed with knowledge about the possibilities of software development, the average joe can then determine when software sucks as opposed to just bumping into current limitations.

One reviewer on Amazon said he “…didn’t find anything new in the book for seasoned UI developers.” That’s a shame, as it shows he clearly didn’t get the point of the book. This book is not targeted at developers. It’s for users, so they will know when you’ve written good software, and when you’re handing them crap.

While it’s true this book is not packed with development techniques, it’s still an important read for any programmer. As a developer with over twenty years experience, what Mr. Platt’s book gave me was insight. To be reminded that the code I write is to be used by people other than developers. He helped me to see my application through the eyes of an average user, or to quote Mr. Platt, “Your users are not you!”

This was not a thick or expensive book, and was filled with enough humor to keep it a quick yet enjoyable read. At the same time it was serious enough to deal with the subject of user interfaces in a meaningful way. After reading this book, I think the best compliment someone will be able to give me about my applications is “it just works!”

For more information see the authors site at http://whysoftwaresucks.com/.

Standard disclaimer, I make no money from book sales, nor have I any financial affiliation with Amazon, the author, David S. Platt, the publisher, the guys who grew the trees that got turned into paper the book was printed on, the truck drivers that delivered the books, the company that hosts the authors website, nor am I the father of Anna Nicole Smith’s baby. Just so that’s all clear.

 

[Why Software Sucks Book Cover]

SSIS, BIDS, and TNSNAMES

Today’s alphabet soup has to deal with an issue we struggled over this week at work. For those unfamiliar, SSIS is SQL Server 2005 Integration Services. It’s the rewrite of SQL Server 2000 DTS (Data Transformation Services). You use SSIS to pull data from one database and put it into another.

You develop SSIS in BIDS, Business Intelligence Developers Studio. BIDS is Visual Studio with the BI tools added in. The issue we’ve been fighting had to do with getting our SSIS packages to use Oracle 10g drivers to talk to the Oracle 9i data source that was the beginning point for our packages.

Over and over we got an error that the OLEDB provider could not “Acquire” the database, yet the data source kept passing the “Test Connection” test. It was one of my associates who came upon the clue.

In our environment, we don’t normally use a TNSNAMES.ORA file. TNSNAMES is where Oracle normally stores information about a schema name. Schema names are kind of like URLs. You use a human readable schema name, something like WAREHOUSE1. Oracle driver then goes into TNSNAMES to find the server information so it knows where to route the data to.

As I said, in our environment we don’t use TNSNAMES, instead we have another file. The data driver looks there to get the server that TNS info is stored at for the whole company. This allows us to have a single place to store (and update) TNS data instead of thousands of workstations.

The problem was, BIDS didn’t like that. Even though we had it redirected, BIDS didn’t recognize that and kept going to the TNSNAMES file to find schema info, and in our case it couldn’t find it because it wasn’t there. Once we added a TNSNAMES file BIDS was able to acquire it’s schema info, connect to the database and get whatever data it needed.

The moral of the story is, if you are having problems in BIDS connecting to an Oracle data source verify that you do indeed have a valid TNSNAMES.ORA file.

Collections in C# – The Stack

Yesterday we looked at the Queue class. The queue is used when you need a first in, first out (FIFO) way to read through your collection. Sometimes though you need to read so that the first item you retrieve is the most recently added item, much like the computer’s stack, or a Pez candy dispenser (http://www.pez.com).

With the stack class, the most recently added item is the first one you pull out. Stacks have a count property and peek method, much like it’s cousin the queue. However, the stack uses push and pop to get items on and off the stack. Let’s take a look.  

      Stack myStack = new Stack();

      myStack.Push(“1. Carl Franklin”);

      myStack.Push(“2. Richard Campbell”);

      myStack.Push(“3. Mark Miller”);

      myStack.Push(“4. Kimberly Tripp”);

      myStack.Push(“5. Billy Hollis”);

 

      while (myStack.Count > 0)

      {

        Console.WriteLine(myStack.Pop());

      }

      Console.ReadLine();

 

[Picture of Stack Output Example 1]

 

As you can see, the pop operation removed the items from the collection in the reverse order from which they were loaded. In other words, the last item on is the first one you’ll be pulling off.

The peek method works just like it does with the queue. Modifying the while loop above thusly:  

      while (myStack.Count > 0)

      {

        Console.WriteLine(“Peek: “ + myStack.Peek());

        Console.WriteLine(“Pop : “ + myStack.Pop());

      }

 

Produces this output:

 

[Picture of Stack Output Example 1]

 

Stacks are handy when you want to keep track of objects that need to be handled in the reverse order, say for creating and disposing. Like queues, stacks enforce reading your data in a specific order. Whenever you have a requirement to read in a LIFO order, the stack class will add the extra safety you need to make your applications work as you designed.

Collections in C# – The Queue

Most .Net developers are familiar with the ArrayList collection. The ArrayList has become a stable in most .Net applications, replacing in most cases the array. But did you know there are other types of collections?

This will begin a series discussing some of the other types of collections available in C#, and how to use them. Most are pretty straight forward, it’s just a matter of getting to know them. We’ll start things off with the queue.

A queue is a type of first in – first out, or FIFO collection. Unlike an array list, you must read things in order. Queues are very structured, you can’t go sifting or randomly plucking data out of the middle of the collection. OK, I can see you out there, scratching your head and asking “well why would I want to use a queue if it’s not as flexible as an arraylist?”

In a way you’ve answered your own question. Because queues are very structured, you can ensure that your application (or consumers of your application) can’t violate your intent.

Queue’s are simple, they have a grand total of three methods and one property. The property, Count, is almost self explanatory. It tells you how many items are in the Queue.

To get data into the queue, use the Enqueue method. Using the Dequeue method will return the next item, removing it from the collection. What if you want to see what the next item is, but don’t want to remove it? You can use the final method, Peek. Let’s take a look at a sample, done as a Console application.  

      Queue myQueue = new Queue();

      myQueue.Enqueue(“1. Carl Franklin”);

      myQueue.Enqueue(“2. Richard Campbell”);

      myQueue.Enqueue(“3. Mark Miller”);

      myQueue.Enqueue(“4. Kimberly Tripp”);

      myQueue.Enqueue(“5. Billy Hollis”);

 

      Console.WriteLine(“Count = “ + myQueue.Count.ToString());

      while (myQueue.Count > 0)

      {

        Console.WriteLine(myQueue.Dequeue());

      }

      Console.WriteLine(“Count = “ + myQueue.Count.ToString());

 

      Console.ReadLine();

 

This routine prints the following output to the command window:

[Pic of Queue Output Example 1]

 

As you can see, the Dequeue method returned the items in the same order they were loaded in. There’s really not much to explain, you load objects into the queue using Enqueue (in this case strings), and remove objects using Dequeue.

I also mentioned a Peek method. This allows you to look at the next item without removing it. Here I’ve modified the while loop to first show the next item on the queue using peek, then actually remove it.

 

      while (myQueue.Count > 0)

      {

        Console.WriteLine(“The next DNR person is:” + myQueue.Peek());

        Console.WriteLine(“Dequeuing them……..:” + myQueue.Dequeue());

      }

 

[Pic of Queue Output Example 2]

 

There are several instances where you may want to use a queue over an array list. Perhaps you are processing messages, or are reading through a list where it’s important you read them in order, say a list of transactions from a database. Data that needs to be processed chronologically could be placed on a queue.

Any time you have data that must be processed in the order in which it was loaded, use a queue. The rigidity of the queue will add an extra layer of safety to your application, ensuring data is read in the order in which you intended.

Arcane Thoughts: Designing for Use

Last week I traveled on business, and the hotel I stayed in had some interesting features that got me to pondering the dilemma of design versus usability. In the bathroom the sink looked like a piece of furniture. Four wooden legs held up a black marble table, atop of which was a large white bowl which was in fact the sink.

Visually, this was quite pleasing, the colors worked well, the contours were pleasing to my eye. The issue came when I tried to actually use the area. There was virtually no counter top area to work with. I had a very tiny space to put my contact lens stuff and my shaving kit. Further, there was no place to sit the hand towel while I was scraping my whiskers or putting my eyeballs in. This was a classic case where the builder went with a design that was visually pleasing over one that was usable.

Another conflict I found was the frosted glass that divided the bathroom from the bedroom. Where the frosted glass pane was located, if someone got up during the night to, well you know, and turned on the light, the light would hit right in the face of the person remaining in the bed. (Since I was alone it was a non issue, but if I’d been with my wife it could have been a problem.) In this case it was something with a design that looked good having negative side effects when put into use.

Lest you think I’m all whiny, there were some good points to the place, such as the closet. When I opened the closet door, the light came on. Didn’t have to think about it, didn’t have to fumble for a switch, it just worked. Simple yet very effective and pleasing.

My point on this post is not to complain about hotel rooms but to get you to think about design versus usability when it comes to your applications. How many websites have you been to that were confusing or hard to use, but visually stunning.

A good example of a bad example is Brown University. (http://www.brown.edu/). If you try to put your mouse over a menu item in an area that is collapsed, that area pops up to show a pretty picture. You then have to slide your mouse up to be able to click on the item you were just hovering on a second ago, before the page helpfully slid the menu up to show you a pretty picture you probably don’t care about. Visually, the effect is cool and the page looks nice, but if you are trying to actually click on a menu option it sucks.

On the other hand, let me mention my favorite site, Google (http://www.google.com). Yes, I said Google. It’s simple, not too much being thrown at you, and it’s obvious what I’m supposed to do (type something in and click Search). Like the light in my hotel room’s closet, it just works.

Windows Presentation Foundation (WPF) included in the new .Net 3.0 Framework gives us some powerful new tools for designing beautiful applications. Like all new technologies, this can be a double edged sword. I hope this post gets you to spend some time thinking about the user experience. Be sure the pretty pictures and cool effects don’t actually get in the way of getting the job done. Spend some time actually using your app. Key in data, do searches, etc. In short, be sure your program isn’t so pretty it’s ugly.

Installing openSUSE 10.2 on Virtual PC Step by Step

My “Installing Ubuntu on VirtualPC Step by Step” post (https://arcanecode.wordpress.com/2006/12/19/installing-ubuntu-on-virtualpc-step-by-step/) continues to be one of the top read posts on my blog each day. I thought it was about time to look at another Linux distribution, openSUSE.

In November 2006 Microsoft and Novell announced a new initiative, stating they were collaborating on Linux / Windows interoperability. Read the full press release at http://www.microsoft.com/presspass/press/2006/nov06/11-02MSNovellPR.mspx or http://shrinkster.com/lwl.

In the spirit of collaboration, many of you may wish to explore openSUSE but may not have a spare machine to use it on. VirtualPC is the answer to your problem.

Before we begin, you’ll need to download a few components. First, you need Microsoft VirtualPC itself. http://www.microsoft.com/windows/virtualpc/default.mspx or http://shrinkster.com/lwm. I’m using the 2007 Beta RC1, but this should work with 2004 as well. Previously I’ve installed openSUSE 10.1 on VirtualPC 2004 with no problems.

Next you will need the openSUSE.distribution, http://en.opensuse.org/Welcome_to_openSUSE.org or http://shrinkster.com/lwn is the place to grab it.

Be warned OpenSUSE ISO image is quite large, you’ll be a while downloading it. You will probably want to burn it to a DVD. If you don’t have a DVD burner handy, you can also use the Microsoft Virtual CD tool (which will work for DVDs too). I blogged about it at https://arcanecode.wordpress.com/2006/09/13/.

A quick note, there are, as of this writing some issues with openSUSE 10.2 not recognizing the sound drivers with Virtual PC 2007 RC1. If sound is important to you, consider staying with Virtual PC 2004, or use openSUSE 10.1. As sound wasn’t that big of a deal, I used 10.2 and VPC 2007, but I’ve also installed 10.1 under VPC 2004 and my experience was almost identical to what I write about here.

Finally before you get started, spend a few minutes getting familiar with VirtualPC if you have not already done so. You can find my step by step instructions for VirtualPC at https://arcanecode.wordpress.com/2006/09/20/virtual-pc-step-by-step/. Keep it handy, at various points I will be referring to it.

Like now. In Step 1 of my VirtualPC Step by Step you are instructed to create a new machine, please do so. I’ve named mine “openSUSE”. In step 2, you are prompted for your OS. You will need to pick Other. In step 3, you are asked about Ram. openSUSE will run OK under 256 megs, however if you have the available space I’d highly suggest upping it to 512, especially if you intend to get into doing some graphics or mono coding.

In step 4 you will want to create a new hard disk, and in step 5 confirm what you’ve selected. OK, now you are up to step 6, installing the OS, which is where this tutorial picks up.

The first thing you will see is the boot screen. Here it asks if you want to boot from the hard drive (you can’t as nothing’s installed yet on your virtual hard disk) or install in a variety of methods. Hit the down arrow so “Install” is highlighted and hit the Enter key.

[openSUSE 01]


The screen will turn blue, churn for a bit, then black with a little clock. Be patient, it’s working. Finally, you get to see a screen to begin your installation journey. On the first one, you get to select which language you want. Select your language of choice, and click next.

[openSUSE 02]


Next you are shown the license agreement. If you are hyped up on Jolt Cola and Double Espressos and need some sleep go ahead and read through it. Otherwise, click the “Yes I agree”, then click next.

[openSUSE 03]


Now you are asked what mode you are doing the install in. Since this is a fresh machine the only valid option is New Installation. If there had been an older version of openSUSE on the machine you would also have the upgrade option. For now, take the default of New Installation and click Next.

[openSUSE 04]


The openSUSE installer will now do some System Analysis. It will read over your system and produce you a list of what it’s going to install. It’ll take a minute or two, so be patient.

On the next screen you are asked about the Time Zone. Pick the time zone you live in and press next.

[openSUSE 05]


Now comes your first difficult decision. openSUSE wants you to pick a default desktop. Unlike Windows, Linux will let you pick from a variety of desktop shells. The desktop defines the look and feel of what you see as you interact with the computer.

If you are a Windows user, you might be more comfortable with the KDE desktop. It has a start bar and “K” menu across the bottom. On the other hand Gnome has something more akin to a look and feel from the Mac line. There are others out there, but these are the top two.

There’s one other item to take into consideration. If you intend to do any coding using Mono, you will need to use the Gnome desktop. The last time I checked, the majority of the Mono development tools were designed for the Gnome desktop. (I don’t claim to be a Mono expert, so if this is incorrect please feel free to leave an enlightening comment.) Mono, by the way, is the open source implementation of the Microsoft .Net Framework. Using Mono you can write C# code for a Linux environment.

Don’t stress over this too much. The nice thing about Linux is you can change your mind later, or you can try out a new desktop just to see what it’s like without making a permanent change to your default desktop.

Since one day I hope to dabble in Mono, I will pick the Gnome desktop and click Next.

[openSUSE 06]


OK, getting close. Now openSUSE will show you an installation summary, with everything it’s going to do and install. Give it a glance, and if you are happy with your options click Next.

[openSUSE 07]


This is where the folks at Novell like to play an April Fool joke, in that you only thought you were done with license agreements. In the 10.2 version I downloaded, I’m additionally asked to confirm the licenses for some Adobe product and the Flash player. I clicked OK on both.

[openSUSE 08]

[openSUSE 09]


OK, openSUSE asks you one last time if you are sure. We are (well at least I am) so click Install to begin the install.

[openSUSE 10]


Now sit back and wait. And wait. And wait some more. This thing takes a long time to install, for me the counter started at over 2 hours, although in the end it didn’t take that long.

First you’ll see some screens that talk about preparing your hard disk. Don’t worry, it’s the virtual disk it’s formatting, you’re safe. Finally you’ll see this screen as it begins the process.

[openSUSE 11]


Over to the right you’ll see the count down timer, and the center part will change during the install, giving you nice little tidbits and tricks. This would be a good time to refill your coffee, put some Jolt Cola on ice and order that pizza. You’ll be sitting here a while. (While you’re waiting might be a good time to explore some of my other posts, LOL.)

One real important thing: if your VirtualPC screen goes blank during the install, don’t freak out! Believe it or not, the screen saver is actually active during the install. All you have to do is click inside the VirtualPC window. The screen will then update to show you where it’s at in the install process.

After it’s finally done, it will tell you it’s going to reboot. Go ahead and let it, obviously. If you do nothing, the machine will reboot itself.

After the reboot you’ll see the same screen you saw when you first started, assuming you didn’t eject the openSUSE dvd. Pick the “Boot from Hard Disk” option, or if you do nothing it will take it as the default.

[openSUSE 12]


The next screen asks if you want the default of openSUSE 10.2, to boot off of Floppy, or the Failsafe mode for 10.2. Failsafe is kind of like Safe Mode under XP. Normally you’ll pick the openSUSE 10.2 option, which is what we will do now. (Doing nothing by the way will automatically select this.)

[openSUSE 13]


After the system finally gets done rebooting, there are some final installation steps that need to take place. First, you are taken to a screen and asked what you want the root user password to be. This is the master password for the system, you need this to install software or do any serious maintenance. Enter something secure, but easy to remember. Most of all don’t forget it, or your lovely Linux install will become severely handicapped. Enter your chosen password now, then click next.

[openSUSE 14]


Next you are prompted for a host name and domain name. Take the defaults and click Next.

[openSUSE 15]


In the next window you are asked about the network configuration. Be patient while openSUSE examines your virtual system. When done, just click Next to take the defaults it finds.

[openSUSE 16]


At the end of the network configuration, openSUSE wants to test your connection. Assuming you are connected to the web, leave Yes selected and click next to perform the test. Now, when I tried to do the test, it kept failing on me. I puzzled, fumed, changed things, but could find nothing wrong.

Finally, out of desperation, I clicked the Back button to return to the screen below, then told it to skip the test, and go on. By golly, it actually worked just fine! I guess the problem is on the Novell end, as openSUSE happily proceeded to download all sorts of online updates with no problems. Your experience may vary a little, but if you try the test and it fails, try using the Back button, tell it No, skip the test, and go on from there. I’m betting it’ll work OK for you too.

[openSUSE 17]


The online update is next, here openSUSE will try to download the latest patches and what-not for your system. You have the option to skip by picking No, but I would suggest you let it run so you can have all the latest security updates and bug fixes. (Note if you are not hooked to the internet, or were unable to get the networking to work, you will want to skip this step.)

As the first step in the updates, you are asked about additional installation sources. For now, take the defaults as shown and tell it Yes, to register the checked sources.

[openSUSE 18]


You will now see a series of update screens flash by as your system is updated from the internet. The screen will look something like this:

[openSUSE 19]

Just let it go, it will take a bit (especially if you have a slow connection). When it’s done openSUSE will automatically take you to the next area.


In this next area you are prompted for users. First, you are asked about the method for authenticating users. There are some nice options here, including the ability to check against a windows domain. For our purposes though, the default of Local (/etc/passwd) will do just fine, so click Next.

[openSUSE 20]


Next you are prompted for user info. Enter your name, what user name you’d like to have, and a password for that user. There’s also a checkbox for Automatic Login. If you will be the only one using this VirtualPC, you can leave this checked on.

On the other hand, if you will be sharing this VPC with friends, you may wish to uncheck this. When you do so openSUSE will request you to login each time. One last note, you will want to make your password different from the one you entered for the root user. It’s not a requirement, but it is a good idea. Once you have entered everything, click Next.

[openSUSE 21]


OK, now sit back and wait a few minutes, as openSUSE is going to finish setting up your user account, then is going to run some cleanup.

[openSUSE 22]


When the cleanup is done you are automatically shown the release notes. This describes changes and the like since the last version. Take a quick glance, and know that you can always pull these up later if you are in a hurry. Go ahead and click Next when you are done.

[openSUSE 23]


In this last step you are shown your hardware configuration and asked to confirm it’s what you want to use. While it’s examining your config your screen may switch back to a text display, then back to the graphical installer. This is normal behavior, just be aware of it.

When it’s done examining, you’ll be ready to click Next. Note one item, there have been some issues with openSUSE not detecting the sound card of Virtual PC 2007. If sound is extremely critical to you, consider sticking with either VPC 2004, or drop back to openSUSE 10.1.

I can wait for the sound issue to get fixed in a later patch, so I’ll be clicking Next at this point.

[openSUSE 24]


You’ve hit the finish line! You installation is complete, all you have to do now is click the Finish button.

[openSUSE 25]


When you do, openSUSE will complete a few tasks, then ‘reboot’ your virtual system. This will take a few minutes, and when done you are logged in and ready to use your openSUSE Virtual PC.

[openSUSE 26]


Click on the “Computer” icon in the lower left, to begin exploring your openSUSE installation.

[openSUSE 27]


To get up and running with openSUSE I’d recommend a good podcast to you called Linux Reality. Chess Griffin is the host, and did a great three part tutorial on openSUSE at these links:

Part 1: http://www.linuxreality.com/podcast/episode-16-suse-linux-101-part-1/

Or: http://shrinkster.com/lxh

Part2: http://www.linuxreality.com/podcast/episode-17-suse-linux-101-part-2/

Or: http://shrinkster.com/lxi

Part 3: http://www.linuxreality.com/podcast/episode-18-suse-linux-101-part-3/

Or: http://shrinkster.com/lxj

His original tutorial was for 10.1, so there may be a few minor differences but not enough to make a difference.

There’s also a support site for SUSE Linux you can find at http://wiki.suselinuxsupport.de/wikka.php?wakka=SuSELinuxSupport or http://shrinkster.com/lxk.

That’s about it, one final note. As I tell my kids, when you are done playing make sure to put away your toys. To shut down your Virtual PC openSUSE, just select Logout from the Computer menu, and it will give you a screen with the standard Logout, Shutdown, etc. menu options. Just pick Shutdown and you are free to go get that cup of coffee you’ve been waiting for.

IEnumerator in C#

In yesterday’s post I mentioned the IEnumerator interface. To be honest it probably was not the best example to cite for an interface, since it is implemented in a non-standard fashion. However, it’s also the interface you will probably want to implement the most often, so I thought it worth showing you a quick example.

For today’s lesson I will continue to use the Employee example I’ve shown over the last few days. The only change I need to make is to the Employee’s class declaration, for easy coding I want it to have a public scope. In looking back I hadn’t put a scope qualifier on the class declaration, and when you omit a scope the compiler defaults to internal.

  public class Employee : IPersonM, IPersonP

 

Now that’s done, let’s create a class that will hold multiple employees. We’ll call it Employees (plural) and have a method to add employees to it. Internally we’ll store the individual Employee objects in a generic List<T> collection.

 

using System;

using System.Collections.Generic;

using System.Text;

 

namespace OOPDemo

{

  public class Employees

  {

    private List<Employee> _employees = new List<Employee>();

 

    public void AddEmployee(Employee emp)

    {

      _employees.Add(emp);

    }

 

    public IEnumerator<Employee> GetEnumerator()

    {

      foreach (Employee emp in _employees)

      {

        yield return emp;

      }

    }

 

  }

}

 

Before I explain the details, let’s look at how to use the new collection.

 

      Employees myEmployees = new Employees();

 

      Employee emp1 = new Employee();

      emp1.FirstName = “Carl”;

      emp1.Lastname = “Franklin”;

      myEmployees.AddEmployee(emp1);

 

      Employee emp2 = new Employee();

      emp2.FirstName = “Richard”;

      emp2.Lastname = “Campbell”;

      myEmployees.AddEmployee(emp2);

 

      Employee emp3 = new Employee();

      emp3.FirstName = “Mark”;

      emp3.Lastname = “Miller”;

      myEmployees.AddEmployee(emp3);

 

      string everyone = “”;

      foreach (Employee emp in myEmployees)

      {

        everyone += (emp.FullName() + Environment.NewLine);

      }

 

      MessageBox.Show(everyone, “Everyone”);

 

As you can see this is pretty straight forward, it created 3 employee objects and called the AddEmployee method to add them to our collection. The code then enters a foreach loop retrieving each individual Employee object from the collection of Employees.

What makes this work is the IEnumerator interface. By having the Employees class have a GetEnumerator method that returns an IEnumerator, we enable it to be used anywhere that an IEnumerator can be used, such as a foreach loop.

The only other thing to explain would be the new keyword yield. Each time through the loop the yield will exit the loop and return to the calling routine. The next time through the foreach loop, the GetEnumerator picks right back up at the yield statement, and loops to the next item in our internal List.

To your method, he yield keyword is sort of like sleep mode is to the computer. It pauses, then returns control to the calling routine. When you return, you re-enter the routine right where you left off, with all the routines and variables just as you left them. Not unlike powering up your computer again from sleep mode.

What makes this a little different is that the method GetEnumerator is what implements the IEnumerator interface. Normally, interfaces are implemented by the entire class, not just a single method.

While not the best example of a standard interface, it does demonstrate the power of extending an existing .Net interface. In this example it suddenly allowed your class to be used by a foreach loop. Take advantage of the built in .Net interfaces to make your own classes even more powerful and fit into the .Net environment.

More OOP: Interfaces in C#, Part 2

Yesterday I introduced you to Interfaces in C#. There’s a bit more about interfaces I wanted to share. With a normal class, it can only inherit from one base class. However, it can implement multiple interfaces.

By the way, this seems like a good time for a little lesson in terminology. A class inherits from another class, but it implements one or more interfaces.

Let’s look at our IPerson interface from yesterday. For various reasons our architect has decided it should actually be implemented as two interfaces, one with the properties and another with the method. (For demo purposes I left both interfaces in the same file, in real life I would have each in it’s own file.)

using System;

using System.Collections.Generic;

using System.Text;

 

namespace OOPDemo

{

  public interface IPersonP

  {

    string FirstName { get; set;}

    string Lastname { get; set;}

  }

 

  public interface IPersonM

  {

    string FullName();

  }

 

}

 

Now we need to modify our Employee class to implement both methods.

 

  class Employee : IPersonP, IPersonM

 

Notice all it took was separating the interface names with commas. If we were also inheriting from a base class, we would list it first. Yes, you can both inherit from a single base and implement one or more interfaces for a class.

Finally, we need to make a quick update to our ShowName, since the old IPerson has been replaced with an M and P version:  

    private void ShowName(IPersonM per)

    {

      MessageBox.Show(per.FullName(), “ShowName Method”);

    }

 

You need to be careful when designing your interfaces, not to get too focused. In the above example, what if in the ShowName method you need to also access the FirstName property? Can’t do it with the code as it is now since IPersonM knows nothing about those properties. Instead you’d have to pass in an Employee, in which case we’ve limited our functionality. The ShowName would no longer be able to accept a Contractor or Vendor (assuming we ever created them).

So, we know that a good time to use an interface is when you have a base set of properties and methods, but not code, that you wish to share among classes so that you can treat them as the same generic type. What other times might you wish to use interfaces?

In his book Programming .Net Components (http://shrinkster.com/ly6) Juval Lowy has an entire chapter devoted to interface based programming. When writing a class library (i.e. a dll) Mr. Lowy suggests only exposing interfaces. Why? This leaves you totally free to redesign even your base classes.

Even further, Juval advocates placing all of your interfaces into their own class library. Because it’s fairly quick to create interfaces, it allows both the user interface team and the class library team to get to work, both referencing the same interface dll.

A final reason for using interfaces is to extend your class so that it is compatible with items in the .Net Framework. .Net exposes a slew of interface types, and you can implement any of them in your classes.

A common example is the IEnumerator interface. If you were to implement the IEnumerator interface in your class, you could then use your class anywhere you would use an enumerator in .Net, such as in a foreach construct.

Hopefully by now you’ve seen the power of an interface, and will begin using them in your own applications.