Welcome to MSDN Blogs Sign in | Join | Help

Mark Schmidt's Abode

On Programming, Writing, Gaming, Fitness, Life

News

  • Have a Question?

    Click here to chat with me

    XBox Live GamerTag


    Twitter



    The Mark Cam


    My MoBlog

    www.flickr.com
    This is a Flickr badge showing public photos from codepunk. Make your own badge here.

    Community-Credit

My Screen Saver Vista Sidebar Gadget

 For some reason, I'm drawn to creating things that are just cool while not altogether useful (see my Animated Activity Designer post, though one could argue that it may in fact be useful). To that end, I decided to create a Vista Sidebar gadget that displays a screen saver of your choosing. Vista has some good screen savers that it shipped with and I've embedded screen savers before (in fact, I show how to do it in one of my books).

So go ahead and grab it from the Windows Live Gallery (link below). If enough people clamor and beg, I will post the source code. Here's a quick rundown of what I did:

1. Create a .NET User Control
2. Embed a screen saver in the user control whenever the ScreenSaverPath property is set (and the control is visible)
3. Create the HTML page for the sidebar (sidebar controls use Javascript and HTML in case you didn't know already)
4. Embed the UserControl in the HTML page (using COM interop naturally)
5. Create a settings page that also uses COM Interop. The settings page calls a .NET component that I wrote that simply returns a collection of screen saver paths on the local system.
6. Create the installation in Javascript. I had to get some help for this one. Basically, I do what regasm does by using the WSHShell object to set registry entries. I found some code on the Internet to help.

Here's a screenshot of it in action using the Ribbons screensaver:

Here's the link:

Screen Saver Vista Sidebar Gadget

Stop Motion Animation using Windows Movie Maker

So I got bored a few nights ago and decided to see if I can do some stop motion animation using my wife's Nikon D70 and Windows Movie Maker. After I imported all the pictures I took of my kids (somewhere around 100) into Windows Movie Maker, I went into options and changed the default time to display pictures in the movie when I drag and drop them. The default is 5 seconds and I changed it to 0.25 seconds. I then did a CTRL-A to select all my pictures and dropped them all on the timeline. I then added a beginning title, transition and end credits. It was topped off with a little music. The whole movie making process took around 5 minutes. So without further ado, here's the link:

The Amazing Crazy Race

WFPad for Windows Workflow Foundation RTM

Since a few people have asked, I updated the source for WFPad to work with the latest and greatest Windows Workflow Foundation.

Click the link to download: WFPad.exe or the zip file: WFPad.zip

 Enjoy!

WPF Post-it Board source updated

Ok, first off let me say that I really really don't try to just create a blog entry that simply links to someone elses blog entry. Most of what I blog about comes straight out of my head and usually involves the use of an IDE and source code. However, the PostIt Board project created by Michael G. Emmons is just too cool to not say anything.

Written using WPF, it interfaces with Flickr and allows you to do a search and display the results as small thumbnails on a post it board interface (see picture below). The source is included. Here are some things I had to do to get it to run and to make the canvas movable.

1. Open the solution and delete the FlickrFX.snk.pfx file from the FlickrFX project (note that when you open the project it will ask for a password to open that file. Simply hit cancel and then go and delete it).

2. The code to move the window is commented out. When I uncomment it I can move the window but clicking on a picture causes the picture to move off screen. Here's the code to fix this so you can move the window as well as move any image.

protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
    IInputElement iie = this.InputHitTest(e.GetPosition(this));
    if (iie is System.Windows.Controls.Canvas)
    {
        base.OnMouseLeftButtonDown(e);
        this.DragMove();
    }
} 

Windows workflow foundation animated activity designer source

As I mentioned in my last post, I have uploaded the Animated Activity Designer for use in your own project. A common question I can anticipate being asked is "Why?". So, here's why I created it and my reason as to why you may want to use something like this.

