Keep an Open Tab at Starbucks

 

On yesterday’s news, there was a teaser about how Starbucks was going to change how we pay for things. “This is old news,” I thought to myself, “they’ve already done that with their mobile app.” I was curious about the story but forgot about it before I actually heard the details.

On this morning’s news, I saw a headline about it: “Starbucks partners with Square.” Until today, I’d never heard of Square, so I did a quick Google search and found this article at NYTimes.com. I gotta say, it sounds pretty cool. This quote from the article does a good job of summarizing how Square will change how you pay for your coffee:

At first, Starbucks customers will need to show the merchant a bar code on their phones. But when Starbucks uses Square’s full GPS technology, the customer’s phone will automatically notify the store that the customer has entered, and the customer’s name and photo will pop up on the cashier’s screen. The customer will give the merchant his or her name, Starbucks will match the photo and the payment will be complete.

That’s amazing! I just tell them my name, and they can look me up in a proximity-based list of users with photos to collect payment. It’s like having an open bar tab at Starbucks but more secure because of GPS and photo identification. It’s more secure than the current Starbucks app, too. Anybody with access to my phone today can walk into Starbucks and buy a drink with the app. With this, you’d need to have my phone and look like me.

Credential-less Authentication in ASP.NET

There are times when you may wish to authenticate a user in an ASP.NET web application without requesting a password. For example, I was working on a client application that had a web counter-part. I needed to authenticate the user by using just their login. Fortunately, the .NET Framework gives us a simple way to accomplish this with the FormsAuthentication.SetAuthCookie method.

FormsAuthentication.SetAuthCookie("adam", true);

One nuance:

The forms-authentication ticket supplies forms-authentication information to the next request made by the browser.

This means you can’t call SetAuthCookie and then execute code that assumes an authenticated user on the next line. A simple workaround is to use a redirect.

Open a URL in VB6

I was modifying a VB6 application to include a button that launches a browser to navigate to a URL. I wanted to use the default browser and open the link in an existing window, if one existed. This was accomplished easily with the ShellExecute API command.

First, you need your API function declaration in a code module:

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpszOp As String, _
     ByVal lpszFile As String, ByVal lpszParams As String, _
     ByVal LpszDir As String, ByVal FsShowCmd As Long) _
    As Long

Then you can use the API to open your URL, like so:

ShellExecute 0, vbNullString, "http://adamprescott.net", vbNullString, vbNullString, vbNormalFocus

Leading by Following

Image borrowed from here

I thought it was somewhat self-serving when my manager sent out an email to the team with a link to an article at Forbes about being a great follower, but it was actually a very good read. The article, titled “The 11 Leadership Secrets You’ve Never Heard About,” makes the point that the leaders among us are simply the best followers, and it reminds us that our leaders have bosses and are followers in their own right. The list of leadership secrets is about being a great follower, and it’s an excellent list.

There were a few items that really spoke to me, and it’s true: these are the things the leaders of tomorrow are doing today.

Great Followers are Great Communicators

I loved this one. (Not surprising, as somebody who clearly values communication!) More specifically, I love the idea of proactively providing relevant information. If I see something and dig into it, totaling numbers and gathering statistics, I’m going to send an email with that information displayed several different ways. Here’s a table. Here’s a graph. Here’s a 3D graph! When somebody else on the team sends out an email with data they’ve collected in a cool graph, I’m absolutely delighted.

And, to the point of the article, I’ve never received an email of this nature from somebody that I didn’t consider a leader on the team.

Great Followers are Goal Driven

There’s a lot of material out there about being successful by setting goals for yourself and being goal-oriented. Earlier in my career, I wanted to embrace this and set goals for myself, but I felt like I was a really bad goal-setter. I simply didn’t know what kinds of goals to set for myself! I like the text in the article on this item because it doesn’t just say, “set goals for yourself.” Instead, it talks about working forward versus working backward.

Great followers reason backwards: they use future goals to prioritize today’s “activity.” Poor followers reason forward: They react to their in-box and email in the forlorn hope that just staying busy will magically produce results somewhere “down the road.”

Well put! The amount of work will always be unending. If you focus solely on fighting it down, you’ll probably be stuck in the same role doing the same thing for longer than you care for. Conversely, if you can identify ways to improve the processes of today down the road, you can steer your activities in the right direction. Once you achieve the goal, you can get on to the next thing!

Great Followers Show Don’t Tell

This is another one that’s near and dear to my heart. I get pulled into a lot of what-do-you-think, consultation-type meetings. In those meetings, I’ll throw out ideas that seem like they should work. Energized by a potentially great idea, I often start putting together a proof-of-concept as soon as I get back to my desk. It’s exciting to me to send an email with a fully-functional example of what I suggested might work an hour before. Unfortunately, based on the amount of emails like this that I receive, I don’t think many people are doing this. Additionally, showing up to a meeting where it’s clear that you’ve put effort into your preparation will impress the room. Take time to prepare a PowerPoint presentation or print handouts on the topic you’re presenting or might be consulted on. You’ll be better prepared, and it’ll be noticed by peers and leadership, alike.

