Friday, September 21, 2007

I just got back from VS Live NY - which was a great show. It sold out, and the people attending were very engaged and fun to be with. I love crowds like that!

In my all-day workshop on building distributed apps using objects I showed how to use WPF commanding to automatically enable/disable Save and Cancel buttons on a form by connecting them to a CslaDataProvider control. That's a really cool feature of WPF that I am leveraging with some of the new CSLA .NET 3.0 features.

An attendee asked if it was possible to hide the Save button, not just disable it. I hadn't thought about that, and came up with some answer involving code.

Josh Smith, who was also in the audience, has given this even further thought and sent me an email with a better, pure XAML, solution. Thank you Josh!! Here's the relevant bit of the email:

During the presentation a fellow asked you how, in WPF, to hide a Button when it is disabled.  The Button was disabled because its associated command could not execute, and he wanted to hide the Button instead of letting it sit in the UI disabled.

The solution you gave him involved some code, which threw a red flag in my mind.  IMO, this is the kind of thing you should use XAML to express, so that there are less "moving parts" in your app.  Here's one way to implement that functionality with no code at all:

<Button Command="Open" Content="_Open">
  <Button.Style>
    <Style TargetType="Button">
      <Style.Triggers>
        <Trigger Property="IsEnabled" Value="False">
          <Setter Property="Visibility" Value="Collapsed" />
        </Trigger>
      </Style.Triggers>
    </Style>
  </Button.Style>
</Button>

Depending on your layout, you might want to set Visibility to Hidden instead.

Friday, September 21, 2007 7:01:20 AM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [1]  | 
 Thursday, September 13, 2007

Every now and then I plug Magenic on my blog. This is because Magenic is a great consulting company, and I really feel good about encouraging people to come work here!

(Please note, I'm just another employee. People often think I own Magenic, but that's not true - I'm just lucky enough to work here :) )

Magenic has offices in Chicago, Atlanta, Boston, San Francisco and Minneapolis, and all the offices really need good .NET developers, Sharepoint experts, Biztalk experts and Business Intelligence/SQL people.

What is spurring this particular post, is that our Chicago office has a particular need for a BI expert :)

But if you are a .NET developer - Windows, Web, VB, C# - please consider applying for a job at Magenic.

And if you are a Sharepoint or Biztalk expert, lucky you! Those technologies are hot (especially Sharepoint/MOSS), and we'd love to talk to you!

Finally, all our offices need BI expertise, not just Chicago.

If you want to work with some of the smartest and most dedicated people in the industry, you owe it to yourself to have a talk with one of our recruiters.

Thursday, September 13, 2007 4:33:59 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [1]  | 
 Tuesday, August 28, 2007

Here's a link to a preliminary list of sessions for the upcoming Twin Cities code camp. Jason needs a few more speakers to fill out the schedule though, so if you are in the Twin Cities area and would like to present on any developer related topic (business, non-business, Microsoft, non-Microsoft - it doesn't matter!) you can find contact information here.

Tuesday, August 28, 2007 7:04:29 AM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  | 
 Friday, August 24, 2007

Thanks to my friend Billy Hollis, I appear to have found the radio station I've been looking for: Pandora.

This is an online streaming service with a brain. You tell it some of your favorite artists and/or songs and it assembles a radio station that plays music similar to (and including) your selections. It calls the artists and songs you pick "seeds", and apparently uses some sort of genome-based algorithm to find that similar music.

I've been listening for nearly an hour now, based on my seeds (Rush, Queensryche, Godsmack and Disturbed) and it absolutely rocks!

The only glitch I've found is that if you open it in two browsers, it plays both songs over the top of each other. But that's more a user error than their issue I think :)

Not since CyberRadio 2000 got squashed by RIAA have I found quite the service I was looking for. I had hoped zune.net would do something like this, but Pandora beat them to it.

Friday, August 24, 2007 3:57:25 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [8]  | 
 Thursday, August 23, 2007

Magenic is providing a series of free online seminars on various IT related topics. The next one is on the value of portals.

Suppose your organization’s existing IT investments could be put to use to make your customer and partner interactions more effective and increase your company’s profits. External Portals are browser-based applications that can enable your business processes to better meet the needs of your customers, your partners and your firm.

In this power-packed agenda, the IT experts from Magenic will  introduce you to the current market trends influencing IT decisions and how External Portals can help you:

  • Generate value by creating and fostering customer intimacy.
  • Maximize customer and partner interactions with a personalized online experience.
  • Increase brand satisfaction by creating unexpected opportunities to serve customers.
  • Better understand your prospects and customers.
  • Provide visibility across your extended value chain.
  • Lower cost and improve overall quality, efficiency and profitability.
  • The extraordinary value to be gained through timely, relevant information exchange
  • The simple steps you can take today to get started.

Click here for full information about the seminar.

Thursday, August 23, 2007 7:12:20 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  | 

I am working on my Using CSLA .NET 3.0 ebook and wrote some content that I don't think I'm going to use in the book now. But I don't want to waste the effort, so I'm posting it here.

The text discusses an answer to a common question: how do I get my read-only list of X to know that some X data has been changed. Obviously the following technique can't detect that some other user has changed some data, but at least it detects and handles the case where the current user changes some data that would impact an existing read-only list in that same process.

 