First off, the reason I wanted to try to created animated activities within the Windows Workflow designer was merely to see if it was possible. I knew that I could override OnPaint so I pretty much already knew it was going to be possible (otherwise I probably wouldn't have gone down the path). The second reason is simply because as a guy that loves cool eye candy in UI's, I just had to do it.

So why would you ever want to create an animated activity? Let's say you create an application that hosts the Windows Workflow Designer. Let's also assume that this application is used by your customers. You present them with the designer surface and within a Toolbox like panel, you have your set of custom activities they can use. If pictures are worth a thousand words, then an animation with 10 frames is worth 10,000 words.

The actual code for this is really simple which is also why it only took a couple of hours to get it up and running. Since it is so easy, I won't waste your time explaining it (but feel free to ping me if you have any questions).

Download the code right here: AnimatedActivityDesigner.zip

To see it in action, open the solution in Visual Studio, build it and then open workflow1.cs in the designer.

Enjoy!

 To see the video better, right click and select Zoom -> Full Screen

P.S. The activities you see in the project and in the video are simply placeholders. They do not actually do anything.

Windows Workflow Animated Activity Designer

Keeping in line with Mark Schmidt tradition, I present to you a little teaser. I will be posting the code for an animated custom activity designer that you can use for your custom activities. Not only will it allow you to create a cool looking animated custom activity in the Windows Workflow Designer, you can integrate the custom activity designer into your project using only 2 lines of code. The flash file you see below for the MoveFilesActivity uses my generic animated activity designer and only needs to apply the following 2 attributes to the custom activity to get it to work:

[Designer(typeof(AnimatedActivityDesigner), typeof(IDesigner))]
[
AnimatedActivityDesigner(EmbeddedGifResourceName = "AnimatedActivityLib.FileMove.gif")]
public partial class MoveFilesActivity : System.Workflow.ComponentModel.Activity
{
      
public MoveFilesActivity()
      {
            
InitializeComponent();
      }
}

Saving WF Designer layout information

So you created a fancy new application and it hosts the WF designer. It's all looking good and when you go to load up that cool state machine workflow you created earlier to add a bit more polish, you notice that all the layout you worked for hours (ok, maybe not that long) is gone. You know need to add the ability to load and save layout information for the workflow definitions your application creates. Note that you'll still need a way to associate specific layout information to a specific workflow, but I'll leave that as an exercise for you since there's about 5001 different ways). So, to save layout information for a workflow within a hosted designer, use the following code from your WorkflowDesignerLoader class:

public void SaveLayout()

{

    using (XmlWriter writer = XmlWriter.Create("wfInstanceId.designer.xml"))  

    {

        IList layoutSaveErrors = new ArrayList() as IList;

        IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));

        ActivityDesigner rootDesigner =

            host.GetDesigner(host.RootComponent) as ActivityDesigner;

        this.SaveDesignerLayout(writer, rootDesigner, out layoutSaveErrors);

    }

}

Programmatically add an activity to the WF designer

Here's a quick code snippet o' the day. If you're hosting the WF designer in an application and want to programmatically add an activity to the designer view, you can use the following code. Basically, grab the IDesignerHost service from your WorkflowView object (the call to GetService below calls the WorkflowView.GetService method and returns the service as an IServiceProvider). Use the IDesignerHost service to get the RootComponent and add your new activity it. For simplicity, we just add a CodeActivity as a child though you can certainly walk the activity tree and insert it wherever you need to. Once this is done, call the AddActivityToDesigner method defined in your WorkflowDesignerLoader object and you're good to go.

public void AddCodeActivityToDesigner()

{

    WorkflowDesignerLoader loader =

        GetService(typeof(WorkflowDesignerLoader)) as WorkflowDesignerLoader;

    if (loader == null)

        return;

 

    IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));

    CompositeActivity rootActivity = designerHost.RootComponent as CompositeActivity;

 

    CodeActivity codeActivity = new CodeActivity();

    rootActivity.Activities.Add(codeActivity);

    loader.AddActivityToDesigner(codeActivity);

    return;

}

