Feeds

Developer Pitfall: When to call it quits on a problem

Tim Gaunt - August 18, 2010 - 16:50
We’ve all done it, you’ve run into a problem while developing which you bash at for a few hours and before you know it, you’ve lost the day, not got anywhere and feel completely frustrated. What’s more, is it’s usually something so screamingly obvious and/or simple that you just know you’ll find the answer on Google. Rather than pulling your hair out for hours on end, there’s a rather simple rule-of-thumb that you should follow: Spend no more than 15-30 minutes trying to fix the issue yourself (don’t forget to check Google for the answer!). If you’ve not found the answer after 30 minutes, “ask a friend” and walk away. If you’re able to bash at it for 30 minutes without feeling you’re getting any closer, you’re probably looking at it from the wrong direction and having someone else’s perspective on the problem will probably answer it within seconds. By walking away from the problem you’re also taking away the pressure and you’ll often find the solution comes to you. Another advantage of putting a time limit on the issue is it avoids you losing the day and should also mean you’ve explored Google and the lists so when you ask your “friend”, it should stop you getting that annoying lmgtfy response when asking for help (it’s a similar concept to the “wait 1 minute before sending” facility within Outlook). So the next time you realise something’s taking longer than you think it should, start the timer!
Categories: Blogroll

Developer Pitfall: When to call it quits on a problem

Tim Gaunt - August 18, 2010 - 16:50

We’ve all done it, you’ve run into a problem while developing which you bash at for a few hours and before you know it, you’ve lost the day, not got anywhere and feel completely frustrated. What’s more, is it’s usually something so screamingly obvious and/or simple that you just know you’ll find the answer on Google.

Rather than pulling your hair out for hours on end, there’s a rather simple rule-of-thumb that you should follow:

Spend no more than 15-30 minutes trying to fix the issue yourself (don’t forget to check Google for the answer!). If you’ve not found the answer after 30 minutes, “ask a friend” and walk away.

If you’re able to bash at it for 30 minutes without feeling you’re getting any closer, you’re probably looking at it from the wrong direction and having someone else’s perspective on the problem will probably answer it within seconds. By walking away from the problem you’re also taking away the pressure and you’ll often find the solution comes to you.

Another advantage of putting a time limit on the issue is it avoids you losing the day and should also mean you’ve explored Google and the lists so when you ask your “friend”, it should stop you getting that annoying lmgtfy response when asking for help (it’s a similar concept to the “wait 1 minute before sending” facility within Outlook).

So the next time you realise something’s taking longer than you think it should, start the timer!


Categories: Blogroll

Getting started with uCommerce

