Frameworks

parent category of all frameworks used in Lbi Project

Posted by Cedric Vandewoude | .NET |

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

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.

First technique

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&amp;vs=1&amp;la=en&amp;sc_content=master&amp;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
The second technique

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/

Posted by Thomas Desmet | .NET |

Yesterday i dug up an old sitecore project. when everything was installed and downloaded i tried to login at the sitecore admin. it kept on giving following error: “Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration”. Nice error he The Sitecore version is 6.1 and it is not really compatible with the “integrated” mode of IIS 7.0. IIS 6.0 uses classic mode so we change the application pool setting to “Classic” mode. but that’s not all, then you need to be sure you are using the correct DLL’s for the system. if you are having a x64 machine you will need to find following DLL’s for x64: dtsearchNetApi2 and System.Data.SQLite. and that fixes the problem. enjoy

Posted by Cedric Vandewoude | .NET |

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.

Posted by Cedric Vandewoude | .NET |

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.

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:

  1. Convert the current webcam video frame to a gray scale image
  2. 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.
  3. Create a “motion array” in which each element represents the amount of movement on a certain location (read pixel).
  4. 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.

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.