Home ::  Admin

chris carter's web log

Son Of A-

5:10 PM Monday Jan 26, 2009 Comments: 0

Grrrr.  I love wasting time.  Take today for example.  I just spent the last 30 minutes trying to figure out why DataContext on the yellow break point line below was null:

XAML To XPS To The Printer

9:21 AM Sunday Jan 25, 2009 Comments: 0

The following was created from Feng Yuan's blog post and a ton of great info at this guy's blog.

OK.  Start a new WPF Application.  By default you start with a window so I'll use that for the example.  Open up Window1.xaml in the designer and use this xaml for the window:

<Window x:Class="XamlXpsPrinting.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <DockPanel>
        <Button x:Name="PrintButton"
        		Content="Print"
        		Height="40"
        		Width="100"
        		Click="PrintButton_Click" />
    </DockPanel>
</Window>
1
2
3
4
5
6
7
8
9
10
11
12

You should see something like this in the designer:

Now create a FlowDocument, this will be VERY simple. Let's add a new item, and select Flow Document:

Add New Item Flow Document

Here's the XAML we'll use:

<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    ColumnWidth="400" FontSize="14" FontFamily="Georgia">
    <Paragraph>
        <Bold>
        	<TextBlock Text="Hello XPS!"></TextBlock>
        </Bold>
    </Paragraph>
</FlowDocument>
1
2
3
4
5
6
7
8

Now we're gonna wire up the PrintButton_Click method. We'll first need to add references to ReachFramework and System.Printing.  Here's the code for the PrintButton_Click method:

//LOAD XAML
var pathToFlowDoc = @"C:\Users\Chris\Documents\Visual Studio 2008\"
+ @"Projects\XamlXpsPrinting\XamlXpsPrinting\FlowDocument1.xaml";

var xamlDoc = XamlReader.Load(File.OpenRead(pathToFlowDoc));

//CREATE XPS
var xpsOutputFile = @"C:\HelloXPS.xps";
using (var container = Package.Open(xpsOutputFile, FileMode.Create))
using (var xpsDoc = new XpsDocument(container, CompressionOption.Maximum))
{
  var policy = new XpsPackagingPolicy(xpsDoc);
  var xsm = new XpsSerializationManager(policy, false);
  var paginator = ((IDocumentPaginatorSource)xamlDoc).DocumentPaginator;
  xsm.SaveAsXaml(paginator);
}

//PRINT XPS
var printServer = new LocalPrintServer();
var defaultQueue = LocalPrintServer.GetDefaultPrintQueue();
defaultQueue.AddJob("Hello XPS", xpsOutputFile, false);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

At this point we can hit F5, click the Print button and see the document print.  However, I'm on week 2 of Windows 7, making the leap from XP, so when I hit the Print button I got this:

I forgot about all the Run As Administrator crap that's not in XP, so I had to run Visual Studio as administrator before this would work:

To change it so VS always runs as administrator you can right click the short cut, select properties, on the Shortcut tab click the Advanced... button and check the "Run As Administrator" checkbox:

Now with that nonsense out of the way, run the app hit the print button and it should send the doc to your default printer.  Here's the VS2008 Solution.

Registry Hack for XPSViewer and Windows XP SP3

4:24 PM Saturday Jan 24, 2009 Comments: 0

I've always wondered why, whenever I try opening an XPS document, that Firefox opens and I'm prompted with the Save As dialog, selecting instead to open with the XPSViewer, all it does is prompt me to save, and the loop continues.  Since I almost never have a need to open an XPS document I've ignored the issue.  Today however, I'm neck deep in XPS and needed to fix the prob.  It has to do with Windows XP SP3.  Apparently if you've already installed the .NET frameworks through 3.5 SP1, the only fix is the following change to the registry:

Karl Snooks comment on an XPS Team Blog post about the issue showed me the way.  Previously, the value of the command node was the full path to XPSViewer.exe located in %WINDIR%\system32\XPSViewer folder.  Thanks Karl!