Vista flavored Talking Rain

Just saw that we now have Vista flavored Talking Rain in the pop coolers (err, soda for you non-northwesterners). Actually, it's Lemon-Lime with the Vista logo on the front. Here's some pictures: 

 

I'm not half the man I used to be...

I'm about 3/4 what I used to be. I recently finished the 20/20 weight management program of which Microsoft pays a large portion of. I started the Monday before Thanksgiving (why oh why did I not start after Thanksgiving) and just recently finished at the end of May. It was a 27 week program consisting of trainer sessions, a personal dietician, psychologist, small group meetings and regular doctor visits. I started at 262 pounds and wittled down to a fit 198 pounds (that's 64 pounds!). In that time I ran a race, climbed a mountain and pushed myself to run 11.6 miles one sunny Saturday.

The cool thing is, I refused to see a lot of my family and friends during the time waiting instead to surprise them on Memorial Day. In fact, all I told them was that I have an announcement to make and want to meet them at my mothers house in Long Beach, WA. The look on everyone's face was priceless.

I also decided to throw together a video (and by "throw together" I literally mean it. The quality isn't that great). I just finished uploading it to iFilm. Take a look if you're interested.

http://www.ifilm.com/ifilmdetail/2732350

Feel free to comment/email and I'll provide more details on what I went through.

WFPad for Windows Workflow Foundation Beta 2 is here!

Back by popular demand, I now release the Beta 2 version of WFPad. However, it's not a simple port but a new and improved version. In this version, you can open workflows contained in any .NET assemblies (if I recall, that feature didn't work so well in the previous version...though I may be mistaken). I did find Lab 10 from the WF Hands on labs to be quite informative and therefore "borrowed" some code but altered it slightly to work with WFPad. So go ahead and play with it. Will there be bugs? Yes. But since you have the source code, you can fix them for me (sinister laugh). Enjoy!

Click here to download the project

WFPad Beta 2 is coming tomorrow

I've been getting quite a few emails/comments about WFPad and it's state for Beta 2. Here's a teaser image for you. I will release it tomorrow to the masses...

 

Windows Workflow Foundation Beta 2 is here!

