July 2008 Entries

Making ClickOnce less annoying.

After chatting with my installer expert, he mentioned ClickOnce does have a ton of options to make this work properly.

MSDN, what would .Net developers do without you.
http://msdn.microsoft.com/en-us/library/s22azw1e(VS.80).aspx

ClickOnce and updating

ClickOnce has some pretty nice advantages.  All I need to do is upload the new files and it magically updates the clients.

But it has a problem, every start up, this pops up.  It is super annoying.

image

I have a project installer with an old school installer that seems to have the auto-updating ability too.

If I migrate from the ClickOnce, I have to figure out also how to do a seamless transition.  The ToDo project already has end users.  Of which, today, got a nice present.  I added in font color and a simple configuration screen.

WPF, Binding, and Background colors.

So for my ToDo applications, one of the first task items was being able to change the font color.  After reading about this on my trusty WPF advisor blog, I learned you can do direct data bindings with Settings.  This is useful since I just have to create the property bind to it, and walk away.  The one thing I have to do is just save the properties.

Here is the WPF for doing the background binding.  Took me a bit to see the error of my ways for binding a background.  I had <Button Background=“{Binding …” and this was a no no even though you can say Background=“Red” and have it be red.  By binding like this, it works great.

I also bolded the important items to have if you want to bind to your settings.

<Window x:Class="ToDo.Configuration"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:Properties="clr-namespace:ToDo.Properties"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Configuration" Height="300" Width="300">
    <Window.Resources>
        <Properties:Settings x:Key="settings" />
    </Window.Resources>
    <Grid DataContext="{StaticResource settings}">
        <Button>
            <Button.Background>
                <SolidColorBrush Color="{Binding Path=Default.FontColor, Mode=TwoWay}" />
            </Button.Background>
        </Button>
    </Grid>
</Window>

Now I can have multiple things bound to a setting and not have to reload after the settings have been updated!

ToDo on Lifehacker!

image

Click here to read ToDo Embeds the Contents of Todo.txt onto Your Desktop

Laptop acting up? Roll it back with WHS

windows-home-server[1] If you follow my twitter feed (http://twitter.com/crutkas), you may have noticed my Lenovo x300 was being much like a spoiled child today.  For the life of me, I couldn’t keep it stable.  I had the svchost.exe that controlled some pretty critical stuff decide to go nuts on me for some random reason.  It was so bad that I couldn’t even launch task manager.  It was like Chernobyl.

So I went home and saw I had a few day old back up of my data.  I backed up data I knew was brand new, put in my PC restore disk and went away.

I did something bad however … I didn’t trust Windows Home Server’s disk settings.  I was all like, “I roll with 5 gangs and live in the 2nd most dangerous city in the US, I do what I want” and set my c:\ to the active drive when it wasn’t.  So a quick bit of background information, my x300 wasn’t reformatted when I got it and has that stupid hidden partion on it.  So I found out that Lenovo has the boot manager on that partition!  It took me about 3 restores before I remembered that I’m a dumb ass.

Had I not messed with the settings, I would have been back up and going at about 9pm instead of 2:30am.  Still, fun lesson and gave me a few hours to mess with Windows Server 2008 “workstation” on my Lenovo t61p.  I must admit, I made it look like Vista.  It gives me a weird sense of containing power too. 

There is a blog that tells you how to make the server OS into a workstation.  After checking that out, reading for 5 minutes, it took 10 minutes to get all the registry keys and services switched on.  Another Server 2008 tips and tricks that I didn’t see can be found over on blogs.msdn.com.

Now do I think the Windows Server 2008 workstation build is faster than Vista?  Initially I thought good god this is fast.  It does seem to boot and shut down super quick too.  But I think this is jumping to conclusions.  I never ran Vista on the computer by itself.  Also Vista SP1 and Windows Server 2008 kernel are the same.  So what I’m going to do is get another backup with the settings as is on my WHS then do a Vista build. 

ClickOnce!

I spent a bit attempting to figure out how to do a ClickOnce installer for ToDo.  I was shocked to see where it was actually.  I had to ask Martin Schray where since he created a how-to video on the “normal” installer.

So if you want to create a ClickOnce application, follow along.

  1. Open up Visual Studio and whatever solution makes you feel good inside about.
  2. Be sure the project you want deployed is selected in your solution window
    image
  3. Go to Build –> Publish
    image
  4. The rest is pretty straight forward.  I picked FTP for my method of delivery.

One issue I dislike however with ClickOnce is it limits what you can do in terms of being an installer.  I would love to put a file in the “Start up” folder, however Click Once doesn’t give me that power.  Due to this fact, I’ll have to add it in programmatically.

ToDo on codeplex

Launched the ToDo project on CodePlex

You can download the source in c#, VB and the executable.

http://codeplex.com/todo/

ToDo’s and WPF

Much like Scott Hanselman with Baby Smash, I used this as an excuse to play with WPF.  If you’re like me, chances are you have a ToDo.txt on your desktop.  It tends to get lost in the sea of windows I have open OR I just forget about it for a few days.

So here is my solution.  It took about 5 hours to code from start to a stable, usable state.  A WPF application that “lives” on my desktop that lists all my todo’s.  The source code will be posted over at CodePlex shortly at http://codeplex.com/todo/ along with post an article over at Coding4FunI need to transcode it to Visual Basic still.

Update:  Code posted over at CodePlex with c# and VB.  Plus I did a release for it too!

The really cool thing is the list on your desktop will update in real time with the ToDo list!

image 

Really?  WPF?

Yup, I tried to do the transparent text with a Win32 app first and gave up after 15 minutes.  Never doing WPF before, I had a rough proof of concept in 3 minutes.  My toolset was WPF due to this.

Smooth Sailing though … just a bit choppy

I had a few WTF moments with WPF.  Dan Fernandez had a few moments of me grumbling due to this.

So with WPF, it works radically different with threading.  I used a FileSystemWatcher object to get notifications with the ToDo’s and in a Win32 application, I could update the user interface directly.

WPF is a bit more, what is the word I’m looking for, anal, yup, that’s it, about thread safety.  This is good and bad.

To update the user interface element, you need to talk to the Dispatcher object.  Here is the code I used for my application.

private delegate void NoArgDelegate();
private void todoWatcher_Changed(object sender, FileSystemEventArgs e)
{
    txtTodoList.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new NoArgDelegate(loadTextBox));
}

Another interesting thing was relearning where stuff was again.  Screen.Width was moved and a this.Handle.

Here is some of the OnLoad code.  As you see, to get a window handle, you have to use the WindowInteropHelper.  To fetch your screen size, use SystemParameters.PrimaryScreenWidth.  The SystemParameters has a ton of other items in it too on top of just screen size.

var helper = new WindowInteropHelper(this);

Win32.SetWindowPos((int) helper.Handle,
                   Win32.HWND_BOTTOM,
                   0, 0, 0, 0,
                   Win32.SWP_NOMOVE | Win32.SWP_NOSIZE |
                   Win32.SWP_SHOWWINDOW);

Win32.HideFromAltTab(helper.Handle);

Width = SystemParameters.PrimaryScreenWidth;
Top = SystemParameters.PrimaryScreenHeight - Height;

Another head turner was the lack of a NotifyIcon in WPF.  The easy workaround is to include the System.Windows.Forms dll and then reference it in.  Also means you need to manually create your ContextMenuStrip which is a tad of a bummer.  Adding in the code below will gain you a notify icon along with an exit button.

private NotifyIcon notifyIcon;
private void createNotifyIcon()
{
    notifyIcon = new NotifyIcon {Text = "ToDo", Icon = new Icon("report.ico"), Visible = true};

    // have to use the Forms version
    var contextMenu = new ContextMenuStrip { Name = "contextMenu" };
    var exitToolStripMenuItem = new ToolStripMenuItem {Name = "exitToolStripMenuItem1", Text = "Exit"};
    
    // contextMenu
    contextMenu.Items.AddRange(new ToolStripItem[] { exitToolStripMenuItem });
    contextMenu.Size = new Size(155, 114);
    
    // exitToolStripMenuItem1
    exitToolStripMenuItem.Size = new Size(154, 22);
    exitToolStripMenuItem.Click += exitToolStripMenuItem_Click;

    notifyIcon.ContextMenuStrip = contextMenu;
}

void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
    notifyIcon.Dispose();

    Close();
}