Great Followers Offer Solutions

This one’s definitely a favorite. Do you have a problem? What can you do about it? What are the advantages and disadvantages of your options? This is decision-maker training. When you’re new at it, evaluate the situation and bring solutions along with your problems to your team leads and managers. You may not come up with the best option, but that’s a learning opportunity. Over time, you’ll learn how to identify the best options, making you a leader capable of finding the best options to other people’s problems: you’ll be down with OPP.

Great Followers are Loyal

I’ll comment on just one more item from the list, and that’s loyalty. The article points out that a great follower will go out of their way to make their boss look good, which really couldn’t be more true. (I was once again chuckling at the self-serving nature of this statement in the article sent from my boss…) It’s true though; a great follower will take pride in making their team great. When it’s time to look for emerging leaders, the best teams are probably a good place to start.

The rest of the list is very good, too, and these were just my favorites. Check out the article and think about how you can improve as a follower. Focus on being a great follower, and you’ll naturally evolve into a leader.

Windows Workflow 4 Designer WPF Application

One of the coolest things about Windows Workflow Foundation is the workflow designer. It’s visual programming.  You drag and drop your components onto the design surface and configure the properties of each module to create a functional application. Microsoft makes it easy to re-host the workflow designer in your own applications, providing you with an easy way to include customization and configuration tools for your workflows.

I found a great bare-bones tutorial at MSDNRehosting the Workflow Designer.

There’s some important functionality missing from this tutorial, though. There are no mechanisms for opening or saving workflow files, and the toolbox is only populated with two controls. So, I’ve taken the MSDN tutorial, compressed the steps, and added some additional key functionality.

  1. Create a new WPF Application. I called mine “WorkflowEditor.”
  2. Add references
    • System.Activities
    • System.Activities.Core.Presentation
    • System.Activities.Presentation
  3. Copy/paste the XAML below into MainWindow.xaml
  4. Copy/paste the code-behind below into MainWindow.xaml.cs

That’s it! Once you’re this far, you should be able to run the program. If you’re looking for a more in-depth, step-by-step explanation of the code, follow the link above to the MSDN tutorial. The only differences below are that I added some reflection code to extract the “standard” workflow activities, and I added Open and Save buttons.

<Window x:Class="adamprescott.net.WorkflowEditor.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="500" Width="800">
    <Grid Name="grid1">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="4*" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="36" />
            <RowDefinition />
        </Grid.RowDefinitions>

        <ToolBar Grid.Row="0" Grid.ColumnSpan="3">
            <Button Click="OnOpenClick">Load</Button>
            <Button Click="OnSaveClick">Save</Button>
        </ToolBar>
    </Grid>
</Window>
using System;
using System.Activities;
using System.Activities.Core.Presentation;
using System.Activities.Presentation;
using System.Activities.Presentation.Toolbox;
using System.Activities.Statements;
using System.Linq;
using System.Reflection;
using System.Windows.Controls;
using Microsoft.Win32;

namespace adamprescott.net.WorkflowEditor
{
    public partial class MainWindow
    {
        private WorkflowDesigner _designer;

        public MainWindow()
        {
            InitializeComponent();
            RegisterMetadata();
            InitializeDesigner();
            AddToolBox();
        }

        private void AddDesigner()
        {
            _designer = new WorkflowDesigner();
            Grid.SetColumn(_designer.View, 1);
            Grid.SetRow(_designer.View, 1);
            grid1.Children.Add(_designer.View);
        }

        private void RegisterMetadata()
        {
            var dm = new DesignerMetadata();
            dm.Register();
        }

        private ToolboxControl GetToolboxControl()
        {
            var toolbox = new ToolboxControl();
            PopulateToolboxCategoryFromAssembly(toolbox, typeof(Assign).Assembly, "Standard");
            return toolbox;
        }

        private void PopulateToolboxCategoryFromAssembly(ToolboxControl toolbox, Assembly assembly, string categoryName)
        {
            var tools = assembly.GetTypes()
                .Where(t => t.IsSubclassOf(typeof(Activity))
                    && t.IsPublic
                    && !t.IsAbstract
                    && HasParameterlessContructor(t))
                .Select(t => new ToolboxItemWrapper(t.FullName, t.Assembly.FullName, null, t.Name))
                .OrderBy(t => t.DisplayName);

            var category = new ToolboxCategory(categoryName);
            foreach (var t in tools)
            {
                category.Add(t);
            }
            toolbox.Categories.Add(category);
        }

        private bool HasParameterlessContructor(Type t)
        {
            var ctors = t.GetConstructors();
            var parameterless = ctors.Where(c => c.GetParameters().Count() == 0)
                .FirstOrDefault();
            return parameterless != null;
        }