I won't blab much, but Beta 2 is here and it's hot. Once again, I worked in the doc's with primary responsibilities being the tutorials and sample content (not the actual samples themselves though). The tutorials have been seriously revamped since Beta 1 using a new task based format with the ability to start on any single task without having to go through the entire tutorial. Many more tutorials are in the pipeline. Here's the info you need (note: this is hot off the press and was just posted by Michael Zammuto. If you get a page not found, the content is still replicating. Just try back later. It'll show up):

English

Page: http://www.microsoft.com/downloads/details.aspx?FamilyId=A2151993-991D-4F58-A707-5883FF4C1DC2&displaylang=en

Install Guide: http://download.microsoft.com/download/2/7/f/27f7a7b1-53bd-48f9-9914-e2e26a5effd7/WFBeta2_Install_Instructions.htm

ReadMe: http://download.microsoft.com/download/2/9/2/2921ef94-007b-4d9f-ba06-021329b88d7c/VS2005Extensions_for_WF_Beta2_Readme.htm

Download: http://download.microsoft.com/download/3/6/1/361f07f8-d6e1-491c-ac00-cd1128e02c81/Visual Studio 2005 Extensions for Windows Workflow Foundation Beta 2(EN).exe

German

Page: http://www.microsoft.com/downloads/details.aspx?FamilyId=A2151993-991D-4F58-A707-5883FF4C1DC2&displaylang=de

Install Guide: http://download.microsoft.com/download/1/8/8/188168e6-4881-4c9d-94a7-34742390f9a0/WFBeta2_Install_Instructions.htm

ReadMe: http://download.microsoft.com/download/5/1/b/51b24af7-8d77-47c0-8947-5768f728237e/VS2005Extensions_for_WF_Beta2_Readme.htm

Download: http://download.microsoft.com/download/3/0/9/30929765-ad9c-4494-b9a4-072b5d553b7c/Visual Studio 2005 Extensions for Windows Workflow Foundation Beta 2(DE).exe  

Japanese

Page: http://www.microsoft.com/downloads/details.aspx?FamilyId=A2151993-991D-4F58-A707-5883FF4C1DC2&displaylang=ja

Install Guide: http://download.microsoft.com/download/6/6/f/66ff81ee-e089-4db5-9da8-ae1d67badf86/WFBeta2_Install_Instructions.htm

ReadMe: http://download.microsoft.com/download/8/4/9/84975e78-5f80-4552-ac18-6463a7a3af38/VS2005Extensions_for_WF_Beta2_Readme.htm

Download:  http://download.microsoft.com/download/e/3/d/e3d477c5-8ca6-47fc-8fe6-d98a10ba651e/Visual Studio 2005 Extensions for Windows Workflow Foundation Beta 2(JA).exe 

Labs

Page: http://www.microsoft.com/downloads/details.aspx?FamilyId=5DF74E3B-FB51-4A94-A11D-DFF70288A8BB&displaylang=en

Download: http://download.microsoft.com/download/a/a/c/aac10b59-e569-47b1-82f6-747e98d5fb0e/Microsoft Hands-on Labs for Windows Workflow Foundation Beta 2.msi

Follow up to interview question
My first interview question was pretty successful. The one that was closest to my solution was Paul Bartrum (that name sounds familiar for some reason) followed closely by domovoi (though I didn't test his). Both Paul and I had just a single for loop enumerating once over the collection. I used the concept of "period" which probably has some other name but that's the best description I could come up with. Basically, a period in this sense (and in my mind) is how long it takes a single dimension's index to change when the lower indices are enumerated. This is determined by multiplying the upper bounds of dimensions following that dimension. For example, if you had: int[,,] arr[3,2,3] the third dimension's period is 1 because no dimensions follow it. The second dimension's period is 3 and the 1st dimension's period is 6 (2 x 3). Once I conceptualized that, the rest was trivial. Paul was pretty much thinking along the same lines. There were some good solutions but due to time, I can't go through all of them (especially the python one which threw me for a loop hehe).

Now, here's the next interview question. I think this one will be a lot easier and it follows along the same line. Here goes.

Given a multidimensional array, set each value in that array as efficiently as possible. In other words, don't have a series of nested for loops. Let's say that I will just give you an array without any preconceived notion of how that array was constructed. Make sense? Then get to it!
WFPad - Viewing/Editing Workflow's in XML

Note: This posting is for Beta 1 of Windows Workflow Foundation. For an updated Beta 2 build, please go to: http://blogs.msdn.com/markhsch/archive/2006/03/02/542596.aspx

Windows Presentation Foundation has XAMLPad as a tool. With this tool, you simply enter in some Xaml at the bottom and view the results within the application itself. Why not create something like that for Windows Workflow Foundation? So I did.

 

WFPad is the XAMLPad for Windows Workflow Foundation (as WF moves to XAML we'll see how XAMLPad works with this). You can use the designer and hit the down arrow for synchronization to instantly view the XOML for that workflow. On the flipside, you can enter in some XOML, hit the up arrow synchronization button and the designer will load that XOML and display the workflow accordingly. Being that it's an editor of sorts, you can save any workflow's to the file system as xoml files as well as load xoml files.

I also gave it the ability to navigate to an assembly containing workflow's, select a workflow within that assembly and then load it. I am able to extract the xoml just fine, but currently the designer is unable to load it (I know why, just not how to fix it yet).

This app only took about an hour to create (which is why I haven't figured out that bug) but would not have been possible without some additional legwork provided by other folks. I used the Workflow Designer Control and I am using the WorkflowAssembly class found in the WorkflowReflector project.

Let me know if you want me to add anything, but since I'm giving the source, it should be easy enough for you to expand.

Click here to download the source/app

Page view tracker