Tim Gaunt - August 17, 2010 - 17:49
I thought seeing as uCommerce is now an actual product I would start to overview an install/configuration of uCommerce assuming no prior knowledge of uCommerce. Firstly, let me start of by saying that once you've got your head around uCommerce and some of it's complexities, you'll find it a fantastic product that makes creating a new ecommerce website as easy as setting up a standard Umbraco website. It is still missing a few features, but you can easily work around these with a bit of custom XSLT/C#. Ok, back to setting up your first uCommerce website. I've grouped these into what I feel are logical sections but if I've missed something, please let me know. 1. Install the uCommerce Package If you've not already done so, go to the uCommerce Download page and download the uCommerce package (at time of writing, I'm using 1.0.4.2) and then download the uCommerce Store package (currently 1.0.1.2). Install the uCommerce package as you do any other package in Umbraco. Once installed you'll be able to install the store package. Assuming all your permissions on your Umbraco install are correct, refresh your browser and you should have a new section "Commerce". If they're not right, you'll be told to add a few web.config settings. 2. Wire up the catalog This is the step that I didn’t “do” when we first got started and it turns out it’s one of the most important steps as it joins the uCommerce catalog to the front end. Go to your Umbraco "Content" section Right click on the page you would like to be the store's "home" page (in the example store, this would be "Shop") Click "Manage hostnames" (see figure below) Enter your hostname (the domain name the site runs on) in the "Domain" box and then choose the default language for the website Click "Add new Domain" and then "Close this window" Click the "Commerce" section button (in the bottom left) Click the little arrow to the left of "Product Catalog" Left click the relevant catalog (if you've installed the store package this will be "uCommerce") Select your new domain from the "Host name" drop down list Click the save disk button in the top left 3. Setup Your Product Definitions A “Product Definition” is uCommerce’s concept of document types, it allows you to add additional information to the product. If you’re using the uCommerce starter store, you’ll get a couple of product definitions out of the box –software and support. At the moment, you can't add additional properties through the uCommerce back end (i.e. if you wanted to add additional information such as Meta Keywords/Descriptions etc -I'll cover how we got around this in a later post) but there are a number of default the category/product properties (I've put their XML reference in brackets where relevant): uCommerce Category Properties Image (@image) Display Name (@displayName) Description (@description) The default XML looks like this: uCommerce Product Properties SKU (@sku) Internal name Display on web site (@displayOnSite) Allow ordering (@allowOrdering) Thumbnail (@thumbnailImage) Primary image (@primaryImage) Display name (@displayName) Short description (@shortDescription) Long description (@longDescription) The default XML looks like this (the variants are not standard but are there because they're setup as part of the store package): Adding additional product properties is simple. Click the "Commerce" section button Navigate to: Settings --> Catalog --> Product Definitions Choose the product definition you would like to edit (or create a new one in the same way that you would with Umbraco document types) Right click the product definition you need to add extra properties to and click "Create" Type in a name for your new property i.e. Size Choose the Data Type for the property (if you need something that's not listed see "Creating your own Data Type" below): ShortText -A textbox LongText -A text area Number -Beleive it or not, a numeric value Boolean -A checkbox Image -A media selector Click the "Create" button You can now choose a few additional options for the new property including how it should be shown to the user and whether it's Multilingual. Name -the text used as the label in the uCommerce product editor (it's also the name of the attribute on the XML that will contain it's value) Data Type -the type of control to render in the uCommerce product editor Multilingual -whether the control should be shown on the "Common" tab of the uCommerce product editor or the language specific tab Display On Web Site -A flag that's sent out in the XML so you can decide whether or not to show it on the website Variant Property -Whether this should appear as a table column heading under the "Variants" tab (I'll go into variants more in a later post) Note: Do not set Multilingual and Variant property to both true as at the moment, it won't be shown in the uCommerce product editor -you've been warned! Render in Editor -Whether the control should be shown in the uCommerce product editor screen or hidden from the administrator (i.e. for data you want to use internally only and should be editable) Finally you'll need to enter in a Display Name for the various languages. This is what's shown to the user if you dynamically pull through the various properties on the product details page. 4. Creating Your Own Data Type Now, you may be thinking that using that set of data types is a little limiting for something like "Size" or "Colour" and you might want to display something a little more flexible to the user -such as a drop down list. This is easy enough: Right click the "Data Types" node Enter a name i.e. "Size" Choose the definition for the Data Type (for size we will use "Enum") Save and Refresh the "Data Types" node Right click your new Data Type and click Create Enter your Option's value i.e. "Small" Repeat 5-6 until all your options are set i.e. add "Medium" and "Large" Note: At the moment, the enum values cannot be re-ordered through the UI so make sure you add them in the order you want them in the editor! 5. Load Your Catalog Once you've finished creating your various product types, it's time to create your catalog. Creating categories and products within uCommerce is as simple as creating pages in Umbraco. Using the same right click menu concept you can create nested categories as deep as your catalog requires. You can add products and categories at any level by choosing either the "Category" or "Product" radio button and choosing your product type. 6. You're Done! Assuming you've followed the steps above, you should now have a (fairly basic) store setup. Go to your site's homepage and click the "uCommerce" menu item and voila, your categories and products should be listed. Not getting the categories you were expecting? Perform the helpful xsl “copy-of” trick within either the "RootCategories[XSLT].xslt" file or "Category[XSLT].xslt" file: and then have a look at the output: No product catalog group found supporting the current URL. If you're getting the above error, currently (and this may be a misunderstanding/changed later) you have to have the catalog and catalogue group names the same –in the example site, they’re both “uCommerce”. As I think the concept store offered with Software/Support isn't particularly real-world, I'm going to work on creating a basic store that you can use to better understand uCommerce and it's intricacies. Check back soon as I'll be posting an overview of the checkout process, the various XSLT files and integrating payment gateways into uCommerce (initially SagePay, PayPoint, WorldPay and PayPal).
Categories: Blogroll