Once I got past doing stuff the new way over the old way, I have to say, WPF has some really powerful stuff built in.  I love how it forces you to think multi-threaded too right off the bat!

Video of me riding (kind of)

My dad is going to love saying “I told you so”

49758[1]I see now why Dean Kamen’s designed the segway with handlebars.  So tonight I finally got the balls confidence to ride the skateboard.  I have to say, is a rather scary thing since if I hurt myself, I’m semi screwed since I lack a roommate in my current apartment.

By using a chair stool, I can keep myself stable enough to slide back and forth.  I haven’t tweaked the PD values enough to really feel safe enough to let go however for more than a split second.  It works though.

One big issue I’m seeing already is the chains in the gearbox dither too much.  What exactly does that mean?  Since there are 2 gear reductions, it has 2 chain belts.  Since there is a very small amount of extra slack in the chain, it causes too much give.  I can feel the extra jerk from the chain drive when moving.

The ironic thing is my dad warned me about this problem.  Good thing he doesn’t read my blog if he doesn’t if there isn’t a Google alert on me.  Bad thing is I think it needs to be solved so I’ll have to give him a jingle.  This has to be a solved problem already.  Hell, bikes have solved this issue if you think about it …

I’ll post a video of me hurting myself shortly.

Using the force sensors Luke

Code added/fixed tonight (or if you view 4am morning instead of night…):

  • Data Logging is now optional
  • Force sensors are added in
  • Is board in a safe area to start
  • Removed I for the PID control loop
  • More compact interface
  • Turning code added but not “enabled”

image

Tomorrow:

  • Verify Force sensor code works
  • Verify board safety code
  • Video tape me running into walls.
  • Tweak PD control loop
  • Get turning tweaked in

Yet another simple function.  This one is for verifying if the board is safe to start riding.  Who knew making something safe could be such a pain in the ass?

private void prepBoard()
{
    var isUserPrepped = false;
            
    const int safeAngle = 5;
    const int safeGyro = 5;

    while (!isUserPrepped && IsUserOnSkateboard())
    {
        var data = imu.GetImuData(PiDividedBySix, PiDividedBySix, PiDividedBySix);

        var angle = data.AccelerationCorrected_X;
        var gyro = data.GyroCorrected_X;

        isUserPrepped = (angle < safeAngle && angle > -safeAngle) && (gyro < safeGyro && gyro > -safeGyro);
    }
}

Best of all, my book chapter is done (I hope, right Dan, right?)

Deadman switch

Some Force resistance sensors and phidgets!

IMG_0773

IMG_0771

IMG_0769