        private void AddToolBox()
        {
            var tc = GetToolboxControl();
            Grid.SetColumn(tc, 0);
            Grid.SetRow(tc, 1);
            grid1.Children.Add(tc);
        }

        private void AddPropertyInspector()
        {
            Grid.SetColumn(_designer.PropertyInspectorView, 2);
            Grid.SetRow(_designer.PropertyInspectorView, 1);
            grid1.Children.Add(_designer.PropertyInspectorView);
        }

        private void OnOpenClick(object sender, System.Windows.RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog();
            if (dlg.ShowDialog().Value)
            {
                InitializeDesigner();
                _designer.Load(dlg.FileName);
            }
        }

        private void OnSaveClick(object sender, System.Windows.RoutedEventArgs e)
        {
            var dlg = new SaveFileDialog();
            if (dlg.ShowDialog().Value)
            {
                _designer.Save(dlg.FileName);
            }
        }

        private void InitializeDesigner()
        {
            AddDesigner();
            AddPropertyInspector();
        }
    }
}

Check the Status of a Windows Service in C#

If you have an application that has a dependency on a Windows service, your application may need to be aware of the status of the service. Luckily, the .Net Framework makes this very easy for us to do.

Here’s how you can retrieve the status of a service:

var serviceName = "IISADMIN";
var sc = new ServiceController(serviceName);

Console.WriteLine("Status: {0}", sc.Status);

If you need your application to wait for a particular status, that’s very easy, too!

Console.WriteLine("Blocking until service is running...");
sc.WaitForStatus(ServiceControllerStatus.Running);

Note that WaitForStatus only blocks when the status doesn’t match the value provided. In other words, if the service in the above example is already running, it will not block.

More information about the ServiceController class can be found here.

Filter Pending Changes By Solution in TFS

I just learned about a neat feature in Visual Studio’s Pending Changes window: filter by solution. If you’re viewing pending changes and have a solution open, you can use this toggle button to filter the list of files in your Pending Changes to only files included in that solution. This is a great way to ensure you’re only checking in changes that are related to the task or story that you’re working on when multitasking or managing several works-in-progress.

 

Spotify launches free and unlimited on Android | Radio & Television Business Report

Hooray! Pandora has always been my favorite music streaming service, but I must admit that I was jealous when Spotify radio was released for iPhone and not Android. Spotify radio let’s you save favorites for playback later–a terrific feature that’s missing from the free version of Pandora.

Spotify launches free and unlimited on Android | Radio & Television Business Report.

Microsoft Introduces Outlook.com

As I was catching up on my current events on CNN, I noticed an interesting headline on their bottom line: “Microsoft replaces Hotmail with Outlook.com.” After I missed out on the ideal Twitter name, I made a decision to always sign up for new services right away regardless of how much I think I’ll use them. So, with the announcement of Outlook.com, I wanted to get over there ASAP and stake my claim! Unfortunately, “adam@outlook.com” was already taken, but I still  took the chance to look around and explore some of the features.

Overall, the UI is quite nice. It feels very crisp and clean, much like the upcoming Office 2013. I wasn’t a Hotmail user, but my Live account was already setup for it, although I wasn’t receiving any email since I hadn’t connected any of my existing email accounts. As I said before, my goal was to get my “@outlook.com” email addresses, and it took me a minute to figure out how. You need to click “More mail settings” under the configuration menu in the upper right corner, and then click “Create a Outlook alias.” (C’mon, Microsoft–do a grammar check! Create an Outlook alias!) You’ll be taken to a screen with a [textbox]@outlook.com prompt, and you can claim your name. Note that you can create multiple aliases, so you may want to grab firstname.lastname and firstnamelastname or whatever other nicknames you might want. (I was hoping they’d make period placement in email addresses irrelevant like gmail, but it appears they didn’t.)

I’ve only spent a few minutes with it at this point, but here’s what I like so far:

  • Multiple @outlook.com aliases
  • Drag and drop messages and folders
  • Keyboard shortcuts
  • Clean UI/look and feel

If you’re a fan of the offline Outlook experience, you’ll probably really like Outlook.com. It’s definitely worth checking out!

Change the Default Text of Controls in Word Templates

One of my pet peeves is when people create and distribute MS Word forms that don’t use controls for the fields. It’s a very easy thing to do, and everybody will be happier to use your form. What makes that form even nicer, though? Changing the default text of your field controls to be friendly and more indicative of what information is being requested.

This is a relatively simple task, accomplished in just 4 very easy steps:

  1. On the Developer tab in the ribbon, enable Design Mode by clicking the toggle button
  2. Select all the text between the prompt tags; be sure to select the text while in design mode, otherwise you may change the font/color of your text to something other than the prompt default
  3. Type the desired prompt text
  4. Disable Design Mode by clicking the toggle button

Use this tip to instantly improve that quality of any Word document form. Share it with your co-workers; they’ll be impressed!

Credit: this is the post where I picked up this little nugget of information.