Code & Technology Cocktail
Frameworks
parent category of all frameworks used in Lbi Project
3
Apr
Sometimes you want to discuss the sitecore tree with colleagues or the customer. The only way to achieve this is taking a screenshots but that does not give you the flexibility to change the structure or text in f.e. an e-mail conversation.
To solve this I wrote a small aspx page (code inspired by a blog post from Sean Kearney) to be able to copy paste the sitecore tree as rich text. (<ul> and <li> is used to achieve this)
How to us it?
Download 2text.zip Copy 2text.aspx in \Website\sitecore\admin\ Browse to http://yoursitecoresite/sitecore/admin/2text.aspx
Feel free to adapt it to your own wishes
13
Oct
Recently I had a bug in one of my website because of a recursive infinite loop. The effect was some random restart of IIS but noting in the sitecore logs and not way to know why.
In the windows event viewer I saw in the IIS section that the I had some IIS crashes with the event code 5011.
After googling a little bit I found this website: http://martinnormark.com/how-to-handle-iis-event-id-1009-event-id-5011-on-iis-7
So, if you create a dll with this class
#region Using
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Web;
#endregion
/// <summary>
/// Handles all unhandled exceptions from in the current AppDomain.
///
/// Works great to catch unhandled exceptions thrown by IIS's child threads, /// which will make the application pool terminate unexpectedly
/// without logging. This makes sure your Exception /// is logged to the Application event log.
/// </summary>
public class UnhandledExceptionModule : IHttpModule
{
#region Fields
private static int _UnhandledExceptionCount = 0;
private static string _SourceName = null;
private static object _InitLock = new object();
private static bool _Initialized = false;
#endregion
#region IHttpModule members
public void Init(HttpApplication app)
{
// Do this one time for each AppDomain.
if (!_Initialized)
{
lock (_InitLock)
{
if (!_Initialized)
{
string webenginePath = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "webengine.dll");
if (!File.Exists(webenginePath))
{
throw new Exception(String.Format(CultureInfo.InvariantCulture, "Failed to locate webengine.dll at '{0}'. This module requires .NET Framework 2.0.", webenginePath));
}
FileVersionInfo ver = FileVersionInfo.GetVersionInfo(webenginePath);
_SourceName = string.Format(CultureInfo.InvariantCulture, "ASP.NET {0}.{1}.{2}.0", ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart);
if (!EventLog.SourceExists(_SourceName))
{
throw new Exception(String.Format(CultureInfo.InvariantCulture, "There is no EventLog source named '{0}'. This module requires .NET Framework 2.0.", _SourceName));
}
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
_Initialized = true;
}
}
}
}
public void Dispose()
{
}
#endregion
#region UnhandledException event handler
public void OnUnhandledException(object o, UnhandledExceptionEventArgs e)
{
// Let this occur one time for each AppDomain.
if (Interlocked.Exchange(ref _UnhandledExceptionCount, 1) != 0)
return;
StringBuilder message = new StringBuilder("\r\n\r\nUnhandledException logged by UnhandledExceptionModule:\r\n\r\nappId=");
string appId = (string)AppDomain.CurrentDomain.GetData(".appId");
if (appId != null)
{
message.Append(appId);
}
Exception currentException = null;
for (currentException = (Exception)e.ExceptionObject; currentException != null; currentException = currentException.InnerException)
{
message.AppendFormat("\r\n\r\ntype={0}\r\n\r\nmessage={1}\r\n\r\nstack=\r\n{2}\r\n\r\n",
currentException.GetType().FullName,
currentException.Message,
currentException.StackTrace);
}
EventLog Log = new EventLog();
Log.Source = _SourceName;
Log.WriteEntry(message.ToString(), EventLogEntryType.Error);
}
#endregion
}
Add add this
<httpModules> <add type="UnhandledExceptionModule" name="UnhandledExceptionModule"/> ..... </httpModules>
You will have more details about the cause of this error a StackOverflowException in my case.
It takes me a lot of time to find why because I didn’t find how to know witch line or class cause the exception but it already help a lot
This class also adds all the unhandled error in the event viewer so it is also great to have it.
12
Oct
useful if you need to generate a link to send to one of your editors.
The format of this link will be : http://Youthostname/sitecore/shell/Applications/Content Editor?id=%7b9822ABDF-F2B7-41BA-B56D-63E73BEB7E88%7d&vs=1&la=en&sc_content=master&fo=%7b9822ABDF-F2B7-41BA-B56D-63E73BEB7E88%7d&ic=People%2f16x16%2fcubes_blue.png&he=Content+Editor&cl=0
Where the parameters are:
- Id & fo: the ID of the target item
- vs: the version of the target item.
- la: the language of the target item
- sc_content: the database
useful of you need to open it from one of your xaml application :
UrlString str = new UrlString();
.Add("id", id);
str.Add("fo", id);
Windows.RunApplication("Content editor", str.ToString());
More sitecore tips on my blog: http://sitecoreblog.blogspot.com/
31
May
9
May
It’s about 1 year ago that Microsoft organized the Windows Phone 7 Developer Hub at Living Tomorrow. The perfect timing to have a look at who is developing #wp7be apps in Belgium.
At the moment (06/05/2011) there are 56 apps by 14 developers, for more details you should certainly check out the Windows Phone 7 Stories Blog.
And guess what I’m one of those 14 developers #BeTrains even made it to the App of The Week selection
Keep an eye on this blog, there certainly will be more posts on Windows Phone 7 development in the future.
9
May
For a small proof of concept I have been doing a bit of research on motion detection with a webcam in Silverlight 4. The goal is to allow the users to “click” a button by waving at it. There will be 4 buttons, one in each corner of the screen. If the user wants to “click” on a button he waves his/her hand at the location of the button.
Before I started coding I did some research on image processing to find the best solution for this “problem”.
There are a couple of good image processing libraries in C#.
- AForge.NET Library for Computer Vision and Artificial Intelligence – image processing, neural networks, genetic algorithms, machine learning, robotics, etc
- EmguCV Library of programming functions for real time computer vision.
Those libraries are actually quite powerful because you can do face/hand/object detection with Haar-like features. Alfréd Haar also proposed the Haar functions later used in Haar wavelets, very powerful math that is being used for image compression and multiresolution curves and surfaces. That’s all very exiting but unfortunately you cannot use them in Silverlight 4 because you can’t execute unmanaged code in a 3rd party app.
No panic, there are also some Silverlight libraries and tutorials on motion detection and object recognition.
- SLARToolkit A flexible Augmented Reality library for Silverlight with the aim to make real time augmented reality applications.
- Touchless SDK A fun webcam multi-”touch” object tracking SDK project.
- FaceLight – Simple Silverlight Face Detection A simple facial recognition method that can be used with Silverlight ‘s webcam.
- Silverlight Motion Detection Motion detection using Silverlight 4 camera support and a simple motion detection algorithm.
I had a look at all the libraries and articles and found that the last one was the most interesting for my proof of concept.
The motion detection is actually quite simple:
- Convert the current webcam video frame to a gray scale image
- Compare the current gray scale image with the previous gray scale image pixel per pixel. If the grayness of a pixel changes in the consecutive video frames then we know that something moved. The algorithm uses gray scale images because each pixel has less possible values: black, white and something in-between. Comparing RGB colors would be much more complicated.
- Create a “motion array” in which each element represents the amount of movement on a certain location (read pixel).
- Calculate how much the motion overlaps with one of our “buttons” in each corner of the screen.
So the algorithm detects areas where there is a lot of movement. Detecting a real hand would be very complicated without an unmanaged code library like EmguCV. A decent hand tracking algorithm in Silverlight would also be too CPU intensive.
9
May
Colorbox is a light-weight, customizable lightbox plugin for jQuery 1.3, 1.4, and 1.5. And I found out that the last part of that sentence is quite important the hard way.
I had a strange error on a page that used colorbox in internet explorer: “a script on this page is causing Internet Explorer to run slowly”. We didn’t change the source at all so it had to be linked to an external script … et voila we found the guilty line:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>
There are good reasons why you should let google host jquery for you but be careful how you use this feature! If you just specify 1/jquery.min.js it will automatically take the latest version. So jQuery changed from 1.5.x to 1.6.x and it broke colorbox which is only supported up to 1.5. To bypass this problem we still let google do the hosting for us but we use a specific version of jQuery which is not automatically updated.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript"></script>
So be careful if you automatically fetch the latest version of jQuery because it might break your site even if you did not change a line of code.
15
Apr
The second day’s keynote was THE keynote that we expected. Today, the main topic was Windows Phone 7 codename “Mango”, the very expected update for the mobile operating system of Microsoft which will be available on October 10. And now we know why it is so expected: it will bring the phone to a new level, with a lot of very interesting features. The two other topics were Silverlight 5 and Kinect (make sure you look at the last link of this post below).
WP7 codename “Mango”The phone will now fully support Silverlight 4.
New API’s to access phone resources. Developers will now have access to the contacts and the calendar, and also be able to launch the Bing maps application. There will also be more possibilities to use the device’s sensors with the help of a framework that will ease the usage of those sensors.
The multitasking will give the possibility to fast switch between applications and will now be available for third party applications, which means that developers will have new API’s at their disposal to:
- Access the phone services like the alarms, the reminders, the background music stream or the possibility to transfer data using a queue mechanism that will persist even if the phone is switched off.
- Use background agents to perform background processing that does not require the UI.
A local SQL CE database will also be available on the phone to support data intensive applications. This local database will support Linq queries.
It will now also be possible to use Sockets to introduce TCP/UDP based communications. Developers are not limited anymore to http requests. The demo demonstrated an IRC application on the phone, and the arrival of Skype on the phone was announced.
More possibilities with the usage of Tiles and Push notifications, with for example the possibility to use both sides of the tile, deep linking from the tile to a specific task of an application, multi-tiles per application, the local access from an application to the tile API…
It will now be possible to mix Silvelight and XNA in one application, bringing the whole bunch of Silverlight controls to the game world, and the 3D capabilities of XNA to Silverlight apps.
IE9 will be fully integrated in the phone, with support of HTML 5, geolocation in the browser and the exact same engine than on the pc, which means that the html markup will not have to be adapted to work on the device (except if we want the website to appear in another way of course).
Scott Guthrie also announced some new tooling for the phone development, like an accelerometer and GPS emulator embedded in the current phone emulator, and also an advanced profiling tool which will help developers fine-tune their application for performance.
Silverlight 5This new release of Silverlight will be available in October. The keynote focused on the new hardware decoding media capabilities of the platform and the introduction of the XNA API to Silverlight, with two great demo’s. The first one is the website that will replace this one in the future: http://www.blueangels.navy.mil, and which will use a lot of embedded videos. A great demonstration of hardware decoding capabilities in Silverlight.
The second demo was an 3D House Builder application which showed us the integration of XNA’s 3D capabilities within Silverlight. The demo will come as open source software along with the beta release of Silverlight 5.
KinectThe Kinect for Windows SDK is now available in beta here: http://research.microsoft.com/kinectsdk, and will be released in May. To demonstrate the use of this SDK, we got 4 great demo’s. It is quite difficult to express the magic of all these demo’s with words. Fortunately, they are already available on channel 9 here: http://channel9.msdn.com/Blogs/C9Team/Kinect-Demos-with-the-Channel-9-team.
Enjoy !
13
Apr
Hello from Las Vegas, where I’m attending the MIX 11 conference. MIX is Microsoft’s biggest event about web and devices technologies, and is a real opportunity to have an eye on what is coming in this area from Microsoft.
Today’s keynote was presented by Dean Hachamovich – Internet Explorer corporate Vice president – and Scott Guthrie – who’s responsible for all development platforms for the .Net framework. The main announcement today was the availability of a preview of Internet Explorer 10, which continues to go in the html and CSS standards adoption and also puts a real focus on performance with it’s hardware accelerated rendering capabilities. Here are the links:
- http://ie.microsoft.com/testdrive/Info/Downloads/Default.html (to download IE10 preview)
- http://ie.microsoft.com/testdrive/ (a lot of demos to see what are the capabilities of IE9 and IE10)
- http://worldsbiggestpacman.com/ (a geeky demo of the pacman game done with HTML5)
- http://foursquareplayground.com/ (another demo using the foursquare data)
Besides Internet explorer, Scott Guthrie (helped by Scott Hanselman), showed us some demos of WebMatrix, a lightweight development environment targeted to web (ASP.Net MVC and php mainly) and from which you can easily create new application from a lot of open source platforms. We also have seen some demos about the Orchard CMS, developed by Microsoft on top of ASP.Net MVC 3 and another cool demo from Niels Hartvig, founder of the Umbraco CMS, about their Windows Azure support. They have a really great deployment to Azure module which can handle also from the admin the scalability of the platform by defining rules used to upscale the deployment to more servers (or downscale if the traffic becomes lower). This demonstrates again how innovative the Umbraco CMS platform is.
After this first day keynote, I heard the the second day’s keynote will be full of great announcements, so stay plugged for the next post !
13
Apr
Since click tracking is implemented in almost every project these days, new ways of triggering events and sending tracking code are very important and vary from project to project. With this context in mind, I was asked to implement tracking code on several links. Each link had different tracking ID’s for each language. Since our content for each language is fetched from the DataBase our basic HTML stays the same.
>>
Adding the onclick event as an attribute is one thing, but adding it with different tracking code in another language is something else. This is where jQuery helped me out since targeting elements and triggering events … well … is basically something jQuery is very good at.
var AdformTracking = function (lang) {
// Init variables
var cId = 25910;
var adformMap = {
"sv-SE": {
0: 350591,
1: 350592,
2: 350593,
3: 350594,
4: 350595,
5: 350596,
6: 350597,
7: 350598
},
"fi-FI": {
0: 350567,
1: 350568,
2: 350569,
3: 350570,
4: 350571,
5: 350572,
6: 350573,
7: 350574
}
};
var buyNow = $("#header .dealer a:first");
var whereToBuy = $("#header .dealer a:last");
var promoItem1 = $(".promoItem .button a").get(0);
var promoItem2 = $(".promoItem .button a").get(1);
var promoItem3 = $(".promoItem .button a").get(2);
var promoItem4 = $(".promoItem .button a").get(3);
var pdf = $(".banners .pdf a");
var facebook = $(".banners .facebook a");
var clickArr = [buyNow, whereToBuy, promoItem1, promoItem2, promoItem3, promoItem4, pdf, facebook];
// Events
$(clickArr).each(function (i, item) {
$(item).click(function () {
Adform.Tracking.Track(cId, adformMap[lang][i], "");
});
});
};
What I did was adding a parameter “lang” to my function so I can switch mapping in the adformMap variable. Once set up I target my elements with jQuery. Enlist all the jQuery objects in the clickArr. Loop over the clickArr and add for each item a click event trigger. Inside the click event we’ll be executing a function which can be our tracking code.
The position of the jQuery object in the clickArr matches the numeric value in the adformMap.
adformMap["sv-SE"][4]
On execution this will give you “350595″.
A couple of benefits popup into my mind …:
- All your tracking code can be mapped in one file (or script)
- Easier to add languages
- More easy to add links to track
- Your HTML code stays nice and clean (if you didn’t mess that up already ofcourse :p)
Works like a charm!

