September 2005 - Posts
In two earlier posts (here and here), way back in beta1, I showed how to create your own CatalogPart which could display a list of available web parts from a database or something. Some people will be quite happy to add web parts in a declarative way, but I wanted a solution which were more dynamic. In the future I'll try to write some sample code where you create web parts in a separate library and just drop them in a directory somewhere in the portal, and the web parts gets picked up automatically in the CatalogZone without the need to change the code. Just as a proof of concept.
Anyway, I noticed that the code changed somewhat in beta2 compared to how it used to work back in beta1. There are two ways (at least) you can add your own CatalogPart to a web page:
- Create your own CatalogPart and declare it in the CatalogZone, in the aspx-page. This is the simplest way. See sample below.
- Create your own CatalogZone and declare it in the aspx-page. This CatalogZone then adds your CatalogZone declaratively or in run-time. A bit more coding and there is no need to do it this way unless you plan on doing something special within your CatalogZone. What that may be, I don't really know :)
So, sample code for MyCatalogPart:
using System;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections;
namespace MyCatalogZones
{
public class MyCatalogPart : CatalogPart
{
public override WebPartDescriptionCollection GetAvailableWebPartDescriptions()
{
//Generate a list of available web parts that shows
//up in the catalog, each with a unique ID
//This sample code just adds one web part
WebPartDescription wpDescription = new WebPartDescription("MyWebPartID", "My Web Part", "A description of the web part", null); ArrayList arrWpDescriptions = new ArrayList();
arrWpDescriptions.Add(wpDescription);
return new WebPartDescriptionCollection(arrWpDescriptions);
}
public override WebPart GetWebPart(WebPartDescription description)
{
//a bit of "dummy" code to add a specific web part
//which maps against "MyWebPartID" from the catalog
if (description.ID == "MyWebPartID") {
//returning an instance of the selected web part
MyWebParts.MyWebPart newPart = new MyWebParts.MyWebPart("My Web Part");
return newPart;
}
return null;
}
}
}
Note that in the code above, when you create the list, you may want to check if the user has already added an instance of the web part to his page before you add it to the list. This depends on if you want to let the users add a web part several times to the page or not. The web part may be such that it can be configured to show different content depending on its properties, so why not...
This is some sample code for adding your CatalogPart to a normal CatalogZone in an aspx-page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="jd" Namespace="MyCatalogZones" Assembly="MyCatalogZones" %>
<!-- lots of aspx code here... -->
<asp:CatalogZone ID="CatalogZone1" runat="server" >
<ZoneTemplate>
<asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">
<WebPartsTemplate>
<asp:label id="aPartInTheCatalog" runat="server" title="Catalog webpart">
<h2>Dummy part</h2>
<p>This is a part in the catalog.</p>
</asp:label>
</WebPartsTemplate>
</asp:DeclarativeCatalogPart>
<asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />
<jd:MyCatalogPart ID="MyCatalogPart1" runat=server Description="My own dynamic catalog part" Title="My Special Parts Catalog" />
</ZoneTemplate>
</asp:CatalogZone>
<!-- lots of aspx code here... -->
You don't really have to have the DeclarativeCatalogPart and the PageCatalogPart there, but if you allow users to close your dynamically added parts, you may want to let them add them again, so the PageCatalogPart may be useful :)
Just spent a couple of hours setting up a couple of VPC images with all "The Goods" we got from PDC'05. Last thing I installed was the LINQ tech preview. I've just spent a few minutes looking at the LINQ samples that comes on disk 4 and I've tried a few DLINQ stuff which was really impressive, but the XLINQ features just blows my mind. The whole style of programming seems so natural compared to the old XmlDocument way of doing things. Let me copy a few lines of code from the RssAggregator sample, a method which pulls Rss from a couple of feeds, extracts the items and returns a list of all these items:
static
IEnumerable<XElement> GetItems() { string[] feeds = { "http://blogs.msdn.com/cyrusn/rss.aspx", "http://blogs.msdn.com/mattwar/rss.aspx", "http://blogs.msdn.com/lucabol/rss.aspx", "http://www.pluralsight.com/blogs/dbox/rss.aspx", "http://blogs.msdn.com/jomo_fisher/rss.aspx" };
foreach (var str in feeds) { var feed =
XDocument.Load(str); var items = feed.Root.Element(
"channel").Elements("item"); foreach (var item in items) yield return item; }
}
I love the way you get hold of a specific element in the document with Element("nodename"). Not sure I'm comfortable with the "var" thing though. That's the "implicitly typed local variables" that comes with C# 3.0. I guess it's the way I read code. If you want to read about the new features in C# 3.0, you can download the spec from here.
As everyone else on the PDC, I got a PDC-version of Windows Vista. I tried to install in on a VPC yesterday, but I never got past the install step where you have to specify on what disk to install to. I tried (within VPC) to delete the virtual partition and format it, but it never got available. I wonder if anyone else experienced the same problem...
Best session yesterday was probably the web services interop session with Simon Guest and Kirill Gavrylyuk. To show reliable messages between .NET and Java, Simon hocked up a heart beat sensor (which sat on his finger) onto a .NET web service. Then he sent data from that sensor over to a Java client, through a pre release of Axis 2.0. Funny (for the audience anyway) was that Simon heart was pounding so rapidly, the scale on the client couldn't handle it. They had set it up to a maximum of 100 bpm, but he was going at around 130 (!) and the annoying beep-beep-beep that was going on all the time didn't make it easier for Simon to calm down. It was hillariously fun. Make sure to watch that webcast if it comes available sometime in the future.
They showed how to send and receive WS-Security messages as well as Reliable Messages and how to send binary data with MTOM. MTOM stands for Message Transmission Optimization Mechanism.
Later in the evening I sat down and had a discussion with Kirill about the WS design we have in the project I'm working with back home. We seem to be on track, but there are a few things I could change on the architecture to be a bit better prepared and in line with the future. Should perhaps start looking at sending SAML tokens instead of just a simple proprietary ticket.
I spent the whole morning (2 sessions in a row) at the Architecture Symposium here, where they discussed a fictionarly SOA case from end to end. It was quite interesting, but the reality isn't always as Microsoft describes it. Setting up Aggregation Services and Entity Services in front of one or more legacy system is the recommended design if you have a heterogenous environment. Maybe stick in BizTalk or similar workflow middlewhere with adapters if you think you need it to talk to bigger systems like SAP, PeopleSoft and such.
After this last session I'm going to now, it's off to the LAX airport for the lovely trip home...
Or WCF (Windows Communication Foundation) as it is now called, and it is very, very powerful. I sat down in the lab area where they have everything you need installed, complete with lab instructions, and tried out a few web services and such. Support for contract first coding is better now, where you first create the "contract" as an interface and you then go on and implement this contract with code. You can do the same sort of things on the client. I like that.
I also had a quick look at the LINQ stuff, and it's pretty cool coding. LINQ style coding will probably replace the ADO.NET code you do in your Data Access Layer if you use such an architecture. It is powerful and intuitive and there is no longer a need for a mapper design pattern where you map a strongly typed data set (or similar datatable object) into a DTO (Data Transfer Object), because you can create the DTOs directly with LINQ. In ADO.NET 2.0 you can continue using the same kind of code and patterns you used in .NET 1.1, but I would suggest everyone to look at the ObjectDataSource stuff and
Something I would like to look at in more detail is the workflow foundation, but that will have to wait until I get home.
Lol, maybe they had as much free coke, coffee, juice and ice cream at the top meeting Mr Bush was attending as we have here at the PDC'05 convention, but if that was the case I understand him. If not, it's another great quote in the never endling list of quotes the most powerful guy in the world has produced, this one in writing... :)
Anyway, it feels encouraging that he actually can write and that he has normal human needs... there is hope for the world after all. ;)
Yesterday was the best day so far at the PDC. Most impressive things was first what will probably become 'ADO.NET 3.0' or something similar - LinkQ or DLinkQ, which is dynamic language integration (or something like that). Eric blogged about that. Next thing which was really, really cool and got lots of applause from the session attendees was the new integrated workflow foundation, which is basically a powerful workflow engine. The Windows Worflow Foundation is a part of the WinFX subsystem and will let you host workflows in lots of different containers, like IIS, a windows forms app, sharepoint, SQL server or even in a console app! It's also dead simple to use. It's as if you ripped out the basic workflow engine from Biz Talk and created a powerful set of APIs to use against it. It will be used ALOT in the future. The graphical workflow designer in Visual Studio was impressive.
Last night was Universal Studio Theme Park night and it was just great! Me and my friends rushed off to the Jurassic Park and The Mummy rides as fast as we could to get a head of all the other 8000 or so people there. Really cool rides I must say :) If you ever go to Los Angeles, don't miss it. We tried most of the rides in the park, but I think Jurassic and Back to the Future was the best :)
Off to the next general session now.... *running*
Just had a great breakfast. Amazingly large selection of weird cereals. We all laughed when my buddy Jan-Erik opened his "TRIX - Fruity Sweetened Corn Puffs!" pack. Looked more like a box of candy than breakfast cereal to me :)
Atm I'm standing in the Windows Vista Internet Alley, where they have set up hundreds of machines running Windows Vista (build 5219). The user experience is just great, lots of animations and stuff. In the future when coding for the WinFX platform I think you have to be a bit careful to not just add all of these moving and zooming stuff just because it is easy to do it. But it is cool, I must admit. Everything got a kind of soft touch to it. I wonder what kind of graphics hardware you need to run Vista graphics in optimal speed. No wonder ATI is platinum sponsor of the PDC event :D
One of the things that drew the longest run of applause was probably when Jim Allchin (I think it was) jacked a standard USB memory into the Vista box and it got recognized as internal memory! Time to dig out all my stray USB memory sticks and get them to use, my laptop will look like a christmas tree, USB mems sticking out in every socket ;)
Off to the next general session now with Eric Rudder and Steven Sinofsky.
One thing I just noticed what that the rich text editor in .Text doesn't load up in IE 7
Shorty we're off to meet with some of the other 100 or so Swedes that are here at the PDC. Microsoft SE has arranged for a get-togeather at a hotel close by. Will be fun to meet a few old friends that I know should be there tonight.
Tomorrow I'll attend sessions about "Avalon" (now called the Windows Presentation Foundation), another (hopefully better) session about "Indigo" and 2 sessions about CRM solutions and "Atlas". Atlas is functionality for more easily doing AJAX-style programming in ASP.NET 2.0 and later. Looking forward to tomorrow.
The concept of pluggable providers in .NET is really interesting and something I want to have a deeper look at when I get back home. The last session I was at today was about providers and how you could (quite easily) replace someting like the default membership and roles provider with your own.
Stefan Schackow did a very good presentation about providers, which sort of saved the afternoon. I attended the COM202 session about "A lap around the Windows Communications Foundation" and it wasn't very good at all. The speaker jumped right into all the nitty gritty details you could play with in WCF and I bet 80% of the guys in there listening didn't follow him at all.
More Posts
Next page »