Getting started with uCommerce

Tim Gaunt - August 17, 2010 - 17:49

I thought seeing as uCommerce is now an actual product I would start to overview an install/configuration of uCommerce assuming no prior knowledge of uCommerce. Firstly, let me start of by saying that once you've got your head around uCommerce and some of it's complexities, you'll find it a fantastic product that makes creating a new ecommerce website as easy as setting up a standard Umbraco website. It is still missing a few features, but you can easily work around these with a bit of custom XSLT/C#.

Ok, back to setting up your first uCommerce website. I've grouped these into what I feel are logical sections but if I've missed something, please let me know.

1. Install the uCommerce Package

If you've not already done so, go to the uCommerce Download page and download the uCommerce package (at time of writing, I'm using 1.0.4.2) and then download the uCommerce Store package (currently 1.0.1.2).

Install the uCommerce package as you do any other package in Umbraco. Once installed you'll be able to install the store package.

Assuming all your permissions on your Umbraco install are correct, refresh your browser and you should have a new section "Commerce". If they're not right, you'll be told to add a few web.config settings.

2. Wire up the catalog

This is the step that I didn’t “do” when we first got started and it turns out it’s one of the most important steps as it joins the uCommerce catalog to the front end.

  1. Go to your Umbraco "Content" section
  2. Right click on the page you would like to be the store's "home" page (in the example store, this would be "Shop")
  3. Click "Manage hostnames" (see figure below)
  4. Enter your hostname (the domain name the site runs on) in the "Domain" box and then choose the default language for the website
  5. Click "Add new Domain" and then "Close this window"
  6. Click the "Commerce" section button (in the bottom left)
  7. Click the little arrow to the left of "Product Catalog"
  8. Left click the relevant catalog (if you've installed the store package this will be "uCommerce")
  9. Select your new domain from the "Host name" drop down list
  10. Click the save disk button in the top left
3. Setup Your Product Definitions

A “Product Definition” is uCommerce’s concept of document types, it allows you to add additional information to the product. If you’re using the uCommerce starter store, you’ll get a couple of product definitions out of the box –software and support. At the moment, you can't add additional properties through the uCommerce back end (i.e. if you wanted to add additional information such as Meta Keywords/Descriptions etc -I'll cover how we got around this in a later post) but there are a number of default the category/product properties (I've put their XML reference in brackets where relevant):

uCommerce Category Properties
  • Image (@image)
  • Display Name (@displayName)
  • Description (@description)

The default XML looks like this:

<category parentCategoryId="" parentCategoryName="" index="0" id="67" name="Software" displayName="Software" displayOnSite="True" description="" image="" /> uCommerce Product Properties
  • SKU (@sku)
  • Internal name
  • Display on web site (@displayOnSite)
  • Allow ordering (@allowOrdering)
  • Thumbnail (@thumbnailImage)
  • Primary image (@primaryImage)
  • Display name (@displayName)
  • Short description (@shortDescription)
  • Long description (@longDescription)

The default XML looks like this (the variants are not standard but are there because they're setup as part of the store package):

<product index="0" sku="100-000-001" displayName="uCommerce 1.0 RTM" shortDescription="uCommerce is a full featured e-commerce platform with content management features powered by Umbraco. Everything you need to build a killer e-commerce solution for your clients!" longDescription="uCommerce is fully integrated with the content management system Umbraco, which provides not only the frontend renderendering enabling you to create beautifully designed stores, but also the back office capabilities where you configure and cuztomize the store to your liking.&#xD;&#xA;&#xD;&#xA;uCommerce_ foundations provide the basis for an e-commerce solution. Each foundation addresses a specific need for providing a full e-commerce solution to your clients. foundations in the box include a Catalog Foundation, a Transactions Foundation, and an Analytics Foundation.&#xD;&#xA;&#xD;&#xA;Each of the foundations within uCommerce_ are fully configurable right in Umbraco. No need to switch between a multitude of tools to manage your stores. It's all available as you would expect in one convenient location." thumbnailImage="1097" primaryImage="1097" allowOrdering="True" isVariant="False" displayOnSite="True" hasVariants="True" price="3495.0000" currency="EUR"> <variants> <product index="0" sku="100-000-001" displayName="Developer Edition" shortDescription="" longDescription="" thumbnailImage="0" primaryImage="0" allowOrdering="False" isVariant="True" displayOnSite="False" hasVariants="False" variantSku="001" price="0.0000" currency="EUR" Downloadable="on" License="Dev" /> <product index="1" sku="100-000-001" displayName="30 Days Evaluation" shortDescription="" longDescription="" thumbnailImage="0" primaryImage="0" allowOrdering="False" isVariant="True" displayOnSite="False" hasVariants="False" variantSku="002" price="3495.0000" currency="EUR" Downloadable="on" License="Eval" /> <product index="2" sku="100-000-001" displayName="Go-Live" shortDescription="" longDescription="" thumbnailImage="0" primaryImage="0" allowOrdering="False" isVariant="True" displayOnSite="False" hasVariants="False" variantSku="003" price="3495.0000" currency="EUR" Downloadable="on" License="Live" /> </variants> </product>

Adding additional product properties is simple.

  1. Click the "Commerce" section button
  2. Navigate to: Settings --> Catalog --> Product Definitions
  3. Choose the product definition you would like to edit (or create a new one in the same way that you would with Umbraco document types)
  4. Right click the product definition you need to add extra properties to and click "Create"
  5. Type in a name for your new property i.e. Size
  6. Choose the Data Type for the property (if you need something that's not listed see "Creating your own Data Type" below):
    • ShortText -A textbox
    • LongText -A text area
    • Number -Beleive it or not, a numeric value
    • Boolean -A checkbox
    • Image -A media selector
  7. Click the "Create" button
  8. You can now choose a few additional options for the new property including how it should be shown to the user and whether it's Multilingual.
    • Name -the text used as the label in the uCommerce product editor (it's also the name of the attribute on the XML that will contain it's value)
    • Data Type -the type of control to render in the uCommerce product editor
    • Multilingual -whether the control should be shown on the "Common" tab of the uCommerce product editor or the language specific tab
    • Display On Web Site -A flag that's sent out in the XML so you can decide whether or not to show it on the website
    • Variant Property -Whether this should appear as a table column heading under the "Variants" tab (I'll go into variants more in a later post)
      Note: Do not set Multilingual and Variant property to both true as at the moment, it won't be shown in the uCommerce product editor -you've been warned!
    • Render in Editor -Whether the control should be shown in the uCommerce product editor screen or hidden from the administrator (i.e. for data you want to use internally only and should be editable)
  9. Finally you'll need to enter in a Display Name for the various languages. This is what's shown to the user if you dynamically pull through the various properties on the product details page.
4. Creating Your Own Data Type

Now, you may be thinking that using that set of data types is a little limiting for something like "Size" or "Colour" and you might want to display something a little more flexible to the user -such as a drop down list. This is easy enough:

  1. Right click the "Data Types" node
  2. Enter a name i.e. "Size"
  3. Choose the definition for the Data Type (for size we will use "Enum")
  4. Save and Refresh the "Data Types" node
  5. Right click your new Data Type and click Create
  6. Enter your Option's value i.e. "Small"
  7. Repeat 5-6 until all your options are set i.e. add "Medium" and "Large"

Note: At the moment, the enum values cannot be re-ordered through the UI so make sure you add them in the order you want them in the editor!

5. Load Your Catalog

Once you've finished creating your various product types, it's time to create your catalog. Creating categories and products within uCommerce is as simple as creating pages in Umbraco. Using the same right click menu concept you can create nested categories as deep as your catalog requires. You can add products and categories at any level by choosing either the "Category" or "Product" radio button and choosing your product type.

6. You're Done!

Assuming you've followed the steps above, you should now have a (fairly basic) store setup. Go to your site's homepage and click the "uCommerce" menu item and voila, your categories and products should be listed.

Not getting the categories you were expecting? Perform the helpful xsl “copy-of” trick within either the "RootCategories[XSLT].xslt" file or "Category[XSLT].xslt" file:

<pre><xsl:copy-of select="$categories" /></pre>

and then have a look at the output:

<errors><error>No product catalog group found supporting the current URL.</error></errors>

If you're getting the above error, currently (and this may be a misunderstanding/changed later) you have to have the catalog and catalogue group names the same –in the example site, they’re both “uCommerce”.

As I think the concept store offered with Software/Support isn't particularly real-world, I'm going to work on creating a basic store that you can use to better understand uCommerce and it's intricacies.

Check back soon as I'll be posting an overview of the checkout process, the various XSLT files and integrating payment gateways into uCommerce (initially SagePay, PayPoint, WorldPay and PayPal).


Categories: Blogroll

Using Linq and Extension Methods to chunk large data sets

Tim Gaunt - August 12, 2010 - 09:32
Ever needed to take a large list and split it into smaller subsets of data for processing? Well this is the Extension Method for you. Tonight we had to split a small dataset (500 items) into even smaller sets of 10 so the provider’s web service wouldn’t timeout. Seeing as I was going to miss out on my evening, I thought I’d see if I could do it a little differently using Linq and this is what I came up with: /// /// Simple method to chunk a source IEnumerable into smaller (more manageable) lists /// /// The large IEnumerable to split /// The maximum number of items each subset should contain /// An IEnumerable of the original source IEnumerable in bite size chunks public static IEnumerable> ChunkData(this IEnumerable source, int chunkSize) { for (int i = 0; i < source.Count(); i += chunkSize) yield return source.Skip(i).Take(chunkSize); } It should extend any IEnumerable and allow you to split it into smaller chunks which you can then process to your heart’s content. Here’s a quick example of it in use: var list = new List() { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10" }; Console.WriteLine("Original list is {0} items", list.Count); var chunked = list.ChunkData(3); Console.WriteLine("Returned the data in {0} subsets", chunked.Count()); int i = 1; foreach (var subset in chunked) { Console.WriteLine("{0} items are in subset #{1}", subset.Count(), i++); int si = 1; foreach (var s in subset) Console.WriteLine("\t\tItem #{0}: {1}", si++, s); } And this will output Original list is 10 items Returned the data in 4 subsets 3 items are in subset #1 Item #1: Item 1 Item #2: Item 2 Item #3: Item 3 3 items are in subset #2 Item #1: Item 4 Item #2: Item 5 Item #3: Item 6 3 items are in subset #3 Item #1: Item 7 Item #2: Item 8 Item #3: Item 9 1 items are in subset #4 Item #1: Item 10 2 lines of code to do all that work -Neat
Categories: Blogroll

Using Linq and Extension Methods to chunk large data sets

Tim Gaunt - August 12, 2010 - 09:32

Ever needed to take a large list and split it into smaller subsets of data for processing? Well this is the Extension Method for you. Tonight we had to split a small dataset (500 items) into even smaller sets of 10 so the provider’s web service wouldn’t timeout.

Seeing as I was going to miss out on my evening, I thought I’d see if I could do it a little differently using Linq and this is what I came up with:

/// <summary> /// Simple method to chunk a source IEnumerable into smaller (more manageable) lists /// </summary> /// <param name="source">The large IEnumerable to split</param> /// <param name="chunkSize">The maximum number of items each subset should contain</param> /// <returns>An IEnumerable of the original source IEnumerable in bite size chunks</returns> public static IEnumerable<IEnumerable<TSource>> ChunkData<TSource>(this IEnumerable<TSource> source, int chunkSize) { for (int i = 0; i < source.Count(); i += chunkSize) yield return source.Skip(i).Take(chunkSize); }

It should extend any IEnumerable and allow you to split it into smaller chunks which you can then process to your heart’s content.

Here’s a quick example of it in use:

var list = new List<string>() { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10" }; Console.WriteLine("Original list is {0} items", list.Count); var chunked = list.ChunkData(3); Console.WriteLine("Returned the data in {0} subsets", chunked.Count()); int i = 1; foreach (var subset in chunked) { Console.WriteLine("{0} items are in subset #{1}", subset.Count(), i++); int si = 1; foreach (var s in subset) Console.WriteLine("\t\tItem #{0}: {1}", si++, s); }

And this will output

Original list is 10 items Returned the data in 4 subsets 3 items are in subset #1 Item #1: Item 1 Item #2: Item 2 Item #3: Item 3 3 items are in subset #2 Item #1: Item 4 Item #2: Item 5 Item #3: Item 6 3 items are in subset #3 Item #1: Item 7 Item #2: Item 8 Item #3: Item 9 1 items are in subset #4 Item #1: Item 10

2 lines of code to do all that work -Neat


Categories: Blogroll

Log4net for package developers

Darren Ferguson - August 10, 2010 - 09:00

Note: This information is also posted on the Umbraco Wiki

See also: ismailmayat.wordpress.com/.../

  • Download log4net
  • In your visual studio project add a reference to log4net.dll (use bin\net\2.0\release in the distribution)
  • Open AssemblyInfo.cs in the properties folder of your solution.
  • Add the following attributes:
[assembly: XmlConfigurator(ConfigFile = @"config\my.log4net.config", Watch = true)] [assembly: RepositoryAttribute("MyAppName")]

Note: RespositoryAttribute is used to identify a distinct configuration for your unique package/assembly it can be any value you wish but try to avoid conflicts.

By specifiying watch=true in the XmlConfigurator attribute you can modify the logging config during development and it will be automatically reloaded without causing an application restart.

A simple configuration file could be as follows:

<?xml version="1.0" encoding="utf-8" ?> <log4net> <appender name="R" type="log4net.Appender.RollingFileAppender"> <file value="${TEMP}/myPackage.log" /> <appendToFile value="true" /> <maximumFileSize value="1000KB" /> <maxSizeRollBackups value="2" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%level %thread %logger - %message%newline" /> </layout> </appender> <root> <level value="DEBUG" /> <appender-ref ref="R" /> </root> </log4net>

The above logs to a file in your system tmp directory - The file is rotated once it reaches 1 MB and the last two versions are maintained. Log4net can log to XML files, databases, email etc and you can define different loggers for different classes and different log targets for different levels of logging. See log4net Manual - Configuration for more details.

In your package classes add a logger declaration, for example:

using System; using umbraco.BusinessLogic; using log4net; using System.Reflection; namespace Umb.Log4Net { public class Class1 : ApplicationBase { private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public Class1() { log.Debug("application starting up"); } } }

Note: When releasing Umbraco packages you may want to set your logging levels to NONE or FATAL to stop DEBUG information being logged.

Categories: Blogroll

Umbraco Workflow foundation project: short update

Darren Ferguson - August 2, 2010 - 00:00

I recently blogged a screencast which demonstrated integration of Microsoft Workflow foundation into Umbraco. Happily, response was positive and I've had a few questions about when it will be available as a package.

To set expectations, the short answer is that it won't.

The implementation I put together works well for a client of mine as well as my own site, but the effort involved in documenting and polishing it so that it could be released as a package isn't insignificant.

On top of that my prototype is based on workflow foundation 3 and MS have now released version 4. There is no backward compatibility and the new version is for .net 4. When you start to throw past present and future versions of Umbraco into the equation you start to come up with silly exponential sums when working out how many versions would need to be maintained.

So, no package I'm afraid.

However: If you'd like to implement workflow in Umbraco and would like to sponsor the project it could happen. Feel free to get in touch and we can talk it through.

Categories: Blogroll

Share ideas through Thought Pipe

Paul Silver - September 5, 2009 - 20:49

During the discussion after my talk at Barcamp Brighton 4, several people wanted a place where they could publically swap ideas, in the hope that someone would pick them up and develop them. This came from Danny Hope’s experience where he described a CSS comment stripping service on his Flickr, and David Stone then built it for him.

As a developer, I like short projects I can build for a fun break from client work, and it looks like I’m not alone in that.

As a starting place for people to talk about ideas, I’ve opened this Google Group – http://groups.google.com/group/thoughtpipe – where people can start talking about their ideas. Please join up and put your oar in.

The inspiration for my small projects was the 5K App competition, organised by John Montgomery and you can read about what I did here in my 5K app posts.

I’ll put some ideas in to the group in the next day or so to try to kick things off. If it sounds interesting to you, please subscribe and join in.

Categories: Blogroll
Syndicate content