Archive by Author

Use Debug output window to monitor SQL generated by LINQ2SQL

Posted on 28. Jun, 2010 by naresh in .net Programming

In all the examples out there to see the SQL generated by a LINQ2SQL query console.out is used, but to monitor the SQL in a debug window we need to write a special text writer implementation

using System.IO;
using System.Text;
using System.Diagnostics;
using System.Globalization;
using System;
namespace nj.Diagnostics
{
    /// <summary>
    /// Implements a <see cref="TextWriter"/> for writing information to the debugger log.
    /// </summary>
    /// <seealso cref="Debugger.Log"/>
    public class DebuggerWriter : TextWriter
    {
        private bool isOpen;
        private static UnicodeEncoding encoding;
        private readonly int level;
        private readonly string category;
 
        /// <summary>
        /// Initializes a new instance of the <see cref="DebuggerWriter"/> class.
        /// </summary>
        public DebuggerWriter()
            : this(0, Debugger.DefaultCategory)
        {
        }
 
        /// <summary>
        /// Initializes a new instance of the <see cref="DebuggerWriter"/> class with the specified level and category.
        /// </summary>
        /// <param name="level">A description of the importance of the messages.</param>
        /// <param name="category">The category of the messages.</param>
        public DebuggerWriter(int level, string category)
            : this(level, category, CultureInfo.CurrentCulture)
        {
        }
 
        /// <summary>
        /// Initializes a new instance of the <see cref="DebuggerWriter"/> class with the specified level, category and format provider.
        /// </summary>
        /// <param name="level">A description of the importance of the messages.</param>
        /// <param name="category">The category of the messages.</param>
        /// <param name="formatProvider">An <see cref="IFormatProvider"/> object that controls formatting.</param>
        public DebuggerWriter(int level, string category, IFormatProvider formatProvider)
            : base(formatProvider)
        {
            this.level = level;
            this.category = category;
            this.isOpen = true;
        }
 
        protected override void Dispose(bool disposing)
        {
            isOpen = false;
            base.Dispose(disposing);
        }
 
        public override void Write(char value)
        {
            if (!isOpen)
            {
                throw new ObjectDisposedException(null);
            }
            Debugger.Log(level, category, value.ToString());
        }
 
        public override void Write(string value)
        {
            if (!isOpen)
            {
                throw new ObjectDisposedException(null);
            }
            if (value != null)
            {
                Debugger.Log(level, category, value);
            }
        }
 
        public override void Write(char[] buffer, int index, int count)
        {
            if (!isOpen)
            {
                throw new ObjectDisposedException(null);
            }
            if (buffer == null || index < 0 || count < 0 || buffer.Length - index < count)
            {
                base.Write(buffer, index, count); // delegate throw exception to base class
            }
            Debugger.Log(level, category, new string(buffer, index, count));
        }
 
        public override Encoding Encoding
        {
            get
            {
                if (encoding == null)
                {
                    encoding = new UnicodeEncoding(false, false);
                }
                return encoding;
            }
        }
 
        public int Level
        {
            get { return level; }
        }
 
        public string Category
        {
            get { return category; }
        }
    }
}

The you can use

datacontext.log = new DebuggerWriter();

Tags: ,

Forms Authentication fails even when browser accepts cookies

Posted on 15. Jun, 2010 by naresh in .net Programming

While using Forms authentication in ASP.net

<forms name=".ASPXAUTH" loginUrl="login.aspx"
		  defaultUrl="Default.aspx" protection="All" timeout="30" path="/"
		  requireSSL="false" slidingExpiration="true"
		  cookieless="AutoDetect" domain=""
		  enableCrossAppRedirects="false">
		  <credentials passwordFormat="SHA1" />
</forms>

please remeber to set path = “/” or else the cookie based authentication fails, I am yet to figure out why this is happening but atleast this solves the problem.

Tags: ,

Xbox Avatars for Phone

Posted on 20. Apr, 2010 by naresh in Concepts

This is really cool. wonder if it will really come….

How to Add Windows XP to Windows 7 Boot Manager

Posted on 23. Mar, 2010 by naresh in Software

1. Open an elevated command prompt.
2. Type the following to create a boot loader for Windows XP.
bcdedit /create {ntldr} /d “Windows XP”
3. Type the following to set the device to where Windows XP is installed. I used D: in this example. Replace it with the drive letter of your XP installation.
bcdedit /set {ntldr} device partition=D:
4. Type the following to set the path.
bcdedit /set {ntldr} path \ntldr
5. Type the following to add this boot loader to the boot up screen.
bcdedit /displayorder {ntldr} /addlast
6. Reboot the computer
.

Tags: ,

Formula 1 2010 Begins

Posted on 15. Mar, 2010 by naresh in Formula 1

Formula 1 began today and with a bang and there are a lot of changes. From teams, drivers, points, and much more. It would take at least few races we get to know which drivers perform, but the prancing horse Ferrari is back with a bang, they finished top 2 but i really felt for Vettel who according to me at least should have won, i also felt for Karun as this was his first race. The points system is also a bit changed with the winner getting 25 points for 1st which is good, Waiting till the next race I am listing teams and respective drivers.

Ferrari Fernando Alonso
Felipe Massa
McLaren Lewis Hamilton
Jenson Button
Red Bull Sebastian Vettel
Mark Webber
Mercedes GP Michael Schumacher
Nico Rosberg
Force India Vitantonio Liuzzi
Adrian Sutil
Williams Rubens Barrichello
Nico Hulkenberg
Renault Robert Kubica
Vitaly Petrov
Toro Rosso Jaime Alguersuari
Sebastien Buemi
Lotus Heikki Kovalainen
Jarno Trulli
BMW Sauber Pedro de la Rosa
Kamui Kobayashi
HRT Karun Chandhok
Bruno Senna
Virgin Timo Glock
Lucas di Grassi

Tags:

Bing Maps

Posted on 23. Feb, 2010 by naresh in Concepts

This is really starting to look cool

Modern Kitchen Design

Posted on 14. Feb, 2010 by naresh in Architecture & Interiors

Modern Home Design

Posted on 13. Feb, 2010 by naresh in Architecture & Interiors

Living Room Ideas

Posted on 13. Feb, 2010 by naresh in Architecture & Interiors

Modern Bathroom

Posted on 11. Feb, 2010 by naresh in Architecture & Interiors