Event Receivers on Content Types
Adding this to the category of things-that-I-didn't-know-but-would-have-made-a-lot-of-stuff-I-previously-wrote-much-more-elegant-and-awesome.
You should add it to yours, too!
As a quick summary, it's common knowledge (well, amongst SharePoint developers at least) that you can associate event receivers with a list template type. However, an interviewer recently brought to light that one can also associate an event receiver directly with a content type. This is immensely useful for anyone building custom solutions on SharePoint, especially if you make heavy usage of content types in your design.
Here's an example using the same basic content type:
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field DisplayName="Model Code"
Name="Model_Code"
StaticName="Model_Code"
ID="{F0000000-0000-0000-0000-000000000001}"
Type="Integer"
SourceID="http://schemas.someusedcarinventory.com"
Group="My Custom Columns"/>
<Field DisplayName="VIN"
Name="VIN"
StaticName="VIN"
ID="{F0000000-0000-0000-0000-000000000002}"
Type="Text"
SourceID="http://schemas.someusedcarinventory.com"
Group="My Custom Columns"/>
<Field DisplayName="Make"
Name="Make"
StaticName="Make"
ID="{F0000000-0000-0000-0000-00000000003}"
Type="Text"
SourceID="http://schemas.someusedcarinventory.com"
Group="My Custom Columns"/>
<ContentType Name="Vehicle"
ID="0x0100FC000000000000000000000000000001"
Description="Used car inventory"
Group="My Custom Content Types" >
<FieldRefs>
<FieldRef ID="{c042a256-787d-4a6f-8a8a-cf6ab767f12d}" Name="ContentType" />
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title"
Required="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" />
<FieldRef ID="{F0000000-0000-0000-0000-000000000001}" Name="Model_Code"/>
<FieldRef ID="{F0000000-0000-0000-0000-000000000002}" Name="VIN"/>
<FieldRef ID="{F0000000-0000-0000-0000-000000000003}" Name="Make"/>
</FieldRefs>
<XmlDocuments>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/events">
<spe:Receivers xmlns:spe="http://schemas.microsoft.com/sharepoint/events">
<Receiver>
<Name>VehicleCreatedHandler</Name>
<Type>ItemCreated</Type>
<SequenceNumber>1</SequenceNumber>
<Assembly>My.Library, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=c5168cbbbb64acf7</Assembly>
<Class>My.Library.EventReceivers.VehicleCreatedHandler</Class>
<Data />
<Filter />
</Receiver>
</spe:Receivers>
</XmlDocument>
</XmlDocuments>
</ContentType>
</Elements>
Oddly enough, I was trying to figure out what the Filter element does when I stumbled upon the stackoverflow posting by accident. As it stands, I still can't figure out what the element is and what XML is valid for it. Perhaps some CAML query filter?
C# and ASP.NET Syntax Highlighting in Trac
Well, spent the good amount of time trying to figure this out. See the configuration info below from my trac.ini file.
[mimeviewer] max_preview_size = 262144 mime_map = text/x-dylan:dylan,text/x-idl:ice,text/x-ada:ads:adb, php_path = php pygments_default_style = trac pygments_modes = text/x-csharp:csharp:7,text/plain:aspx-cs:7 tab_width = 4 treat_as_binary = application/octet-stream,application/pdf,application/postscript,application/rtf
Oh yeah, it helps if you actually install Pygments, too.
Host Headers, SharePoint (2010), and Access Denied (401)
I've been working on setting up a VM to play around with SharePoint 2010 and kept running into a weird issue where I would be prompted for my credentials repeatedly and I was denied access to the site entirely, even when using an administrator account.
I had set up my SharePoint web application using a host header; for example, beta.dev.com.
Meanwhile, I was able to access the same site from my host environment without any issue. What gives? Turns out that there is a slight registry tweak you have to make when working with host headers and IIS.
Phil Harding has a good writeup with links to the Microsoft KBs and additional details.
Self Reminder
I've been meaning to put together a series of articles on how to build a system to support software automation (where automation is not supported natively) after completing what I would say is my most significant project of my career a few months ago (it was indeed, quite awesome to see in action.
What's the motivation for this? There are somethings that you simply cannot do via APIs that require automation of the UI. For example, what if you want to write an engine that will browse a site list and grab screenshots of the pages? What if you need to generate content on the server in Excel, Word, or PowerPoint (pre-2007)? What if you need to adjust and auto-publish a large number of project plans in Microsoft Project Professional?
These types of actions require an automation engine and a supporting framework to allow for manipulation of the UI and some clever tricks to take care of the exceptional cases since they were written to be used in interactive sessions. While I obviously cannot release any of the code I wrote previously line for line, I would like to discuss the strategies and some code snippets and use new code to cover this topic which I found to be lacking when I myself was searching for a way to do this.
As a summary, I think I'm going to break it down into a few chapters:
- An Introduction: Automating Internet Explorer. As an example, we'll start by looking at the foundation of automating any of the Windows applications using .Net. The ideas here apply not only to IE, but to almost any Windows application that exposes an API.
- Simulating User Input. We'll continue the example by examining how to deal with cases where the application is expecting user input. If so inclined, we could disregard the API completely and simply use this methodology throughout.
- UI Mapped Input Sequences. We'll discuss how to take the example a bit further by examining how to trap UI elements and send the proper key sequences to handle them.
I think this will be a great series (once I actually get around to putting it together) as it will cover a whole host of technologies from Spring.Net to log4net to Enterprise Library.
WinFX February CTP
This is definitely something I'm going to have to download and play around with in the next few weeks.
DHTML Games
Finally figured out how to fix some of the bugs and problems I
had with jsTetris last night as I was laying down to sleep (I hate
that).
Each list element needs to have a property, State, which takes one of two values:
- 0 when the list element is empty (no pieces in it) or the list element is holding an active block (a block that can still move).
- 1 when the list element is holding a fixed block (a block that can no longer move).
One of the big problems I had previously was that it was difficult to
calculate when a piece could still move. The method I was using
was too inefficient and took too many lines of code. It tried to
examine each of the target blocks to see if it contained an inactive
block. This should make it easier by performing some simple math
instead.
Each block of each piece must be examined in the direction of the move
and simply do a sum between each block and the list element in the
target block. If the sum of the State is 0, then we can move the block. If the sum is anything other than 0, then the block cannot be moved anymore.
Once a block stops moving, before the next buffered piece is moved (may
have to cancel timer), we sum across the bottom most row up 4 rows and
see if the sum in that row divided by the number of columns is exactly
1. If so, this means that every list element in that row is
holding a fixed block and we can move get rid of that row. Once
we've checked 4 rows, we can then move all of the remaining straggling
pieces down before reactivating the timer on the buffered piece.
Seems like a plan.
I was also thinking about doing two other games last night.
One of them would be based off of pipe dreams. Remember that game
where you have to move around blocks which contained pipes as this
green ooze started flowing? I think it can be done with .gif
animations if each of the animations takes precisely the same amount of
time. There are a total of 7 different pieces. 6 of those
pieces would need two sets of animations and one of them, a cross
shaped piece, would need 4 animations. This brings the total
number of pieces up to 16. The idea would be to cache each of
these images and swap them out as the flow of the ooze moves through
the pipes. This one should be interesting.
The other game would be based off of a game that I had on my TI-83 back
in my highschool days which is kind of along the lines of Dr. Mario or
Tetris Attack, except without falling pieces. Basically, you get
a random m*n board, which is completely filled with
pieces (maybe 5-6 different types). When you have three or more
adjacent pieces, those pieces disappear. And "loose" pieces fall
into the space left by those pieces and can cause "combos". The
objective is to clear the entire board with as high a score as possible
(factoring in time and combos). Like Tetris Attack (I don't
completely remember the mechanics of Dr. Mario), you can manipulate two
adjacent blocks in the grid at a time.
Neither of these seem too difficult and sound like fun.
Oh yeah, I'm also working on a ASP.Net Beta 2 based version of Chinese chess or Xiangqi.
The idea is to use Atlas to allow two players to play in real time,
with the moves and chat being relayed using calls to web services from
the client. So far, I have the board and objects laid out.
I still have to figure out how I want to implement the game rules and
how complex to make it in terms of supporting multiple games at
once. I'm also waiting for my Beta 2 hosting account from ServerIntellect, my webhost.
That's it for now.