Another common example occurs when there is a read-only list that should be updated when an associated editable object is saved. For instance, you might have a CustomerList object that should be updated any time a Customer is saved.

To solve that issue, the CustomerList object needs to subscribe to an event that is raised any time a Customer is saved. Such an event should be a static event on the Customer class:

  public class Customer : BusinessBase<Customer>

  {

    public static event EventHandler<Csla.Core.SavedEventArgs> CustomerSaved;

 

    protected static virtual void OnCustomerSaved(Customer sender, Csla.Core.SavedEventArgs e)

    {

      if (CustomerSaved != null)

        CustomerSaved(sender, e);

    }

 

    // ...

 

    protected override Customer Save()

    {

      Customer result = base.Save();

      OnCustomerSaved(this, new Csla.Core.SavedEventArgs(result));

      return result;

    }

  }

The CustomerSaved event is declared using the standard EventHandler<T> model, where the argument parameter is of type Csla.Core.SavedEventArgs. The reason for the use of this type is that it includes a reference to the new object instance created as a result of the Save() call.

Then the Save() method is overridden so the CustomerSaved event can be raised after the call to base.Save().

The CustomerList class can then handle this static event to be notified as any Customer object is saved:

  public class CustomerList : ReadOnlyListBase<CustomerList, CustomerInfo>

  {

    private CustomerList()

    {

      Customer.CustomerSaved += new EventHandler<Csla.Core.SavedEventArgs>(Customer_Saved);

    }

 

    private void Customer_Saved(object sender, Csla.Core.SavedEventArgs e)

    {

      // find item corresponding to sender

      // and update item with e.NewObject

      Customer old = (Customer)sender;

      if (old.IsNew)

      {

        // it is a new item

        IsReadOnly = false;

        Add(CustomerInfo.LoadInfo((Customer)e.NewObject));

        IsReadOnly = true;

      }

      else

      {

        // it is an existing item

        foreach (CustomerInfo child in this)

          if (child.Id == old.Id)

          {

            child.UpdateValues((Customer)e.NewObject);

            break;

          }

      }

    }

  }

The final requirement is that the read-only CustomerInfo business object implement a LoadInfo() factory method, and an UpdateValues() method.

The LoadInfo() factory method is used to initialize a new instance of the read-only object with the data from the new Customer object. Loading the data from the Customer object avoids having to reload the data from the database when it is already available in memory:

  internal static CustomerInfo LoadInfo(Customer cust)

  {

    CustomerInfo info = new CustomerInfo();

    info.UpdateValues(cust);

    return info;

  }

The UpdateValues() method sets the read-only object’s fields based on the values from the Customer object:

  internal void UpdateValues(Customer cust)

  {

    _id = cust.Id;

    _name = cust.Name;

    // and so on ...

  }

The end result is that the CustomerList object is updated to reflect changes to the saved Customer object. The CustomerSaved event notifies CustomerList of the change, and (in most cases) CustomerInfo can update itself without hitting the database by loading the data from the Customer object that is already in memory.

Thursday, August 23, 2007 3:35:30 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [10]  | 
 Thursday, August 09, 2007

I just spent the past few days pulling my hair out trying to get a custom principal to work in WCF.

Google returned all sorts of interesting, but often outdated and/or overly complex results. I kept looking at the techniques people were using, thinking this can't be so hard!!!

Well, it turns out that it isn't that hard, but it is terribly obscure... Fortunately I was able to get help from various people, including Clemens Vasters, Juval Lowy and (in this case most importantly) Christian Weyer. Even these noted WCF experts provided an array of options rather than a unified, simple answer like I'd expected.

My conclusion: while WCF really is cool as can be, it is also a deep plumbing technology that begs for abstraction for use by "normal" people.

Anyway, as a result of my queries, Christian got one of his colleagues to write the blog post I wish I had found a few days ago: www.leastprivilege.com - Custom Principals and WCF.

One of my motivations in researching this issue was for the WCF chapter in my upcoming Using CSLA .NET 3.0 ebook. There's now a comprehensive discussion of the topic in that chapter, starting with the creation and use of X.509 certificates and walking through the whole process of implementing custom authentication and using a custom principal in a WCF service. Dominick's blog post is great, but only covers about a third of the overall solution in the end.

The ebook should be out toward the end of September, for those who are wondering.

Thursday, August 09, 2007 2:28:24 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [0]  | 
 Tuesday, August 07, 2007

Aaron Erickson, a fellow Magenic consultant, has done a lot of research and work on how to index LINQ queries over objects. He just published an article on the topic: Indexed LINQ.

While indexing these queries has a cost, due to building the index, it can be very beneficial if you are doing a lot of queries over a large set of data.

Tuesday, August 07, 2007 10:13:56 AM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [3]  | 
 Wednesday, August 01, 2007

For those that don't know, I live in the Twin Cities area: Minneapolis and St. Paul, Minnesota.

This evening one of the major bridges crossing the Mississippi River collapsed. It is a horrible disaster. The kind of thing that you simply hope never to see.

My family and I are fine. We've called our friends who might have been affected and they are fine.

My heart goes out to the people who were caught in this disaster, and their families and friends.

Wednesday, August 01, 2007 9:18:16 PM (Central Standard Time, UTC-06:00)  #    Disclaimer  |  Comments [3]  |