April 2005 - Posts
As you can see from
Robert Green's blog entry, he has decided to join up with MCW Technologies and be one of the gang. We're thrilled to have him, especially since we've worked together on several projects over the years. Personally, I've known Robert since his days back at
IMG in Chicago, through his stint on the FoxPro and VBA teams, and on to the VSTO and VB teams.I'm looking forward to working with Robert on projects, speaking at conferences, and more. Welcome, Robert--and remember, the newest member gets to do the grunt infrastructure work!
I've recently been asked to present a session at Tech-Ed 2005 on one of my favorite topics--developing .NET solutions for Office, and spent the day digging into VSTO 2005. Here are the details on the session:
CLI361 Microsoft Visual Studio 2005 Tools for the Office System: Building Office Solutions Using Visual Studio 2005 Tools for Office
Track(s): Architecture, Smart Client Development
Day/Time: Wednesday, June 8 3:45 PM - 5:00 PM Room: S 220 E
Incorporating Office capabilities into applications using the Word and Excel object models is often a challenge for .NET developers. Visual Studio 2005 Tools for the Microsoft Office System now provides Host controls that allow developers to use some native Word 2003 and Excel 2003 objects as standard .NET controls. In this session, we look at how you can incorporate databinding, the new Actions Pane control and smart tags into your Microsoft Office solutions. We then build on these concepts to demonstrate how Host controls enable you to create Microsoft Office smart client applications quickly and easily.
I'll post more on VSTO 2005 as I dig more into it, but it's a great solution for building Office 2003 solutions using managed code. Although VSTO 2003 was cool enough, the 2005 version adds so many new features that it's worth investigating, if you haven't already. If you want some walkthroughs to get you started with VSTO 2005, try these links:
Doing a lot of writing over the past ten years, but to be honest, this is the piece I'm happiest with so far. The technology discussed is awfully simply (the System.Diagnostics.Stopwatch class in .NET 2.0), but the final leg of the moving story came out as well as anything I'm going to write. Drop by Code Magazine's site for the finale of the three-part cross-country move story. While you're there, why not peruse some of the other articles? Even better, subscribe to the printed magazine! (Yes, it's a plug. But I can try, can't I?)
For those that are coming in late, here are the links to the entire series of three whine-fest/articles dealing with the big move. Really, there are some coding issues buried in there:
Are We There Yet? (Part 3) (May/Jun 2005)
Stay Put. Understand Your Space (Part 2) (Mar/Apr 2005)
Elegant Isn't Always Best (Part 1) (Jan/Feb 2005)
Visual Basic 2005 developers: Download a free beta version of Developer Express' Refactor! product.
Although you may have picked this up on one of the zillions of other blogs that will be mentioning this, let me risk redundancy by repeating the big news: VB 2005 will have refactoring support, after all! Because of an arrangement between Microsoft and Developer Express, Visual Basic 2005 developers will be able to take advantage of Developer Express' Refactor! product, for free. This isn't a crippled version or some sort of upsell, but a full, working copy of an excellent implementation of refactoring. (In case you've missed it, "refactoring" is the process by which developers can quickly and easily change the shape of their code: converting blocks of code into procedures, renaming tokens, converting public fields into property procedures with backing fields, and much more.)
This is really exciting news, and I'd like to add a special thanks to the folks on the VB team at Microsoft who proactively pulled this off. Rather than simply live with the lack of this competitive feature, the VB folks found a solution and made it work. (You'll probably be amused to know that there are not currently plans to make this product available for free to C# developers, although both C# and VB developers can currently "upgrade" to the Professional edition, including support, for $99US.)
Download the current beta (corresponding to Beta 2 of Visual Studio 2005) of Refactor! here, or visit the Visual Basic 2005 Developer Center for more information. (If you have a previous version of Refactor! installed, make sure you uninstall the old version before installing this new version.)
To get started using refactoring, try some simple activities:
- Rename: Hover over a variable, note the graphic "..." symbol. Click on the symbol, and rename the variable. Note that as you change the variable name, all instances of the name change as well.
- Convert to property: Create a public variable inside a class. Use Refactor! to convert the variable into a set of property procedures with a private backing field.
- Extract a procedure: within an existing procedure, highlight a block of code, and use Refactor! to extract the block into its own procedure.
These are just a few of the many refactoring tasks you can accomplish. Have fun modifying your code. (My suggestion--make a backup of the code first! This is a beta product, and it's easy to get carried away with the refactoring efforts while playing, as well.)
Early last year, I had the privilege to create an article for MSDN offering a sneak peek of new features in Visual Basic 2005. Of course, many things in the product changed between January 2004 (when I wrote the thing) and April 2005 (where we are now).
Jay Roxe, Senior Product Manager on the VB team, offered me the opportunity to update the article for Beta 2. You can find the shiny new version
here.
Playing with ASP.NET 2.0 today, and although I appreciate the intent of the Web Site Configuration tool, it still isn't working in this build. At least in the VPC I'm working in, my attempts to set the SMTP settings (so ASP.NET can send email to change a password) failed with compile errors. Clearly, the code associated with this site is attempting to use classes that don't exist in the framework.
Luckily, a little sleuthing in machine.config found the solution: If you want to be able to send email to send out a password reminder or new password, you can add the necessary section to your Web.config file manually.
<mailSettings>
<smtp deliveryMethod = "Network" [Network | SpecifiedPickupDirectory | PickupDirectoryFromIis]>
<network
defaultCredentials = "False" [true|false]
host = "" [String]
password = "" [String]
port = "25" [number]
userName = "" [String]
from = "" [String]
/>
<specifiedPickupDirectory pickupDirectoryLocation = "" [String]/>
</smtp>
</mailSettings>
My web.config file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web>
<authorization>
<deny users="?" />
</authorization>
<roleManager enabled="true" />
<authentication mode="Forms" />
</system.web>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network
defaultCredentials="False"
host="MyServerURL"
password="MyPassword"
port="25"
userName="MyUserName"
from="admin@mcwtech.com"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
Obviously, you should replace MyServerURL, MyPassword, and MyUserName with the appropriate values for your site.
Once I made these changes to my web.config, I was able to place a PasswordRecovery control on a page, and all the plumbing worked fine. It's just the Website Configuration tool that doesn't work. (If it does work for you, please let me know.)
The MCW Web server runs at a locked, remote, hosted location in Los Angeles. We get our service from a great local company, US Internet, and they're incredibly helpful and supportive. None of us lives nearby (at least, not anymore). We use Terminal Server to access the server, and occasionally the hosting company folks drop by to do some things that we can't handle remotely. (PC Anywhere used to work, but to be honest, it's got some issues with Windows Remote Access, so it hasn't worked in a while.)
Today, I needed to add in Russ Nemhauser as a user so he could do some work on the site for us, but I didn't want to add him as a member of the Administrators group. Not really knowing what I was doing, I found local security policies that allowed me to grant him access to log in locally, and to log in using Terminal Server. Seemed like the right thing to do.
Was I wrong, or what? Because we had never had a discrete policy concerning the ability to log in using Terminal Server, anyone who had rights to log in locally could log in using Terminal Server. But the moment I created the policy and added Russ to it, suddenly, he was the only person who could log in using Terminal Server. And he's not an administrator! Yikes. No one can log in but Russ, and no one can add administrators into the policy.
Luckily, the folks at US Internet can bail us out this time. But what other havoc might I have caused by poking around at security policies on a remote computer? I'm amazed I got off this lucky.
Kids, don't try this at home. It's way too easy to lock yourself out. I certainly proved that. Ain't no one logging in to our server remotely that can fix the problem. The moral of this story: Don't poke around at security, hoping you'll figure it out. Get help.
Update, a few days later:
Once we got the machine rebooted, it was easy enough to get in using PC Anywhere and grant rights back to log in using Terminal Server. One important issue I haven't worked out: Once we log in using TS, PCA no longer works. We get the "blue checkerboard of death." (If you've been there, you know what I'm talking about). Only done a little research on this one, but hope to work it out soon. We've found that the combination of TS and PCA (or some other remote control tool that isn't TS) makes the best combination of remote support tools.
Want to learn a little about ASP.NET 2.0? The training company with whom I've been associated for over 10 years,
AppDev (Application Developer's Training Company) has partnered with Microsoft to give away a portion of the ASP.NET 2.0 preview training we recorded late last year. If you want to download one CD of content, drop by the
download site. You can download one of the course's CDs, and give it a try.
If you're interested in more .NET training, visit AppDev and see what they've got. I worked on most of their .NET content, including courses on ADO.NET, C#, VB.NET, ASP.NET, and more. Working with partners Andy Baron and Mary Chipman, we've recorded tons and tons of content for AppDev. (If I may--the one thing that AppDev has that no other video courseware vendor seems to have is full written content and hands-on labs. We spend most of our time preparing the written materials, and I've been quite happy with the results.) OK, enough advertising. I was just happy to see the content available for free on Microsoft's site.
In the past few weeks, I've had several friends IM me and ask why their VPCs were running so slowly. (Brian Randell has blogged about this in the past, and his points are valid, but in the cases I've seen, the problem was far more obvious.) Brian also hints at versioning issues here. In my experience, this is the real problem: people build VPCs using Virtual PC 2004, and then upgrade the Windows XP operating system to SP2. It seems like the right thing to do, but the original version of Virtual PC 2004 runs quite slowly with Windows XP SP2.
When you create a new virtual machine using VPC, you need to install the virtual machine additions--a set of drivers that make the VPC interact better with the screen, mouse, and more. The problem is, those additions are specific to the version of the Virtual PC 2004 software that you used when you created the VPC image. In both cases I've seen recently, the exact same scenario ensued (and this is why I'm mentioning it here, with a little more specificity than Brian had in his entries): we had VPC images with Windows XP SP2 running under Virtual PC 2004 without applying the service pack. In each case, the VPC had the non-SP1 additions installed, causing the performance to deteriorate.
In both cases, the solution was the same:
1. Boot the slow VPC, and uninstall the VPC additions.
2. Shut down the VPC.
3. Install Virtual PC SP1.
4. Reboot the VPC.
5. Install the new additions.
For both friends, this solved the slowness issues. When Paul Litwin tried it, his VPC was so slow it took overnight to install the new additions. No kidding. Russ Nemhauser tried it today, and saw an immediate improvement without indulging in the long nap.
For more information on Virtual PC and VPC optimizations, check out these sites:
RobertMoir.co.uk
Ben Armstrong's blog (Program Manager on the VPC team at Microsoft)
Brian Randell's blog
and, of course, the VPC site at Microsoft.com
Too many people install beta software on their production computers. Unless you just like pain and suffering, don't do this! Some people work around this by using multiple hard drives, or dual boot situations. These solutions work, but they're expensive and hard to manage.
If you're going to install and play with Visual Studio 2005 Beta 2 (or any beta, actually), you need to be using software that allows you to create virtual computers. We are obligated to pimp Microsoft's Virtual PC, of course, but there are others you can use. In any case, this software allows you to create a full operating system installation that can run within a window. You can enable undo, so changes you make to the entire computer can be undone. You can layer functionality, so you can build a complete install of the operating system that is read-only, and run a "differencing drive" on top of the read-only virtual PC, allowing you to have multiple copies of the environment all based on the same operating system installation. I'll let me cohort, Brian Randell, wax rhapsodic about the joys of Virtual PC, but every time I use it in public, a lot of people ask me what the heck I'm doing. It works flawlessly. For demos, there's nothing like starting up a virtual PC, doing what you need to do, and never impact the host PC at all.
If you're going to use VPC, however, you're going to need hard drive space, and a relatively fast hard drive, to boot. Although Brian likes using large external Firewire 800 drives for their speed, I am happier with external drives that are small and self-powered. I know there are a lot of external USB 2.0 drives out there, and everyone has their favorite. As with most things, I buy into the "you get what you pay for" theory, and this has turned out to be generally true. In that vein, I've purchased several fast external drives from Pocketec. They use standard laptop hard drives, encased in the smallest possible case along with a USB 2.0/ATA bridge card. You simply won't find a smaller, faster drive. To be honest, the hard drives are no different than those you'll find from any other vendor, but the case and circuitry sets this one apart.
One note: Continuing in the same vein, I've always purchased IBM Thinkpads--I'm a big fan. I've never had a problem powering the Pockey drive using the USB 2.0 ports available on my Thinkpads, but I've never managed to get one to power correctly with a Dell computer. The drive requires a certain amount of power to run, of course, and it seems that Dell simply doesn't provide enough power through its USB 2.0 ports. Pocketec does, however, supply a second USB cable that can be used to supply additional power. This means that your Pockey drive will consume two USB ports, but it's still better than hauling around a power brick.(At least, they used to. Can't vouch for their current packages. It's been a while...)
And for those who like to tinker, these astounding thin and light cases use standard 9mm laptop hard drives. If you outgrow the size of your Pockey, you can extract the existing drive from its case, and replace it with a new, larger one in the future. I've done this twice now, and the case continues to travel with me everywhere.
In addition to the VPCs I use as part of my work, I carry 40GB of ripped CDs, and copies of the installation DVDs for most of the products I would ever need to install on the road. I couldn't imagine travelling without my Pockey.
Today, at VSLive Toronto, I did a workshop (co-presented with Paul D. Sheriff) that I've done many times before, in various guises. Originally co-written with Brian Randell, the Build a .NET App in a Day workshop covers many parts of .NET in a single application (console apps, Windows apps, Web apps, Windows Services, Web Services, ADO.NET, COM interop, MSMQ/Serialization) and by the end of the day, we've got an app that actually does something using all these pieces. We test it as we go, but don't see it actually run completely until the end of the day. Paul and I go on and on and on for 8 hours, get to the end of the day, and the @%$(^ thing just doesn't work. No idea why. We still haven't worked it out. It's never failed before. I've done it with Brian, with Paul, and on my own, and it's always worked.
I guess I'm writing this before retiring for the day more as an apology to the attendees than anything else. It's never failed before. Really. Normally, we click that button, and it just works. Darn.
Follow up (the next day):
So we worked it out. Turns out that we added the concept of running the Windows service as a user with few rights late in the game, and we neglected to add rights to the database for this user. When the service attempted to write to the database, the code failed quietly. Adding the user to the users who can write to the database solved the problem. The downloads for this session now include the modified setup instructions so that it works as planned.
About this time last year, I got an email from a manager on the Office team, asking for help writing a bunch of managed code samples for Word and Excel 2003. Rather than simply write samples, I thought it would be cool to tie them all together in an environment that would allow you to try each one, as well. In addition, if going that far, why not make it so that anyone could add more samples to the test bed simply by dropping an assembly into a known folder?
The end product of this is the Office 2003 PIA Sample Launcher tool, available on GotDotNet. John Durant, "owner" of the Office Developer Web site, championed the project once we got it started. He provided a list of methods to be covered, and made sure things kept on track. It's important to mention Russ Nemhauser, who spent several days near the beginning of the project helping to design the architecture for the various assemblies, and the custom controls that provide the pages for method parameters.
If you want to write managed code that interacts with Word or Excel (including some Office components, as well), you might want to check out this demo. (To be honest, the product was named DemoRunner up until the last minute, because it can actually run any demo you throw at it, as long as you follow the rules setting up the demo code. If you do a lot of presentations, this is useful functionality. Brian Randell and I had written a similar, if slightly less-flexible, demo runner for VB6 presentations, and I had long been looking for a reason to write a demo-running application for .NET. This effort was that excuse!)
Check out John's blog entry here.
Download the application here.
Read John's article describing the tool here.
A few years ago, way back when .NET was new, the VB marketing team contracted with MCW to write some samples using VB.NET to be posted on MSDN. I agreed to write one showing off GDI+, and it ended up being a little clock component that I actually use often, especially when speaking. Many folks have asked where they can get it, 'cause it's not easy to find. Here's the link where you can download the original version of this little clock utility I've been using for a few years.
Of course, not willing to leave good enough alone (to be honest, I've learned a lot about .NET since writing this first version), I've totally ripped out the guts of the thing and am currently revising it for an MSDN magazine column coming up this summer. It all started when I realized that using trigonometry to calculate the rotations involved to draw the clock and its hands was only a good idea if I was trying to prove to myself that I still understood trig after all these years. What I had missed is that the .NET Framework supports rotations, translations, and other matrix operations natively. I had originally written a ton of code that used sin, cos, and tan to figure out where to put, say, the tick marks around the edge of the clock face. When I figured out that you didn't need to do any math at all, I kicked myself. And had to rewrite the whole thing.
Try this out, if you want to see the rotation and translation possibilities in the .NET Framework. Create a Windows application (I'm using VB.NET here), and add the following code to the sample form:
Private Sub Form1_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
Dim gfx As Graphics = e.Graphics
Dim center As New Point(100, 100)
Dim radius As Integer = 100
Dim pt As New Point(80, 0)
For tickDegree As Integer = 0 To 360 Step 6
' Rotate and translate the graphics region
' as necessary, then draw the tick mark
gfx.ResetTransform()
gfx.RotateTransform(tickDegree, MatrixOrder.Append)
gfx.TranslateTransform(center.X, center.Y, MatrixOrder.Append)
DrawCircle(gfx, pt, 2, Pens.Black, Brushes.Black)
Next
End Sub
Private Sub DrawCircle(ByVal gfx As Graphics, ByVal pt As Point, _
ByVal Radius As Integer, ByVal pen As Pen, _
ByVal brush As Brush)
' Center the circle around the center point,
' moving back the size of the radius in both
' x and y directions.
Dim diameter As Integer = Radius * 2
pt.Offset(-Radius, -Radius)
Dim rct As _
New Rectangle(pt.X, pt.Y, diameter, diameter)
gfx.DrawEllipse(pen, rct)
If Not brush Is Nothing Then
gfx.FillEllipse(brush, rct)
End If
End Sub
When you run the form, you'll get the idea -- 60 little circles around the edge of a larger circle. The "active ingredient" code looks like this:
gfx.ResetTransform()
gfx.RotateTransform(tickDegree, MatrixOrder.Append)
gfx.TranslateTransform(center.X, center.Y, MatrixOrder.Append)
Rather than attempting to work out exactly where on the big circle these little circles go, the code simply puts every circle at the same point (80, 0), but rotates the frame of reference the correct number of degrees, and then translates the whole mess from the upper left corner to the center of the circle. Play with the code -- I found it was pretty simple to get proficient at manipulating translations and rotations with little effort. And it's a lot easier than figuring it out on your own, using trig!
I've been lucky to have been able to write for MSDN magazine a number of times, and currently co-write a column with Duncan Mackenzie, named Advanced Basics. Every now and then, the folks at MSDN send us a Word document containing all the comments people have posted as they're rating the articles. Most of them are uniformly helpful, and most are positive. A few, however, seem a bit misguided. I love it when someone rates an article 1 (out of 9) simply because they don't like Microsoft, or because they don't agree with the technology. (Got many low scores on the article on multi-threading simply because it's too hard to accomplish safe multi-threading in 1.x, even though the article was on 2.0 technology.) I can't complain--anyone can post whatever they're feeling, and that's the way it should be.
I do find it amazing, however, that this comment appeared (along with a rating of 1 on an article):
You've started putting a lot of your samples solely in VB.NET -- what about us C# users?
This is wrong on so many counts. First of all, a huge fraction of the samples out there are in C# only. Go to any conference, and a huge percentage of the presentations are in C# only. Even on MSDN, many samples are only in C#. And, to be honest, if you're a C# developer, reading Visual Basic should be a no-brainer, right? You're smart. (I will not start or get involved in the "which language is better?" wars, 'cause I really don't care.)
But let's examine the column title: "Advanced Basics". I guess they could have named it "A Column That Helps Visual Basic Developers Find Out Stuff They Might Not Otherwise Have Found Out On Their Own" but that's a rather long title, don't you think? It's called "poetic license." Or advertising. Or something. But it's pretty clear that it's about Visual Basic, I would think. In any case, C# developers complaining about a column devoted to Visual Basic having its code in Visual Basic, not C#, is like adult straight white males complaining that there when they turn on the WB, all the shows don't target their demographic. Just my opinion, of course.
Greetings from lovely Toronto. Here for VS Live, along with Brian Randell and many others.
...but I was honored to be interviewed on .NET Rocks a few weeks ago. I had a great time chatting with old friends Richard Campbell and Carl Franklin. Poor Carl--his mike wasn't quite loud enough, and I just couldn't hear him many times while we were recording. (Had no problems hearing Richard, however!) Sounds like Richard and I were just trying to blab right on top of him. Sorry, Carl! The event was great fun, and some of that comes across on the recording, I hope.
More Posts
Next page »