<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0"><channel><title>CodeVerity</title><link>http://codeverity.com/</link><description>Software Engineering, Security and whatever else I feel like writing about</description><generator>Graffiti CMS 1.1 (build 1.1.0.1083)</generator><lastBuildDate>Mon, 24 Nov 2008 12:09:50 GMT</lastBuildDate><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/museverity" type="application/rss+xml" /><item><title>Using Cache-Control Header And Making IE Obey</title><link>http://codeverity.com/timweaver/using-cache-control-header-and-making-ie-obey/</link><pubDate>Mon, 24 Nov 2008 12:09:50 GMT</pubDate><guid isPermaLink="true">http://codeverity.com/timweaver/using-cache-control-header-and-making-ie-obey/</guid><dc:creator>timweaver</dc:creator><slash:comments>0</slash:comments><category domain="http://codeverity.com/timweaver/">timweaver</category><description>&lt;p&gt;We had an interesting problem last week where we found that images were not being cached by browsers other than IE. IE 7, for reasons we didn't really understand IE was "correctly" returning the cached images, while every other browser was incorrectly making another HTTP GET request.&lt;/p&gt; &lt;p&gt;The scenario was that we have a Flex 3 application that was using an &amp;lt;mx:Image&amp;gt; control. In Flex, when you use an mx:Image and the source you supply is the same as a previously used source the image is supposed to be returned from the browser cache. IE was the only browser that seemed to be correct.&lt;/p&gt; &lt;p&gt;Now I should know better. Thinking that IE was correct and every other browser wrong is just plain silly. The truth was that IE was wrong and every other browser was correct. &lt;/p&gt; &lt;p&gt;Pay attention to HTTP Headers.&lt;/p&gt; &lt;p&gt;In our case the images, .swf files, were being returned via IIS and handled by the .NET framework. The response header contained:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Cache-Control private&lt;/strong&gt; &lt;p&gt;I've previously written about &lt;a href="http://codeverity.com/timweaver/how-do-browsers-determine-if-a-file-is-cached/"&gt;Cache-Control&lt;/a&gt;. Since our server returned &lt;em&gt;private &lt;/em&gt;what should have happened is that each browser would request a new image from the server each time. Why IE chose to ignore this header I have no idea. By changing the header to have a max-age value and setting it to public we were able to get all flavors of browser on both MAC and IE to "correctly" work.&lt;/p&gt;</description></item><item><title>NHibernate Invalid Index For This SqlParameterCollection</title><link>http://codeverity.com/timweaver/nhibernate-invalid-index-for-this-sqlparametercollection/</link><pubDate>Tue, 11 Nov 2008 01:11:28 GMT</pubDate><guid isPermaLink="true">http://codeverity.com/timweaver/nhibernate-invalid-index-for-this-sqlparametercollection/</guid><dc:creator>timweaver</dc:creator><slash:comments>2</slash:comments><category domain="http://codeverity.com/timweaver/">timweaver</category><description>&lt;p&gt;I ran into a problem last week where I kept getting this exception: Invalid index 6 for this SqlParameterCollection with Count=6.&lt;/p&gt; &lt;p&gt;I spent a lot of time trying to figure out what object was causing the issue. Individually, each object would persist correctly, but only as the aggregate did the problem surface. &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;I found this post where someone had a similar issue: &lt;a title="http://forum.hibernate.org/viewtopic.php?p=2394781" href="http://forum.hibernate.org/viewtopic.php?p=2394781"&gt;http://forum.hibernate.org/viewtopic.php?p=2394781&lt;/a&gt;. That and the forthcoming book &lt;a href="http://www.manning.com/kuate/"&gt;NHibernate in Action&lt;/a&gt; from Manning got me thinking and I finally deduced the problem.&lt;/p&gt; &lt;p&gt;I must say this one was not obvious to someone just learning NHibernate. I lost a good 12 hours of effort both in trying to discover an answer and in simply trying to work my way around the problem.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Here's my mapping file: [I swear I'm switching to attributes first chance I get, but I learned the Xml mapping and time doesn't permit the change at this point]&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;&amp;lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; schema="TestDB.dbo"&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; namespace="Domain.Foo"&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;class name="Domain.Foo.ProfileP, Domain" table="ProfileP" lazy="false" &amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;id name="ID" column="ID" type="Int32" unsaved-value="0"&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;generator class="native" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/id&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="ProfileId" column="profileId" type="Int32" /&amp;gt;&lt;br&gt;&amp;nbsp; &lt;font color="#800000"&gt;&amp;nbsp; &amp;lt;property name="PaymentId" column="paymentId"&amp;nbsp;&amp;nbsp; type="Int32"&amp;nbsp; insert="false" update="false" /&amp;gt;&lt;/font&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;property name="Status" column="status"&amp;nbsp;&amp;nbsp;&amp;nbsp; type="string" length="10" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;many-to-one name="PaymentS" class="Domain.Foo.Sub, Domain" column="paymentId" cascade="save-update" not-null="true"&amp;nbsp; /&amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;/class&amp;gt;&lt;br&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#000080"&gt;&lt;/font&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The problem is the line in red. The PaymentID is the ID value of the PaymentS class in the Domain.Foo.Sub namespace. So, NHibernate already knew the ID value and was using it in the update/save queries. In effect it was declared twice in the mapping file: once explicitly and once implicitly via the many-to-one relationship. The fix was to add &lt;font color="#000080"&gt;insert="false"&lt;/font&gt; and &lt;font color="#0000a0"&gt;update="false"&lt;/font&gt; to the paymentId property.&lt;/p&gt; &lt;p&gt;I ended up purchasing the NHibernate in Action book via the early access program. So far I am pleased with the purchase. The book has shed light on a lot of pieces of information that were unclear to me. Getting concise and complete information on NHibernate seems to be a lot harder than I would have thought.&lt;/p&gt;</description></item><item><title>Happy Birthday Marines - Proud To Be One of the Few</title><link>http://codeverity.com/timweaver/happy-birthday-marines-proud-to-be-one-of-the-few/</link><pubDate>Tue, 11 Nov 2008 00:43:32 GMT</pubDate><guid isPermaLink="true">http://codeverity.com/timweaver/happy-birthday-marines-proud-to-be-one-of-the-few/</guid><dc:creator>timweaver</dc:creator><slash:comments>1</slash:comments><category domain="http://codeverity.com/timweaver/">timweaver</category><description>&lt;p&gt;Here's to all Marines - past, present and future: Happy Birthday and Semper Fi.&lt;/p&gt; &lt;p&gt;&lt;a title="https://www.godaddy.com/gdshop/holiday/usmc2008/playmovie.asp" href="https://www.godaddy.com/gdshop/holiday/usmc2008/playmovie.asp"&gt;https://www.godaddy.com/gdshop/holiday/usmc2008/playmovie.asp&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Iraq Budget Surplus So Give Them Another Thirteen Million</title><link>http://codeverity.com/museverity/iraq-budget-surplus-so-give-them-another-thirteen-million/</link><pubDate>Thu, 30 Oct 2008 00:04:39 GMT</pubDate><guid isPermaLink="true">http://codeverity.com/museverity/iraq-budget-surplus-so-give-them-another-thirteen-million/</guid><dc:creator>timweaver</dc:creator><slash:comments>0</slash:comments><category domain="http://codeverity.com/museverity/">museverity</category><description>&lt;p&gt;Apparently U.S. auditors told Congress that Iraq was heading towards a "&lt;a href="http://www.msnbc.msn.com/id/23578542/"&gt;massive budget&lt;/a&gt;" surplus. Not sure this is a surprise to anyone given the price of oil, but at least it is now public knowledge. &lt;/p&gt; &lt;p&gt;Here is the question, if Iraq has so much surplus why is the US State department &lt;a href="http://www.state.gov/r/pa/prs/ps/2008/oct/111017.htm"&gt;investing&lt;/a&gt; 13 million to help Iraq protect its antiquities? It seems like such a small number given the outrageous amounts of money being thrown at things these days, but still it seems highly unnecessary. Iraq certainly has a spare 13 million lying around somewhere. Right?&lt;/p&gt;</description></item><item><title>Adding Images to Icovia Space Planner</title><link>http://codeverity.com/timweaver/adding-images-to-icovia-space-planner/</link><pubDate>Wed, 22 Oct 2008 11:08:28 GMT</pubDate><guid isPermaLink="true">http://codeverity.com/timweaver/adding-images-to-icovia-space-planner/</guid><dc:creator>timweaver</dc:creator><slash:comments>0</slash:comments><category domain="http://codeverity.com/timweaver/">timweaver</category><description>&lt;p&gt;One of the many features available in the Icovia &lt;a href="http://v5pcsdemo.icovia.com/icovia.html"&gt;Space Planner&lt;/a&gt; is the ability to add an image to your floor plan. &lt;/p&gt; &lt;p&gt;If you want the image can be part of the plan itself:&lt;/p&gt; &lt;p&gt;&lt;a href="http://codeverity.com/images/blogsposts/AddingImagestoIcoviaSpacePlanner_12706/room_with_pic1.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="249" alt="room_with_pic1" src="http://codeverity.com/images/blogsposts/AddingImagestoIcoviaSpacePlanner_12706/room_with_pic1_thumb.png" width="404" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Or you can place a picture Icon that will popup a bubble when clicked:&lt;/p&gt; &lt;p&gt;&lt;a href="http://codeverity.com/images/blogsposts/AddingImagestoIcoviaSpacePlanner_12706/image_window.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="240" alt="image_window" src="http://codeverity.com/images/blogsposts/AddingImagestoIcoviaSpacePlanner_12706/image_window_thumb.png" width="279" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;From this bubble you can click View Photo to see the image.&lt;/p&gt; &lt;p&gt;In order to add an image your your plan you must click on the Show All Tools Link and then the Camera icon&lt;/p&gt; &lt;p&gt;&lt;a href="http://codeverity.com/images/blogsposts/AddingImagestoIcoviaSpacePlanner_12706/show_all_tools.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="128" alt="show_all_tools" src="http://codeverity.com/images/blogsposts/AddingImagestoIcoviaSpacePlanner_12706/show_all_tools_thumb.png" width="118" border="0"&gt;&lt;/a&gt;&amp;nbsp; then &lt;a href="http://codeverity.com/images/blogsposts/AddingImagestoIcoviaSpacePlanner_12706/camera_icon.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="41" alt="camera_icon" src="http://codeverity.com/images/blogsposts/AddingImagestoIcoviaSpacePlanner_12706/camera_icon_thumb.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;The img URL must be a fully qualified URL e.g. &lt;a href="http://www.xxxxx.com/image.jpg"&gt;http://www.xxxxx.com/image.jpg&lt;/a&gt;&lt;/p&gt; &lt;p&gt;If you host your images on flickr then be sure to sign in, select the image size you are interested in and then the static fully qualified URL is displayed for you to copy.&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:773f7c42-5bab-42ed-8169-e2e12955abcc" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/Icovia%20Space%20Planner" rel="tag"&gt;Icovia Space Planner&lt;/a&gt;&lt;/div&gt;</description></item><item><title>Desktop Design Innovation</title><link>http://codeverity.com/timweaver/desktop-design-innovation/</link><pubDate>Mon, 20 Oct 2008 11:11:43 GMT</pubDate><guid isPermaLink="true">http://codeverity.com/timweaver/desktop-design-innovation/</guid><dc:creator>timweaver</dc:creator><slash:comments>0</slash:comments><category domain="http://codeverity.com/timweaver/">timweaver</category><description>&lt;p&gt;Way back in June of 2004 I wrote a post called &lt;a href="http://codeverity.com/timweaver/innovation/"&gt;Innovation&lt;/a&gt;. In it, I wrote about how much I hate the folder metaphor that we are stuck with on our computers. &lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;em&gt;Why, for example, if I click on the Start button and select explore to I end up n levels down under Documents and Settings\UserName\Start? I’ve never once wanted to be at this local. Why can’t I easily (keyword easily) change this so that when I right click I end up in a more logical place in my file structure. Why are we still using the concept of folders to store files? Can’t someone come up with a more logical solution so that I don’t have to traverse up and down the tree structure each time I want to find something?&lt;/em&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Today I saw &lt;a href="http://bumptop.com/"&gt;Bumptop&lt;/a&gt; and was struck by how closely the desktop mirrors the type of things I was wishing were available. As soon as its available I'll be moving to Bumptop. It might not solve any real problems, but it will certainly change my daily interaction with my desktop.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d325e72a-7b5b-4ef3-9c9d-efa9cc893ad3" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;del.icio.us Tags: &lt;a href="http://del.icio.us/popular/Bumptop" rel="tag"&gt;Bumptop&lt;/a&gt;, &lt;a href="http://del.icio.us/popular/Vista" rel="tag"&gt;Vista&lt;/a&gt;&lt;/div&gt;</description></item><item><title>Room Layout Planning</title><link>http://codeverity.com/timweaver/room-layout-planning/</link><pubDate>Sun, 19 Oct 2008 20:20:20 GMT</pubDate><guid isPermaLink="true">http://codeverity.com/timweaver/room-layout-planning/</guid><dc:creator>timweaver</dc:creator><slash:comments>0</slash:comments><category domain="http://codeverity.com/timweaver/">timweaver</category><description>&lt;p&gt;Carol and I bought our house in May of this year. We didn't have much furniture when we moved in and one of the things we need to purchase was a couch and or chairs for the living room. We took advantage of Jordan's Red Sox Deal (Go Sox) and bought an oversized couch, chairs and a carpet. Before we went to the store we measured the room so we had a good idea of what would fit and what wouldn't. At the store we measured the furniture and determined that it would fit in the space we had.&lt;/p&gt; &lt;p&gt;Fast forward two weeks. The furniture shows up and we realize that it will fit, but it doesn't fit well. We over-estimated how much room would exist between the pieces and under-estimated how they would look in the room.&lt;/p&gt; &lt;p&gt;The simple solution to this would have been to use the Icovia &lt;a href="http://v5pcsdemo.icovia.com/icovia.aspx"&gt;Space Planner&lt;/a&gt;. [Note I used the 5.0 version that you can access via the Test Drive button on the &lt;a href="http://www.icovia.com"&gt;www.icovia.com&lt;/a&gt; home page].&lt;/p&gt; &lt;p&gt;I took me about an hour to measure my room, furniture and then set it up using the &lt;a href="http://www.designedition50.icovia.com"&gt;www.designedition50.icovia.com&lt;/a&gt; planner.&lt;/p&gt; &lt;p&gt;&lt;a href="http://codeverity.com/images/blogsposts/RoomLayoutPlanning_E3F9/mylivingroom.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="224" alt="mylivingroom" src="http://codeverity.com/images/blogsposts/RoomLayoutPlanning_E3F9/mylivingroom_thumb.jpg" width="371" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;As you can see we still need to buy more furniture. The area along the left-hand wall is currently a big pile of books, a wireless router, and few other miscellaneous things, or in other words a mess. We could use a few lamps and the possibility exists that we might reconfigure the room all together.&lt;/p&gt; &lt;p&gt;Using &lt;a href="http://www.icovia.com"&gt;Icovia's&lt;/a&gt; tool I was able to pick the colors that somewhat matched my actual room. I was able to clearly size and resize all the furniture to match my layout. As you can see my room isn't a standard box type room. The south wall is completely open into another room and the east door juts into the room itself. That makes for a challenging layout.&lt;/p&gt; &lt;p&gt;I was also able to add actual images of the furniture to the plan. The stuffed animal shrine is my daughters and yes, it makes it hard to use the couch.&lt;/p&gt; &lt;p&gt;You can check out a copy of the live plan by following this link:&lt;/p&gt; &lt;p&gt;&lt;a title="http://designedition50.icovia.com/default.aspx?projGuid=B2FFF32F-425F-4875-AA79-38F28B63D7C5" href="http://designedition50.icovia.com/icovia.html?projGuid=B2FFF32F-425F-4875-AA79-38F28B63D7C5"&gt;http://designedition50.icovia.com/icovia.html?projGuid=B2FFF32F-425F-4875-AA79-38F28B63D7C5&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I won't be purchasing any more furniture without first laying out the room and making sure that what I want to buy actually fits in my space.&lt;/p&gt; &lt;p&gt;[disclaimer: A few months after purchasing the above furniture I accepted a position at Icovia]&lt;/p&gt;</description></item><item><title>Rebuild or Fix Broken Code</title><link>http://codeverity.com/timweaver/rebuild-or-fix-broken-code/</link><pubDate>Fri, 17 Oct 2008 11:14:22 GMT</pubDate><guid isPermaLink="true">http://codeverity.com/timweaver/rebuild-or-fix-broken-code/</guid><dc:creator>timweaver</dc:creator><slash:comments>0</slash:comments><category domain="http://codeverity.com/timweaver/">timweaver</category><description>&lt;p&gt;Everyone has done development for even a short period of time has run into this question. Especially when you are faced with code you didn't write, that seems overly complex, or just doesn't do what it should, the temptation to throw it away and rewrite is very strong. &lt;/p&gt; &lt;p&gt;Early in a developers career I see a trend towards chucking the old and starting fresh.&lt;/p&gt; &lt;p&gt;&lt;a href="http://codeverity.com/images/blogsposts/RebuildorFixBrokenCode_65C3/trendline.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="185" alt="trendline" src="http://codeverity.com/images/blogsposts/RebuildorFixBrokenCode_65C3/trendline_thumb.jpg" width="252" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;As a developer matures he/she comes to realize that rewriting, though seemingly the most expedient approach, has its problems:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Missing features  &lt;li&gt;Missing bugs that are "expected" e.g. you fixed something, which broke something  &lt;li&gt;Misunderstanding how something works&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;It is no mistake that the above three bullets are all "mis-ings". Each of these cause a very unintended and from a business standpoint, expensive cost.&lt;/p&gt; &lt;ul&gt; &lt;li&gt;The opportunity cost of the developer(s) lost time  &lt;li&gt;The actual cost of development  &lt;li&gt;The cost of QA/Testing of the code&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;As these costs became more apparent the trend reverses itself. If you aren't careful you can end up pushing the envelop too far to the left.&lt;/p&gt; &lt;p&gt;Case in point:&lt;/p&gt; &lt;p&gt;I had a &lt;a href="http://www.microsoft.com/technet/prodtechnol/sql/2005/intro2is.mspx"&gt;SSIS package&lt;/a&gt; that was doing a relatively easy set of tasks:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Query the database and execute a stored procedure  &lt;li&gt;Load an XSLT  &lt;li&gt;Transform the results of the Query  &lt;li&gt;Send an Email&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;The problem was this package didn't work on our production servers. It worked just fine in every other environment I tried, but not production. If you have ever used a custom SSIS package in SQL 2005 you know that these things are over engineered, immensely configurable, sink holes of time, that can basically do anything you can possibly think of. I spent about 2 full days trying to get the package to run in the production environment. Every single thing I tried to gather more information on why it was failing either wouldn't work in production or wouldn't give any useful information. &lt;/p&gt; &lt;p&gt;Finally, in frustration, I took a step back and realized that I had made a mistake in pursuing the need to get this thing to run. The package is doing work on our SQL Server that doesn't need to take place on the DB server. It is impossible to test via automated unit tests and it contained some custom VB Script code (okay that last one was just a pet peeve). &lt;/p&gt; &lt;p&gt;I rewrote the entire thing as a simple C# console app. &lt;/p&gt; &lt;ul&gt; &lt;li&gt;It now has 95% code coverage.  &lt;li&gt;It is portable.  &lt;li&gt;It works in all environments.  &lt;li&gt;I fixed some bugs along with the rewrite.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;The rewrite cost me about 2 1/2 hours from start to push to production server. &lt;/p&gt; &lt;p&gt;Like everything else in software development the answer to the throw it away or fix question is always "it depends". I couldn't have known I would lose so much time trying to fix this less than ideal code before starting, but I probably should have thrown in the towel and rewrote it much sooner than I had.&lt;/p&gt; &lt;p&gt;Note to self: always question any assumption, especially when things don't appear to be going well.&lt;/p&gt;</description></item><item><title>Custom GraffitiCMS Views</title><link>http://codeverity.com/timweaver/custom-graffiticms-views/</link><pubDate>Sun, 05 Oct 2008 13:37:02 GMT</pubDate><guid isPermaLink="true">http://codeverity.com/timweaver/custom-graffiticms-views/</guid><dc:creator>timweaver</dc:creator><slash:comments>0</slash:comments><category domain="http://codeverity.com/timweaver/">timweaver</category><description>&lt;p&gt;I'm doing a lot of customization of &lt;a href="http://telligent.com"&gt;Telligent's&lt;/a&gt; &lt;a href="http://graffiticms.com"&gt;GraffitiCMS&lt;/a&gt; system lately. One thing that I found that was unclear from the documentation was how to override a view.&lt;/p&gt; &lt;p&gt;I created a Category: News and Events (If you don't set the link name property then you will get a dash where there are spaces in the title).&lt;/p&gt; &lt;p&gt;&lt;a href="http://codeverity.com/images/blogsposts/CustomGraffitiCMSViews_8734/newsandevents.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="195" alt="newsandevents" src="http://codeverity.com/images/blogsposts/CustomGraffitiCMSViews_8734/newsandevents_thumb.png" width="244" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Under that Category I created three new categories whose parents are the News and Events category: News, Events, Other&lt;/p&gt; &lt;p&gt;Now when you click on the News and Events link you go to: &lt;strong&gt;/newsandevents/&lt;/strong&gt;&amp;nbsp; &lt;/p&gt; &lt;p&gt;I created a custom view to show two columns where the left was News and the right was Events.&lt;/p&gt; &lt;p&gt;Add a file to the theme you are using and name it: &lt;strong&gt;newsandevents.view&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://codeverity.com/images/blogsposts/CustomGraffitiCMSViews_8734/add_file_theme.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="244" alt="add_file_theme" src="http://codeverity.com/images/blogsposts/CustomGraffitiCMSViews_8734/add_file_theme_thumb.png" width="233" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;So far everything works easy enough. The next step was to add a link to view just the News posts that exist under News and Events. &lt;/p&gt; &lt;p&gt;The link takes you to: /&lt;strong&gt;newsandevents/news&lt;/strong&gt;. However the rendered&amp;nbsp; page looks identical to the newsandevents page. What gives?&lt;/p&gt; &lt;p&gt;Well, since there wasn't a view for the News posting, it fell back to the custom view for newsandevents. That view didn't contain the logic to render just the news view. I could have added that there, but the views are complex enough as it is so I decided to create a new view.&lt;/p&gt; &lt;p&gt;The new view is: &lt;strong&gt;news.view&lt;/strong&gt;. When I executed the page I got the same results as before. I then took the news.view and renamed it to &lt;strong&gt;newsandevents.news.view&lt;/strong&gt;. That worked. Now I have a page that renders just the News and Events/News feeds. &lt;/p&gt; &lt;p&gt;However, I still had a problem. When I clicked on an individual feed the page wouldn't render. I would get a 404. What gives?&lt;/p&gt; &lt;p&gt;I had to add another view. In this case the view was to render any News postings. &lt;/p&gt; &lt;p&gt;The correct name for this file was:&amp;nbsp; &lt;strong&gt;newsandevents.news.post.view&lt;/strong&gt;. &lt;/p&gt; &lt;p&gt;Now when I click an individual news posting I get the view I was expecting. &lt;/p&gt;</description></item><item><title>Violating Open Closed Principal: Xml Domain Object</title><link>http://codeverity.com/timweaver/violating-open-closed-principal-xml-domain-object/</link><pubDate>Thu, 18 Sep 2008 10:16:39 GMT</pubDate><guid isPermaLink="true">http://codeverity.com/timweaver/violating-open-closed-principal-xml-domain-object/</guid><dc:creator>timweaver</dc:creator><slash:comments>0</slash:comments><category domain="http://codeverity.com/timweaver/">timweaver</category><description>&lt;p&gt;Let's just get this out of the way:&lt;/p&gt; &lt;p&gt;If you are using XML as your domain object you need to stop. If you are thinking that you are using DataSets or DataTables as domain objects so you are "better" than the XML crowd you are wrong...&lt;/p&gt; &lt;p&gt;When you use an XML Document or Node as your domain object you are completely exposing the structure of your XML to every consumer in your application. That means if you need to change the XML structure for any reason you are likely to have to make multiple changes to support it.&lt;/p&gt; &lt;p&gt;Case in Point:&lt;/p&gt; &lt;p&gt;I recently had&amp;nbsp; to add a set or XML to query that returned XML from SQL 2005. The stored procedure returned the xml using For XML Auto.&lt;/p&gt; &lt;p&gt;Here's the type of structure that was being returned:&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;xml&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;user&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;userid&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;""&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;roles&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;""&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;permissionmask&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;""&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;company&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;company&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;user&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;xml&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p&gt;The change added a new set of Xml so that the query looked like this:&lt;/p&gt; &lt;p&gt;select role, permissionmask, company, ..., &lt;font color="#ff0000"&gt;userXml&lt;/font&gt; &lt;/p&gt; &lt;p&gt;&amp;nbsp; from [tables] where [criteria] &lt;/p&gt; &lt;p&gt;&amp;nbsp; for xml auto&lt;/p&gt; &lt;p&gt;The &lt;font color="#ff0000"&gt;red &lt;/font&gt;&lt;font color="#000000"&gt;text was added.&lt;/font&gt;&lt;/p&gt; &lt;p&gt;So the returned Xml looked like this:&lt;/p&gt; &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;xml&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;userXml&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;.....&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;userXml&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;user&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;userid&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;""&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;roles&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;""&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;permissionmask&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;""&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: maroon"&gt;company&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;company&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;user&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: maroon"&gt;xml&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/div&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;When using &lt;em&gt;For Xml Auto&lt;/em&gt; Sql Server uses its own internal heuristic to determine the Xml output. In this case it put the userXml at the top of the results, which immediately broke a number of the consumers including other consumers in the database.&lt;/p&gt; &lt;p&gt;The reason this broke so many things is because when you are relying on XML as your domain object you tend to pass it around as either a string, an XmlDocument or an XmlNode. When you need a value you execute XPath against it: xmlNode.SelectSinglenode('/xml/user/[@userid]').value. That of course breaks because now that the structure is different. When you consider that the consumer of that xml can be both application and database you end up with a large problem. Ideally the fix is to stop relying on Xml as my domain object, but that isn't a short term fix and I needed a fix right away.&lt;/p&gt; &lt;p&gt;The next step then, was to turn to &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb522438.aspx"&gt;Xml Explicit&lt;/a&gt;&lt;/em&gt; and define each column as appropriate. This certainly gave me the correct results, however it is a bear to create and you can forget about maintenance.&lt;/p&gt; &lt;p&gt;There is another option introduced in SQL 2005: &lt;em&gt;for &lt;/em&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms189885.aspx"&gt;&lt;em&gt;xml Path ('root')&lt;/em&gt;&lt;/a&gt;&lt;em&gt;. &lt;/em&gt;It turns out that building complex and explicitly ordered results is a thousand times easier using the Path option. If you are using Xml in your database (a) I'm sorry and (b) do yourself a favor and go look at how &lt;a href="http://msdn.microsoft.com/en-us/library/ms189885.aspx"&gt;Path&lt;/a&gt; works.&lt;/p&gt;</description></item></channel></rss>