For an amazingly detailed explanation of the core problem and a fix(if you don't already have it installed), see Rafael Rivera Jr's post: Microsoft: I fixed the XPS Essentials Pack for you. It took 10 minutes.

Database Diagram Support Objects Cannot Be Installed...

2:53 PM Friday Jan 23, 2009 Comments: 0

This is mostly a reminder to myself.  Ever get this after restoring a sql server backup and trying to create a diagram:

I got a script from here that looks like this(if your database is named pantera):

 

EXEC sp_dbcmptlevel 'pantera', '90';
go
ALTER AUTHORIZATION ON DATABASE::pantera TO "sa"
go
use [pantera]
go
EXECUTE AS USER = N'dbo' REVERT
go
1
2
3
4
5
6
7
8

After running the script I can now add diagrams.

What Is So Bad About Html That We Have To Create a RedirectButton Control?

7:19 PM Thursday Jan 22, 2009 Comments: 1

Don't get me wrong, I like Scott Mitchell, and I've beed subscribed to his blog for some time.  However, a recent article of Scott's on 4guysfromrolla goes overboard with abstracting a simple html concept and making it way more complicated than it needs to be by masking html simplicity with asp.net complexity.

The RedirectButton Control

Essentially it writes out the html needed to generate an input button that uses location.href to redirect one's browser to a different url.  Here's the asp.net code that uses the control:

<cc1:RedirectButton runat="server" ID="btnToGoogle"
    RedirectUrl="http://www.google.com/"
    Text="And We're Off to Google!" />
1
2
3

And when the page is rendered, the client is delivered this html:

<input type="button" name="btnToGoogle" value="And We're Off to Google!" id="btnToGoogle"
       onclick="skm_Redirect('http://www.google.com/', '');" />
1
2

Redirecting With Old School Html

The same code can be written using POH(Plain Ol' Html) like this:

<input type="button" value="And We're Off to
    onclick="location.href='http://www.google.com/'" />
1
2

Notice anything? EVERYTHING needed to understand what's going on is right in front of you(the developer).  There's no ASP.NET control to muddle through, and there's no unneccessary javascript methods with zero value-add like the skm_Redirect shown above.

There's 105 characters in the simple html snippet.  The ASP.NET control generates 146 characters(for this example), but the code for the control has 237 lines of C# code along with including a javascript library with 184 lines of javascript code, most of which has nothing to do redirecting.

Ya, But What About User Input and The QueryString Shite?

Ok, here's the code using the RedirectButton control:

Search Google: <asp:TextBox ID="txtSearchGoogle" runat="server"></asp:TextBox>

<cc1:RedirectButton runat="server" ID="btnSearchGoog"
               AssociatedControlId="txtSearchGoogle"
               QueryStringParameterName="q"
               RedirectUrl="http://www.google.com/search"
               Text="Go!" />
1
2
3
4
5
6
7

which produces HTML like this:

<input type="button" name="btnSearchGoogle" value="Go!" id="btnSearchGoogle"
    onclick="skm_Redirect('http://www.google.com/search?q={AssocCtrlValue}&amp;safe=on', 'txtSearchGoogle');"
1
2

Old School Html:

<input type="button" value="Go!"
    onclick="location.href='http://google.com/search?q='+document.getElementById('txtSearchGoogle').value" />
1
2

What's The Point

Reinventing the wheel is easy, anyone can do it.  Let's make progress!  I like HTML.  It's simple.  The spec hasn't changed since 4.01(which came out in December 1999 which is a huge lifespan for technology these days), and I'm doubting the 5.0 spec will be implemented fully anytime soon by enough browsers to make it a worthwhile investment(the current browsers still don't all agree on how 4.01 should be implemented).

Even if you're still mucking around with ASP.NET Webforms, remember, it's OK to still drop back to POH to get simple things done and done well.

Windows 7 and msnmsgr.exe

7:27 PM Tuesday Jan 20, 2009 Comments: 0

Hmmm....now why would msnmsgr.exe randomly need to read my cd/dvd drive?

click to enlarge

Developing on Windows 7, One Week Later

2:36 PM Sunday Jan 18, 2009 Comments: 0

I'm liking the Windows 7 Beta bits...ALOT. 

Hardware

The box I'm running has the following specs: 

  • AMD Athlon 64X2 4200(2.2GHz)
  • 2GB(4x512MB) DDR400
  • 320GB 7200 RPM 16MB Cache SATA II
  • GeForce 8500GT 512MB 128-bit GDDR2 PCI Express
  • MSI K8NGM2 Motherboard

I decided to use a physical box over a Vmware image so I can get all the UI goodness(which you don't get in a virtual machine, not yet anyway).  I get a 4.6 experience rating on that box.

Software

In order to see how it really is I needed to set the machine up as a real dev machine, one that I will be making code commits from.  This involves installing VS2008 and all the tools I use on a regular basis.  The VS2008 install was not smooth.

VS2008

The installer crashed right off the bat, not sure why exactly, but it wouldn't install the Web Authoring component.  A quick google search points to a workaround for an issue that affected VS2008 Beta 2 versions, but it actually fixed my problem.  I got most of it installed before it died again.  I then "Repaired" the installation and it worked like a champ...almost.  At the end of the repair, it said everything was perfect(the green checkmarks next to everything), but Windows pops up  a message indicating that setup.exe encountered a problem and needs to be uninstalled...huh? Windows wanted to undo my installation, I politely cancelled that operation.  SP1 for VS2008 installed without a hitch.

Most of the other tools(CodeRush, GhostDoc, TestDriven.NET) installed without any problems.  CoolCommands failed to install, so I had to install VS Power Commands, which does pretty much the same thing as CoolCommands.  Also installed Tortoise SVN, and that worked without issue.

.NET 3.5 sp1

This one I thought was installed with Windows installation but apparently not, I couldn't find any signs of the install. I downloaded the little bootstrapper exe for .NET 3.5 sp1 and tried running it, it didn't work. I unblocked it, cuz it needs to hit the internet to pull down more files, but that didn't help either. I'm gonna claim user error was the problem, but Windows didn't tell me anything either, I double click the exe and nothing happened, check task manager and couldn't see anything running. I found someone with a similar problem installing sp1 on Vista and the recommendation was to download the whole service pack as a single download and skip the boot strapper.  That worked, but I still would like to know why it didn't [appear] to work for me.

Microsoft LifeCam

This is the software for my webcam, and it blue screened right after install.  So no LifeCam software on Windows 7 yet.  On a positive note, from blue screen to restart was quick, like 30 seconds round trip, so that's encouraging.

Quake III

This probably has less to do with the quality of the operating system, but it's good to know that Quake III Arena still plays flawlessly on that machine.

Start Up Times

This is cool.  I have my main desktop dev machine, that's running Windows Server 2003 R2 and has a raptor 10k drive, and tons of bells and whistles.  But the machine with Windows 7 fires up apps much faster.   Visual Studio normally take s a few seconds to start up, like 15 to 30.  On the Windows 7 box, it's about 3 seconds to load up visual studio which KICKS ass.

My Dream Might Be Coming True

I have successfully stayed away from Vista, and based on my Windows 7 experience so far I think it will be possible to jump from Windows XP, over Vista, and straight to Windows 7.  And that rocks.

Window 7 Official Beta Installed

10:5 PM Saturday Jan 10, 2009 Comments: 0

Yay! Microsoft kickstarted the download process today for the windows 7 beta, after bout 2 hours I got the download.  Here's a screencap(click to enlarge but there's not much to look at). More to come after I play around a little more tonight and tomorrow.

Windows 7 Screen Capture

Because That's How They Do It In Sharp# Architecture...

1:2 PM Friday Jan 9, 2009 Comments: 2

Really, it should be "Because That's How They Do It In [InsertBuzzWordArchitectureOfTheWeekHere] Architecure" but I just read this post by Billy McCafferty so I used Sharp# in the title of this post.  But you could easily insert, OptionatedMVC(or whatever that thing is called) or CSLA.NET, or whatever framework calls itself a framework.

NOTE: This has nothing to do with Billy McCafferty and/or Sharp# Architecture(or any other architecture).  This has to do with developers blindly picking tools, techniques, or frameworks without thinking first.

I heard it once this week from a team member, "I did it this way, because that's how they do it in Sharp# Architecture".... After reading the Billy's post, I'm fearful that starting next week  I'm now gonna hear, "Well, Billy said to put controllers in their own assembly, can we start doing that too?" 

Here's the problem.  We need to be thinking with our brains not the blogs we read and/or samples we find on the web.  Look at the problem, solve the problem.  Did you solve the problem, even take a stab at it? Don't like what you came up with? Hit google to find better ones, try them out and make sure they solve your original problem.  Get ideas from as many sources as possible, make your own decision on how to move forward with whatever you're doing.  I

It's OK to pick ideas from various blogs, solutions, etc around the web, but at least be able to think through your problem and make sure you're only solving your problem rather than just implementing someone else's solution that solved their problem.

 

According To O'Reilly, A Tree Is Only Worth $6 US Dollars

10:59 AM Friday Jan 9, 2009 Comments: 0

Here's what's funny. Had there been a bigger discrepancy between the ebook and print book, I may have actually purchased the ebook regardless of the price, just because it makes me feel like I'm doing something other than handing cash over to O'Reilly. But c'mon, 6 bucks difference? The book is only 170 pages to boot!

Self Publication

Is this even happening? Sure it is. Karl Seguin published his own Foundations of Programming EBook, free of charge.  The free of charge bit was really nice, HOWEVER, had Karl requested 5 or 10 bucks for the book, I woulda paid it, especially knowing that 100% of the cash goes right into his bank account.

Anyone know of any online ebook publishing companies(good or bad)?  I'd like to know about how that sort of  business model works, ie, how much of a cut are the authors getting(ie fair or unfair).

Uh Oh....Windows 7 Beta? Tomorrow?? Hell YA!

8:17 PM Thursday Jan 8, 2009 Comments: 0

Via Wired.com, looks like Build 7000 of Windows 7 will be made available to the first 2.5 million peeps.  Visit the Windows 7 page for details.  I have an extra machine that has plenty enough hardware for the new version and is primed and ready for install.

Giles's Balls Are Fuzzy Today

8:11 PM Thursday Jan 8, 2009 Comments: 0

Apparently some people on reddit are not happy with the content on Giles Bowket's blog

He's a Ruby guy.  I'm not, I dabble VERY rarely in Ruby, especially since starting in on WPF.  Anyway, his  blog contains a very wide range of topics, many don't have anything to do with Ruby.  But it's entertainment value for me along with some interesting look into non-MS stuff. 

I first learned about the term Muppet F*cker back in October while watching Giles's RubyFringe talk. That term is hilarious(again, to me).  Had I not seen this post, I would have missed the Squirrel poster, that's funny to me. 

Here's the thing, if it wasn't funny to me and there wasn't anything interesting to read, I wouldn't subscribe to his blog(or anyone elses for that matter).  If you don't like what you're reading, stop reading it.

CodeRush and INotifyPropertyChanged

7:52 PM Thursday Jan 8, 2009 Comments: 0

I've been writing a few too many of these types of properties recently:

private string _firstName;
public string FirstName {
  get{
    return this._firstName;
  }
  set{
    if (_firstName != value){
      this._firstName = value;
      this.OnPropertyChanged(new PropertyChangedEventArgs("FirstName"));
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12

So I decided to put CodeRush to work for me and came up with the following.(The video, after YouTube processed it, kinda sucks, too small until I zoom in,  but the little balloon that appears contains the text The CodeRush template is invoked with pn?Type?)

.I have a tough time uploading code screencasts to youtube, the quality always sucks.  I'm sure it's me, the format I upload, screen resolution, or various other factors.  Vimeo seems like it offers better quality, but this HUGE 9 sec screencast kept timing out when I was trying to upload so I went with YouTube instead.

Corporate Coders

1:16 PM Wednesday Jan 7, 2009 Comments: 0

Zed Shaw describes the corporate coder around minute 39 of his keynote speech from CUSEC 2008.  Beware of corporate coders....

Book: The Art of War

7:41 AM Wednesday Jan 7, 2009 Comments: 1

I knocked one book off of my list! woo hoo!

So, this was mostly on my "list of books to read before I die",and I didn't have any other particular reason for reading it.  That's really all I got out of it, I get to check that off the list. 

It's written by a military general who existed a long time ago or a really long time ago(apparently that's under debate).  It's about tactics and strategy of fighting a war, that this general wrote up in this short(less than 100 pages) little manual.

I found it to be a little boring of a read for me, your mileage may vary.

Lenovo Dual Screen Notebooks

7:29 AM Wednesday Jan 7, 2009 Comments: 0

I saw this one via Wired.com, http://www.5min.com/Video/First-look-on-Lenovo-New-Dual-Screen-Laptop-81638558.  I like the concept but the second screen is tiny to be of much of use, at least at a glance.  The video shows them maximizing IE in the little screen, and while it's neat it didn't seem practical.  I'd love to see the seam between the main screen and the second screen be almost seamless.  Oh, and I'd want to be able to pull out another screen from the left side, only one little screen off to the right side just seems out of balance.

WPF And Visual Studio Crashes

6:56 AM Tuesday Jan 6, 2009 Comments: 0

I don't know what changed in the last week or so with my dev environment, but [seemingly] randomly, when working on WPF projects, Visual Studio kept crashing.  I found a link yesterday(can't remember where), that suggested repairing my .NET 3.5 SP1 installation.  I did that and and now no more crashes, since yesterday anyway.  So that's weird, why was that happening just in the last week? I haven't installed anything recently....at least not to my knowledge(Windows Update maybe??)

Looking Forward To 2009

3:43 PM Thursday Jan 1, 2009 Comments: 0

Here are some of the things I'm looking forward to in 2009.

This Blog

I wrote the code for this blog, but it's not great.  Why write my own blog software? I write code for a living, and I write code for fun, it's what I do.  Part of the fun for me is using my creations, dogfooding if you will.  It gives me insight on how to build better software.  I'm no usability expert but I know what I like, so using my own shite helps to get better at usability.

Finding stuff on this blog is nearly impossible.  I have google search hooked up but the way it's set up is not helpful.  Either it's the way I post stuff or my lack of understanding of how to search my own crap with google, but I need to improve my blog search capability, that's a biggy on my todo list.  I've implemented my own search tool for the admin area, once I'm fairly confident that I can fend off a sql injection attack I'll put it on the main page.

Offline capability.  Blogging online is not fun.  Connectivity is annoyingly inconsistent, I don't know if it's my host, my connection, just the way it is, but it's annoying.  I would love to be able to compose everythingoffline and if it automagically stay in syc with panteravb.com.  Windows Live Writer? Nah, that sounds like a job for me and WPF, perfect chance to play in DirectX goodness.

The topics of this blog are not always technical.  This isn't going to change, HOWEVER, I do want to make sure those who couldn't give a crap about anything I have to say that's non-technical have the option to exclude that content. 

I tried tagging the content on this blog before but I didn't do a good job of it so that's on my todo list.

Screencasts/Codecasts

My 2009 plan involves at least one codecast per week on anything software related.  Huh, I guess that means one is due tomorrow, I better get crackin!

Personal Software Projects

I have so many little projects I'm working on, I want to set a schedule for getting them all done. I believe that having project plans and schedules works not just for stuff you get paid to do for work but also for personal projects. So I'm tasking myself with coming up with a timeline for all of my little projects.

Books

I have soooooooooooooooooooo many books I need slash want to read.  If you don't plan to read you won't, at least that's me, so in the new year I want to plan on reading  my non-tech books.  First on my list is a little one, The Art of War.  The rest of the books on my todo list in no specific order include Kitchen Confidential, Wisdom of our Fathers, Big Russ and Me, Notes From The Underground,The Omnivore's Dilemma,The Heroin Diaries: A Year in the Life of a Shattered Rock Star,The Forgotten Man, and World Without End.

Other Platforms and Tools

Sometimes(or most of the time) the best way to learn is to look outside of the platform and or tools that you're familar with and see how others do it.  Platforms that I want to take a look at include those running on a non-windows os, probably linux.   Php, Ruby on Rails, Java(yes, I said Java), and anything else to help me learn how to build better software faster.

Fitness

Today starts my serious commitment to my local crossfit affiliate, Emerfit.  I've been going zero to four times a week since September but have yet to follow the nutritional plan(which is the cornerstone to any fitness program).  So for the next 6 weeks, my commitment involves no eating out and no alcohol.  Also no food(or drink[except water]) after 7pm any night of the week.  I've taken on the The Power of Less challenge, and you can follow my progress at the forum here.